3 /* Drive the bit test routines */
7 calc (const char *call
,
12 if (strcmp (call
, "MASK") == 0)
13 return MASKED (val
, row
, col
);
14 if (strcmp (call
, "MASK8") == 0)
15 return MASKED8 (val
, row
, col
);
16 if (strcmp (call
, "MASK16") == 0)
17 return MASKED16 (val
, row
, col
);
18 if (strcmp (call
, "MASK32") == 0)
19 return MASKED32 (val
, row
, col
);
20 if (strcmp (call
, "MASK64") == 0)
21 return MASKED64 (val
, row
, col
);
23 if (strcmp (call
, "EXTRACT") == 0)
24 return EXTRACTED (val
, row
, col
);
25 if (strcmp (call
, "EXTRACT8") == 0)
26 return EXTRACTED8 (val
, row
, col
);
27 if (strcmp (call
, "EXTRACT16") == 0)
28 return EXTRACTED16 (val
, row
, col
);
29 if (strcmp (call
, "EXTRACT32") == 0)
30 return EXTRACTED32 (val
, row
, col
);
31 if (strcmp (call
, "EXTRACT64") == 0)
32 return EXTRACTED64 (val
, row
, col
);
34 if (strcmp (call
, "LSEXTRACT") == 0)
35 return LSEXTRACTED (val
, row
, col
);
36 if (strcmp (call
, "LSEXTRACT8") == 0)
37 return LSEXTRACTED8 (val
, row
, col
);
38 if (strcmp (call
, "LSEXTRACT16") == 0)
39 return LSEXTRACTED16 (val
, row
, col
);
40 if (strcmp (call
, "LSEXTRACT32") == 0)
41 return LSEXTRACTED32 (val
, row
, col
);
42 if (strcmp (call
, "LSEXTRACT64") == 0)
43 return LSEXTRACTED64 (val
, row
, col
);
45 if (strcmp (call
, "MSEXTRACT") == 0)
46 return MSEXTRACTED (val
, row
, col
);
47 if (strcmp (call
, "MSEXTRACT8") == 0)
48 return MSEXTRACTED8 (val
, row
, col
);
49 if (strcmp (call
, "MSEXTRACT16") == 0)
50 return MSEXTRACTED16 (val
, row
, col
);
51 if (strcmp (call
, "MSEXTRACT32") == 0)
52 return MSEXTRACTED32 (val
, row
, col
);
53 if (strcmp (call
, "MSEXTRACT64") == 0)
54 return MSEXTRACTED64 (val
, row
, col
);
56 if (strcmp (call
, "INSERT") == 0)
57 return INSERTED (val
, row
, col
);
58 if (strcmp (call
, "INSERT8") == 0)
59 return INSERTED8 (val
, row
, col
);
60 if (strcmp (call
, "INSERT16") == 0)
61 return INSERTED16 (val
, row
, col
);
62 if (strcmp (call
, "INSERT32") == 0)
63 return INSERTED32 (val
, row
, col
);
64 if (strcmp (call
, "INSERT64") == 0)
65 return INSERTED64 (val
, row
, col
);
67 if (strcmp (call
, "LSINSERT") == 0)
68 return LSINSERTED (val
, row
, col
);
69 if (strcmp (call
, "LSINSERT8") == 0)
70 return LSINSERTED8 (val
, row
, col
);
71 if (strcmp (call
, "LSINSERT16") == 0)
72 return LSINSERTED16 (val
, row
, col
);
73 if (strcmp (call
, "LSINSERT32") == 0)
74 return LSINSERTED32 (val
, row
, col
);
75 if (strcmp (call
, "LSINSERT64") == 0)
76 return LSINSERTED64 (val
, row
, col
);
78 if (strcmp (call
, "MSINSERT") == 0)
79 return MSINSERTED (val
, row
, col
);
80 if (strcmp (call
, "MSINSERT8") == 0)
81 return MSINSERTED8 (val
, row
, col
);
82 if (strcmp (call
, "MSINSERT16") == 0)
83 return MSINSERTED16 (val
, row
, col
);
84 if (strcmp (call
, "MSINSERT32") == 0)
85 return MSINSERTED32 (val
, row
, col
);
86 if (strcmp (call
, "MSINSERT64") == 0)
87 return MSINSERTED64 (val
, row
, col
);
89 if (strcmp (call
, "MSMASK") == 0)
90 return MSMASKED (val
, row
, col
);
91 if (strcmp (call
, "MSMASK8") == 0)
92 return MSMASKED8 (val
, row
, col
);
93 if (strcmp (call
, "MSMASK16") == 0)
94 return MSMASKED16 (val
, row
, col
);
95 if (strcmp (call
, "MSMASK32") == 0)
96 return MSMASKED32 (val
, row
, col
);
97 if (strcmp (call
, "MSMASK64") == 0)
98 return MSMASKED64 (val
, row
, col
);
100 if (strcmp (call
, "LSMASK") == 0)
101 return LSMASKED (val
, row
, col
);
102 if (strcmp (call
, "LSMASK8") == 0)
103 return LSMASKED8 (val
, row
, col
);
104 if (strcmp (call
, "LSMASK16") == 0)
105 return LSMASKED16 (val
, row
, col
);
106 if (strcmp (call
, "LSMASK32") == 0)
107 return LSMASKED32 (val
, row
, col
);
108 if (strcmp (call
, "LSMASK64") == 0)
109 return LSMASKED64 (val
, row
, col
);
111 if (strcmp (call
, "ROT64") == 0)
112 return ROT64 (val
, col
);
113 if (strcmp (call
, "ROT8") == 0)
114 return ROT8 (val
, col
);
115 if (strcmp (call
, "ROT16") == 0)
116 return ROT16 (val
, col
);
117 if (strcmp (call
, "ROT32") == 0)
118 return ROT32 (val
, col
);
120 if (strcmp (call
, "SEXT") == 0)
121 return SEXT (val
, col
);
122 if (strcmp (call
, "SEXT8") == 0)
123 return SEXT8 (val
, col
);
124 if (strcmp (call
, "SEXT16") == 0)
125 return SEXT16 (val
, col
);
126 if (strcmp (call
, "SEXT32") == 0)
127 return SEXT32 (val
, col
);
128 if (strcmp (call
, "SEXT64") == 0)
129 return SEXT64 (val
, col
);
131 if (strcmp (call
, "LSSEXT") == 0)
132 return LSSEXT (val
, col
);
133 if (strcmp (call
, "LSSEXT8") == 0)
134 return LSSEXT8 (val
, col
);
135 if (strcmp (call
, "LSSEXT16") == 0)
136 return LSSEXT16 (val
, col
);
137 if (strcmp (call
, "LSSEXT32") == 0)
138 return LSSEXT32 (val
, col
);
139 if (strcmp (call
, "LSSEXT64") == 0)
140 return LSSEXT64 (val
, col
);
142 if (strcmp (call
, "MSSEXT8") == 0)
143 return MSSEXT8 (val
, col
);
144 if (strcmp (call
, "MSSEXT16") == 0)
145 return MSSEXT16 (val
, col
);
146 if (strcmp (call
, "MSSEXT32") == 0)
147 return MSSEXT32 (val
, col
);
148 if (strcmp (call
, "MSSEXT64") == 0)
149 return MSSEXT64 (val
, col
);
150 if (strcmp (call
, "MSSEXT") == 0)
151 return MSSEXT (val
, col
);
156 "Unknown call passed to calc (%s, 0x%08lx%08lx, %d, %d)\n",
157 call
, (long)(val
>> 32), (long)val
, row
, col
);
165 check_sext (int nr_bits
,
169 const char *msmasked
)
173 for (col
= 0; col
< nr_bits
; col
++)
175 long long mask
= calc (masked
, -1, col
, col
);
176 long long msmask
= calc (msmasked
, -1,
177 0, (msb_nr
? nr_bits
- col
- 1 : col
));
178 long long sext
= calc (sexted
, mask
, -1, col
);
179 long long mask_1
= mask
>> 1;
180 long long sext_1
= calc (sexted
, mask_1
, -1, col
);
181 long long mask_0
= (mask
<< 1) | mask_1
;
182 long long sext_0
= calc (sexted
, mask_0
, -1, col
);
183 if (sext_0
!= mask_1
)
186 "%s:%d: ", __FILE__
, __LINE__
);
188 " %s(0x%08lx%08lx,%d) == 0x%08lx%08lx wrong, != 0x%08lx%08lx\n",
189 sexted
, (long)(mask_0
>> 32), (long)mask_0
, col
,
190 (long)(sext_0
>> 32), (long)sext_0
,
191 (long)(mask_1
>> 32), (long)mask_1
);
194 if (sext_1
!= mask_1
)
197 "%s:%d: ", __FILE__
, __LINE__
);
199 " %s(0x%08lx%08lx,%d) == 0x%08lx%08lx wrong, != 0x%08lx%08lx\n",
200 sexted
, (long)(mask_1
>> 32), (long)mask_1
, col
,
201 (long)(sext_1
>> 32), (long)sext_1
,
202 (long)(mask_1
>> 32), (long)mask_1
);
208 "%s:%d: ", __FILE__
, __LINE__
);
210 " %s(0x%08lx%08lx,%d) == 0x%08lx%08lx wrong, != 0x%08lx%08lx (%s(%d,%d))\n",
211 sexted
, (long)(mask
>> 32), (long)mask
, col
,
212 (long)(sext
>> 32), (long)sext
,
213 (long)(msmask
>> 32), (long)msmask
,
214 msmasked
, 0, (msb_nr
? nr_bits
- col
- 1 : col
));
224 check_rot (int nr_bits
,
231 for (row
= 0; row
< nr_bits
; row
++)
232 for (col
= 0; col
< nr_bits
; col
++)
233 if ((WITH_TARGET_WORD_MSB
== 0 && row
<= col
)
234 || (WITH_TARGET_WORD_MSB
!= 0 && row
>= col
))
236 long long mask
= calc (masked
, -1, row
, col
);
238 for (shift
= -nr_bits
+ 1; shift
< nr_bits
; shift
++)
240 long long rot
= calc (roted
, mask
, -1, shift
);
241 long long urot
= calc (roted
, rot
, -1, -shift
);
243 || (shift
== 0 && rot
!= mask
)
244 || (shift
!= 0 && rot
== mask
&& abs(row
- col
) != (nr_bits
- 1)))
246 fprintf (stderr
, "%s:%d: ", __FILE__
, __LINE__
);
247 fprintf (stderr
, " %s(%s(0x%08lx%08lx,%d) == 0x%08lx%08lx, %d) failed\n",
249 (long)(mask
>> 32), (long)mask
, shift
,
250 (long)(urot
>> 32), (long)urot
, -shift
);
260 check_extract (int nr_bits
,
261 const char *extracted
,
262 const char *inserted
,
268 for (row
= 0; row
< nr_bits
; row
++)
269 for (col
= 0; col
< nr_bits
; col
++)
270 if ((WITH_TARGET_WORD_MSB
== 0 && row
<= col
)
271 || (WITH_TARGET_WORD_MSB
!= 0 && row
>= col
))
273 long long mask
= calc (masked
, -1, row
, col
);
274 long long extr
= calc (extracted
, mask
, row
, col
);
275 long long inst
= calc (inserted
, extr
, row
, col
);
278 fprintf (stderr
, "%s:%d: ", __FILE__
, __LINE__
);
279 fprintf (stderr
, " %s(%d,%d)=0x%08lx%08lx -> %s=0x%08lx%08lx -> %s=0x%08lx%08lx failed\n",
280 masked
, row
, col
, (long)(mask
>> 32), (long)mask
,
281 extracted
, (long)(extr
>> 32), (long)extr
,
282 inserted
, (long)(inst
>> 32), (long)inst
);
291 check_bits (int call
,
297 while (*tests
!= NULL
)
299 int nr_rows
= (*tests
)->nr_rows
;
300 int nr_cols
= (*tests
)->nr_cols
;
301 test_tuples
*tuples
= (*tests
)->tuples
;
302 for (r
= 0; r
< nr_rows
; r
++)
303 for (c
= 0; c
< nr_cols
; c
++)
305 int i
= r
* nr_rows
+ c
;
306 test_tuples
*tuple
= &tuples
[i
];
309 long long val
= (!call
? tuple
->val
: calc ((*tests
)->macro
, -1,
310 tuple
->row
, tuple
->col
));
311 long long check
= tuple
->check
;
314 fprintf (stderr
, "%s:%d:", (*tests
)->file
, tuple
->line
);
315 fprintf (stderr
, " %s", (*tests
)->macro
);
317 fprintf (stderr
, " (%d, %d)", tuple
->row
, tuple
->col
);
319 fprintf (stderr
, " (%d)", tuple
->col
);
320 fprintf (stderr
, " == 0x%08lx%08lx wrong, != 0x%08lx%08lx\n",
321 (long) (val
>> 32), (long) val
,
322 (long) (check
>> 32), (long) check
);
341 #if defined (DO_BIT_TESTS)
342 printf ("Checking BIT*\n");
343 errors
+= check_bits (0, bit_tests
);
347 #if defined (DO_MASK_TESTS)
348 printf ("Checking MASK*\n");
349 errors
+= check_bits (0, mask_tests
);
351 printf ("Checking MASKED*\n");
352 errors
+= check_bits (1, mask_tests
);
356 #if defined (DO_LSMASK_TESTS)
357 printf ("Checking LSMASK*\n");
358 errors
+= check_bits (0, lsmask_tests
);
360 printf ("Checking LSMASKED*\n");
361 errors
+= check_bits (1, lsmask_tests
);
365 #if defined (DO_MSMASK_TESTS)
366 printf ("Checking MSMASK*\n");
367 errors
+= check_bits (0, msmask_tests
);
369 printf ("Checking MSMASKED*\n");
370 errors
+= check_bits (1, msmask_tests
);
374 printf ("Checking EXTRACTED*\n");
375 errors
+= check_extract ( 8, "EXTRACT8", "INSERT8", "MASK8");
376 errors
+= check_extract (16, "EXTRACT16", "INSERT16", "MASK16");
377 errors
+= check_extract (32, "EXTRACT32", "INSERT32", "MASK32");
378 errors
+= check_extract (64, "EXTRACT64", "INSERT64", "MASK64");
379 errors
+= check_extract (64, "EXTRACT", "INSERT", "MASK");
381 printf ("Checking SEXT*\n");
382 errors
+= check_sext ( 8, WITH_TARGET_WORD_MSB
, "SEXT8", "MASK8", "MSMASK8");
383 errors
+= check_sext (16, WITH_TARGET_WORD_MSB
, "SEXT16", "MASK16", "MSMASK16");
384 errors
+= check_sext (32, WITH_TARGET_WORD_MSB
, "SEXT32", "MASK32", "MSMASK32");
385 errors
+= check_sext (64, WITH_TARGET_WORD_MSB
, "SEXT64", "MASK64", "MSMASK64");
386 errors
+= check_sext (64, WITH_TARGET_WORD_MSB
, "SEXT", "MASK", "MSMASK");
388 printf ("Checking LSSEXT*\n");
389 errors
+= check_sext ( 8, 8 - 1, "LSSEXT8", "LSMASK8", "MSMASK8");
390 errors
+= check_sext (16, 16 - 1, "LSSEXT16", "LSMASK16", "MSMASK16");
391 errors
+= check_sext (32, 32 - 1, "LSSEXT32", "LSMASK32", "MSMASK32");
392 errors
+= check_sext (64, 64 - 1, "LSSEXT64", "LSMASK64", "MSMASK64");
393 errors
+= check_sext (64, WITH_TARGET_WORD_BITSIZE
- 1, "LSSEXT", "LSMASK", "MSMASK");
395 printf ("Checking MSSEXT*\n");
396 errors
+= check_sext (8, 0, "MSSEXT8", "MSMASK8", "MSMASK8");
397 errors
+= check_sext (16, 0, "MSSEXT16", "MSMASK16", "MSMASK16");
398 errors
+= check_sext (32, 0, "MSSEXT32", "MSMASK32", "MSMASK32");
399 errors
+= check_sext (64, 0, "MSSEXT64", "MSMASK64", "MSMASK64");
400 errors
+= check_sext (64, 0, "MSSEXT", "MSMASK", "MSMASK");
402 printf ("Checking ROT*\n");
403 errors
+= check_rot (16, "ROT16", "MASK16");
404 errors
+= check_rot (32, "ROT32", "MASK32");
405 errors
+= check_rot (64, "ROT64", "MASK64");
This page took 0.039149 seconds and 4 git commands to generate.