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.
29 /* Check the result of a unary operation. */
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
) {
41 expected_vbits
= undefined_vbits(num_bits
);
45 expected_vbits
= opnd
->vbits
;
49 expected_vbits
= truncate_vbits(opnd
->vbits
, num_bits
);
53 expected_vbits
= left_vbits(opnd
->vbits
, num_bits
);
57 assert(num_bits
* 2 == opnd
->vbits
.num_bits
);
58 expected_vbits
= upper_vbits(opnd
->vbits
);
62 expected_vbits
= sextend_vbits(opnd
->vbits
, num_bits
);
66 expected_vbits
= zextend_vbits(opnd
->vbits
, num_bits
);
70 assert(num_bits
== 128);
71 expected_vbits
= undefined_vbits_BxE(64, 2, opnd
->vbits
);
75 assert(num_bits
== 128);
76 expected_vbits
= undefined_vbits_BxE(32, 4, opnd
->vbits
);
80 assert(num_bits
== 128);
81 expected_vbits
= undefined_vbits_BxE(16, 8, opnd
->vbits
);
85 assert(num_bits
== 128);
86 expected_vbits
= undefined_vbits_BxE(8, 16, opnd
->vbits
);
89 case UNDEF_64x2_TRANSPOSE
:
90 assert(num_bits
== 128);
91 expected_vbits
= undefined_vbits_64x2_transpose(opnd
->vbits
);
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
;
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
);