improved optest testapp to test more cases, added an optest_float testapp
[libfirm] / ir / be / test / optest.h
1 #ifndef TESTANZ
2 #define TESTANZ 16
3 #define IMM         23
4 #define test16_1        42
5 #define test16_2        11
6 #define test32_1        0x001200AB
7 #define test32_2        0x00341501
8 #define test32_s    7
9 #endif
10
11 T tname(test_add_) (T a, T b) {
12         return a+b;
13 }
14
15 T tname(test_addi_) (T a) {
16         return a+IMM;
17 }
18
19 T tname(test_sub_) (T a, T b) {
20         return a-b;
21 }
22
23 T tname(test_subi_) (T a) {
24         return a-IMM;
25 }
26
27 T tname(test_subfi_) (T a) {
28         return IMM-a;
29 }
30
31 T tname(test_mul_) (T a, T b) {
32         return a*b;
33 }
34
35 T tname(test_muli_) (T a) {
36         return a*IMM;
37 }
38
39 T tname(test_div_) (T a, T b) {
40         return a/b;
41 }
42
43 T tname(test_divi_) (T a) {
44         return a/IMM;
45 }
46
47 #ifndef TEST_FLOAT
48 T tname(test_shl_) (T a, T b) {
49         return a<<b;
50 }
51
52 T tname(test_shli_) (T a) {
53         return a<<IMM;
54 }
55
56 T tname(test_shr_) (T a, T b) {
57         return a>>b;
58 }
59
60 T tname(test_shri_) (T a) {
61         return a>>IMM;
62 }
63 #endif
64
65 T tname(test_cmp_) (T a, T b) {
66         return (a>b) ? 1 : 0;
67 }
68
69 T tname(test_cmpi_) (T a) {
70         return (a>IMM) ? 1 : 0;
71 }
72
73 T tname(res16_) [TESTANZ];
74 T tname(res32_) [TESTANZ];
75
76 void tname(test_) () {
77         int i;
78         T *res16 = tname(res16_);
79         T *res32 = tname(res32_);
80
81         res16[ 0] = tname(test_add_)  (test16_1, test16_2);
82         res16[ 1] = tname(test_sub_)  (test16_1, test16_2);
83         res16[ 2] = tname(test_mul_)  (test16_1, test16_2);
84         res16[ 3] = tname(test_div_)  (test16_1, test16_2);
85 #ifndef TEST_FLOAT
86         res16[ 4] = tname(test_shl_)  (test16_1, test16_2);
87         res16[ 5] = tname(test_shr_)  (test16_1, test16_2);
88 #endif
89         res16[ 6] = tname(test_div_)  (test16_1, test16_2);
90         res16[ 7] = tname(test_cmp_)  (test16_1, test16_2);
91         res16[ 8] = tname(test_addi_) (test16_1);
92         res16[ 9] = tname(test_subi_) (test16_1);
93         res16[10] = tname(test_subfi_)(test16_1);
94         res16[11] = tname(test_muli_) (test16_1);
95         res16[12] = tname(test_divi_) (test16_1);
96 #ifndef TEST_FLOAT
97         res16[13] = tname(test_shli_) (test16_1);
98         res16[14] = tname(test_shri_) (test16_1);
99 #endif
100         res16[15] = tname(test_cmpi_) (test16_1);
101
102         res32[ 0] = tname(test_add_)  (test32_1, test32_2);
103         res32[ 1] = tname(test_sub_)  (test32_1, test32_2);
104         res32[ 2] = tname(test_mul_)  (test32_1, test32_2);
105         res32[ 3] = tname(test_div_)  (test32_1, test32_2);
106 #ifndef TEST_FLOAT
107         res32[ 4] = tname(test_shl_)  (test32_1, test32_2);
108         res32[ 5] = tname(test_shr_)  (test32_1, test32_2);
109 #endif
110         res32[ 6] = tname(test_div_)  (test32_1, test32_2);
111         res32[ 7] = tname(test_cmp_)  (test32_1, test32_2);
112         res32[ 8] = tname(test_addi_) (test32_1);
113         res32[ 9] = tname(test_subi_) (test32_1);
114         res32[10] = tname(test_subfi_)(test32_1);
115         res32[11] = tname(test_muli_) (test32_1);
116         res32[12] = tname(test_divi_) (test32_1);
117 #ifndef TEST_FLOAT
118         res32[13] = tname(test_shli_) (test32_1);
119         res32[14] = tname(test_shri_) (test32_1);
120 #endif
121         res32[15] = tname(test_cmpi_) (test32_1);
122
123         printf("Result for %s\n", __PRETTY_FUNCTION__);
124         for (i=0; i<TESTANZ; i++) {
125 #ifndef TEST_FLOAT
126                 printf("res16[%d] = %d\n", i, res16[i]);
127                 printf("res32[%d] = %d\n", i, res32[i]);
128 #else
129                 printf("res16[%d] = %f\n", i, res16[i]);
130                 printf("res32[%d] = %f\n", i, res32[i]);
131 #endif
132         }
133 }