Home | History | Annotate | Download | only in vbit-test
      1 /* -*- mode: C; c-basic-offset: 3; -*- */
      2 
      3 /*
      4    This file is part of MemCheck, a heavyweight Valgrind tool for
      5    detecting memory errors.
      6 
      7    Copyright (C) 2012-2017  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 
     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 
     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 
     96    default:
     97       panic(__func__);
     98    }
     99 
    100    if (! equal_vbits(result->vbits, expected_vbits))
    101       complain(op, data, expected_vbits);
    102 }
    103 
    104 
    105 int
    106 test_unary_op(const irop_t *op, test_data_t *data)
    107 {
    108    unsigned num_input_bits, bitpos;
    109    int tests_done = 0;
    110 
    111    /* Immediate operands are currently not supported here */
    112    assert(op->immediate_index == 0);
    113 
    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);
    122       tests_done++;
    123    }
    124    return tests_done;
    125 }
    126