Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / vbit-test / unary.c
blob836026597ac952cffbc0cfe9b2088e4fbce751d6
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 unary operation. */
30 static void
31 check_result_for_unary(const irop_t *op, const test_data_t *data)
33 const opnd_t *result = &data->result;
34 const opnd_t *opnd = &data->opnds[0];
35 unsigned num_bits = result->vbits.num_bits;
36 vbits_t expected_vbits;
38 /* Only handle those undef-kinds that actually occur. */
39 switch (op->undef_kind) {
40 case UNDEF_ALL:
41 expected_vbits = undefined_vbits(num_bits);
42 break;
44 case UNDEF_SAME:
45 expected_vbits = opnd->vbits;
46 break;
48 case UNDEF_TRUNC:
49 expected_vbits = truncate_vbits(opnd->vbits, num_bits);
50 break;
52 case UNDEF_LEFT:
53 expected_vbits = left_vbits(opnd->vbits, num_bits);
54 break;
56 case UNDEF_UPPER:
57 assert(num_bits * 2 == opnd->vbits.num_bits);
58 expected_vbits = upper_vbits(opnd->vbits);
59 break;
61 case UNDEF_SEXT:
62 expected_vbits = sextend_vbits(opnd->vbits, num_bits);
63 break;
65 case UNDEF_ZEXT:
66 expected_vbits = zextend_vbits(opnd->vbits, num_bits);
67 break;
69 case UNDEF_ALL_64x2:
70 assert(num_bits == 128);
71 expected_vbits = undefined_vbits_BxE(64, 2, opnd->vbits);
72 break;
74 case UNDEF_ALL_32x4:
75 assert(num_bits == 128);
76 expected_vbits = undefined_vbits_BxE(32, 4, opnd->vbits);
77 break;
79 case UNDEF_ALL_16x8:
80 assert(num_bits == 128);
81 expected_vbits = undefined_vbits_BxE(16, 8, opnd->vbits);
82 break;
84 case UNDEF_ALL_8x16:
85 assert(num_bits == 128);
86 expected_vbits = undefined_vbits_BxE(8, 16, opnd->vbits);
87 break;
89 case UNDEF_64x2_TRANSPOSE:
90 assert(num_bits == 128);
91 expected_vbits = undefined_vbits_64x2_transpose(opnd->vbits);
92 break;
94 default:
95 panic(__func__);
98 if (! equal_vbits(result->vbits, expected_vbits))
99 complain(op, data, expected_vbits);
104 test_unary_op(const irop_t *op, test_data_t *data)
106 unsigned num_input_bits, bitpos;
107 int tests_done = 0;
109 /* Immediate operands are currently not supported here */
110 assert(op->immediate_index == 0);
112 num_input_bits = bitsof_irtype(data->opnds[0].type);
114 for (bitpos = 0; bitpos < num_input_bits; ++bitpos) {
115 data->opnds[0].vbits = onehot_vbits(bitpos, num_input_bits);
117 valgrind_execute_test(op, data);
119 check_result_for_unary(op, data);
120 tests_done++;
122 return tests_done;