abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extraUtilCube.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "misc/vec/vec.h"
#include "misc/vec/vecHsh.h"

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START void 
Abc_StatePush (Vec_Int_t *vData, char *pState, int k)
 DECLARATIONS ///. More...
 
static void Abc_StatePerm (char *pState, char *pPerm, char *pRes)
 
static void Abc_StatePrint (char *pState)
 
void Abc_EnumerateCubeStates2 ()
 FUNCTION DEFINITIONS ///. More...
 
static int Abc_DataHasBit (word *p, word i)
 
static void Abc_DataXorBit (word *p, word i)
 
static int Abc_DataGetCube (word w, int i)
 
static word Abc_DataXorCube (word w, int i, int c)
 
static word Abc_CubeGenerateSign (char *pState)
 
void Abc_EnumerateCubeStates ()
 

Function Documentation

static word Abc_CubeGenerateSign ( char *  pState)
inlinestatic

Definition at line 166 of file extraUtilCube.c.

167 {
168  static int Var2Cor[24] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, -1, -1, -1, 6, 6, 6 };
169  static int Var2Per[24] = { 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, -1, -1, -1, 0, 1, 2 };
170  word Res = 0;
171  Res = Abc_DataXorCube( Res, 0, (Var2Cor[(int)pState[ 0]] << 2) | Var2Per[(int)pState[ 0]] );
172  Res = Abc_DataXorCube( Res, 1, (Var2Cor[(int)pState[ 3]] << 2) | Var2Per[(int)pState[ 3]] );
173  Res = Abc_DataXorCube( Res, 2, (Var2Cor[(int)pState[ 6]] << 2) | Var2Per[(int)pState[ 6]] );
174  Res = Abc_DataXorCube( Res, 3, (Var2Cor[(int)pState[ 9]] << 2) | Var2Per[(int)pState[ 9]] );
175  Res = Abc_DataXorCube( Res, 4, (Var2Cor[(int)pState[12]] << 2) | Var2Per[(int)pState[12]] );
176  Res = Abc_DataXorCube( Res, 5, (Var2Cor[(int)pState[15]] << 2) | Var2Per[(int)pState[15]] );
177  Res = Abc_DataXorCube( Res, 6, (Var2Cor[(int)pState[21]] << 2) | Var2Per[(int)pState[21]] );
178  return Res;
179 }
static word Abc_DataXorCube(word w, int i, int c)
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static int Abc_DataGetCube ( word  w,
int  i 
)
inlinestatic

Definition at line 164 of file extraUtilCube.c.

164 { return (w >> (5*i)) & 31; }
static int Abc_DataHasBit ( word p,
word  i 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 162 of file extraUtilCube.c.

162 { return (p[(i)>>6] & (1<<((i) & 63))) > 0; }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Abc_DataXorBit ( word p,
word  i 
)
inlinestatic

Definition at line 163 of file extraUtilCube.c.

163 { p[(i)>>6] ^= (1<<((i) & 63)); }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static word Abc_DataXorCube ( word  w,
int  i,
int  c 
)
inlinestatic

Definition at line 165 of file extraUtilCube.c.

165 { return w ^ (((word)c) << (5*i)); }
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
void Abc_EnumerateCubeStates ( )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 192 of file extraUtilCube.c.

193 {
194  int pXYZ[3][9][2] = {
195  { {3, 5}, {3,17}, {3,15}, {1, 6}, {1,16}, {1,14}, {2, 4}, {2,18}, {2,13} },
196  { {2,14}, {2,24}, {2,12}, {3,13}, {3,23}, {3,10}, {1,15}, {1,22}, {1,11} },
197  { {1,10}, {1, 7}, {1, 4}, {3,12}, {3, 9}, {3, 6}, {2,11}, {2, 8}, {2, 5} } };
198 
199  Vec_Int_t * vData = Vec_IntStart( 6 * (1 << 22) ); // 96 MB
200  word State, * pHash = ABC_CALLOC( word, 1 << 29 ); // 4 GB
201  int i, k, v, Beg, End, Counter = 0;
202  char * pPrev, * pState, pStart[24], pFirst[9][24];
203  abctime clk = Abc_Clock();
204  printf( "Enumerating states of 2x2x2 cube.\n" );
205  // init state
206  for ( v = 0; v < 24; v++ )
207  pStart[v] = v;
208  Abc_StatePush( vData, pStart, Counter );
209  Abc_DataXorBit( pHash, Abc_CubeGenerateSign(pStart) );
210  Counter++;
211  // first nine states
212  for ( i = 0; i < 3; i++ )
213  {
214  memcpy( pFirst[i], pStart, 24 );
215  for ( v = 0; v < 9; v++ )
216  ABC_SWAP( char, pFirst[i][pXYZ[i][v][0]-1], pFirst[i][pXYZ[i][v][1]-1] );
217  Abc_StatePush( vData, pFirst[i], Counter );
218  Abc_DataXorBit( pHash, Abc_CubeGenerateSign(pFirst[i]) );
219  Counter++;
220  //Abc_StatePrint( pFirst[i] );
221 
222  memcpy( pFirst[3+i], pFirst[i], 24 );
223  for ( v = 0; v < 9; v++ )
224  ABC_SWAP( char, pFirst[3+i][pXYZ[i][v][0]-1], pFirst[3+i][pXYZ[i][v][1]-1] );
225  Abc_StatePush( vData, pFirst[3+i], Counter );
226  Abc_DataXorBit( pHash, Abc_CubeGenerateSign(pFirst[3+i]) );
227  Counter++;
228  //Abc_StatePrint( pFirst[3+i] );
229 
230  memcpy( pFirst[6+i], pFirst[3+i], 24 );
231  for ( v = 0; v < 9; v++ )
232  ABC_SWAP( char, pFirst[6+i][pXYZ[i][v][0]-1], pFirst[6+i][pXYZ[i][v][1]-1] );
233  Abc_StatePush( vData, pFirst[6+i], Counter );
234  Abc_DataXorBit( pHash, Abc_CubeGenerateSign(pFirst[6+i]) );
235  Counter++;
236  //Abc_StatePrint( pFirst[6+i] );
237  }
238  printf( "Iter %2d -> %8d ", 0, 1 );
239  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
240  printf( "Iter %2d -> %8d ", 1, Counter );
241  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
242  Beg = 1; End = 10;
243  for ( i = 2; i <= 100; i++ )
244  {
245  if ( Beg == End )
246  break;
247  for ( k = Beg; k < End; k++ )
248  {
249  pPrev = (char *)Vec_IntEntryP(vData, 6*k);
250  for ( v = 0; v < 9; v++ )
251  {
252  pState = (char *)Vec_IntEntryP(vData, 6*Counter);
253  Abc_StatePerm( pPrev, pFirst[v], pState );
254  State = Abc_CubeGenerateSign( pState );
255  if ( !Abc_DataHasBit(pHash, State) )
256  Abc_DataXorBit(pHash, State), Counter++;
257  if ( Counter == (1<<22) )
258  {
259  printf( "Did not converge. " );
260  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
261  return;
262  }
263  }
264  }
265  Beg = End; End = Counter;
266  printf( "Iter %2d -> %8d ", i, Counter );
267  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
268  }
269  Vec_IntFree( vData );
270  ABC_FREE( pHash );
271 }
static void Abc_DataXorBit(word *p, word i)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
char * memcpy()
static abctime Abc_Clock()
Definition: abc_global.h:279
#define ABC_SWAP(Type, a, b)
Definition: abc_global.h:218
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
static int Abc_DataHasBit(word *p, word i)
static void Abc_StatePerm(char *pState, char *pPerm, char *pRes)
Definition: extraUtilCube.c:35
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static int Counter
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static ABC_NAMESPACE_IMPL_START void Abc_StatePush(Vec_Int_t *vData, char *pState, int k)
DECLARATIONS ///.
Definition: extraUtilCube.c:34
static int * Vec_IntEntryP(Vec_Int_t *p, int i)
Definition: vecInt.h:417
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static word Abc_CubeGenerateSign(char *pState)
ABC_INT64_T abctime
Definition: abc_global.h:278
void Abc_EnumerateCubeStates2 ( )

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 53 of file extraUtilCube.c.

54 {
55  int pXYZ[3][9][2] = {
56  { {3, 5}, {3,17}, {3,15}, {1, 6}, {1,16}, {1,14}, {2, 4}, {2,18}, {2,13} },
57  { {2,14}, {2,24}, {2,12}, {3,13}, {3,23}, {3,10}, {1,15}, {1,22}, {1,11} },
58  { {1,10}, {1, 7}, {1, 4}, {3,12}, {3, 9}, {3, 6}, {2,11}, {2, 8}, {2, 5} } };
59 
60  Vec_Int_t * vData = Vec_IntStart( 6 * (1 << 22) ); // 96 MB
61  Hsh_IntMan_t * vHash = Hsh_IntManStart( vData, 6, 1 << 22 ); // 32 MB
62  int i, k, v, RetValue, Beg, End, Counter = 0;
63  char pStart[24], pFirst[9][24];
64  abctime clk = Abc_Clock();
65  printf( "Enumerating states of 2x2x2 cube.\n" );
66  // init state
67  for ( v = 0; v < 24; v++ )
68  pStart[v] = v;
69  Abc_StatePush( vData, pStart, Counter );
70  RetValue = Hsh_IntManAdd( vHash, Counter );
71  assert( RetValue == Counter );
72  Counter++;
73  // first nine states
74  for ( i = 0; i < 3; i++ )
75  {
76  memcpy( pFirst[i], pStart, 24 );
77  for ( v = 0; v < 9; v++ )
78  ABC_SWAP( char, pFirst[i][pXYZ[i][v][0]-1], pFirst[i][pXYZ[i][v][1]-1] );
79  Abc_StatePush( vData, pFirst[i], Counter );
80  RetValue = Hsh_IntManAdd( vHash, Counter );
81  assert( RetValue == Counter );
82  Counter++;
83  //Abc_StatePrint( pFirst[i] );
84 
85  memcpy( pFirst[3+i], pFirst[i], 24 );
86  for ( v = 0; v < 9; v++ )
87  ABC_SWAP( char, pFirst[3+i][pXYZ[i][v][0]-1], pFirst[3+i][pXYZ[i][v][1]-1] );
88  Abc_StatePush( vData, pFirst[3+i], Counter );
89  RetValue = Hsh_IntManAdd( vHash, Counter );
90  assert( RetValue == Counter );
91  Counter++;
92  //Abc_StatePrint( pFirst[3+i] );
93 
94  memcpy( pFirst[6+i], pFirst[3+i], 24 );
95  for ( v = 0; v < 9; v++ )
96  ABC_SWAP( char, pFirst[6+i][pXYZ[i][v][0]-1], pFirst[6+i][pXYZ[i][v][1]-1] );
97  Abc_StatePush( vData, pFirst[6+i], Counter );
98  RetValue = Hsh_IntManAdd( vHash, Counter );
99  assert( RetValue == Counter );
100  Counter++;
101  //Abc_StatePrint( pFirst[6+i] );
102  }
103  printf( "Iter %2d -> %8d ", 0, 1 );
104  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
105  printf( "Iter %2d -> %8d ", 1, Counter );
106  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
107  Beg = 1; End = 10;
108  for ( i = 2; i <= 100; i++ )
109  {
110  if ( Beg == End )
111  break;
112  for ( k = Beg; k < End; k++ )
113  for ( v = 0; v < 9; v++ )
114  {
115  Abc_StatePerm( (char *)Vec_IntEntryP(vData, 6*k), pFirst[v], (char *)Vec_IntEntryP(vData, 6*Counter) );
116  RetValue = Hsh_IntManAdd( vHash, Counter );
117  if ( RetValue == Counter )
118  Counter++;
119  if ( Counter == (1<<22) )
120  {
121  printf( "Did not converge. " );
122  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
123  return;
124  }
125  }
126  Beg = End; End = Counter;
127  printf( "Iter %2d -> %8d ", i, Counter );
128  Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
129  }
130  Hsh_IntManStop( vHash );
131  Vec_IntFree( vData );
132 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
char * memcpy()
static abctime Abc_Clock()
Definition: abc_global.h:279
#define ABC_SWAP(Type, a, b)
Definition: abc_global.h:218
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
static void Abc_StatePerm(char *pState, char *pPerm, char *pRes)
Definition: extraUtilCube.c:35
static int Counter
static void Hsh_IntManStop(Hsh_IntMan_t *p)
Definition: vecHsh.h:119
static int Hsh_IntManAdd(Hsh_IntMan_t *p, int iData)
Definition: vecHsh.h:157
static ABC_NAMESPACE_IMPL_START void Abc_StatePush(Vec_Int_t *vData, char *pState, int k)
DECLARATIONS ///.
Definition: extraUtilCube.c:34
#define assert(ex)
Definition: util_old.h:213
static int * Vec_IntEntryP(Vec_Int_t *p, int i)
Definition: vecInt.h:417
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static Hsh_IntMan_t * Hsh_IntManStart(Vec_Int_t *vData, int nSize, int nEntries)
FUNCTION DEFINITIONS ///.
Definition: vecHsh.h:109
ABC_INT64_T abctime
Definition: abc_global.h:278
static void Abc_StatePerm ( char *  pState,
char *  pPerm,
char *  pRes 
)
inlinestatic

Definition at line 35 of file extraUtilCube.c.

35 { int i; for ( i = 0; i < 24; i++ ) pRes[i] = pState[(int)pPerm[i]]; }
static int pPerm[13719]
Definition: rwrTemp.c:32
static void Abc_StatePrint ( char *  pState)
inlinestatic

Definition at line 36 of file extraUtilCube.c.

36 { int i; for ( i = 0; i < 24; i++ ) printf(" %2d", pState[i]); printf( "\n" ); }
static ABC_NAMESPACE_IMPL_START void Abc_StatePush ( Vec_Int_t vData,
char *  pState,
int  k 
)
inlinestatic

DECLARATIONS ///.

CFile****************************************************************

FileName [extraUtilCube.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [extra]

Synopsis [Permutation computation.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
extraUtilCube.c,v 1.0 2003/02/01 00:00:00 alanmi Exp

]

Definition at line 34 of file extraUtilCube.c.

34 { int i; for ( i = 0; i < 6; i++ ) Vec_IntWriteEntry(vData, 6*k+i, ((int*)pState)[i]); }
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285