• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mode: C; c-basic-offset: 3; -*- */
2 
3 #include <assert.h>
4 #include "vtest.h"
5 
6 
7 /* Check the result of a ternary operation. */
8 static void
check_result_for_ternary(const irop_t * op,const test_data_t * data)9 check_result_for_ternary(const irop_t *op, const test_data_t *data)
10 {
11    const opnd_t *result = &data->result;
12    const opnd_t *opnd1  = &data->opnds[0];
13    const opnd_t *opnd2  = &data->opnds[1];
14    const opnd_t *opnd3  = &data->opnds[2];
15    vbits_t expected_vbits;
16 
17    /* Only handle those undef-kinds that actually occur. */
18    switch (op->undef_kind) {
19    case UNDEF_ALL:
20       expected_vbits = undefined_vbits(result->vbits.num_bits);
21       break;
22 
23    case UNDEF_SAME:
24       // SAME with respect to the 1-bits in all operands
25       expected_vbits = or_vbits(or_vbits(opnd1->vbits, opnd2->vbits),
26                                 opnd3->vbits);
27       break;
28 
29    default:
30       panic(__func__);
31    }
32 
33    if (! equal_vbits(result->vbits, expected_vbits))
34       complain(op, data, expected_vbits);
35 }
36 
37 
38 int
test_ternary_op(const irop_t * op,test_data_t * data)39 test_ternary_op(const irop_t *op, test_data_t *data)
40 {
41    unsigned num_input_bits, i, bitpos;
42    opnd_t *opnds = data->opnds;
43    int tests_done = 0;
44 
45    /* For each operand, set a single bit to undefined and observe how
46       that propagates to the output. Do this for all bits in each
47       operand. */
48    for (i = 0; i < 3; ++i) {
49       num_input_bits = bitsof_irtype(opnds[i].type);
50 
51       opnds[0].vbits = defined_vbits(bitsof_irtype(opnds[0].type));
52       opnds[1].vbits = defined_vbits(bitsof_irtype(opnds[1].type));
53       opnds[2].vbits = defined_vbits(bitsof_irtype(opnds[2].type));
54 
55       for (bitpos = 0; bitpos < num_input_bits; ++bitpos) {
56          opnds[i].vbits = onehot_vbits(bitpos, bitsof_irtype(opnds[i].type));
57 
58          valgrind_execute_test(op, data);
59 
60          check_result_for_ternary(op, data);
61 
62 	 tests_done++;
63       }
64    }
65    return tests_done;
66 }
67