aboutsummaryrefslogtreecommitdiff
path: root/sim/testsuite/common/alu-n-tst.h
blob: bf2635f08fe2f390149339dcea9f51f7891348b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef N
#error "N must be #defined"
#endif

#include "sim-xcat.h"

/* NOTE: see end of file for #undef of these macros */
#define unsignedN    XCONCAT2(unsigned,N)
#define OP_BEGIN     XCONCAT3(ALU,N,_BEGIN)
#define OP_ADD       XCONCAT3(ALU,N,_ADD)
#define OP_SUB       XCONCAT3(ALU,N,_SUB)
#define HAD_OVERFLOW (XCONCAT3(ALU,N,_HAD_OVERFLOW) != 0)
#define HAD_CARRY    (XCONCAT3(ALU,N,_HAD_CARRY) != 0)
#define RESULT          XCONCAT3(ALU,N,_RESULT)
#define OVERFLOW_RESULT XCONCAT3(ALU,N,_OVERFLOW_RESULT)
#define CARRY_RESULT    XCONCAT3(ALU,N,_CARRY_RESULT)
#define do_op_N      XCONCAT2(do_op_,N)

void
do_op_N (const alu_test *tst)
{
  const alu_op *op;
  /* without type cast */
  {
    OP_BEGIN (tst->begin);
    print_hex (tst->begin, N);
    for (op = tst->ops; op->op != NULL; op++)
      {
	printf (" %s ", op->op);
	print_hex (op->arg, N);
	if (strcmp (op->op, "add") == 0
	    || strcmp (op->op, "ADD") == 0)
	  OP_ADD (op->arg);
	else if (strcmp (op->op, "sub") == 0
		 || strcmp (op->op, "SUB") == 0)
	  OP_SUB (op->arg);
	else
	  {
	    printf (" -- operator unknown\n");
	    abort ();
	  }
      }
    printf (" = ");
    print_hex (tst->result, N);
    printf (" C%d V%d", tst->carry, tst->overflow);
    if (tst->carry != HAD_CARRY)
      {
	printf (" -- carry wrong %d", HAD_CARRY);
	errors ++;
      }
    if (tst->overflow != HAD_OVERFLOW)
      {
	printf (" -- overflow wrong %d", HAD_OVERFLOW);
	errors ++;
      }
    if ((unsignedN) CARRY_RESULT != (unsignedN) tst->result)
      {
	printf (" -- carry result wrong ");
	print_hex (CARRY_RESULT, N);
	errors ++;
      }
    if ((unsignedN) OVERFLOW_RESULT != (unsignedN) tst->result)
      {
	printf (" -- overflow result wrong ");
	print_hex (OVERFLOW_RESULT, N);
	errors ++;
      }
    if ((unsignedN) RESULT != (unsignedN) tst->result)
      {
	printf (" -- result wrong ");
	print_hex (RESULT, N);
	errors ++;
      }
    printf ("\n");
  }
}

#undef OP_BEGIN
#undef OP_ADD
#undef OP_SUB
#undef HAD_OVERFLOW
#undef HAD_CARRY
#undef OVERFLOW_RESULT
#undef CARRY_RESULT
#undef RESULT
#undef do_op_N
#undef unsignedN