Skip to content

Commit 423d929

Browse files
committed
QBF-based code generation (extending beyond 32 bits).
1 parent de82737 commit 423d929

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

src/aig/gia/giaQbf.c

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "sat/bsat/satStore.h"
2424
#include "misc/extra/extra.h"
2525
#include "sat/glucose/AbcGlucose.h"
26+
#include "misc/util/utilTruth.h"
2627

2728
ABC_NAMESPACE_IMPL_START
2829

@@ -282,7 +283,7 @@ Gia_Man_t * Gia_Gen2CreateMiter( int nLutSize, int nLutNum )
282283
pNew = Gia_ManCleanup( pTemp = pNew );
283284
Gia_ManStop( pTemp );
284285
printf( "Generated QBF miter with %d parameters, %d functional variables, and %d AIG nodes.\n",
285-
nLutNum * (1 << nLutSize), 2*nLutNum, Gia_ManAndNum(pNew) );
286+
nLutNum * (1 << nLutSize), 2*nLutSize, Gia_ManAndNum(pNew) );
286287
return pNew;
287288
}
288289
int Gia_Gen2CodeOne( int nLutSize, int nLutNum, Vec_Int_t * vCode, int x )
@@ -293,62 +294,80 @@ int Gia_Gen2CodeOne( int nLutSize, int nLutNum, Vec_Int_t * vCode, int x )
293294
Code |= (1 << k);
294295
return Code;
295296
}
297+
word * Gia_Gen2CodeOneP( int nLutSize, int nLutNum, Vec_Int_t * vCode, int x )
298+
{
299+
word * pRes = ABC_CALLOC( word, Abc_Bit6WordNum(nLutNum) );
300+
int k;
301+
for ( k = 0; k < nLutNum; k++ )
302+
if ( Vec_IntEntry(vCode, k*(1 << nLutSize)+x) )
303+
Abc_InfoSetBit( (unsigned *)pRes, k );
304+
return pRes;
305+
}
296306
void Gia_Gen2CodePrint( int nLutSize, int nLutNum, Vec_Int_t * vCode )
297307
{
298308
// |<-- PVars(0)-->|...|<-- PVars(nLutNum-1)-->|
299309
int i, n, nPairs = 16;
300310
printf( "%d-input %d-output code table:\n", nLutSize, nLutNum );
301311
for ( i = 0; i < (1 << nLutSize); i++ )
302312
{
303-
int Code = Gia_Gen2CodeOne( nLutSize, nLutNum, vCode, i );
313+
word * CodeX = Gia_Gen2CodeOneP( nLutSize, nLutNum, vCode, i );
304314
printf( "%3d ", i );
305315
Extra_PrintBinary( stdout, (unsigned *)&i, nLutSize );
306316
printf( " --> " );
307-
printf( "%3d ", Code );
308-
Extra_PrintBinary( stdout, (unsigned *)&Code, nLutNum );
317+
if ( nLutNum <= 16 )
318+
printf( "%5d ", (int)CodeX[0] );
319+
Extra_PrintBinary( stdout, (unsigned *)CodeX, nLutNum );
309320
printf( "\n" );
321+
ABC_FREE( CodeX );
310322
}
311323
// create several different pairs
312324
srand( time(NULL) );
313325
printf( "Simulation of the encoding with %d random pairs:\n", nPairs );
314326
for ( n = 0; n < nPairs; n++ )
315327
{
316328
unsigned MaskIn = Abc_InfoMask( nLutSize );
317-
unsigned MaskOut = Abc_InfoMask( nLutNum );
318-
int CodeX, CodeY, CodeXY, CodeXCodeY;
319-
int NumX = 0, NumY = 0, NumXY;
329+
int NumX = 0, NumY = 0, NumXY, nWords = Abc_Bit6WordNum(nLutNum);
330+
word * CodeX, * CodeY, * CodeXY;
331+
word * CodeXCodeY = ABC_CALLOC( word, nWords );
320332
while ( NumX == NumY )
321333
{
322334
NumX = rand() % (1 << nLutSize);
323335
NumY = rand() % (1 << nLutSize);
324336
NumXY = MaskIn & ~(NumX & NumY);
325337
}
326-
CodeX = Gia_Gen2CodeOne( nLutSize, nLutNum, vCode, NumX );
327-
CodeY = Gia_Gen2CodeOne( nLutSize, nLutNum, vCode, NumY );
328-
CodeXY = Gia_Gen2CodeOne( nLutSize, nLutNum, vCode, NumXY );
329-
CodeXCodeY = MaskOut & ~(CodeX & CodeY);
338+
CodeX = Gia_Gen2CodeOneP( nLutSize, nLutNum, vCode, NumX );
339+
CodeY = Gia_Gen2CodeOneP( nLutSize, nLutNum, vCode, NumY );
340+
CodeXY = Gia_Gen2CodeOneP( nLutSize, nLutNum, vCode, NumXY );
341+
Abc_TtAnd( CodeXCodeY, CodeX, CodeY, nWords, 1 );
342+
if ( nLutNum < 64*nWords )
343+
CodeXCodeY[nWords-1] &= Abc_Tt6Mask(nLutNum % 64);
330344

331345
printf( "%2d :", n );
332-
printf( " x =%3d ", NumX );
346+
printf( " x =%3d ", NumX );
333347
Extra_PrintBinary( stdout,(unsigned *) &NumX, nLutSize );
334-
printf( " y =%3d ", NumY );
348+
printf( " y =%3d ", NumY );
335349
Extra_PrintBinary( stdout, (unsigned *)&NumY, nLutSize );
336-
printf( " nand =%3d ", NumXY );
350+
printf( " nand =%3d ", NumXY );
337351
Extra_PrintBinary( stdout, (unsigned *)&NumXY, nLutSize );
338352
printf( " " );
339353

340-
printf( " c(x) =%3d ", CodeX );
341-
Extra_PrintBinary( stdout, (unsigned *)&CodeX, nLutNum );
342-
printf( " c(y) =%3d ", CodeY );
343-
Extra_PrintBinary( stdout, (unsigned *)&CodeY, nLutNum );
344-
printf( " c(nand) =%3d ", CodeXY );
345-
Extra_PrintBinary( stdout, (unsigned *)&CodeXY, nLutNum );
346-
printf( " nand(c(x), c(y)) =%3d ", CodeXCodeY );
347-
Extra_PrintBinary( stdout, (unsigned *)&CodeXCodeY, nLutNum );
348-
printf( " " );
349-
350-
printf( "%s", CodeXCodeY == CodeXY ? "yes" : "no" );
354+
printf( " c(x) = " );
355+
Extra_PrintBinary( stdout, (unsigned *)CodeX, nLutNum );
356+
printf( " c(y) = " );
357+
Extra_PrintBinary( stdout, (unsigned *)CodeY, nLutNum );
358+
printf( " c(nand) = " );
359+
Extra_PrintBinary( stdout, (unsigned *)CodeXY, nLutNum );
360+
printf( " nand(c(x),c(y)) = " );
361+
Extra_PrintBinary( stdout, (unsigned *)CodeXCodeY, nLutNum );
362+
printf( " " );
363+
364+
printf( "%s", Abc_TtEqual(CodeXCodeY, CodeXY, nWords) ? "yes" : "no" );
351365
printf( "\n" );
366+
367+
ABC_FREE( CodeX );
368+
ABC_FREE( CodeY );
369+
ABC_FREE( CodeXY );
370+
ABC_FREE( CodeXCodeY );
352371
}
353372
}
354373
void Gia_Gen2CodeTest()

0 commit comments

Comments
 (0)