abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
luckySwapIJ.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [luckySwapIJ.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Semi-canonical form computation package.]
8 
9  Synopsis [just for support of swap_ij() function]
10 
11  Author [Jake]
12 
13  Date [Started - September 2012]
14 
15 ***********************************************************************/
16 
17 #include "luckyInt.h"
18 
19 
21 
22 
23 void swap_ij_case1( word* f,int totalVars, int i, int j)
24 {
25  int e,wordsNumber,n,shift;
26  word maskArray[45]=
27  { ABC_CONST(0x9999999999999999), ABC_CONST(0x2222222222222222), ABC_CONST(0x4444444444444444) ,ABC_CONST(0xA5A5A5A5A5A5A5A5), ABC_CONST(0x0A0A0A0A0A0A0A0A), ABC_CONST(0x5050505050505050),
28  ABC_CONST(0xAA55AA55AA55AA55), ABC_CONST(0x00AA00AA00AA00AA), ABC_CONST(0x5500550055005500) ,ABC_CONST(0xAAAA5555AAAA5555), ABC_CONST(0x0000AAAA0000AAAA), ABC_CONST(0x5555000055550000),
29  ABC_CONST(0xAAAAAAAA55555555), ABC_CONST(0x00000000AAAAAAAA), ABC_CONST(0x5555555500000000) ,ABC_CONST(0xC3C3C3C3C3C3C3C3), ABC_CONST(0x0C0C0C0C0C0C0C0C), ABC_CONST(0x3030303030303030),
30  ABC_CONST(0xCC33CC33CC33CC33), ABC_CONST(0x00CC00CC00CC00CC), ABC_CONST(0x3300330033003300) ,ABC_CONST(0xCCCC3333CCCC3333), ABC_CONST(0x0000CCCC0000CCCC), ABC_CONST(0x3333000033330000),
31  ABC_CONST(0xCCCCCCCC33333333), ABC_CONST(0x00000000CCCCCCCC), ABC_CONST(0x3333333300000000) ,ABC_CONST(0xF00FF00FF00FF00F), ABC_CONST(0x00F000F000F000F0), ABC_CONST(0x0F000F000F000F00),
32  ABC_CONST(0xF0F00F0FF0F00F0F), ABC_CONST(0x0000F0F00000F0F0), ABC_CONST(0x0F0F00000F0F0000) ,ABC_CONST(0xF0F0F0F00F0F0F0F), ABC_CONST(0x00000000F0F0F0F0), ABC_CONST(0x0F0F0F0F00000000),
33  ABC_CONST(0xFF0000FFFF0000FF), ABC_CONST(0x0000FF000000FF00), ABC_CONST(0x00FF000000FF0000) ,ABC_CONST(0xFF00FF0000FF00FF), ABC_CONST(0x00000000FF00FF00), ABC_CONST(0x00FF00FF00000000),
34  ABC_CONST(0xFFFF00000000FFFF), ABC_CONST(0x00000000FFFF0000), ABC_CONST(0x0000FFFF00000000)
35  };
36  e = 3*((9*i - i*i -2)/2 + j); // Exact formula for index in maskArray
37  wordsNumber = Kit_TruthWordNum_64bit(totalVars);
38  shift = (1<<j)-(1<<i);
39  for(n = 0; n < wordsNumber; n++)
40  f[n] = (f[n]&maskArray[e])+((f[n]&(maskArray[e+1]))<< shift)+((f[n]&(maskArray[e+2]))>> shift);
41 }
42 // "width" - how many "Words" in a row have "1s" (or "0s")in position "i"
43 // wi - width of i
44 // wj - width of j
45 // wwi = 2*wi; wwj = 2*wj;
46 
47 void swap_ij_case2( word* f,int totalVars, int i, int j)
48 {
49  word mask[] = { ABC_CONST(0xAAAAAAAAAAAAAAAA), ABC_CONST(0xCCCCCCCCCCCCCCCC), ABC_CONST(0xF0F0F0F0F0F0F0F0),
50  ABC_CONST(0xFF00FF00FF00FF00), ABC_CONST(0xFFFF0000FFFF0000), ABC_CONST(0xFFFFFFFF00000000) };
51  word temp;
52  int x,y,wj;
53  int WORDS_IN_TT = Kit_TruthWordNum_64bit(totalVars);
54  // int forShift = ((Word)1)<<i;
55  int forShift = (1<<i);
56  wj = 1 << (j - 6);
57  x = 0;
58  y = wj;
59  for(y=wj; y<WORDS_IN_TT;y+=2*wj)
60  for(x=y-wj; x < y; x++)
61  {
62  temp = f[x+wj];
63  f[x+wj] = ((f[x+wj])&(mask[i])) + (((f[x]) & (mask[i])) >> forShift);
64  f[x] = ((f[x])&(~mask[i])) + ((temp&(~mask[i])) << forShift);
65  }
66 }
67 
68 void swap_ij_case3( word* f,int totalVars, int i, int j)
69 {
70  int x,y,wwi,wwj,shift;
71  int WORDS_IN_TT;
72  int SizeOfBlock;
73  word* temp;
74  wwi = 1 << (i - 5);
75  wwj = 1 << (j - 5);
76  shift = (wwj - wwi)/2;
77  WORDS_IN_TT = Kit_TruthWordNum_64bit(totalVars);
78  SizeOfBlock = sizeof(word)*wwi/2;
79  temp = (word *)malloc(SizeOfBlock);
80  for(y=wwj/2; y<WORDS_IN_TT; y+=wwj)
81  for(x=y-shift; x<y; x+=wwi)
82  {
83  memcpy(temp,&f[x],SizeOfBlock);
84  memcpy(&f[x],&f[x+shift],SizeOfBlock);
85  memcpy(&f[x+shift],temp,SizeOfBlock);
86  }
87 }
88 void swap_ij( word* f,int totalVars, int varI, int varJ)
89 {
90  if (varI == varJ)
91  return;
92  else if(varI>varJ)
93  swap_ij( f,totalVars,varJ,varI);
94  else if((varI <= 4) && (varJ <= 5))
95  swap_ij_case1(f,totalVars, varI, varJ);
96  else if((varI <= 5) && (varJ > 5))
97  swap_ij_case2(f,totalVars, varI, varJ);
98  else if((varI > 5) && (varJ > 5))
99  swap_ij_case3(f,totalVars,varI,varJ);
100 }
101 
char * malloc()
int Kit_TruthWordNum_64bit(int nVars)
Definition: luckySwap.c:36
char * memcpy()
void swap_ij_case3(word *f, int totalVars, int i, int j)
Definition: luckySwapIJ.c:68
void swap_ij(word *f, int totalVars, int varI, int varJ)
Definition: luckySwapIJ.c:88
void swap_ij_case2(word *f, int totalVars, int i, int j)
Definition: luckySwapIJ.c:47
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
ABC_NAMESPACE_IMPL_START void swap_ij_case1(word *f, int totalVars, int i, int j)
Definition: luckySwapIJ.c:23
#define ABC_CONST(number)
PARAMETERS ///.
Definition: abc_global.h:206