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.
28 /* Main header file for the V-bit tester */
30 #include <stdint.h> // uint64_t
31 #include "libvex.h" // IROp
32 #include "vbits.h" // vbits_t
35 /* How undefinedness propagates from input to output */
38 // For any undefined input bit, all output bits are defined.
41 // For any undefined input bit, all output bits are undefined.
44 // For each undefined input bit, the corresponding output bit
45 // in the same position is undefined. No other bit is undefined.
48 // For each undefined input bit, the corresponding output bit
49 // in the same position is undefined. No other bit is undefined.
50 // If the corresponding output bit does not exist, the input bit
51 // does not cause any output bits to be undefined.
54 // For each undefined input bit, the corresponding output bit
55 // in the same position is undefined. No other bit is undefined.
56 // Output bits that do no not have a corresponding input bit are
60 // For each undefined input bit, the corresponding output bit
61 // in the same position is undefined. If the MSB of the input value
62 // is undefined, so are all output bits with higher significance
63 // than the MSB input bit.
66 // For each undefined input bit, the corresponding output bit
67 // and all output bits with higher significance are undefined.
70 UNDEF_CONCAT
, // nHLto2n ops e.g. Iop_32HLto64
71 UNDEF_UPPER
, // 2nHIton ops e.g. Iop_64HIto32
72 UNDEF_SHL
, // shift-left
73 UNDEF_SHR
, // logical shift-right
74 UNDEF_SAR
, // arithmetic shift-right
75 UNDEF_OR
, // bitwise OR operation
76 UNDEF_AND
, // bitwise AND operation
78 UNDEF_ORD
, // Iop_CmpORD compare
80 // Expensive (exact) integer EQ and NE
83 // Expensive (exact) integer addition and subtraction
87 /* For each of the following UNDEF_ALL_BxE, E is the number of
88 * elements and B is the number of bits in the element.
90 * If any bits in one of the E elements is not defined, then the
91 * return value has all bits in the corresponding element set to 1.
93 UNDEF_ALL_64x2
, // 128-bit vector, two 64-bit elements
94 UNDEF_ALL_32x4
, // 128-bit vector, four 32-bit elements
95 UNDEF_ALL_16x8
, // 128-bit vector, eight 16-bit elements
96 UNDEF_ALL_8x16
, // 128-bit vector, sixteen 8-bit elements
98 /* For each of the following UNDEF_ALL_BxE_EVEN, E is the number of
99 * elements and B is the number of bits in the element. Elements are
100 * numbered from right to left starting with element number 0.
102 * If any bits in one of the even numbered elements is not defined, then
103 * the return value has all bits in the corresponding element set to 1.
104 * The bits in the odd numbered elements are not checked
106 UNDEF_ALL_32x4_EVEN
, // 128-bit vector, four 32-bit elements
107 UNDEF_ALL_16x8_EVEN
, // 128-bit vector, eight 16-bit elements
108 UNDEF_ALL_8x16_EVEN
, // 128-bit vector, sixteen 8-bit elements
110 /* For each of the following UNDEF_BxE_TRANSPOSE, E is the number of
111 * elements and B is the number of bits in the element.
113 * Concatenate bit i from each byte j. Place concatenated 8 bit value
114 * into byte i of the result. Do for each bit i from 0 to 7 and
115 * byte j from 0 to 7 of each 64-bit element.
117 UNDEF_64x2_TRANSPOSE
,
119 /* For each of the following UNDEF_BxE_ROTATE, E is the number of
120 * elements and B is the number of bits in the element.
122 * The result is the undefined bits in each element rotated by the
123 * specified amount. Bits rotated out of the element are discarded.
124 * No additional bits are set to undefined.
126 UNDEF_64x2_ROTATE
, /* 128-bit vector, two 64-bit elements, rotate
129 UNDEF_32x4_ROTATE
, /* 128-bit vector, four 32-bit elements, rotate
132 UNDEF_16x8_ROTATE
, /* 128-bit vector, eight 16-bit elements, rotate
135 UNDEF_8x16_ROTATE
, /* 128-bit vector, sixteen 8-bit elements, rotate
139 /* If the input had some vbits set, the result will have one or more
140 * vbits set. Minimal test when the vbit propagation can not be easily
145 /* For UNDEF_NARROW256_AtoB, narrow the elements of size A-bits in
146 * the 256-bit source (stored in two 128-bit values) to a 128-bit
147 * result with elements of size B-bits.
149 * If the source element will fit into the corresponding destination
150 * element, then only the undefined bits in the source element are
151 * undefined in the corresponding bit position of the destination element.
153 * If the source element will not fit into the destination element, then
154 * only the lower B undefined bits of the source element will be
155 * undefined in the corresponding result element unless the saturate
156 * flag is true. If the saturate flag is true and the element in the
157 * source will not fit into the corresponding destination element, then
158 * all of the bits in the corresponding destination element are set to one.
160 UNDEF_NARROW256_AtoB
,
171 // For IROps I don't know anything about
176 // Everything we want to know about an IROp
181 /* The following two members describe if this operand has immediate
182 * operands. There are a few restrictions:
183 * (1) An operator can have at most one immediate operand.
184 * (2) If there is an immediate operand, it is the right-most operand.
185 * An immediate_index of 0 means there is no immediate operand.
187 unsigned immediate_index
;
188 unsigned immediate_type
;
190 // Indicate whether IROp can be tested on a particular architecture
203 /* The maximum number of input operands */
204 #define MAX_OPERANDS 4
206 /* An operand of an IROp (also used for the result) */
214 /* Carries the data needed to execute and evaluate a test. I.e.
215 inputs and results (V-bits and actual value). */
218 opnd_t opnds
[MAX_OPERANDS
];
219 unsigned rounding_mode
;
223 /* Function prototypes */
224 irop_t
*get_irop(IROp
);
225 int is_floating_point_op_with_rounding_mode(IROp
);
226 int get_num_operands(IROp
);
228 void print_opnd(FILE *, const opnd_t
*);
230 int test_unary_op(const irop_t
*, test_data_t
*);
231 int test_binary_op(const irop_t
*, test_data_t
*);
232 int test_ternary_op(const irop_t
*, test_data_t
*);
233 int test_qernary_op(const irop_t
*, test_data_t
*);
235 void valgrind_vex_init_for_iri(IRICB
*);
236 void valgrind_execute_test(const irop_t
*, test_data_t
*);
238 IRICB
new_iricb(const irop_t
*, test_data_t
*);
240 void panic(const char *) __attribute__((noreturn
));
241 void complain(const irop_t
*, const test_data_t
*, vbits_t expected
);
243 /* Imported from VEX */
244 unsigned sizeof_irtype(IRType
);
245 void typeof_primop(IROp
, IRType
*t_dst
, IRType
*t_arg1
, IRType
*t_arg2
,
246 IRType
*t_arg3
, IRType
*t_arg4
);
248 static __inline__
unsigned bitsof_irtype(IRType type
)
250 return type
== Ity_I1
? 1 : sizeof_irtype(type
) * 8;
254 /* Exported variables */