示例#1
0
文件: ternary.c 项目: robryk/valgrind
void
test_ternary_op(const irop_t *op, test_data_t *data)
{
   unsigned num_input_bits, i, bitpos;
   opnd_t *opnds = data->opnds;

   /* For each operand, set a single bit to undefined and observe how
      that propagates to the output. Do this for all bits in each
      operand. */
   for (i = 0; i < 3; ++i) {
      num_input_bits = bitsof_irtype(opnds[i].type);

      opnds[0].vbits = defined_vbits(bitsof_irtype(opnds[0].type));
      opnds[1].vbits = defined_vbits(bitsof_irtype(opnds[1].type));
      opnds[2].vbits = defined_vbits(bitsof_irtype(opnds[2].type));

      for (bitpos = 0; bitpos < num_input_bits; ++bitpos) {
         opnds[i].vbits = onehot_vbits(bitpos, bitsof_irtype(opnds[i].type));

         valgrind_execute_test(op, data);

         check_result_for_ternary(op, data);
      }
   }
}
示例#2
0
/* Ity_I1 values cannot be stored or loaded. So vex_inject_ir will load/store
   such a value from/to a 4-byte container. It uses 32to1 and 1Uto32,
   respectively. */
static void
valgrind_set_vbits(opnd_t *opnd)
{
   unsigned rc, num_bytes;
   
   /* 1-bit wide values cannot be read. So we read a 4 bytes here */
   num_bytes = opnd->type == Ity_I1 ? 4 : sizeof_irtype(opnd->type);
   rc = VALGRIND_SET_VBITS(&opnd->value, &opnd->vbits.bits, num_bytes);
   assert(rc == 1);

   // Make sure the v-bits were set correctly
   vbits_t actual = { .num_bits = opnd->vbits.num_bits };
   rc = VALGRIND_GET_VBITS(&opnd->value, &actual.bits, num_bytes);
   assert(rc == 1);

   assert(equal_vbits(opnd->vbits, actual));
}


static void
valgrind_get_vbits(opnd_t *opnd)
{
   unsigned rc, num_bytes;

   /* 1-bit wide values cannot be stored. So we store them by writing a
      single byte */
   num_bytes = opnd->type == Ity_I1 ? 4 : sizeof_irtype(opnd->type);
   opnd->vbits.num_bits = bitsof_irtype(opnd->type);
   rc = VALGRIND_GET_VBITS(&opnd->value, &opnd->vbits.bits, num_bytes);
   assert(rc == 1);
}
示例#3
0
int
test_qernary_op(const irop_t *op, test_data_t *data)
{
   unsigned num_input_bits, i, bitpos;
   opnd_t *opnds = data->opnds;
   int tests_done = 0;

   /* Immediate operands are currently not supported here */
   assert(op->immediate_index == 0);

   /* For each operand, set a single bit to undefined and observe how
      that propagates to the output. Do this for all bits in each
      operand. */
   for (i = 0; i < 4; ++i) {
      num_input_bits = bitsof_irtype(opnds[i].type);

      opnds[0].vbits = defined_vbits(bitsof_irtype(opnds[0].type));
      opnds[1].vbits = defined_vbits(bitsof_irtype(opnds[1].type));
      opnds[2].vbits = defined_vbits(bitsof_irtype(opnds[2].type));
      opnds[3].vbits = defined_vbits(bitsof_irtype(opnds[3].type));

      for (bitpos = 0; bitpos < num_input_bits; ++bitpos) {
         opnds[i].vbits = onehot_vbits(bitpos, bitsof_irtype(opnds[i].type));

         valgrind_execute_test(op, data);

         check_result_for_qernary(op, data);

         tests_done++;
      }
   }
   return tests_done;
}
示例#4
0
文件: unary.c 项目: robryk/valgrind
void
test_unary_op(const irop_t *op, test_data_t *data)
{
    unsigned num_input_bits, bitpos;

    num_input_bits = bitsof_irtype(data->opnds[0].type);

    for (bitpos = 0; bitpos < num_input_bits; ++bitpos) {
        data->opnds[0].vbits = onehot_vbits(bitpos, num_input_bits);

        valgrind_execute_test(op, data);

        check_result_for_unary(op, data);
    }
}
示例#5
0
int
test_unary_op(const irop_t *op, test_data_t *data)
{
   unsigned num_input_bits, bitpos;
   int tests_done = 0;

   /* Immediate operands are currently not supported here */
   assert(op->immediate_index == 0);

   num_input_bits = bitsof_irtype(data->opnds[0].type);

   for (bitpos = 0; bitpos < num_input_bits; ++bitpos) {
      data->opnds[0].vbits = onehot_vbits(bitpos, num_input_bits);

      valgrind_execute_test(op, data);

      check_result_for_unary(op, data);
      tests_done++;
   }
   return tests_done;
}