florian | bb913cd | 2012-08-28 16:50:39 +0000 | [diff] [blame] | 1 | /* -*- mode: C; c-basic-offset: 3; -*- */ |
| 2 | |
florian | 5aa9d1e | 2015-09-22 07:21:50 +0000 | [diff] [blame] | 3 | /* |
| 4 | This file is part of MemCheck, a heavyweight Valgrind tool for |
| 5 | detecting memory errors. |
| 6 | |
| 7 | Copyright (C) 2012-2015 Florian Krohm |
| 8 | |
| 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. |
| 13 | |
| 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. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 22 | 02111-1307, USA. |
| 23 | |
| 24 | The GNU General Public License is contained in the file COPYING. |
| 25 | */ |
| 26 | |
florian | bb913cd | 2012-08-28 16:50:39 +0000 | [diff] [blame] | 27 | #include <assert.h> |
| 28 | #include "vtest.h" |
| 29 | |
| 30 | |
| 31 | /* Check the result of a unary operation. */ |
| 32 | static void |
| 33 | check_result_for_unary(const irop_t *op, const test_data_t *data) |
| 34 | { |
| 35 | const opnd_t *result = &data->result; |
| 36 | const opnd_t *opnd = &data->opnds[0]; |
| 37 | unsigned num_bits = result->vbits.num_bits; |
| 38 | vbits_t expected_vbits; |
| 39 | |
| 40 | /* Only handle those undef-kinds that actually occur. */ |
| 41 | switch (op->undef_kind) { |
| 42 | case UNDEF_ALL: |
| 43 | expected_vbits = undefined_vbits(num_bits); |
| 44 | break; |
| 45 | |
| 46 | case UNDEF_SAME: |
| 47 | expected_vbits = opnd->vbits; |
| 48 | break; |
| 49 | |
| 50 | case UNDEF_TRUNC: |
| 51 | expected_vbits = truncate_vbits(opnd->vbits, num_bits); |
| 52 | break; |
| 53 | |
| 54 | case UNDEF_LEFT: |
| 55 | expected_vbits = left_vbits(opnd->vbits, num_bits); |
| 56 | break; |
| 57 | |
| 58 | case UNDEF_UPPER: |
| 59 | assert(num_bits * 2 == opnd->vbits.num_bits); |
| 60 | expected_vbits = upper_vbits(opnd->vbits); |
| 61 | break; |
| 62 | |
| 63 | case UNDEF_SEXT: |
| 64 | expected_vbits = sextend_vbits(opnd->vbits, num_bits); |
| 65 | break; |
| 66 | |
| 67 | case UNDEF_ZEXT: |
| 68 | expected_vbits = zextend_vbits(opnd->vbits, num_bits); |
| 69 | break; |
| 70 | |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame^] | 71 | case UNDEF_ALL_64x2: |
| 72 | assert(num_bits == 128); |
| 73 | expected_vbits = undefined_vbits_BxE(64, 2, opnd->vbits); |
| 74 | break; |
| 75 | |
| 76 | case UNDEF_ALL_32x4: |
| 77 | assert(num_bits == 128); |
| 78 | expected_vbits = undefined_vbits_BxE(32, 4, opnd->vbits); |
| 79 | break; |
| 80 | |
| 81 | case UNDEF_ALL_16x8: |
| 82 | assert(num_bits == 128); |
| 83 | expected_vbits = undefined_vbits_BxE(16, 8, opnd->vbits); |
| 84 | break; |
| 85 | |
| 86 | case UNDEF_ALL_8x16: |
| 87 | assert(num_bits == 128); |
| 88 | expected_vbits = undefined_vbits_BxE(8, 16, opnd->vbits); |
| 89 | break; |
| 90 | |
| 91 | case UNDEF_64x2_TRANSPOSE: |
| 92 | assert(num_bits == 128); |
| 93 | expected_vbits = undefined_vbits_64x2_transpose(opnd->vbits); |
| 94 | break; |
| 95 | |
florian | bb913cd | 2012-08-28 16:50:39 +0000 | [diff] [blame] | 96 | default: |
| 97 | panic(__func__); |
| 98 | } |
| 99 | |
| 100 | if (! equal_vbits(result->vbits, expected_vbits)) |
| 101 | complain(op, data, expected_vbits); |
| 102 | } |
| 103 | |
| 104 | |
carll | 24c9e7f | 2012-11-16 19:41:21 +0000 | [diff] [blame] | 105 | int |
florian | bb913cd | 2012-08-28 16:50:39 +0000 | [diff] [blame] | 106 | test_unary_op(const irop_t *op, test_data_t *data) |
| 107 | { |
| 108 | unsigned num_input_bits, bitpos; |
carll | 24c9e7f | 2012-11-16 19:41:21 +0000 | [diff] [blame] | 109 | int tests_done = 0; |
florian | bb913cd | 2012-08-28 16:50:39 +0000 | [diff] [blame] | 110 | |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame^] | 111 | /* Immediate operands are currently not supported here */ |
| 112 | assert(op->immediate_index == 0); |
| 113 | |
florian | bb913cd | 2012-08-28 16:50:39 +0000 | [diff] [blame] | 114 | num_input_bits = bitsof_irtype(data->opnds[0].type); |
| 115 | |
| 116 | for (bitpos = 0; bitpos < num_input_bits; ++bitpos) { |
| 117 | data->opnds[0].vbits = onehot_vbits(bitpos, num_input_bits); |
| 118 | |
| 119 | valgrind_execute_test(op, data); |
| 120 | |
| 121 | check_result_for_unary(op, data); |
carll | 24c9e7f | 2012-11-16 19:41:21 +0000 | [diff] [blame] | 122 | tests_done++; |
florian | bb913cd | 2012-08-28 16:50:39 +0000 | [diff] [blame] | 123 | } |
carll | 24c9e7f | 2012-11-16 19:41:21 +0000 | [diff] [blame] | 124 | return tests_done; |
florian | bb913cd | 2012-08-28 16:50:39 +0000 | [diff] [blame] | 125 | } |