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