48 fprintf( pFile,
".model HA\n" );
49 fprintf( pFile,
".inputs a b\n" );
50 fprintf( pFile,
".outputs s cout\n" );
53 fprintf( pFile,
".names a b s\n" );
54 fprintf( pFile,
"10 1\n" );
55 fprintf( pFile,
"01 1\n" );
56 fprintf( pFile,
".names a b cout\n" );
57 fprintf( pFile,
"11 1\n" );
61 fprintf( pFile,
".names a b cout\n" );
62 fprintf( pFile,
"11 1\n" );
63 fprintf( pFile,
".names a b and1_\n" );
64 fprintf( pFile,
"00 1\n" );
65 fprintf( pFile,
".names cout and1_ s\n" );
66 fprintf( pFile,
"00 1\n" );
68 fprintf( pFile,
".end\n" );
69 fprintf( pFile,
"\n" );
74 fprintf( pFile,
".model FA\n" );
75 fprintf( pFile,
".inputs a b cin\n" );
76 fprintf( pFile,
".outputs s cout\n" );
91 fprintf( pFile,
".names a b s0\n" );
92 fprintf( pFile,
"10 1\n" );
93 fprintf( pFile,
"01 1\n" );
94 fprintf( pFile,
".names a b c0\n" );
95 fprintf( pFile,
"11 1\n" );
96 fprintf( pFile,
".names s0 cin s\n" );
97 fprintf( pFile,
"10 1\n" );
98 fprintf( pFile,
"01 1\n" );
99 fprintf( pFile,
".names s0 cin c1\n" );
100 fprintf( pFile,
"11 1\n" );
101 fprintf( pFile,
".names c0 c1 cout\n" );
102 fprintf( pFile,
"00 0\n" );
106 fprintf( pFile,
".names a b and1\n" );
107 fprintf( pFile,
"11 1\n" );
108 fprintf( pFile,
".names a b and1_\n" );
109 fprintf( pFile,
"00 1\n" );
110 fprintf( pFile,
".names and1 and1_ xor\n" );
111 fprintf( pFile,
"00 1\n" );
113 fprintf( pFile,
".names cin xor and2\n" );
114 fprintf( pFile,
"11 1\n" );
115 fprintf( pFile,
".names cin xor and2_\n" );
116 fprintf( pFile,
"00 1\n" );
117 fprintf( pFile,
".names and2 and2_ s\n" );
118 fprintf( pFile,
"00 1\n" );
120 fprintf( pFile,
".names and1 and2 cout\n" );
121 fprintf( pFile,
"00 0\n" );
123 fprintf( pFile,
".end\n" );
124 fprintf( pFile,
"\n" );
128 int i, nDigits = Abc_Base10Log( nVars );
131 fprintf( pFile,
".model ADD%d\n", nVars );
133 fprintf( pFile,
".inputs" );
134 for ( i = 0; i < nVars; i++ )
135 fprintf( pFile,
" a%0*d", nDigits, i );
136 for ( i = 0; i < nVars; i++ )
137 fprintf( pFile,
" b%0*d", nDigits, i );
138 fprintf( pFile,
"\n" );
140 fprintf( pFile,
".outputs" );
141 for ( i = 0; i <= nVars; i++ )
142 fprintf( pFile,
" s%0*d", nDigits, i );
143 fprintf( pFile,
"\n" );
145 fprintf( pFile,
".names c\n" );
147 fprintf( pFile,
".subckt FA a=a0 b=b0 cin=c s=y0 cout=s1\n" );
150 fprintf( pFile,
".subckt FA a=a%0*d b=b%0*d cin=c s=s%0*d cout=%0*d\n", nDigits, 0, nDigits, 0, nDigits, 0, nDigits, 0 );
151 for ( i = 1; i < nVars-1; i++ )
152 fprintf( pFile,
".subckt FA a=a%0*d b=b%0*d cin=%0*d s=s%0*d cout=%0*d\n", nDigits, i, nDigits, i, nDigits, i-1, nDigits, i, nDigits, i );
153 fprintf( pFile,
".subckt FA a=a%0*d b=b%0*d cin=%0*d s=s%0*d cout=s%0*d\n", nDigits, i, nDigits, i, nDigits, i-1, nDigits, i, nDigits, i+1 );
155 fprintf( pFile,
".end\n" );
156 fprintf( pFile,
"\n" );
163 pFile = fopen( pFileName,
"w" );
164 fprintf( pFile,
"# %d-bit ripple-carry adder generated by ABC on %s\n", nVars,
Extra_TimeStamp() );
182 int i, k, nDigits = Abc_Base10Log( nVars ), nDigits2 = Abc_Base10Log( 2*nVars );
185 fprintf( pFile,
".model Multi%d\n", nVars );
187 fprintf( pFile,
".inputs" );
188 for ( i = 0; i < nVars; i++ )
189 fprintf( pFile,
" a%0*d", nDigits, i );
190 for ( i = 0; i < nVars; i++ )
191 fprintf( pFile,
" b%0*d", nDigits, i );
192 fprintf( pFile,
"\n" );
194 fprintf( pFile,
".outputs" );
195 for ( i = 0; i < 2*nVars; i++ )
196 fprintf( pFile,
" m%0*d", nDigits2, i );
197 fprintf( pFile,
"\n" );
199 for ( i = 0; i < 2*nVars; i++ )
200 fprintf( pFile,
".names x%0*d_%0*d\n", nDigits, 0, nDigits2, i );
201 for ( k = 0; k < nVars; k++ )
203 for ( i = 0; i < 2 * nVars; i++ )
204 if ( i >= k && i < k + nVars )
205 fprintf( pFile,
".names b%0*d a%0*d y%0*d_%0*d\n11 1\n", nDigits, k, nDigits, i-k, nDigits, k, nDigits2, i );
207 fprintf( pFile,
".names y%0*d_%0*d\n", nDigits, k, nDigits2, i );
208 fprintf( pFile,
".subckt ADD%d", 2*nVars );
209 for ( i = 0; i < 2*nVars; i++ )
210 fprintf( pFile,
" a%0*d=x%0*d_%0*d", nDigits2, i, nDigits, k, nDigits2, i );
211 for ( i = 0; i < 2*nVars; i++ )
212 fprintf( pFile,
" b%0*d=y%0*d_%0*d", nDigits2, i, nDigits, k, nDigits2, i );
213 for ( i = 0; i <= 2*nVars; i++ )
214 fprintf( pFile,
" s%0*d=x%0*d_%0*d", nDigits2, i, nDigits, k+1, nDigits2, i );
215 fprintf( pFile,
"\n" );
217 for ( i = 0; i < 2 * nVars; i++ )
218 fprintf( pFile,
".names x%0*d_%0*d m%0*d\n1 1\n", nDigits, k, nDigits2, i, nDigits2, i );
219 fprintf( pFile,
".end\n" );
220 fprintf( pFile,
"\n" );
227 pFile = fopen( pFileName,
"w" );
228 fprintf( pFile,
"# %d-bit multiplier generated by ABC on %s\n", nVars,
Extra_TimeStamp() );
246 fprintf( pFile,
".model Comp\n" );
247 fprintf( pFile,
".inputs a b\n" );
248 fprintf( pFile,
".outputs x y\n" );
249 fprintf( pFile,
".names a b x\n" );
250 fprintf( pFile,
"11 1\n" );
251 fprintf( pFile,
".names a b y\n" );
252 fprintf( pFile,
"1- 1\n" );
253 fprintf( pFile,
"-1 1\n" );
254 fprintf( pFile,
".end\n" );
255 fprintf( pFile,
"\n" );
260 fprintf( pFile,
".model Layer%d\n", fSkip1 );
261 fprintf( pFile,
".inputs" );
262 for ( i = 0; i < nVars; i++ )
263 fprintf( pFile,
" x%02d", i );
264 fprintf( pFile,
"\n" );
265 fprintf( pFile,
".outputs" );
266 for ( i = 0; i < nVars; i++ )
267 fprintf( pFile,
" y%02d", i );
268 fprintf( pFile,
"\n" );
271 fprintf( pFile,
".names x00 y00\n" );
272 fprintf( pFile,
"1 1\n" );
277 for ( ; i + 1 < nVars; i += 2 )
278 fprintf( pFile,
".subckt Comp a=x%02d b=x%02d x=y%02d y=y%02d\n", i, i+1, i, i+1 );
281 fprintf( pFile,
".names x%02d y%02d\n", i, i );
282 fprintf( pFile,
"1 1\n" );
284 fprintf( pFile,
".end\n" );
285 fprintf( pFile,
"\n" );
302 int i, k, Counter, nDigits;
306 pFile = fopen( pFileName,
"w" );
307 fprintf( pFile,
"# %d-bit sorter generated by ABC on %s\n", nVars,
Extra_TimeStamp() );
308 fprintf( pFile,
".model Sorter%02d\n", nVars );
310 fprintf( pFile,
".inputs" );
311 for ( i = 0; i < nVars; i++ )
312 fprintf( pFile,
" x%02d", i );
313 fprintf( pFile,
"\n" );
315 fprintf( pFile,
".outputs" );
316 for ( i = 0; i < nVars; i++ )
317 fprintf( pFile,
" y%02d", i );
318 fprintf( pFile,
"\n" );
321 nDigits = Abc_Base10Log( (nVars-2)*nVars );
323 fprintf( pFile,
".subckt Comp a=x00 b=x01 x=y00 y=y01\n" );
326 fprintf( pFile,
".subckt Layer0" );
327 for ( k = 0; k < nVars; k++ )
328 fprintf( pFile,
" x%02d=x%02d", k, k );
329 for ( k = 0; k < nVars; k++ )
330 fprintf( pFile,
" y%02d=%0*d", k, nDigits, Counter++ );
331 fprintf( pFile,
"\n" );
333 for ( i = 1; i < 2*nVars-2; i++ )
335 fprintf( pFile,
".subckt Layer%d", (i&1) );
336 for ( k = 0; k < nVars; k++ )
337 fprintf( pFile,
" x%02d=%0*d", k, nDigits, Counter++ );
338 for ( k = 0; k < nVars; k++ )
339 fprintf( pFile,
" y%02d=%0*d", k, nDigits, Counter++ );
340 fprintf( pFile,
"\n" );
343 fprintf( pFile,
".subckt Layer%d", (i&1) );
344 for ( k = 0; k < nVars; k++ )
345 fprintf( pFile,
" x%02d=%0*d", k, nDigits, Counter++ );
346 for ( k = 0; k < nVars; k++ )
347 fprintf( pFile,
" y%02d=y%02d", k, k );
348 fprintf( pFile,
"\n" );
350 fprintf( pFile,
".end\n" );
351 fprintf( pFile,
"\n" );
372 fprintf( pFile,
".model cell\n" );
373 fprintf( pFile,
".inputs px1 px2 py1 py2 x y\n" );
374 fprintf( pFile,
".outputs fx fy\n" );
375 fprintf( pFile,
".names x y a\n" );
376 fprintf( pFile,
"11 1\n" );
377 fprintf( pFile,
".names px1 a x nx\n" );
378 fprintf( pFile,
"11- 1\n" );
379 fprintf( pFile,
"0-1 1\n" );
380 fprintf( pFile,
".names py1 a y ny\n" );
381 fprintf( pFile,
"11- 1\n" );
382 fprintf( pFile,
"0-1 1\n" );
383 fprintf( pFile,
".names px2 nx fx\n" );
384 fprintf( pFile,
"10 1\n" );
385 fprintf( pFile,
"01 1\n" );
386 fprintf( pFile,
".names py2 ny fy\n" );
387 fprintf( pFile,
"10 1\n" );
388 fprintf( pFile,
"01 1\n" );
389 fprintf( pFile,
".end\n" );
390 fprintf( pFile,
"\n" );
411 pFile = fopen( pFileName,
"w" );
412 fprintf( pFile,
"# %dx%d mesh generated by ABC on %s\n", nVars, nVars,
Extra_TimeStamp() );
413 fprintf( pFile,
".model mesh%d\n", nVars );
415 for ( i = 0; i < nVars; i++ )
416 for ( k = 0; k < nVars; k++ )
418 fprintf( pFile,
".inputs" );
419 fprintf( pFile,
" p%d%dx1", i, k );
420 fprintf( pFile,
" p%d%dx2", i, k );
421 fprintf( pFile,
" p%d%dy1", i, k );
422 fprintf( pFile,
" p%d%dy2", i, k );
423 fprintf( pFile,
"\n" );
425 fprintf( pFile,
".inputs" );
426 for ( i = 0; i < nVars; i++ )
427 fprintf( pFile,
" v%02d v%02d", 2*i, 2*i+1 );
428 fprintf( pFile,
"\n" );
430 fprintf( pFile,
".outputs" );
431 fprintf( pFile,
" fx00" );
432 fprintf( pFile,
"\n" );
434 for ( i = 0; i < nVars; i++ )
435 for ( k = 0; k < nVars; k++ )
437 fprintf( pFile,
".subckt cell" );
438 fprintf( pFile,
" px1=p%d%dx1", i, k );
439 fprintf( pFile,
" px2=p%d%dx2", i, k );
440 fprintf( pFile,
" py1=p%d%dy1", i, k );
441 fprintf( pFile,
" py2=p%d%dy2", i, k );
442 if ( k == nVars - 1 )
443 fprintf( pFile,
" x=v%02d", i );
445 fprintf( pFile,
" x=fx%d%d", i, k+1 );
446 if ( i == nVars - 1 )
447 fprintf( pFile,
" y=v%02d", nVars+k );
449 fprintf( pFile,
" y=fy%d%d", i+1, k );
451 fprintf( pFile,
" fx=fx%d%d", i, k );
452 fprintf( pFile,
" fy=fy%d%d", i, k );
453 fprintf( pFile,
"\n" );
455 fprintf( pFile,
".end\n" );
456 fprintf( pFile,
"\n" );
457 fprintf( pFile,
"\n" );
477 int i, iVar, iNext, nPars = (1 << nLutSize);
478 fprintf( pFile,
"\n" );
479 fprintf( pFile,
".model lut%d\n", nLutSize );
480 fprintf( pFile,
".inputs" );
481 for ( i = 0; i < nPars; i++ )
482 fprintf( pFile,
" p%02d", i );
483 fprintf( pFile,
"\n" );
484 fprintf( pFile,
".inputs" );
485 for ( i = 0; i < nLutSize; i++ )
486 fprintf( pFile,
" i%d", i );
487 fprintf( pFile,
"\n" );
488 fprintf( pFile,
".outputs o\n" );
489 fprintf( pFile,
".names n01 o\n" );
490 fprintf( pFile,
"1 1\n" );
494 for ( i = 1; i < nPars; i++ )
501 if ( iVar == nLutSize - 1 )
502 fprintf( pFile,
".names i%d p%02d p%02d n%02d\n", iVar, 2*(i-nPars/2), 2*(i-nPars/2)+1, i );
504 fprintf( pFile,
".names i%d n%02d n%02d n%02d\n", iVar, 2*i, 2*i+1, i );
505 fprintf( pFile,
"01- 1\n" );
506 fprintf( pFile,
"1-1 1\n" );
508 fprintf( pFile,
".end\n" );
509 fprintf( pFile,
"\n" );
523void Abc_GenFpga(
char * pFileName,
int nLutSize,
int nLuts,
int nVars )
525 int fGenerateFunc = 1;
527 int nVarsLut = (1 << nLutSize);
528 int nVarsLog = Abc_Base2Log( nVars + nLuts - 1 );
529 int nVarsDeg = (1 << nVarsLog);
530 int nParsLut = nLuts * (1 << nLutSize);
531 int nParsVar = nLuts * nLutSize * nVarsLog;
536 pFile = fopen( pFileName,
"w" );
537 fprintf( pFile,
"# Structure with %d %d-LUTs for %d-var function generated by ABC on %s\n", nLuts, nLutSize, nVars,
Extra_TimeStamp() );
538 fprintf( pFile,
".model struct%dx%d_%d\n", nLuts, nLutSize, nVars );
540 fprintf( pFile,
".inputs" );
541 for ( i = 0; i < nParsLut; i++ )
545 fprintf( pFile,
" pl%02d", i );
547 fprintf( pFile,
"\n" );
549 fprintf( pFile,
".inputs" );
550 for ( i = 0; i < nParsVar; i++ )
551 fprintf( pFile,
" pv%02d", i );
552 fprintf( pFile,
"\n" );
554 fprintf( pFile,
".inputs" );
555 for ( i = 0; i < nVars; i++ )
556 fprintf( pFile,
" v%02d", i );
557 fprintf( pFile,
"\n" );
559 fprintf( pFile,
".outputs" );
561 fprintf( pFile,
" out" );
562 fprintf( pFile,
"\n" );
563 fprintf( pFile,
".names Gnd\n" );
564 fprintf( pFile,
" 0\n" );
569 fprintf( pFile,
".names v%02d func out\n", nVars + nLuts - 1 );
570 fprintf( pFile,
"00 1\n11 1\n" );
571 fprintf( pFile,
".names" );
572 for ( i = 0; i < nVars; i++ )
573 fprintf( pFile,
" v%02d", i );
574 fprintf( pFile,
" func\n" );
575 for ( i = 0; i < nVars; i++ )
576 fprintf( pFile,
"1" );
577 fprintf( pFile,
" 1\n" );
580 fprintf( pFile,
".names v%02d out\n1 1\n", nVars + nLuts - 1 );
583 for ( i = 0; i < nLuts; i++ )
585 fprintf( pFile,
".subckt lut%d", nLutSize );
587 for ( k = 0; k < nVarsLut; k++ )
588 fprintf( pFile,
" p%02d=pl%02d", k, i * nVarsLut + k );
590 for ( k = 0; k < nLutSize; k++ )
591 fprintf( pFile,
" i%d=s%02d", k, i * nLutSize + k );
593 fprintf( pFile,
" o=v%02d", nVars + i );
594 fprintf( pFile,
"\n" );
598 for ( i = 0; i < nLuts; i++ )
600 for ( j = 0; j < nLutSize; j++ )
602 fprintf( pFile,
".subckt lut%d", nVarsLog );
604 for ( k = 0; k < nVarsDeg; k++ )
606 if ( k < nVars + nLuts - 1 && k < nVars + i )
607 fprintf( pFile,
" p%02d=v%02d", k, k );
609 fprintf( pFile,
" p%02d=Gnd", k );
612 for ( k = 0; k < nVarsLog; k++ )
613 fprintf( pFile,
" i%d=pv%02d", k, (i * nLutSize + j) * nVarsLog + k );
615 fprintf( pFile,
" o=s%02d", i * nLutSize + j );
616 fprintf( pFile,
"\n" );
620 fprintf( pFile,
".end\n" );
621 fprintf( pFile,
"\n" );
625 if ( nVarsLog != nLutSize )
644 int i, k, Counter, nDigitsIn, nDigitsOut;
645 pFile = fopen( pFileName,
"w" );
646 fprintf( pFile,
"# One-hotness condition for %d vars generated by ABC on %s\n", nVars,
Extra_TimeStamp() );
647 fprintf( pFile,
".model 1hot_%dvars\n", nVars );
648 fprintf( pFile,
".inputs" );
649 nDigitsIn = Abc_Base10Log( nVars );
650 for ( i = 0; i < nVars; i++ )
651 fprintf( pFile,
" i%0*d", nDigitsIn, i );
652 fprintf( pFile,
"\n" );
653 fprintf( pFile,
".outputs" );
654 nDigitsOut = Abc_Base10Log( nVars * (nVars - 1) / 2 );
655 for ( i = 0; i < nVars * (nVars - 1) / 2; i++ )
656 fprintf( pFile,
" o%0*d", nDigitsOut, i );
657 fprintf( pFile,
"\n" );
659 for ( i = 0; i < nVars; i++ )
660 for ( k = i+1; k < nVars; k++ )
662 fprintf( pFile,
".names i%0*d i%0*d o%0*d\n", nDigitsIn, i, nDigitsIn, k, nDigitsOut, Counter );
663 fprintf( pFile,
"11 0\n" );
666 fprintf( pFile,
".end\n" );
667 fprintf( pFile,
"\n" );
686 int i, j, k, iReg1, iReg2, Counter, Counter2, nDigitsIn, nDigitsOut;
687 pFile = fopen( pFileName,
"w" );
688 fprintf( pFile,
"# One-hotness with %d vars and %d regs generated by ABC on %s\n", nPis, nRegs,
Extra_TimeStamp() );
689 fprintf( pFile,
"# Used %d intervals of 1-hot registers: { ", Vec_PtrSize(vOnehots) );
693 fprintf( pFile,
"%d ", Vec_IntSize(vLine) );
694 Counter += Vec_IntSize(vLine) * (Vec_IntSize(vLine) - 1) / 2;
696 fprintf( pFile,
"}\n" );
697 fprintf( pFile,
".model 1hot_%dvars_%dregs\n", nPis, nRegs );
698 fprintf( pFile,
".inputs" );
699 nDigitsIn = Abc_Base10Log( nPis+nRegs );
700 for ( i = 0; i < nPis+nRegs; i++ )
701 fprintf( pFile,
" i%0*d", nDigitsIn, i );
702 fprintf( pFile,
"\n" );
703 fprintf( pFile,
".outputs" );
704 nDigitsOut = Abc_Base10Log( Counter );
705 for ( i = 0; i < Counter; i++ )
706 fprintf( pFile,
" o%0*d", nDigitsOut, i );
707 fprintf( pFile,
"\n" );
714 fprintf( pFile,
".names i%0*d i%0*d o%0*d\n", nDigitsIn, nPis+iReg1, nDigitsIn, nPis+iReg2, nDigitsOut, Counter2 );
715 fprintf( pFile,
"11 0\n" );
719 assert( Counter == Counter2 );
720 fprintf( pFile,
".end\n" );
721 fprintf( pFile,
"\n" );
747 int i, b, w,
nWords = Abc_TruthWordNum( nPis );
751 for ( w = 0; w <
nWords; w++ )
753 pFile = fopen( pFileName,
"w" );
754 fprintf( pFile,
"# Random function with %d inputs generated by ABC on %s\n", nPis,
Extra_TimeStamp() );
755 fprintf( pFile,
".model rand%d\n", nPis );
756 fprintf( pFile,
".inputs" );
757 nDigitsIn = Abc_Base10Log( nPis );
758 for ( i = 0; i < nPis; i++ )
759 fprintf( pFile,
" i%0*d", nDigitsIn, i );
760 fprintf( pFile,
"\n" );
761 fprintf( pFile,
".outputs f\n" );
762 fprintf( pFile,
".names" );
763 nDigitsIn = Abc_Base10Log( nPis );
764 for ( i = 0; i < nPis; i++ )
765 fprintf( pFile,
" i%0*d", nDigitsIn, i );
766 fprintf( pFile,
" f\n" );
767 for ( i = 0; i < (1<<nPis); i++ )
768 if ( Abc_InfoHasBit(pTruth, i) )
770 for ( b = nPis-1; b >= 0; b-- )
771 fprintf( pFile,
"%d", (i>>b)&1 );
772 fprintf( pFile,
" 1\n" );
774 fprintf( pFile,
".end\n" );
775 fprintf( pFile,
"\n" );
795 Vec_StrClear( vCond );
796 for ( i = 0; i < nPis; i++ )
799 if ( Rand % 100 > Prob )
800 Vec_StrPush( vCond,
'-' );
802 Vec_StrPush( vCond,
'1' );
804 Vec_StrPush( vCond,
'0' );
806 Vec_StrPush( vCond,
'\0' );
808void Abc_GenFsm(
char * pFileName,
int nPis,
int nPos,
int nStates,
int nLines,
int ProbI,
int ProbO )
813 int i, iState, iState2;
814 int nDigits = Abc_Base10Log( nStates );
816 vStates = Vec_WrdAlloc( nLines );
817 vCond = Vec_StrAlloc( 1000 );
818 for ( i = 0; i < nStates; )
823 Vec_WrdPush( vStates, ((
word)i << 32) | iState );
826 for ( ; i < nLines; )
830 if ( iState2 == iState )
832 Vec_WrdPush( vStates, ((
word)iState << 32) | iState2 );
835 Vec_WrdSort( vStates, 0 );
837 pFile = fopen( pFileName,
"w" );
838 fprintf( pFile,
"# This random FSM was generated by ABC on %s\n",
Extra_TimeStamp() );
839 fprintf( pFile,
"# Command line was: \"genfsm -I %d -O %d -S %d -L %d -P %d -Q %d %s\"\n", nPis, nPos, nStates, nLines, ProbI, ProbO, pFileName );
840 fprintf( pFile,
"# FSM has %d inputs, %d outputs, %d states, and %d products\n", nPis, nPos, nStates, nLines );
841 fprintf( pFile,
".i %d\n", nPis );
842 fprintf( pFile,
".o %d\n", nPos );
843 fprintf( pFile,
".p %d\n", nLines );
844 fprintf( pFile,
".s %d\n", nStates );
845 for ( i = 0; i < nLines; i++ )
848 fprintf( pFile,
"%s ", Vec_StrArray(vCond) );
849 fprintf( pFile,
"%0*d ", nDigits, (
int)(Vec_WrdEntry(vStates, i) >> 32) );
850 fprintf( pFile,
"%0*d ", nDigits, (
int)(Vec_WrdEntry(vStates, i)) );
854 fprintf( pFile,
"%s", Vec_StrArray(vCond) );
856 fprintf( pFile,
"\n" );
858 fprintf( pFile,
".e" );
859 fprintf( pFile,
"\n" );
861 Vec_WrdFree( vStates );
862 Vec_StrFree( vCond );
878 int i, k, nDigits = Abc_Base10Log( nBits ), Log2 = Abc_Base2Log( nArgs );
879 assert( nArgs > 1 && nBits > 1 );
880 fprintf( pFile,
"module adder_tree_%d_%d (\n ", nArgs, nBits );
881 for ( i = 0; i < nBits; i++, fprintf(pFile,
"\n ") )
882 for ( k = 0; k < nArgs; k++ )
883 fprintf( pFile,
" i%0*d_%0*d,", nDigits, k, nDigits, nBits-1-i );
884 fprintf( pFile,
" z\n" );
885 fprintf( pFile,
" );\n" );
886 for ( i = 0; i < nBits; i++ )
888 fprintf( pFile,
" input" );
889 for ( k = 0; k < nArgs; k++ )
890 fprintf( pFile,
" i%0*d_%0*d%s", nDigits, k, nDigits, nBits-1-i, k==nArgs-1 ?
"":
"," );
891 fprintf( pFile,
";\n" );
893 fprintf( pFile,
" output [%d:0] z;\n", nBits+Log2-1 );
894 for ( i = 0; i < nArgs; i++ )
896 fprintf( pFile,
" wire [%d:0] t%d = {", nBits-1, i );
897 for ( k = 0; k < nBits; k++ )
898 fprintf( pFile,
" i%0*d_%0*d%s", nDigits, i, nDigits, nBits-1-k, k==nBits-1 ?
"":
"," );
899 fprintf( pFile,
" };\n" );
901 for ( i = 0; i < nArgs-1; i++ )
902 fprintf( pFile,
" wire [%d:0] s%d = t%d + %s%d;\n", nBits+Log2-1, i+1, i+1, i ?
"s":
"t", i );
903 fprintf( pFile,
" assign z = s%d;\n", nArgs-1 );
904 fprintf( pFile,
"endmodule\n\n" );
908 FILE * pFile = fopen( pFileName,
"w" );
909 fprintf( pFile,
"// %d-argument %d-bit adder-tree generated by ABC on %s\n", nArgs, nBits,
Extra_TimeStamp() );
952 pNew->
pName = Abc_UtilStrsav(
"booth" );
953 for ( i = 0; i < 5; i++ )
954 Gia_ManAppendCi(pNew);
956 Gia_ManAppendCo(pNew, iLit);
1019 int nWidth = nArgN + nArgM + 1;
1020 int Length = (nArgM + 1) / 2;
1023 Vec_Int_t * vPPs = Vec_IntAlloc( nWidth * (Length + 1) );
1024 Vec_Int_t * vArgN = Vec_IntAlloc( nArgN + 2 );
1025 Vec_Int_t * vArgM = Vec_IntAlloc( nArgM + 2 );
1026 int * pArgN = Vec_IntArray( vArgN );
1027 int * pArgM = Vec_IntArray( vArgM );
1031 pNew->
pName = Abc_UtilStrsav(
"booth" );
1033 Vec_IntPush( vArgN, 0 );
1034 for ( i = 0; i < nArgN; i++ )
1035 Vec_IntPush( vArgN, Gia_ManAppendCi(pNew) );
1036 Vec_IntPush( vArgN, Vec_IntEntryLast(vArgN) );
1038 Vec_IntPush( vArgM, 0 );
1039 for ( i = 0; i < nArgM; i++ )
1040 Vec_IntPush( vArgM, Gia_ManAppendCi(pNew) );
1041 Vec_IntPush( vArgM, Vec_IntEntryLast(vArgM) );
1043 for ( i = 0; i < nWidth; i++ )
1044 Vec_IntPush( vPPs, (i%2 == 0 && i/2 < Length) ? pArgM[i+2] : 0 );
1047 for ( k = 0; k < 2*Length; k += 2 )
1049 for ( i = 0; i < k; i++ )
1050 Vec_IntPush( vPPs, 0 );
1051 for ( i = 0; i <= nArgN; i++ )
1054 Vec_IntPush( vPPs, Abc_LitNotCond( iLit, k > 0 && i == nArgN ) );
1056 iLit = Vec_IntEntryLast(vPPs);
1057 Vec_IntPush( vPPs, k > 0 ? 1 : iLit );
1058 for ( i = k+nArgN+2; i < nWidth; i++ )
1059 Vec_IntPush( vPPs, (k > 0 || i > k+nArgN+2) ? 0 : Abc_LitNot(iLit) );
1063 for ( k = 0; k <= Length; k++ )
1064 for ( i = 0; i < nArgN+nArgM; i++ )
1065 Gia_ManAppendCo( pNew, Vec_IntEntry(vPPs, k*(nArgN+nArgM+1) + i) );
1066 Vec_IntFree( vPPs );
1067 Vec_IntFree( vArgN );
1068 Vec_IntFree( vArgM );
1098 int i, nNodes = Mini_AigNodeNum(
p);
1099 int nDigits = Abc_Base10Log( nVars );
1100 int nDigits2 = Abc_Base10Log( 2*nVars );
1101 int nDigits3 = Abc_Base10Log( nNodes );
1103 fprintf( pFile,
".names pp%0*d\n", nDigits3, 0 );
1104 for ( i = 1; i < nNodes; i++ )
1106 if ( Mini_AigNodeIsPi(
p, i ) )
1108 if ( i > 0 && i <= nVars )
1109 fprintf( pFile,
".names a%0*d pp%0*d\n1 1\n", nDigits, i-1, nDigits3, i );
1110 else if ( i > nVars && i <= 2*nVars )
1111 fprintf( pFile,
".names b%0*d pp%0*d\n1 1\n", nDigits, i-1-nVars, nDigits3, i );
1114 else if ( Mini_AigNodeIsPo(
p, i ) )
1116 int Lit = Mini_AigNodeFanin0(
p, i );
1117 fprintf( pFile,
".names pp%0*d y%0*d_%0*d\n%d 1\n", nDigits3, Abc_Lit2Var(Lit), nDigits, nOut/(2*nVars), nDigits2, nOut%(2*nVars), !Abc_LitIsCompl(Lit) );
1120 else if ( Mini_AigNodeIsAnd(
p, i ) )
1122 int Lit0 = Mini_AigNodeFanin0(
p, i );
1123 int Lit1 = Mini_AigNodeFanin1(
p, i );
1124 fprintf( pFile,
".names pp%0*d pp%0*d pp%0*d\n%d%d 1\n",
1125 nDigits3, Abc_Lit2Var(Lit0), nDigits3, Abc_Lit2Var(Lit1), nDigits3, i, !Abc_LitIsCompl(Lit0), !Abc_LitIsCompl(Lit1) );
1133 int i, k, nDigits = Abc_Base10Log( nVars ), nDigits2 = Abc_Base10Log( 2*nVars );
1134 int Length = 1+(nVars + 1)/2;
1137 fprintf( pFile,
".model Multi%d\n", nVars );
1139 fprintf( pFile,
".inputs" );
1140 for ( i = 0; i < nVars; i++ )
1141 fprintf( pFile,
" a%0*d", nDigits, i );
1142 for ( i = 0; i < nVars; i++ )
1143 fprintf( pFile,
" b%0*d", nDigits, i );
1144 fprintf( pFile,
"\n" );
1146 fprintf( pFile,
".outputs" );
1147 for ( i = 0; i < 2*nVars; i++ )
1148 fprintf( pFile,
" m%0*d", nDigits2, i );
1149 fprintf( pFile,
"\n" );
1153 for ( i = 0; i < 2*nVars; i++ )
1154 fprintf( pFile,
".names x%0*d_%0*d\n", nDigits, 0, nDigits2, i );
1155 for ( k = 0; k < Length; k++ )
1157 fprintf( pFile,
".subckt ADD%d", 2*nVars );
1158 for ( i = 0; i < 2*nVars; i++ )
1159 fprintf( pFile,
" a%0*d=x%0*d_%0*d", nDigits2, i, nDigits, k, nDigits2, i );
1160 for ( i = 0; i < 2*nVars; i++ )
1161 fprintf( pFile,
" b%0*d=y%0*d_%0*d", nDigits2, i, nDigits, k, nDigits2, i );
1162 for ( i = 0; i <= 2*nVars; i++ )
1163 fprintf( pFile,
" s%0*d=x%0*d_%0*d", nDigits2, i, nDigits, k+1, nDigits2, i );
1164 fprintf( pFile,
"\n" );
1166 for ( i = 0; i < 2 * nVars; i++ )
1167 fprintf( pFile,
".names x%0*d_%0*d m%0*d\n1 1\n", nDigits, k, nDigits2, i, nDigits2, i );
1168 fprintf( pFile,
".end\n" );
1169 fprintf( pFile,
"\n" );
1176 pFile = fopen( pFileName,
"w" );
1177 fprintf( pFile,
"# %d-bit signed Booth multiplier generated by ABC on %s\n", nVars,
Extra_TimeStamp() );
1197 int i, a, b, w, nDigitsIn,
nWords = Abc_TruthWordNum( nPis*(nPis-1)/2 );
1199 unsigned char M[10][10] = {{0}}, C[100][2] = {{0}}, nVars = 0;
1201 for ( a = 0; a < nPis; a++ )
1202 for ( b = a+1; b < nPis; b++ )
1203 C[nVars][0] = a, C[nVars][1] = b, nVars++;
1204 for ( i = 0; i < (1<<nVars); i++ )
1207 for ( w = 0; w < nVars; w++ )
1208 M[C[w][0]][C[w][1]] =
M[C[w][1]][C[w][0]] = (i >> w) & 1;
1209 while ( fChanges && !
M[0][1] ) {
1211 for ( a = 0; a < nPis; a++ )
1212 for ( b = 0; b < nPis; b++ )
1214 for ( w = 0; w < nPis; w++ )
1215 if (
M[b][w] && !
M[a][w] )
1216 M[a][w] = 1, fChanges = 1;
1219 Abc_InfoSetBit(pTruth, i);
1221 pFile = fopen( pFileName,
"w" );
1222 fprintf( pFile,
"# Function with %d inputs generated by ABC on %s\n", nVars,
Extra_TimeStamp() );
1223 fprintf( pFile,
".model fun%d\n", nVars );
1224 fprintf( pFile,
".inputs" );
1225 nDigitsIn = Abc_Base10Log( nVars );
1226 for ( i = 0; i < nVars; i++ )
1227 fprintf( pFile,
" i%0*d", nDigitsIn, i );
1228 fprintf( pFile,
"\n" );
1229 fprintf( pFile,
".outputs f\n" );
1230 fprintf( pFile,
".names" );
1231 nDigitsIn = Abc_Base10Log( nVars );
1232 for ( b = nVars-1; b >= 0; b-- )
1233 fprintf( pFile,
" i%0*d", nDigitsIn, b );
1234 fprintf( pFile,
" f\n" );
1235 for ( i = 0; i < (1<<nVars); i++ )
1236 if ( Abc_InfoHasBit(pTruth, i) )
1238 for ( b = nVars-1; b >= 0; b-- )
1239 fprintf( pFile,
"%d", (i>>b)&1 );
1240 fprintf( pFile,
" 1\n" );
1242 fprintf( pFile,
".end\n" );
1243 fprintf( pFile,
"\n" );
1261 fprintf( pFile,
".model C63a\n" );
1262 fprintf( pFile,
".inputs x0 x1 x2 x3 x4 x5\n" );
1263 fprintf( pFile,
".outputs z0 z1 z2\n" );
1264 fprintf( pFile,
".names x1 x2 x3 x0 n10\n" );
1265 fprintf( pFile,
"--00 1\n" );
1266 fprintf( pFile,
"-0-0 1\n" );
1267 fprintf( pFile,
"0--0 1\n" );
1268 fprintf( pFile,
"000- 1\n" );
1269 fprintf( pFile,
".names x4 x5 n13 n10 z0\n" );
1270 fprintf( pFile,
"--00 1\n" );
1271 fprintf( pFile,
"-1-0 1\n" );
1272 fprintf( pFile,
"1--0 1\n" );
1273 fprintf( pFile,
"111- 1\n" );
1274 fprintf( pFile,
".names x1 x2 x3 x0 n13\n" );
1275 fprintf( pFile,
"-110 1\n" );
1276 fprintf( pFile,
"1-10 1\n" );
1277 fprintf( pFile,
"11-0 1\n" );
1278 fprintf( pFile,
"-001 1\n" );
1279 fprintf( pFile,
"0-01 1\n" );
1280 fprintf( pFile,
"00-1 1\n" );
1281 fprintf( pFile,
".names x4 x5 n13 n16 z1\n" );
1282 fprintf( pFile,
"1-00 1\n" );
1283 fprintf( pFile,
"0-10 1\n" );
1284 fprintf( pFile,
"-101 1\n" );
1285 fprintf( pFile,
"-011 1\n" );
1286 fprintf( pFile,
".names x1 x2 x3 x4 n16\n" );
1287 fprintf( pFile,
"1000 1\n" );
1288 fprintf( pFile,
"0100 1\n" );
1289 fprintf( pFile,
"0010 1\n" );
1290 fprintf( pFile,
"1110 1\n" );
1291 fprintf( pFile,
"0001 1\n" );
1292 fprintf( pFile,
"1101 1\n" );
1293 fprintf( pFile,
"1011 1\n" );
1294 fprintf( pFile,
"0111 1\n" );
1295 fprintf( pFile,
".names x5 n16 z2\n" );
1296 fprintf( pFile,
"10 1\n" );
1297 fprintf( pFile,
"01 1\n" );
1298 fprintf( pFile,
".end\n\n" );
1302 fprintf( pFile,
".model C63a\n" );
1303 fprintf( pFile,
".inputs x0 x1 x2 x3 x4 x5\n" );
1304 fprintf( pFile,
".outputs z0 z1 z2\n" );
1305 fprintf( pFile,
".names x1 x2 x3 x4 x5 x0 z0\n" );
1306 fprintf( pFile,
"---111 1\n" );
1307 fprintf( pFile,
"--1-11 1\n" );
1308 fprintf( pFile,
"--11-1 1\n" );
1309 fprintf( pFile,
"-1--11 1\n" );
1310 fprintf( pFile,
"-1-1-1 1\n" );
1311 fprintf( pFile,
"-11--1 1\n" );
1312 fprintf( pFile,
"-1111- 1\n" );
1313 fprintf( pFile,
"1---11 1\n" );
1314 fprintf( pFile,
"1--1-1 1\n" );
1315 fprintf( pFile,
"1-1--1 1\n" );
1316 fprintf( pFile,
"1-111- 1\n" );
1317 fprintf( pFile,
"11---1 1\n" );
1318 fprintf( pFile,
"11-11- 1\n" );
1319 fprintf( pFile,
"111-1- 1\n" );
1320 fprintf( pFile,
"1111-- 1\n" );
1321 fprintf( pFile,
".names x1 x2 x3 x4 x5 x0 z1\n" );
1322 fprintf( pFile,
"-00001 1\n" );
1323 fprintf( pFile,
"-00110 1\n" );
1324 fprintf( pFile,
"-01010 1\n" );
1325 fprintf( pFile,
"-01100 1\n" );
1326 fprintf( pFile,
"-10010 1\n" );
1327 fprintf( pFile,
"-10100 1\n" );
1328 fprintf( pFile,
"-11000 1\n" );
1329 fprintf( pFile,
"-11111 1\n" );
1330 fprintf( pFile,
"0-0001 1\n" );
1331 fprintf( pFile,
"0-0110 1\n" );
1332 fprintf( pFile,
"0-1010 1\n" );
1333 fprintf( pFile,
"0-1100 1\n" );
1334 fprintf( pFile,
"00-001 1\n" );
1335 fprintf( pFile,
"00-110 1\n" );
1336 fprintf( pFile,
"000-01 1\n" );
1337 fprintf( pFile,
"0000-1 1\n" );
1338 fprintf( pFile,
"1-0010 1\n" );
1339 fprintf( pFile,
"1-0100 1\n" );
1340 fprintf( pFile,
"1-1000 1\n" );
1341 fprintf( pFile,
"1-1111 1\n" );
1342 fprintf( pFile,
"11-000 1\n" );
1343 fprintf( pFile,
"11-111 1\n" );
1344 fprintf( pFile,
"111-11 1\n" );
1345 fprintf( pFile,
"1111-1 1\n" );
1346 fprintf( pFile,
".names x1 x2 x3 x4 x5 z2\n" );
1347 fprintf( pFile,
"00001 1\n" );
1348 fprintf( pFile,
"00010 1\n" );
1349 fprintf( pFile,
"00100 1\n" );
1350 fprintf( pFile,
"00111 1\n" );
1351 fprintf( pFile,
"01000 1\n" );
1352 fprintf( pFile,
"01011 1\n" );
1353 fprintf( pFile,
"01101 1\n" );
1354 fprintf( pFile,
"01110 1\n" );
1355 fprintf( pFile,
"10000 1\n" );
1356 fprintf( pFile,
"10011 1\n" );
1357 fprintf( pFile,
"10101 1\n" );
1358 fprintf( pFile,
"10110 1\n" );
1359 fprintf( pFile,
"11001 1\n" );
1360 fprintf( pFile,
"11010 1\n" );
1361 fprintf( pFile,
"11100 1\n" );
1362 fprintf( pFile,
"11111 1\n" );
1363 fprintf( pFile,
".end\n\n" );
1368 fprintf( pFile,
".model A%02d_4x\n", nBits );
1369 for ( n = 0; n < 4; n++ ) {
1370 fprintf( pFile,
".inputs" );
1371 for ( i = 0; i < nBits; i++ )
1372 fprintf( pFile,
" %c%02d",
'a'+n, i );
1373 fprintf( pFile,
"\n" );
1375 fprintf( pFile,
".outputs" );
1376 for ( i = 0; i < nBits; i++ )
1377 fprintf( pFile,
" s%02d", i );
1378 fprintf( pFile,
"\n" );
1379 fprintf( pFile,
".names v00\n" );
1380 fprintf( pFile,
".names w00\n" );
1381 for ( i = 0; i < nBits; i++ ) {
1382 fprintf( pFile,
".subckt C63a" );
1383 fprintf( pFile,
" x0=w%02d", i );
1384 fprintf( pFile,
" x1=v%02d", i );
1385 fprintf( pFile,
" x2=a%02d", i );
1386 fprintf( pFile,
" x3=b%02d", i );
1387 fprintf( pFile,
" x4=c%02d", i );
1388 fprintf( pFile,
" x5=d%02d", i );
1389 fprintf( pFile,
" z0=w%02d", i+1 );
1390 fprintf( pFile,
" z1=v%02d", i+1 );
1391 fprintf( pFile,
" z2=s%02d", i );
1392 fprintf( pFile,
"\n" );
1394 fprintf( pFile,
".end\n\n" );
1395 if ( nLutSize == 4 )
1397 else if ( nLutSize == 6 )
1405 fprintf( pFile,
".model A%02d\n", nVars );
1406 fprintf( pFile,
".inputs c\n" );
1407 fprintf( pFile,
".inputs" );
1408 for ( i = 0; i < nVars; i++ )
1409 fprintf( pFile,
" a%02d", i );
1410 fprintf( pFile,
"\n" );
1411 fprintf( pFile,
".inputs" );
1412 for ( i = 0; i < nVars; i++ )
1413 fprintf( pFile,
" b%02d", i );
1414 fprintf( pFile,
"\n" );
1415 fprintf( pFile,
".outputs" );
1416 for ( i = 0; i <= nVars; i++ )
1417 fprintf( pFile,
" s%02d", i );
1418 fprintf( pFile,
"\n" );
1419 fprintf( pFile,
".names c t00\n1 1\n" );
1420 for ( i = 0; i < nVars; i++ )
1421 fprintf( pFile,
".subckt FA a=a%02d b=b%02d cin=t%02d s=s%02d cout=t%02d\n", i, i, i, i, i+1 );
1422 fprintf( pFile,
".names t%02d s%02d\n1 1\n", nVars, nVars );
1423 fprintf( pFile,
".end\n\n" );
1429 fprintf( pFile,
".model A%02d_4x\n", nBits );
1430 for ( n = 0; n < 4; n++ ) {
1431 fprintf( pFile,
".inputs" );
1432 for ( i = 0; i < nBits; i++ )
1433 fprintf( pFile,
" %c%02d",
'a'+n, i );
1434 fprintf( pFile,
"\n" );
1436 fprintf( pFile,
".outputs" );
1437 for ( i = 0; i < nBits; i++ )
1438 fprintf( pFile,
" o%02d", i );
1439 fprintf( pFile,
"\n" );
1441 fprintf( pFile,
".names zero\n" );
1442 fprintf( pFile,
".subckt A%02d c=zero", nBits );
1443 fprintf( pFile,
" \\\n" );
1444 for ( i = 0; i < nBits; i++ )
1445 fprintf( pFile,
" a%0d=a%02d", i, i );
1446 fprintf( pFile,
" \\\n" );
1447 for ( i = 0; i < nBits; i++ )
1448 fprintf( pFile,
" b%0d=b%02d", i, i );
1449 fprintf( pFile,
" \\\n" );
1450 for ( i = 0; i <= nBits; i++ )
1451 fprintf( pFile,
" s%0d=t%02d", i, i );
1452 fprintf( pFile,
"\n" );
1454 fprintf( pFile,
".subckt A%02d c=zero", nBits );
1455 fprintf( pFile,
" \\\n" );
1456 for ( i = 0; i < nBits; i++ )
1457 fprintf( pFile,
" a%0d=c%02d", i, i );
1458 fprintf( pFile,
" \\\n" );
1459 for ( i = 0; i < nBits; i++ )
1460 fprintf( pFile,
" b%0d=t%02d", i, i );
1461 fprintf( pFile,
" \\\n" );
1462 for ( i = 0; i <= nBits; i++ )
1463 fprintf( pFile,
" s%0d=u%02d", i, i );
1464 fprintf( pFile,
"\n" );
1466 fprintf( pFile,
".subckt A%02d c=zero", nBits );
1467 fprintf( pFile,
" \\\n" );
1468 for ( i = 0; i < nBits; i++ )
1469 fprintf( pFile,
" a%0d=d%02d", i, i );
1470 fprintf( pFile,
" \\\n" );
1471 for ( i = 0; i < nBits; i++ )
1472 fprintf( pFile,
" b%0d=u%02d", i, i );
1473 fprintf( pFile,
" \\\n" );
1474 for ( i = 0; i <= nBits; i++ )
1475 fprintf( pFile,
" s%0d=o%02d", i, i );
1476 fprintf( pFile,
"\n" );
1478 fprintf( pFile,
".end\n\n" );
1484 fprintf( pFile,
".model W%02d\n", Num );
1485 fprintf( pFile,
".inputs i\n" );
1486 fprintf( pFile,
".outputs" );
1487 for ( i = 0; i < nBits; i++ )
1488 fprintf( pFile,
" o%02d", i );
1489 fprintf( pFile,
"\n" );
1490 for ( i = 0; i < nBits; i++ )
1491 if ( (Weight >> i) & 1 )
1492 fprintf( pFile,
".names i o%02d\n1 1\n", i );
1494 fprintf( pFile,
".names o%02d\n", i );
1495 fprintf( pFile,
".end\n\n" );
1502 assert( pTree[iPos] ==
'(' );
1503 while ( pTree[++iPos] ) {
1504 if ( pTree[iPos] ==
'(' ) {
1505 if ( Counter++ == 1 ) {
1507 vRes = Vec_IntAlloc( 4 );
1508 Vec_IntPush( vRes, iPos );
1511 if ( pTree[iPos] ==
')' )
1519int Abc_GenTree_rec( FILE * pFile,
int nBits,
char * pTree,
int iPos,
int * pSig,
int * pUsed )
1522 if ( vGroups == NULL )
1523 return atoi(pTree+iPos+1);
1527 Vec_IntWriteEntry( vGroups, g, Group );
1529 if ( Vec_IntSize(vGroups) == 3 )
1530 Vec_IntPush(vGroups, 0);
1531 if ( Vec_IntSize(vGroups) == 4 )
1532 fprintf( pFile,
".subckt A%02d_4x", nBits ), *pUsed = 1;
1533 else if ( Vec_IntSize(vGroups) == 2 )
1534 fprintf( pFile,
".subckt A%02d c=zero", nBits );
1537 fprintf( pFile,
" \\\n" );
1538 for ( i = 0; i < nBits; i++ )
1539 fprintf( pFile,
" %c%02d=%02d_%02d",
'a'+g, i, Group, i );
1541 fprintf( pFile,
" \\\n" );
1542 for ( i = 0; i < nBits; i++ )
1543 fprintf( pFile,
" s%02d=%02d_%02d", i, *pSig, i );
1544 fprintf( pFile,
"\n\n" );
1549 if ( A > B )
ABC_SWAP(
int, A, B );
int i;
1550 fprintf( pFile,
".subckt A%02d c=%s", nBits, fOne ?
"one" :
"zero" );
1551 fprintf( pFile,
" \\\n" );
1552 for ( i = 0; i < nBits; i++ )
1553 fprintf( pFile,
" a%02d=%02d_%02d", i, A, i );
1554 fprintf( pFile,
" \\\n" );
1555 for ( i = 0; i < nBits; i++ )
1556 fprintf( pFile,
" b%02d=%02d_%02d", i, B, i );
1557 fprintf( pFile,
" \\\n" );
1558 for ( i = 0; i <= nBits; i++ )
1559 fprintf( pFile,
" s%02d=%02d_%02d", i, S, i );
1560 fprintf( pFile,
"\n" );
1564 FILE * pFile = fopen( pFileName,
"w" );
1565 int c, i, k, Temp, iPrev = 1, nNums = 1, nSigs = 1, fUsed = 0;
1566 fprintf( pFile,
"# %d-bit threshold function with %d variables generated by ABC on %s\n",
1568 fprintf( pFile,
"# Weights:" );
1570 fprintf( pFile,
" %d", Temp );
1571 fprintf( pFile,
"\n# Threshold: %d\n", Vec_IntEntryLast(vNums) );
1572 fprintf( pFile,
".model TF%d_%d\n", Vec_IntSize(vNums)-1, nBits );
1573 fprintf( pFile,
".inputs" );
1574 for ( i = 0; i < Vec_IntSize(vNums)-1; i++ )
1575 fprintf( pFile,
" x%02d", i );
1576 fprintf( pFile,
"\n" );
1577 fprintf( pFile,
".outputs F\n" );
1578 for ( i = 0; i < nBits; i++ )
1579 fprintf( pFile,
".names %02d_%02d\n", 0, i );
1580 fprintf( pFile,
".names zero\n" );
1581 fprintf( pFile,
".names one\n 1\n" );
1583 fprintf( pFile,
".subckt W%02d", k );
1584 if ( k < Vec_IntSize(vNums)-1 )
1585 fprintf( pFile,
" i=x%02d", k );
1587 fprintf( pFile,
" i=one" );
1588 for ( i = 0; i < nBits; i++ )
1589 fprintf( pFile,
" o%02d=%02d_%02d", i, nSigs, i );
1590 fprintf( pFile,
"\n" );
1593 fprintf( pFile,
"\n" );
1594 if ( pArch == NULL )
1600 fprintf( pFile,
".names %02d_%02d F\n0 1\n", iPrev, nBits-1 );
1604 Vec_Str_t * vArch = Vec_StrAlloc( 100 );
1605 for ( c = 0; c <
strlen(pArch); c++ ) {
1606 if ( pArch[c] ==
'(' || pArch[c] ==
')' ) {
1607 Vec_StrPush( vArch, pArch[c] );
1610 Temp = pArch[c] >=
'0' && pArch[c] <=
'9' ? pArch[c] -
'0' : pArch[c] -
'A' + 10;
1613 if ( nNums + Temp == Vec_IntSize(vNums) )
1620 assert( nNums + Temp <= Vec_IntSize(vNums) );
1621 if ( nNums + Temp == Vec_IntSize(vNums) )
1624 for ( k = 1; k < Temp; k++ ) {
1628 fprintf( pFile,
"\n" );
1630 Vec_StrPrintF( vArch,
"(%d)", iPrev );
1632 Vec_StrPush( vArch,
'\0' );
1633 Temp =
Abc_GenTree_rec( pFile, nBits, Vec_StrArray(vArch), 0, &nSigs, &fUsed );
1634 fprintf( pFile,
".names %02d_%02d F\n0 1\n", Temp, nBits-1 );
1635 Vec_StrFree( vArch );
1637 fprintf( pFile,
".end\n\n" );
1639 Abc_WriteWeight( pFile, k, nBits, k == Vec_IntSize(vNums)-1 ? ~Temp : Temp );
1665 fprintf( pFile,
".model MDFA\n" );
1666 fprintf( pFile,
".inputs z x1 y1 x2 y2\n" );
1667 fprintf( pFile,
".outputs s c1 c2\n" );
1668 fprintf( pFile,
".names x1 z g1\n" );
1669 fprintf( pFile,
"10 1\n" );
1670 fprintf( pFile,
"01 1\n" );
1671 fprintf( pFile,
".names y1 g1 g2\n" );
1672 fprintf( pFile,
"00 0\n" );
1673 fprintf( pFile,
".names y1 z g3\n" );
1674 fprintf( pFile,
"10 1\n" );
1675 fprintf( pFile,
"01 1\n" );
1676 fprintf( pFile,
".names g2 g3 g4\n" );
1677 fprintf( pFile,
"10 1\n" );
1678 fprintf( pFile,
"01 1\n" );
1679 fprintf( pFile,
".names x2 g3 g5\n" );
1680 fprintf( pFile,
"10 1\n" );
1681 fprintf( pFile,
"01 1\n" );
1682 fprintf( pFile,
".names g3 y2 g6\n" );
1683 fprintf( pFile,
"10 1\n" );
1684 fprintf( pFile,
"01 1\n" );
1685 fprintf( pFile,
".names g5 y2 g7\n" );
1686 fprintf( pFile,
"10 1\n" );
1687 fprintf( pFile,
".names g2 g7 g8\n" );
1688 fprintf( pFile,
"10 1\n" );
1689 fprintf( pFile,
"01 1\n" );
1690 fprintf( pFile,
".names g6 s\n" );
1691 fprintf( pFile,
"1 1\n" );
1692 fprintf( pFile,
".names g4 c1\n" );
1693 fprintf( pFile,
"1 1\n" );
1694 fprintf( pFile,
".names g8 c2\n" );
1695 fprintf( pFile,
"1 1\n" );
1696 fprintf( pFile,
".end\n" );
1701 word Sum = 0;
int i, k, Num, nBits = 0;
1703 Sum += ((
word)1 << i) * Num;
1707 Vec_Int_t * vTemp;
int nFAs = 0, nHAs = 0, nItem = 0;
1708 Vec_Wec_t * vItems = Vec_WecStart( nBits );
1710 for ( k = 0; k < Num; k++ )
1711 Vec_WecPush( vItems, i, nItem++ );
1713 FILE * pFile = fopen( pFileName,
"w" );
1714 fprintf( pFile,
"# %d-bit %d-input adder tree generated by ABC on %s\n", nBits, nItem,
Extra_TimeStamp() );
1715 fprintf( pFile,
"# Profile:" );
1717 fprintf( pFile,
" %d", Num );
1718 fprintf( pFile,
"\n" );
1720 fprintf( pFile,
".model AT%d_%d\n", nItem, nBits );
1722 if ( Vec_IntSize(vTemp) == 0 )
1724 fprintf( pFile,
".inputs" );
1726 fprintf( pFile,
" %02d", Num );
1727 fprintf( pFile,
"\n" );
1729 fprintf( pFile,
".outputs" );
1730 for ( k = 0; k < nBits; k++ )
1731 fprintf( pFile,
" o%02d", k );
1732 fprintf( pFile,
"\n\n" );
1734 assert( nItem == Vec_IntSum(vNums) );
1736 fprintf( pFile,
"# Rank %d:\n", i );
1738 if ( Vec_IntSize(vTemp) < 2 )
1740 while ( Vec_IntSize(vTemp) > 2 ) {
1741 int i1 = Vec_IntPop(vTemp);
1742 int i2 = Vec_IntPop(vTemp);
1743 int i3 = Vec_IntPop(vTemp);
1746 fprintf( pFile,
".subckt FA a=%02d b=%02d cin=%02d s=%02d cout=%02d\n", i3, i2, i1, i4, i5 ); nFAs++;
1747 Vec_IntPush( vTemp, i4 );
1748 if ( i+1 < Vec_WecSize(vItems) )
1749 Vec_WecPush( vItems, i+1, i5 );
1751 if ( Vec_IntSize(vTemp) == 2 ) {
1752 int i1 = Vec_IntPop(vTemp);
1753 int i2 = Vec_IntPop(vTemp);
1756 fprintf( pFile,
".subckt HA a=%02d b=%02d s=%02d cout=%02d\n", i2, i1, i4, i5 ); nHAs++;
1757 Vec_IntPush( vTemp, i4 );
1758 if ( i+1 < Vec_WecSize(vItems) )
1759 Vec_WecPush( vItems, i+1, i5 );
1761 assert( Vec_IntSize(vTemp) == 1 );
1765 if ( Vec_IntSize(vTemp) == 0 )
1766 fprintf( pFile,
".names o%02d\n", i );
1767 else if ( Vec_IntSize(vTemp) == 1 )
1768 fprintf( pFile,
".names %02d o%02d\n1 1\n", Vec_IntEntry(vTemp, 0), i );
1770 fprintf( pFile,
".end\n\n" );
1773 printf(
"Created %d-bit %d-input AT with %d FAs and %d HAs.\n", nBits, Vec_IntSum(vNums), nFAs, nHAs );
1775 Vec_WecFree( vItems );
1779 word Sum = 0;
int i, k, Num, nBits = 0, Iter = 0, fUsed = 0;
1781 Sum += ((
word)1 << i) * Num;
1785 Vec_Int_t * vTemp;
int nFAs = 0, nHAs = 0, nXors = 0, nItem = 1;
1786 Vec_Wec_t * vItems = Vec_WecStart( nBits );
1788 for ( k = 0; k < Num; k++ )
1789 Vec_WecPush( vItems, i, nItem++ );
1791 FILE * pFile = fopen( pFileName,
"w" );
1792 fprintf( pFile,
"# %d-bit %d-input adder tree generated by ABC on %s\n", nBits, Vec_IntSum(vNums),
Extra_TimeStamp() );
1793 fprintf( pFile,
"# Profile:" );
1795 fprintf( pFile,
" %d", Num );
1796 fprintf( pFile,
"\n" );
1798 fprintf( pFile,
".model AT%d_%d\n", nItem, nBits );
1800 if ( Vec_IntSize(vTemp) == 0 )
1802 fprintf( pFile,
".inputs" );
1804 fprintf( pFile,
" %02d", Num );
1805 fprintf( pFile,
"\n" );
1807 fprintf( pFile,
".outputs" );
1808 for ( k = 0; k < nBits; k++ )
1809 fprintf( pFile,
" o%02d", k );
1810 fprintf( pFile,
"\n\n" );
1812 fprintf( pFile,
".names %02d\n", 0 );
1813 while ( Vec_WecMaxLevelSize(vItems) > 2 )
1815 fprintf( pFile,
"# Iter %d:\n", Iter++ );
1816 Vec_Wec_t * vItems2 = Vec_WecStart( nBits );
1818 while ( Vec_IntSize(vTemp) > 3 ) {
1819 int i0 = Vec_IntEntry(vTemp, 0); Vec_IntDrop(vTemp, 0);
1820 int i1 = Vec_IntEntry(vTemp, 0); Vec_IntDrop(vTemp, 0);
1821 int i2 = Vec_IntEntry(vTemp, 0); Vec_IntDrop(vTemp, 0);
1822 int i3 = Vec_IntEntry(vTemp, 0); Vec_IntDrop(vTemp, 0);
1823 int i4 = (Vec_IntSize(vTemp) > 0 && Vec_IntEntryLast(vTemp) > 0) ? Vec_IntPop(vTemp) : 0;
1824 assert( (i0 < 0) == (i1 < 0) );
1825 assert( (i2 < 0) == (i3 < 0) );
1827 fprintf( pFile,
".names %02d %02d %02d\n01 1\n10 1\n", i0, i1, nItem ), i1 = nItem++, nXors++;
1831 fprintf( pFile,
".names %02d %02d %02d\n01 1\n10 1\n", i2, i3, nItem ), i3 = nItem++, nXors++;
1837 fprintf( pFile,
".subckt MDFA z=%02d x1=%02d y1=%02d x2=%02d y2=%02d s=%02d c1=%02d c2=%02d\n", i4, i0, i1, i2, i3, o0, o1, o2 ); nFAs += 2, fUsed = 1;
1838 Vec_WecPush( vItems2, i, o0 );
1839 if ( i+1 < Vec_WecSize(vItems2) ) {
1840 Vec_WecPush( vItems2, i+1, -o1 );
1841 Vec_WecPush( vItems2, i+1, -o2 );
1844 if ( Vec_IntSize(vTemp) == 3 ) {
1845 int i2 = Vec_IntPop(vTemp);
1846 int i1 = Vec_IntPop(vTemp);
1847 int i0 = Vec_IntPop(vTemp);
1848 assert( (i0 < 0) == (i1 < 0) );
1851 fprintf( pFile,
".names %02d %02d %02d\n01 1\n10 1\n", -i0, -i1, nItem ), i0 = -i0, i1 = nItem++, nXors++;
1854 fprintf( pFile,
".subckt FA a=%02d b=%02d cin=%02d s=%02d cout=%02d\n", i0, i1, i2, o0, o1 ); nFAs++;
1855 Vec_WecPush( vItems2, i, o0 );
1856 if ( i+1 < Vec_WecSize(vItems2) )
1857 Vec_WecPush( vItems2, i+1, o1 );
1859 if ( Vec_IntSize(vTemp) == 2 ) {
1860 int i1 = Vec_IntPop(vTemp);
1861 int i0 = Vec_IntPop(vTemp);
1862 assert( (i0 < 0) == (i1 < 0) );
1864 Vec_IntInsert( Vec_WecEntry(vItems2, i), 0, i1 );
1865 Vec_IntInsert( Vec_WecEntry(vItems2, i), 0, i0 );
1868 Vec_WecPush( vItems2, i, i0 );
1869 Vec_WecPush( vItems2, i, i1 );
1872 if ( Vec_IntSize(vTemp) == 1 ) {
1873 int i0 = Vec_IntPop(vTemp);
1875 Vec_WecPush( vItems2, i, i0 );
1877 assert( Vec_IntSize(vTemp) == 0 );
1879 Vec_WecFree( vItems );
1883 if ( Vec_IntSize(vTemp) == 2 ) {
1884 int i1 = Vec_IntPop(vTemp);
1885 int i0 = Vec_IntPop(vTemp);
1886 assert( (i0 < 0) == (i1 < 0) );
1888 fprintf( pFile,
".names %02d %02d %02d\n01 1\n10 1\n", -i0, -i1, nItem ), i0 = -i0, i1 = nItem++, nXors++;
1889 Vec_IntPush( vTemp, i0 );
1890 Vec_IntPush( vTemp, i1 );
1892 if ( Vec_IntSize(vTemp) == 1 ) {
1893 int i0 = Vec_IntPop(vTemp);
1895 Vec_IntPush( vTemp, i0 );
1896 Vec_IntPush( vTemp, 0 );
1898 if ( Vec_IntSize(vTemp) == 0 ) {
1899 Vec_IntPush( vTemp, 0 );
1900 Vec_IntPush( vTemp, 0 );
1902 assert( Vec_IntSize(vTemp) == 2 );
1906 int i1 = Vec_IntPop(vTemp);
1907 int i0 = Vec_IntPop(vTemp);
1908 assert( i0 >= 0 && i1 >= 0 );
1909 fprintf( pFile,
".subckt FA a=%02d b=%02d cin=%02d s=o%02d cout=%02d\n", i0, i1, cin, i, nItem ); nFAs++;
1912 fprintf( pFile,
".end\n\n" );
1916 printf(
"Created %d-bit %d-input AT with %d FAs, %d HAs, and %d XORs.\n", nBits, Vec_IntSum(vNums), nFAs, nHAs, nXors );
1918 Vec_WecFree( vItems );
void Abc_WriteCell(FILE *pFile)
Vec_Int_t * Abc_GenTreeFindGroups(char *pTree, int iPos)
ABC_NAMESPACE_IMPL_START void Abc_WriteHalfAdder(FILE *pFile)
DECLARATIONS ///.
void Abc_GenFsmCond(Vec_Str_t *vCond, int nPis, int Prob)
Mini_Aig_t * Abc_GenSignedBoothMini(int nArgN, int nArgM)
Gia_Man_t * Abc_GenSignedBoothPPTest(int nArgA, int nArgB)
void Abc_WriteBooth(FILE *pFile, int nVars)
void Abc_GenOneHotIntervals(char *pFileName, int nPis, int nRegs, Vec_Ptr_t *vOnehots)
void Abc_GenGraph(char *pFileName, int nPis)
int Abc_GenSignedBoothPP(Gia_Man_t *p, int a, int b, int c, int d, int e)
void Abc_GenComp63a4(FILE *pFile)
void Abc_GenAdder4test(FILE *pFile, int nBits)
void Abc_GenFpga(char *pFileName, int nLutSize, int nLuts, int nVars)
void Abc_WriteAdder2(FILE *pFile, int nVars)
void Abc_GenMesh(char *pFileName, int nVars)
void Abc_GenAdder(char *pFileName, int nVars)
void Abc_GenAT(char *pFileName, Vec_Int_t *vNums)
void Abc_GenThresh(char *pFileName, int nBits, Vec_Int_t *vNums, int nLutSize, char *pArch)
void Abc_GenComp63a6(FILE *pFile)
void Abc_GenOneHot(char *pFileName, int nVars)
void Abc_GenSorter(char *pFileName, int nVars)
void Abc_WriteBoothPartialProducts(FILE *pFile, int nVars)
void Abc_WriteFullAdder(FILE *pFile)
void Abc_GenFsm(char *pFileName, int nPis, int nPos, int nStates, int nLines, int ProbI, int ProbO)
void Abc_AdderTree(FILE *pFile, int nArgs, int nBits)
void Abc_WriteKLut(FILE *pFile, int nLutSize)
void Abc_WriteMulti(FILE *pFile, int nVars)
void Abc_WriteLayer(FILE *pFile, int nVars, int fSkip1)
int Abc_GenTree_rec(FILE *pFile, int nBits, char *pTree, int iPos, int *pSig, int *pUsed)
void Abc_GenBooth(char *pFileName, int nVars)
void Abc_GenThreshAdder(FILE *pFile, int nBits, int A, int B, int S, int fOne)
void Abc_GenATDual(char *pFileName, Vec_Int_t *vNums)
void Abc_GenAdder4(FILE *pFile, int nBits, int nLutSize)
void Abc_GenMulti(char *pFileName, int nVars)
void Abc_WriteWeight(FILE *pFile, int Num, int nBits, int Weight)
void Abc_WriteComp(FILE *pFile)
void Abc_WriteMDFA(FILE *pFile)
Gia_Man_t * Abc_GenSignedBooth(int nArgN, int nArgM)
void Abc_GenAdderTree(char *pFileName, int nArgs, int nBits)
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_START void Abc_GenRandom(char *pFileName, int nPis)
void Abc_WriteAdder(FILE *pFile, int nVars)
#define ABC_SWAP(Type, a, b)
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
unsigned Aig_ManRandom(int fReset)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
Mini_Aig_t * Gia_ManToMiniAig(Gia_Man_t *pGia)
void Gia_ManStop(Gia_Man_t *p)
void Gia_ManHashAlloc(Gia_Man_t *p)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
struct Gia_Man_t_ Gia_Man_t
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
void Gia_ManHashStop(Gia_Man_t *p)
unsigned __int64 word
DECLARATIONS ///.
word M(word f1, word f2, int n)
struct Mini_Aig_t_ Mini_Aig_t
BASIC TYPES ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStop(vVec, Entry, i, Stop)
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.