1 /* -*- mode: C; c-basic-offset: 3; -*- */
4 This file is part of MemCheck, a heavyweight Valgrind tool for
5 detecting memory errors.
7 Copyright (C) 2012-2017 Florian Krohm
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, see <http://www.gnu.org/licenses/>.
22 The GNU General Public License is contained in the file COPYING.
26 #include <string.h> // memset
30 /* A convenience function to compute either v1 & ~v2 & val2 or
31 v1 & ~v2 & ~val2 depending on INVERT_VAL2. */
33 and_combine(vbits_t v1
, vbits_t v2
, value_t val2
, int invert_val2
)
35 assert(v1
.num_bits
== v2
.num_bits
);
37 vbits_t
new = { .num_bits
= v2
.num_bits
};
40 switch (v2
.num_bits
) {
41 case 1: val2
.u32
= ~val2
.u32
& 1; break;
42 case 8: val2
.u8
= ~val2
.u8
& 0xff; break;
43 case 16: val2
.u16
= ~val2
.u16
& 0xffff; break;
44 case 32: val2
.u32
= ~val2
.u32
; break;
45 case 64: val2
.u64
= ~val2
.u64
; break;
51 switch (v2
.num_bits
) {
53 new.bits
.u32
= (v1
.bits
.u32
& ~v2
.bits
.u32
& val2
.u32
) & 1;
56 new.bits
.u8
= (v1
.bits
.u8
& ~v2
.bits
.u8
& val2
.u8
) & 0xff;
59 new.bits
.u16
= (v1
.bits
.u16
& ~v2
.bits
.u16
& val2
.u16
) & 0xffff;
62 new.bits
.u32
= (v1
.bits
.u32
& ~v2
.bits
.u32
& val2
.u32
);
65 new.bits
.u64
= (v1
.bits
.u64
& ~v2
.bits
.u64
& val2
.u64
);
73 /* Check the result of a binary operation. */
75 check_result_for_binary(const irop_t
*op
, const test_data_t
*data
)
77 const opnd_t
*result
= &data
->result
;
78 const opnd_t
*opnd1
= &data
->opnds
[0];
79 const opnd_t
*opnd2
= &data
->opnds
[1];
81 vbits_t expected_vbits
;
83 /* Only handle those undef-kinds that actually occur. */
84 switch (op
->undef_kind
) {
86 expected_vbits
= defined_vbits(result
->vbits
.num_bits
);
90 /* Iop_ShlD64, Iop_ShrD64, Iop_ShlD128, Iop_ShrD128 have
91 * one immediate operand in operand 2.
93 expected_vbits
= undefined_vbits(result
->vbits
.num_bits
);
97 // LEFT with respect to the leftmost 1-bit in both operands
98 expected_vbits
= left_vbits(or_vbits(opnd1
->vbits
, opnd2
->vbits
),
99 result
->vbits
.num_bits
);
103 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
104 assert(opnd1
->vbits
.num_bits
== result
->vbits
.num_bits
);
106 // SAME with respect to the 1-bits in both operands
107 expected_vbits
= or_vbits(opnd1
->vbits
, opnd2
->vbits
);
111 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
112 assert(result
->vbits
.num_bits
== 2 * opnd1
->vbits
.num_bits
);
113 expected_vbits
= concat_vbits(opnd1
->vbits
, opnd2
->vbits
);
117 /* If any bit in the 2nd operand is undefined, so are all bits
119 if (! completely_defined_vbits(opnd2
->vbits
)) {
120 expected_vbits
= undefined_vbits(result
->vbits
.num_bits
);
122 assert(opnd2
->vbits
.num_bits
== 8);
123 unsigned shift_amount
= opnd2
->value
.u8
;
125 expected_vbits
= shl_vbits(opnd1
->vbits
, shift_amount
);
130 /* If any bit in the 2nd operand is undefined, so are all bits
132 if (! completely_defined_vbits(opnd2
->vbits
)) {
133 expected_vbits
= undefined_vbits(result
->vbits
.num_bits
);
135 assert(opnd2
->vbits
.num_bits
== 8);
136 unsigned shift_amount
= opnd2
->value
.u8
;
138 expected_vbits
= shr_vbits(opnd1
->vbits
, shift_amount
);
143 /* If any bit in the 2nd operand is undefined, so are all bits
145 if (! completely_defined_vbits(opnd2
->vbits
)) {
146 expected_vbits
= undefined_vbits(result
->vbits
.num_bits
);
148 assert(opnd2
->vbits
.num_bits
== 8);
149 unsigned shift_amount
= opnd2
->value
.u8
;
151 expected_vbits
= sar_vbits(opnd1
->vbits
, shift_amount
);
156 /* Let v1, v2 be the V-bits of the 1st and 2nd operand, respectively
157 Let b1, b2 be the actual value of the 1st and 2nd operand, respect.
158 And output bit is undefined (i.e. its V-bit == 1), iff
159 (1) (v1 == 1) && (v2 == 1) OR
160 (2) (v1 == 1) && (v2 == 0 && b2 == 1) OR
161 (3) (v2 == 1) && (v1 == 0 && b1 == 1)
163 vbits_t term1
, term2
, term3
;
164 term1
= and_vbits(opnd1
->vbits
, opnd2
->vbits
);
165 term2
= and_combine(opnd1
->vbits
, opnd2
->vbits
, opnd2
->value
, 0);
166 term3
= and_combine(opnd2
->vbits
, opnd1
->vbits
, opnd1
->value
, 0);
167 expected_vbits
= or_vbits(term1
, or_vbits(term2
, term3
));
172 /* Let v1, v2 be the V-bits of the 1st and 2nd operand, respectively
173 Let b1, b2 be the actual value of the 1st and 2nd operand, respect.
174 And output bit is undefined (i.e. its V-bit == 1), iff
175 (1) (v1 == 1) && (v2 == 1) OR
176 (2) (v1 == 1) && (v2 == 0 && b2 == 0) OR
177 (3) (v2 == 1) && (v1 == 0 && b1 == 0)
179 vbits_t term1
, term2
, term3
;
180 term1
= and_vbits(opnd1
->vbits
, opnd2
->vbits
);
181 term2
= and_combine(opnd1
->vbits
, opnd2
->vbits
, opnd2
->value
, 1);
182 term3
= and_combine(opnd2
->vbits
, opnd1
->vbits
, opnd1
->value
, 1);
183 expected_vbits
= or_vbits(term1
, or_vbits(term2
, term3
));
188 /* Set expected_vbits for the Iop_CmpORD category of iops.
189 * If any of the input bits is undefined the least significant
190 * three bits in the result will be set, i.e. 0xe.
192 expected_vbits
= cmpord_vbits(opnd1
->vbits
.num_bits
,
193 opnd2
->vbits
.num_bits
);
196 case UNDEF_CMP_EQ_NE
:
197 expected_vbits
= cmp_eq_ne_vbits(opnd1
->vbits
, opnd2
->vbits
,
198 opnd1
->value
, opnd2
->value
);
202 expected_vbits
= int_add_or_sub_vbits(1/*isAdd*/,
203 opnd1
->vbits
, opnd2
->vbits
,
204 opnd1
->value
, opnd2
->value
);
208 expected_vbits
= int_add_or_sub_vbits(0/*!isAdd*/,
209 opnd1
->vbits
, opnd2
->vbits
,
210 opnd1
->value
, opnd2
->value
);
214 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
216 undefined_vbits_BxE(64, 2,
217 or_vbits(opnd1
->vbits
, opnd2
->vbits
));
221 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
223 undefined_vbits_BxE(32, 4,
224 or_vbits(opnd1
->vbits
, opnd2
->vbits
));
228 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
230 undefined_vbits_BxE(16, 8,
231 or_vbits(opnd1
->vbits
, opnd2
->vbits
));
235 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
237 undefined_vbits_BxE(8, 16,
238 or_vbits(opnd1
->vbits
, opnd2
->vbits
));
241 case UNDEF_ALL_32x4_EVEN
:
242 /* Only even input bytes are used, result can be twice as wide */
243 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
245 undefined_vbits_BxE(64, 2,
246 undefined_vbits_128_even_element(32, 4,
247 or_vbits(opnd1
->vbits
, opnd2
->vbits
)));
250 case UNDEF_ALL_16x8_EVEN
:
251 /* Only even input bytes are used, result can be twice as wide */
252 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
254 undefined_vbits_BxE(32, 4,
255 undefined_vbits_128_even_element(16, 8,
256 or_vbits(opnd1
->vbits
, opnd2
->vbits
)));
259 case UNDEF_ALL_8x16_EVEN
:
260 /* Only even input bytes are used, result can be twice as wide */
261 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
263 undefined_vbits_BxE(16, 8,
264 undefined_vbits_128_even_element(8, 16,
265 or_vbits(opnd1
->vbits
, opnd2
->vbits
)));
268 case UNDEF_64x2_ROTATE
:
269 /* Rotate left each element in opnd1 by the amount in the corresponding
272 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
273 /* Setup the tmp to match what the vbit tester seems to use. I can't
274 * use opnd2-value since valgrind doesn't think it has been set.
276 tmp
.value
.u128
[0] = -1;
277 tmp
.value
.u128
[1] = -1;
278 /* Calculate expected for the first operand when it is shifted.
279 * If any of the vbits are set for the shift field of the second operand
280 * then the result of the expected result for that element is all 1's.
282 expected_vbits
= or_vbits(undefined_vbits_BxE_rotate(64, 2, opnd1
->vbits
,
284 undefined_vbits_BxE(64, 2, opnd2
->vbits
));
287 case UNDEF_32x4_ROTATE
:
288 /* Rotate left each element in opnd1 by the amount in the corresponding
291 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
292 expected_vbits
= undefined_vbits_BxE_rotate(32, 4, opnd1
->vbits
,
296 case UNDEF_16x8_ROTATE
:
297 /* Rotate left each element in opnd1 by the amount in the corresponding
300 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
301 expected_vbits
= undefined_vbits_BxE_rotate(16, 8, opnd1
->vbits
,
305 case UNDEF_8x16_ROTATE
:
306 /* Rotate left each element in opnd1 by the amount in the corresponding
309 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
310 expected_vbits
= undefined_vbits_BxE_rotate(16, 8, opnd1
->vbits
,
315 /* The result for the Iop_SHA256 and Iop_SHA256 is a secure hash. If
316 * one of the input bits is not defined there must be atleast one
317 * undefined bit in the output. Which bit and how many depends on
318 * which bit is undefined. Don't know the secure hash algorithm so
319 * we can only make sure at least one of the result bits is set.
321 * The Iop_SHA256, Iop_SHA512 iops have one immediate value in the
324 expected_vbits
.num_bits
= result
->vbits
.num_bits
;
326 if ((result
->vbits
.bits
.u128
[0] != 0) ||
327 (result
->vbits
.bits
.u128
[1] != 0)) {
328 expected_vbits
.bits
.u128
[0] = result
->vbits
.bits
.u128
[0];
329 expected_vbits
.bits
.u128
[1] = result
->vbits
.bits
.u128
[1];
332 /* The input had at least one vbit set but the result doesn't have any
333 * bit set. Set them all so we will trigger the error on the call
336 expected_vbits
.bits
.u128
[0] = ~0x0ULL
;
337 expected_vbits
.bits
.u128
[1] = ~0x0ULL
;
341 case UNDEF_NARROW256_AtoB
:
342 assert(opnd1
->vbits
.num_bits
== opnd2
->vbits
.num_bits
);
344 case Iop_NarrowBin64to32x4
:
346 undefined_vbits_Narrow256_AtoB(64, 32, opnd1
->vbits
, opnd1
->value
,
347 opnd2
->vbits
, opnd2
->value
,
350 case Iop_QNarrowBin64Sto32Sx4
:
352 undefined_vbits_Narrow256_AtoB(64, 32, opnd1
->vbits
, opnd1
->value
,
353 opnd2
->vbits
, opnd2
->value
,
356 case Iop_QNarrowBin64Uto32Ux4
:
358 undefined_vbits_Narrow256_AtoB(64, 32, opnd1
->vbits
, opnd1
->value
,
359 opnd2
->vbits
, opnd2
->value
,
363 fprintf(stderr
, "ERROR, unknown Iop for UNDEF_NARROW256_AtoB\n");
367 case UNDEF_GT_S_8x16
:
368 expected_vbits
= cmp_gt_vbits(1/* is_signed */, 8 /* bits_per_element */, 16 /* element_count */,
369 opnd1
->vbits
, opnd2
->vbits
, opnd1
->value
, opnd2
->value
);
371 case UNDEF_GT_S_16x8
:
372 expected_vbits
= cmp_gt_vbits(1/* is_signed */, 16 /* bits_per_element */, 8 /* element_count */,
373 opnd1
->vbits
, opnd2
->vbits
, opnd1
->value
, opnd2
->value
);
375 case UNDEF_GT_S_32x4
:
376 expected_vbits
= cmp_gt_vbits(1/* is_signed */, 32 /* bits_per_element */, 4 /* element_count */,
377 opnd1
->vbits
, opnd2
->vbits
, opnd1
->value
, opnd2
->value
);
379 case UNDEF_GT_S_64x2
:
380 expected_vbits
= cmp_gt_vbits(1/* is_signed */, 64 /* bits_per_element */, 2 /* element_count */,
381 opnd1
->vbits
, opnd2
->vbits
, opnd1
->value
, opnd2
->value
);
383 case UNDEF_GT_U_8x16
:
384 expected_vbits
= cmp_gt_vbits(0/* is_signed */, 8 /* bits_per_element */, 16 /* element_count */,
385 opnd1
->vbits
, opnd2
->vbits
, opnd1
->value
, opnd2
->value
);
387 case UNDEF_GT_U_16x8
:
388 expected_vbits
= cmp_gt_vbits(0/* is_signed */, 16 /* bits_per_element */, 8 /* element_count */,
389 opnd1
->vbits
, opnd2
->vbits
, opnd1
->value
, opnd2
->value
);
391 case UNDEF_GT_U_32x4
:
392 expected_vbits
= cmp_gt_vbits(0/* is_signed */, 32 /* bits_per_element */, 4 /* element_count */,
393 opnd1
->vbits
, opnd2
->vbits
, opnd1
->value
, opnd2
->value
);
395 case UNDEF_GT_U_64x2
:
396 expected_vbits
= cmp_gt_vbits(0/* is_signed */, 64 /* bits_per_element */, 2 /* element_count */,
397 opnd1
->vbits
, opnd2
->vbits
, opnd1
->value
, opnd2
->value
);
404 if (! equal_vbits(result
->vbits
, expected_vbits
))
405 complain(op
, data
, expected_vbits
);
410 test_shift(const irop_t
*op
, test_data_t
*data
)
412 unsigned num_input_bits
, i
;
413 opnd_t
*opnds
= data
->opnds
;
416 /* When testing the 1st operand's undefinedness propagation,
417 do so with all possible shift amnounts */
418 for (unsigned amount
= 0; amount
< bitsof_irtype(opnds
[0].type
); ++amount
) {
419 opnds
[1].value
.u8
= amount
;
421 // 1st (left) operand
422 num_input_bits
= bitsof_irtype(opnds
[0].type
);
424 for (i
= 0; i
< num_input_bits
; ++i
) {
425 opnds
[0].vbits
= onehot_vbits(i
, bitsof_irtype(opnds
[0].type
));
426 opnds
[1].vbits
= defined_vbits(bitsof_irtype(opnds
[1].type
));
428 valgrind_execute_test(op
, data
);
430 check_result_for_binary(op
, data
);
435 // 2nd (right) operand
437 /* If the operand is an immediate value, there are no v-bits to set. */
438 if (!op
->immediate_index
) return tests_done
;
440 num_input_bits
= bitsof_irtype(opnds
[1].type
);
442 for (i
= 0; i
< num_input_bits
; ++i
) {
443 opnds
[0].vbits
= defined_vbits(bitsof_irtype(opnds
[0].type
));
444 opnds
[1].vbits
= onehot_vbits(i
, bitsof_irtype(opnds
[1].type
));
446 valgrind_execute_test(op
, data
);
448 check_result_for_binary(op
, data
);
457 all_bits_zero_value(unsigned num_bits
)
462 case 8: val
.u8
= 0; break;
463 case 16: val
.u16
= 0; break;
465 case 32: val
.u32
= 0; break;
466 case 64: val
.u64
= 0; break;
475 all_bits_one_value(unsigned num_bits
)
480 case 1: val
.u32
= 1; break;
481 case 8: val
.u8
= 0xff; break;
482 case 16: val
.u16
= 0xffff; break;
483 case 32: val
.u32
= ~0u; break;
484 case 64: val
.u64
= ~0ull; break;
493 test_and(const irop_t
*op
, test_data_t
*data
)
495 unsigned num_input_bits
, bitpos
;
496 opnd_t
*opnds
= data
->opnds
;
499 /* Undefinedness does not propagate if the other operand is 0.
500 Use an all-bits-zero operand and test the other operand in
501 the usual way (one bit undefined at a time). */
503 // 1st (left) operand variable, 2nd operand all-bits-zero
504 num_input_bits
= bitsof_irtype(opnds
[0].type
);
506 for (bitpos
= 0; bitpos
< num_input_bits
; ++bitpos
) {
507 opnds
[0].vbits
= onehot_vbits(bitpos
, bitsof_irtype(opnds
[0].type
));
508 opnds
[1].vbits
= defined_vbits(bitsof_irtype(opnds
[1].type
));
509 opnds
[1].value
= all_bits_zero_value(bitsof_irtype(opnds
[1].type
));
511 valgrind_execute_test(op
, data
);
513 check_result_for_binary(op
, data
);
517 // 2nd (right) operand variable, 1st operand all-bits-zero
518 num_input_bits
= bitsof_irtype(opnds
[1].type
);
520 for (bitpos
= 0; bitpos
< num_input_bits
; ++bitpos
) {
521 opnds
[1].vbits
= onehot_vbits(bitpos
, bitsof_irtype(opnds
[1].type
));
522 opnds
[0].vbits
= defined_vbits(bitsof_irtype(opnds
[0].type
));
523 opnds
[0].value
= all_bits_zero_value(bitsof_irtype(opnds
[0].type
));
525 valgrind_execute_test(op
, data
);
527 check_result_for_binary(op
, data
);
531 /* Undefinedness propagates if the other operand is 1.
532 Use an all-bits-one operand and test the other operand in
533 the usual way (one bit undefined at a time). */
535 // 1st (left) operand variable, 2nd operand all-bits-one
536 num_input_bits
= bitsof_irtype(opnds
[0].type
);
538 for (bitpos
= 0; bitpos
< num_input_bits
; ++bitpos
) {
539 opnds
[0].vbits
= onehot_vbits(bitpos
, bitsof_irtype(opnds
[0].type
));
540 opnds
[1].vbits
= defined_vbits(bitsof_irtype(opnds
[1].type
));
541 opnds
[1].value
= all_bits_one_value(bitsof_irtype(opnds
[1].type
));
543 valgrind_execute_test(op
, data
);
545 check_result_for_binary(op
, data
);
549 // 2nd (right) operand variable, 1st operand all-bits-one
550 num_input_bits
= bitsof_irtype(opnds
[1].type
);
552 for (bitpos
= 0; bitpos
< num_input_bits
; ++bitpos
) {
553 opnds
[1].vbits
= onehot_vbits(bitpos
, bitsof_irtype(opnds
[1].type
));
554 opnds
[0].vbits
= defined_vbits(bitsof_irtype(opnds
[0].type
));
555 opnds
[0].value
= all_bits_one_value(bitsof_irtype(opnds
[0].type
));
557 valgrind_execute_test(op
, data
);
559 check_result_for_binary(op
, data
);
567 test_or(const irop_t
*op
, test_data_t
*data
)
569 unsigned num_input_bits
, bitpos
;
570 opnd_t
*opnds
= data
->opnds
;
573 /* Undefinedness does not propagate if the other operand is 1.
574 Use an all-bits-one operand and test the other operand in
575 the usual way (one bit undefined at a time). */
577 // 1st (left) operand variable, 2nd operand all-bits-one
578 num_input_bits
= bitsof_irtype(opnds
[0].type
);
580 opnds
[0].vbits
= defined_vbits(bitsof_irtype(opnds
[0].type
));
581 opnds
[1].vbits
= defined_vbits(bitsof_irtype(opnds
[1].type
));
582 opnds
[1].value
= all_bits_one_value(bitsof_irtype(opnds
[1].type
));
584 for (bitpos
= 0; bitpos
< num_input_bits
; ++bitpos
) {
585 opnds
[0].vbits
= onehot_vbits(bitpos
, bitsof_irtype(opnds
[0].type
));
587 valgrind_execute_test(op
, data
);
589 check_result_for_binary(op
, data
);
593 // 2nd (right) operand variable, 1st operand all-bits-one
594 num_input_bits
= bitsof_irtype(opnds
[1].type
);
596 opnds
[0].vbits
= defined_vbits(bitsof_irtype(opnds
[0].type
));
597 opnds
[1].vbits
= defined_vbits(bitsof_irtype(opnds
[1].type
));
598 opnds
[0].value
= all_bits_one_value(bitsof_irtype(opnds
[0].type
));
600 for (bitpos
= 0; bitpos
< num_input_bits
; ++bitpos
) {
601 opnds
[1].vbits
= onehot_vbits(bitpos
, bitsof_irtype(opnds
[1].type
));
603 valgrind_execute_test(op
, data
);
605 check_result_for_binary(op
, data
);
609 /* Undefinedness propagates if the other operand is 0.
610 Use an all-bits-zero operand and test the other operand in
611 the usual way (one bit undefined at a time). */
613 // 1st (left) operand variable, 2nd operand all-bits-zero
614 num_input_bits
= bitsof_irtype(opnds
[0].type
);
616 opnds
[0].vbits
= defined_vbits(bitsof_irtype(opnds
[0].type
));
617 opnds
[1].vbits
= defined_vbits(bitsof_irtype(opnds
[1].type
));
618 opnds
[1].value
= all_bits_zero_value(bitsof_irtype(opnds
[1].type
));
620 for (bitpos
= 0; bitpos
< num_input_bits
; ++bitpos
) {
621 opnds
[0].vbits
= onehot_vbits(bitpos
, bitsof_irtype(opnds
[0].type
));
623 valgrind_execute_test(op
, data
);
625 check_result_for_binary(op
, data
);
629 // 2nd (right) operand variable, 1st operand all-bits-zero
630 num_input_bits
= bitsof_irtype(opnds
[1].type
);
632 opnds
[0].vbits
= defined_vbits(bitsof_irtype(opnds
[0].type
));
633 opnds
[1].vbits
= defined_vbits(bitsof_irtype(opnds
[1].type
));
634 opnds
[0].value
= all_bits_zero_value(bitsof_irtype(opnds
[0].type
));
636 for (bitpos
= 0; bitpos
< num_input_bits
; ++bitpos
) {
637 opnds
[1].vbits
= onehot_vbits(bitpos
, bitsof_irtype(opnds
[1].type
));
639 valgrind_execute_test(op
, data
);
641 check_result_for_binary(op
, data
);
649 test_binary_op(const irop_t
*op
, test_data_t
*data
)
651 unsigned num_input_bits
, i
, bitpos
;
652 opnd_t
*opnds
= data
->opnds
;
655 /* Handle special cases upfront */
656 switch (op
->undef_kind
) {
660 return test_shift(op
, data
);
663 return test_and(op
, data
);
666 return test_or(op
, data
);
672 /* For each operand, set a single bit to undefined and observe how
673 that propagates to the output. Do this for all bits in each
675 for (i
= 0; i
< 2; ++i
) {
677 /* If this is a Iop that requires an immediate amount,
678 do not iterate the v-bits of the operand */
679 if (((i
+1) == op
->immediate_index
)
680 && (op
->immediate_index
)) break;
682 num_input_bits
= bitsof_irtype(opnds
[i
].type
);
683 opnds
[0].vbits
= defined_vbits(bitsof_irtype(opnds
[0].type
));
684 opnds
[1].vbits
= defined_vbits(bitsof_irtype(opnds
[1].type
));
686 /* Set the value of the 2nd operand to something != 0. So division
688 memset(&opnds
[1].value
, 0xff, sizeof opnds
[1].value
);
690 /* For immediate shift amounts choose a value of '1'. That value should
691 not cause a problem. Note: we always assign to the u64 member here.
692 The reason is that in ir_inject.c the value_t type is not visible.
693 The value is picked up there by interpreting the memory as an
694 ULong value. So, we rely on
696 ULong v1; // value picked up in ir_inject.c
697 value_t v2; // value assigned here
699 assert(sizeof xx.v1 == sizeof xx.v2.u64);
700 assert(xx.v1 == xx.v2.u64);
703 if (op
->immediate_index
> 0) {
704 assert((op
->immediate_type
== Ity_I8
)
705 || (op
->immediate_type
== Ity_I16
)
706 || (op
->immediate_type
== Ity_I32
));
707 opnds
[1].value
.u64
= 1;
710 for (bitpos
= 0; bitpos
< num_input_bits
; ++bitpos
) {
711 opnds
[i
].vbits
= onehot_vbits(bitpos
, bitsof_irtype(opnds
[i
].type
));
713 valgrind_execute_test(op
, data
);
715 check_result_for_binary(op
, data
);