ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
rewire_tt.h
Go to the documentation of this file.
1
20
21#ifndef RAR_TT_H
22#define RAR_TT_H
23
24/*************************************************************
25 truth table manipulation
26**************************************************************/
27
28#include "base/abc/abc.h"
29
31
32// the bit count for the first 256 integer numbers
33static int Tt_BitCount8[256] = {
34 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
35 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
36 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
37 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
38 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
39 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
40 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
41 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
42
43static inline int Tt_BitCount16(int i) {
44 return Tt_BitCount8[i & 0xFF] + Tt_BitCount8[i >> 8];
45}
46
47static word ss_Truths6[6] = {
48 ABC_CONST(0xAAAAAAAAAAAAAAAA),
49 ABC_CONST(0xCCCCCCCCCCCCCCCC),
50 ABC_CONST(0xF0F0F0F0F0F0F0F0),
51 ABC_CONST(0xFF00FF00FF00FF00),
52 ABC_CONST(0xFFFF0000FFFF0000),
53 ABC_CONST(0xFFFFFFFF00000000)};
54
55static inline int Tt_HexDigitNum(int n) {
56 return n <= 2 ? 1 : 1 << (n - 2);
57}
58
59static inline void Tt_Print(word *p, int nWords) {
60 int k, Digit, nDigits = nWords * 16;
61 for (k = nDigits - 1; k >= 0; k--) {
62 Digit = (int)((p[k / 16] >> ((k % 16) * 4)) & 15);
63 if (Digit < 10)
64 printf("%d", Digit);
65 else
66 printf("%c", 'A' + Digit - 10);
67 }
68 printf("\n");
69}
70
71static inline int Tt_CountOnes(word x) {
72 x = x - ((x >> 1) & ABC_CONST(0x5555555555555555));
73 x = (x & ABC_CONST(0x3333333333333333)) + ((x >> 2) & ABC_CONST(0x3333333333333333));
74 x = (x + (x >> 4)) & ABC_CONST(0x0F0F0F0F0F0F0F0F);
75 x = x + (x >> 8);
76 x = x + (x >> 16);
77 x = x + (x >> 32);
78 return (int)(x & 0xFF);
79}
80
81static inline int Tt_CountOnes2(word x) {
82 return x ? Tt_CountOnes(x) : 0;
83}
84
85static inline int Tt_CountOnesVec(word *x, int nWords) {
86 int w, Count = 0;
87 for (w = 0; w < nWords; w++)
88 Count += Tt_CountOnes2(x[w]);
89 return Count;
90}
91
92static inline int Tt_CountOnesVecMask(word *x, word *pMask, int nWords) {
93 int w, Count = 0;
94 for (w = 0; w < nWords; w++)
95 Count += Tt_CountOnes2(pMask[w] & x[w]);
96 return Count;
97}
98
99static inline void Tt_Clear(word *pOut, int nWords) {
100 int w;
101 for (w = 0; w < nWords; w++)
102 pOut[w] = 0;
103}
104
105static inline void Tt_Fill(word *pOut, int nWords) {
106 int w;
107 for (w = 0; w < nWords; w++)
108 pOut[w] = ~(word)0;
109}
110
111static inline void Tt_Dup(word *pOut, word *pIn, int nWords) {
112 int w;
113 for (w = 0; w < nWords; w++)
114 pOut[w] = pIn[w];
115}
116
117static inline void Tt_DupC(word *pOut, word *pIn, int fC, int nWords) {
118 int w;
119 if (fC)
120 for (w = 0; w < nWords; w++)
121 pOut[w] = ~pIn[w];
122 else
123 for (w = 0; w < nWords; w++)
124 pOut[w] = pIn[w];
125}
126
127static inline void Tt_Not(word *pOut, word *pIn, int nWords) {
128 int w;
129 for (w = 0; w < nWords; w++)
130 pOut[w] = ~pIn[w];
131}
132
133static inline void Tt_And(word *pOut, word *pIn1, word *pIn2, int nWords) {
134 int w;
135 for (w = 0; w < nWords; w++)
136 pOut[w] = pIn1[w] & pIn2[w];
137}
138
139static inline void Tt_Sharp(word *pOut, word *pIn, int fC, int nWords) {
140 int w;
141 if (fC)
142 for (w = 0; w < nWords; w++)
143 pOut[w] &= ~pIn[w];
144 else
145 for (w = 0; w < nWords; w++)
146 pOut[w] &= pIn[w];
147}
148
149static inline void Tt_OrXor(word *pOut, word *pIn1, word *pIn2, int nWords) {
150 int w;
151 for (w = 0; w < nWords; w++)
152 pOut[w] |= pIn1[w] ^ pIn2[w];
153}
154
155static inline void Tt_OrXorAnd(word *pOut, word *pIn1, word *pIn2, word *pIn3, int nWords) {
156 int w;
157 for (w = 0; w < nWords; w++)
158 pOut[w] |= (pIn1[w] ^ pIn2[w]) & pIn3[w];
159}
160
161static inline int Tt_WordNum(int n) {
162 return n > 6 ? (1 << (n - 6)) : 1;
163}
164
165static inline void Tt_ElemInit(word *pTruth, int iVar, int nWords) {
166 int k;
167 if (iVar < 6)
168 for (k = 0; k < nWords; k++)
169 pTruth[k] = ss_Truths6[iVar];
170 else
171 for (k = 0; k < nWords; k++)
172 pTruth[k] = (k & (1 << (iVar - 6))) ? ~(word)0 : 0;
173}
174
175static inline int Tt_IntersectC(word *pIn1, word *pIn2, int fC, int nWords) {
176 int w;
177 if (fC) {
178 for (w = 0; w < nWords; w++)
179 if (pIn1[w] & ~pIn2[w])
180 return 1;
181 } else {
182 for (w = 0; w < nWords; w++)
183 if (pIn1[w] & pIn2[w])
184 return 1;
185 }
186 return 0;
187}
188
189static inline int Tt_Equal(word *pIn1, word *pIn2, int nWords) {
190 int w;
191 for (w = 0; w < nWords; w++)
192 if (pIn1[w] != pIn2[w])
193 return 0;
194 return 1;
195}
196
197static inline int Tt_EqualOnCare(word *pCare, word *pIn1, word *pIn2, int nWords) {
198 int w;
199 for (w = 0; w < nWords; w++)
200 if (pCare[w] & (pIn1[w] ^ pIn2[w]))
201 return 0;
202 return 1;
203}
204
205static inline int Tt_IsConst0(word *pIn, int nWords) {
206 int w;
207 for (w = 0; w < nWords; w++)
208 if (pIn[w])
209 return 0;
210 return 1;
211}
212
213static inline int Tt_IsConst1(word *pIn, int nWords) {
214 int w;
215 for (w = 0; w < nWords; w++)
216 if (pIn[w] != ~(word)0)
217 return 0;
218 return 1;
219}
220
221// read/write/flip i-th bit of a bit string table:
222static inline int Tt_GetBit(word *p, int k) {
223 return (int)(p[k >> 6] >> (k & 63)) & 1;
224}
225
226static inline void Tt_SetBit(word *p, int k) {
227 p[k >> 6] |= (((word)1) << (k & 63));
228}
229
230static inline void Tt_XorBit(word *p, int k) {
231 p[k >> 6] ^= (((word)1) << (k & 63));
232}
233
235
236#endif // RAR_TT_H
int nWords
Definition abcNpn.c:127
#define ABC_CONST(number)
PARAMETERS ///.
Definition abc_global.h:240
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Cube * p
Definition exorList.c:222
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36