giaTransduction.cpp 4.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/**CFile****************************************************************

  FileName    [giaTransduction.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Scalable AIG package.]

  Synopsis    [Implementation of transduction method.]

  Author      [Yukio Miyasaka]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - May 2023.]

  Revision    [$Id: giaTransduction.c,v 1.00 2023/05/10 00:00:00 Exp $]

***********************************************************************/
20 21 22

#ifndef _WIN32

MyskYko committed
23 24 25 26 27 28 29 30 31 32 33 34
#ifdef _WIN32
#ifndef __MINGW32__
#pragma warning(disable : 4786) // warning C4786: identifier was truncated to '255' characters in the browser information
#endif
#endif

#include "giaTransduction.h"
#include "giaNewBdd.h"
#include "giaNewTt.h"

ABC_NAMESPACE_IMPL_START

MyskYko committed
35
Gia_Man_t *Gia_ManTransductionBdd(Gia_Man_t *pGia, int nType, int fMspf, int nRandom, int nSortType, int nPiShuffle, int nParameter, int fLevel, Gia_Man_t *pExdc, int fNewLine, int nVerbose) {
MyskYko committed
36 37 38 39 40 41 42
  if(nRandom) {
    srand(nRandom);
    nSortType = rand() % 4;
    nPiShuffle = rand();
    nParameter = rand() % 16;
  }
  NewBdd::Param p;
MyskYko committed
43
  Transduction::Transduction<NewBdd::Man, NewBdd::Param, NewBdd::lit, 0xffffffff> t(pGia, nVerbose, fNewLine, nSortType, nPiShuffle, fLevel, pExdc, p);
MyskYko committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  int count = t.CountWires();
  switch(nType) {
  case 0:
    count -= fMspf? t.Mspf(): t.Cspf();
    break;
  case 1:
    count -= t.Resub(fMspf);
    break;
  case 2:
    count -= t.ResubMono(fMspf);
    break;
  case 3:
    count -= t.ResubShared(fMspf);
    break;
  case 4:
    count -= t.RepeatResub(false, fMspf);
    break;
  case 5:
    count -= t.RepeatResub(true, fMspf);
    break;
  case 6: {
    bool fInner = (nParameter / 4) % 2;
MyskYko committed
66
    count -= t.RepeatInner(fMspf, fInner);
MyskYko committed
67 68 69 70 71
    break;
  }
  case 7: {
    bool fInner = (nParameter / 4) % 2;
    bool fOuter = (nParameter / 8) % 2;
MyskYko committed
72
    count -= t.RepeatOuter(fMspf, fInner, fOuter);
MyskYko committed
73 74 75 76 77 78 79
    break;
  }
  case 8: {
    bool fFirstMerge = nParameter % 2;
    bool fMspfMerge = fMspf? (nParameter / 2) % 2: false;
    bool fInner = (nParameter / 4) % 2;
    bool fOuter = (nParameter / 8) % 2;
MyskYko committed
80
    count -= t.RepeatAll(fFirstMerge, fMspfMerge, fMspf, fInner, fOuter);
MyskYko committed
81 82 83
    break;
  }
  default:
MyskYko committed
84
    std::cout << "Unknown transduction type " << nType << std::endl;
MyskYko committed
85 86 87 88 89 90
  }
  assert(t.Verify());
  assert(count == t.CountWires());
  return t.GenerateAig();
}

MyskYko committed
91
Gia_Man_t *Gia_ManTransductionTt(Gia_Man_t *pGia, int nType, int fMspf, int nRandom, int nSortType, int nPiShuffle, int nParameter, int fLevel, Gia_Man_t *pExdc, int fNewLine, int nVerbose) {
MyskYko committed
92 93 94 95 96 97 98
  if(nRandom) {
    srand(nRandom);
    nSortType = rand() % 4;
    nPiShuffle = rand();
    nParameter = rand() % 16;
  }
  NewTt::Param p;
MyskYko committed
99
  Transduction::Transduction<NewTt::Man, NewTt::Param, NewTt::lit, 0xffffffff> t(pGia, nVerbose, fNewLine, nSortType, nPiShuffle, fLevel, pExdc, p);
MyskYko committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
  int count = t.CountWires();
  switch(nType) {
  case 0:
    count -= fMspf? t.Mspf(): t.Cspf();
    break;
  case 1:
    count -= t.Resub(fMspf);
    break;
  case 2:
    count -= t.ResubMono(fMspf);
    break;
  case 3:
    count -= t.ResubShared(fMspf);
    break;
  case 4:
    count -= t.RepeatResub(false, fMspf);
    break;
  case 5:
    count -= t.RepeatResub(true, fMspf);
    break;
  case 6: {
    bool fInner = (nParameter / 4) % 2;
MyskYko committed
122
    count -= t.RepeatInner(fMspf, fInner);
MyskYko committed
123 124 125 126 127
    break;
  }
  case 7: {
    bool fInner = (nParameter / 4) % 2;
    bool fOuter = (nParameter / 8) % 2;
MyskYko committed
128
    count -= t.RepeatOuter(fMspf, fInner, fOuter);
MyskYko committed
129 130 131 132 133 134 135
    break;
  }
  case 8: {
    bool fFirstMerge = nParameter % 2;
    bool fMspfMerge = fMspf? (nParameter / 2) % 2: false;
    bool fInner = (nParameter / 4) % 2;
    bool fOuter = (nParameter / 8) % 2;
MyskYko committed
136
    count -= t.RepeatAll(fFirstMerge, fMspfMerge, fMspf, fInner, fOuter);
MyskYko committed
137 138 139
    break;
  }
  default:
MyskYko committed
140
    std::cout << "Unknown transduction type " << nType << std::endl;
MyskYko committed
141 142 143 144 145 146 147
  }
  assert(t.Verify());
  assert(count == t.CountWires());
  return t.GenerateAig();
}

ABC_NAMESPACE_IMPL_END
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

#else

#include "gia.h"

ABC_NAMESPACE_IMPL_START

Gia_Man_t * Gia_ManTransductionBdd(Gia_Man_t *pGia, int nType, int fMspf, int nRandom, int nSortType, int nPiShuffle, int nParameter, int fLevel, Gia_Man_t *pExdc, int fNewLine, int nVerbose)
{
    return NULL;
}
Gia_Man_t * Gia_ManTransductionTt(Gia_Man_t *pGia, int nType, int fMspf, int nRandom, int nSortType, int nPiShuffle, int nParameter, int fLevel, Gia_Man_t *pExdc, int fNewLine, int nVerbose)
{
    return NULL;
}

ABC_NAMESPACE_IMPL_END

#endif