1/* -*- mode: C; c-basic-offset: 3; -*- */ 2 3#ifndef VTEST_H 4#define VTEST_H 5 6/* Main header file for the V-bit tester */ 7 8#include <stdint.h> // uint64_t 9#include "libvex.h" // IROp 10#include "vbits.h" // vbits_t 11 12 13/* How undefinedness propagates from input to output */ 14 15typedef enum { 16 // For any undefined input bit, all output bits are defined. 17 UNDEF_NONE, 18 19 // For any undefined input bit, all output bits are undefined. 20 UNDEF_ALL, 21 22 // For each undefined input bit, the corresponding output bit 23 // in the same position is undefined. No other bit is undefined. 24 UNDEF_SAME, 25 26 // For each undefined input bit, the corresponding output bit 27 // in the same position is undefined. No other bit is undefined. 28 // If the corresponding output bit does not exist, the input bit 29 // does not cause any output bits to be undefined. 30 UNDEF_TRUNC, 31 32 // For each undefined input bit, the corresponding output bit 33 // in the same position is undefined. No other bit is undefined. 34 // Output bits that do no not have a corresponding input bit are 35 // defined. 36 UNDEF_ZEXT, 37 38 // For each undefined input bit, the corresponding output bit 39 // in the same position is undefined. If the MSB of the input value 40 // is undefined, so are all output bits with higher significance 41 // than the MSB input bit. 42 UNDEF_SEXT, 43 44 // For each undefined input bit, the corresponding output bit 45 // and all output bits with higher significance are undefined. 46 UNDEF_LEFT, 47 48 UNDEF_CONCAT, // nHLto2n ops e.g. Iop_32HLto64 49 UNDEF_UPPER, // 2nHIton ops e.g. Iop_64HIto32 50 UNDEF_SHL, // shift-left 51 UNDEF_SHR, // logical shift-right 52 UNDEF_SAR, // arithmetic shift-right 53 UNDEF_OR, // bitwise OR operation 54 UNDEF_AND, // bitwise AND operation 55 56 UNDEF_ORD, // Iop_CmpORD compare 57 58 // For IROps I don't know anything about 59 UNDEF_UNKNOWN 60} undef_t; 61 62 63// Everything we want to know about an IROp 64typedef struct { 65 IROp op; 66 const char *name; 67 undef_t undef_kind; 68 int shift_amount_is_immediate; 69 // Indicate whether IROp can be tested on a particular architecture 70 unsigned s390x : 1; 71 unsigned amd64 : 1; 72 unsigned ppc32 : 1; 73 unsigned ppc64 : 1; 74 unsigned arm : 1; 75 unsigned x86 : 1; 76 unsigned mips32 : 1; 77 unsigned mips64 : 1; 78} irop_t; 79 80 81/* The maximum number of input operands */ 82#define MAX_OPERANDS 4 83 84/* An operand of an IROp (also used for the result) */ 85typedef struct { 86 IRType type; 87 vbits_t vbits; 88 value_t value; 89} opnd_t; 90 91 92/* Carries the data needed to execute and evaluate a test. I.e. 93 inputs and results (V-bits and actual value). */ 94typedef struct { 95 opnd_t result; 96 opnd_t opnds[MAX_OPERANDS]; 97 unsigned rounding_mode; 98} test_data_t; 99 100 101/* Function prototypes */ 102irop_t *get_irop(IROp); 103int is_floating_point_op_with_rounding_mode(IROp); 104int get_num_operands(IROp); 105 106void print_opnd(FILE *, const opnd_t *); 107 108int test_unary_op(const irop_t *, test_data_t *); 109int test_binary_op(const irop_t *, test_data_t *); 110int test_ternary_op(const irop_t *, test_data_t *); 111int test_qernary_op(const irop_t *, test_data_t *); 112 113void valgrind_vex_init_for_iri(IRICB *); 114void valgrind_execute_test(const irop_t *, test_data_t *); 115 116IRICB new_iricb(const irop_t *, test_data_t *); 117 118void panic(const char *) __attribute__((noreturn)); 119void complain(const irop_t *, const test_data_t *, vbits_t expected); 120 121/* Imported from VEX */ 122unsigned sizeof_irtype(IRType); 123void typeof_primop(IROp, IRType *t_dst, IRType *t_arg1, IRType *t_arg2, 124 IRType *t_arg3, IRType *t_arg4); 125 126static unsigned __inline__ bitsof_irtype(IRType type) 127{ 128 return type == Ity_I1 ? 1 : sizeof_irtype(type) * 8; 129} 130 131 132/* Exported variables */ 133extern int verbose; 134 135#endif // VTEST_H 136