Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / vbit-test / qernary.c
blob3e719110bcfccf8b869cc6c81311f6d8203d029e
1 /* -*- mode: C; c-basic-offset: 3; -*- */
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.
25 #include <assert.h>
26 #include "vtest.h"
29 /* Check the result of a quarternary operation. */
30 static void
31 check_result_for_qernary(const irop_t *op, const test_data_t *data)
33 const opnd_t *result = &data->result;
34 const opnd_t *opnd1 = &data->opnds[0];
35 const opnd_t *opnd2 = &data->opnds[1];
36 const opnd_t *opnd3 = &data->opnds[2];
37 const opnd_t *opnd4 = &data->opnds[3];
38 vbits_t expected_vbits;
40 /* Only handle those undef-kinds that actually occur. */
41 switch (op->undef_kind) {
42 case UNDEF_ALL:
43 expected_vbits = undefined_vbits(result->vbits.num_bits);
44 break;
46 case UNDEF_SAME:
47 // SAME with respect to the 1-bits in all operands
48 expected_vbits = or_vbits(or_vbits(or_vbits(opnd1->vbits, opnd2->vbits),
49 opnd3->vbits), opnd4->vbits);
50 break;
52 default:
53 panic(__func__);
56 if (! equal_vbits(result->vbits, expected_vbits))
57 complain(op, data, expected_vbits);
61 int
62 test_qernary_op(const irop_t *op, test_data_t *data)
64 unsigned num_input_bits, i, bitpos;
65 opnd_t *opnds = data->opnds;
66 int tests_done = 0;
68 /* Immediate operands are currently not supported here */
69 assert(op->immediate_index == 0);
71 /* For each operand, set a single bit to undefined and observe how
72 that propagates to the output. Do this for all bits in each
73 operand. */
74 for (i = 0; i < 4; ++i) {
75 num_input_bits = bitsof_irtype(opnds[i].type);
77 opnds[0].vbits = defined_vbits(bitsof_irtype(opnds[0].type));
78 opnds[1].vbits = defined_vbits(bitsof_irtype(opnds[1].type));
79 opnds[2].vbits = defined_vbits(bitsof_irtype(opnds[2].type));
80 opnds[3].vbits = defined_vbits(bitsof_irtype(opnds[3].type));
82 for (bitpos = 0; bitpos < num_input_bits; ++bitpos) {
83 opnds[i].vbits = onehot_vbits(bitpos, bitsof_irtype(opnds[i].type));
85 valgrind_execute_test(op, data);
87 check_result_for_qernary(op, data);
89 tests_done++;
92 return tests_done;