1 /* { dg-do run } */
2 /* { dg-options "-msim" } */
3 /* Note: The -msim above is actually there to override the default
4 options which include -ansi -pendantic and -Wlong-long... */
5
6 extern int printf (const char *, ...);
7 extern void exit (int);
8 extern void abort (void);
9
10 extern signed long _COM_CONVf32s (float);
11 extern unsigned long _COM_CONVf32u (float);
12 extern float _COM_CONV32sf (signed long);
13 extern float _COM_CONV32uf (unsigned long);
14 extern float _COM_ADDf (float, float);
15 extern float _COM_SUBf (float, float);
16 extern float _COM_MULf (float, float);
17 extern float _COM_DIVf (float, float);
18
19 #ifdef __RX_64BIT_DOUBLES__
20 extern int _COM_CMPLTf (double, double);
21 extern int _COM_CMPGTf (double, double);
22 extern int _COM_CMPLEf (double, double);
23 extern int _COM_CMPGEf (double, double);
24 extern int _COM_CMPEQf (double, double);
25 extern int _COM_CMPNEf (double, double);
26 #else
27 extern int _COM_CMPLTf (float, float);
28 extern int _COM_CMPGTf (float, float);
29 extern int _COM_CMPLEf (float, float);
30 extern int _COM_CMPGEf (float, float);
31 extern int _COM_CMPEQf (float, float);
32 extern int _COM_CMPNEf (float, float);
33 #endif
34
35 extern int _COM_CMPLTd (double, double);
36 extern int _COM_CMPGTd (double, double);
37 extern int _COM_CMPLEd (double, double);
38 extern int _COM_CMPGEd (double, double);
39 extern int _COM_CMPEQd (double, double);
40 extern int _COM_CMPNEd (double, double);
41
42 extern long long _COM_MUL64 (long long, long long);
43 extern signed long long _COM_DIV64s (long long, long long);
44 extern unsigned long long _COM_DIV64u (unsigned long long, unsigned long long);
45 extern long long _COM_SHLL64 (long long, int);
46 extern long long _COM_SHLR64 (long long, int);
47 extern long long _COM_SHAR64 (long long, int);
48 extern signed long long _COM_CONVf64s (float);
49 extern unsigned long long _COM_CONVf64u (float);
50 extern signed long long _COM_CONVd64s (double);
51 extern unsigned long long _COM_CONVd64u (double);
52 extern float _COM_CONV64sf (signed long long);
53 extern float _COM_CONV64uf (unsigned long long);
54 extern double _COM_CONV64sd (signed long long);
55 extern double _COM_CONV64ud (unsigned long long);
56 extern signed long long _COM_MOD64s (long long, long long);
57 extern unsigned long long _COM_MOD64u (unsigned long long, unsigned long long);
58 extern int _COM_CMPLT64s (long long, long long);
59 extern int _COM_CMPLT64u (unsigned long long, unsigned long long);
60 extern int _COM_CMPGT64s (long long, long long);
61 extern int _COM_CMPGT64u (unsigned long long, unsigned long long);
62 extern int _COM_CMPLE64s (long long, long long);
63 extern int _COM_CMPLE64u (unsigned long long, unsigned long long);
64 extern int _COM_CMPGE64s (long long, long long);
65 extern int _COM_CMPGE64u (unsigned long long, unsigned long long);
66 extern int _COM_CMPEQ64 (long long, long long);
67 extern int _COM_CMPNE64 (long long, long long);
68
69 extern double _COM_ADDd (double, double);
70 extern double _COM_SUBd (double, double);
71 extern double _COM_MULd (double, double);
72 extern double _COM_DIVd (double, double);
73 extern signed long _COM_CONVd32s (double);
74 extern unsigned long _COM_CONVd32u (double);
75 extern double _COM_CONV32sd (signed long);
76 extern double _COM_CONV32ud (unsigned long);
77 extern double _COM_CONVfd (float);
78 extern float _COM_CONVdf (double);
79 extern double _COM_NEGd (double);
80
81
82 /* #define DEBUG 1 */
83
84 #ifdef DEBUG
85 # define TEST1(func,arg1,result) if (func (arg1) != result) printf ("fail: " #func " (" #arg1 ") returns %x rather than " #result "\n", func (arg1))
86 # define TEST2(func,arg1,arg2,result) if (func (arg1, arg2) != result) printf ("fail: " #func " (" #arg1 ", " #arg2 ") returns %x rather than " #result "\n", func (arg1, arg2))
87 # define TEST_CMP(func, low_arg, high_arg, lt_result, eq_result, gt_result) \
88 do \
89 { \
90 int res; \
91 \
92 if ((res = func (low_arg, high_arg)) != lt_result) printf ("fail: " #func " (" #low_arg ", " #high_arg ") returns %d rather than %d\n", res, lt_result); \
93 if ((res = func (high_arg, low_arg)) != gt_result) printf ("fail: " #func " (" #high_arg ", " #low_arg ") returns %d rather than %d\n", res, gt_result); \
94 if ((res = func (low_arg, low_arg)) != eq_result) printf ("fail: " #func " (" #low_arg ", " #low_arg ") returns %d rather than %d\n", res, eq_result); \
95 } \
96 while (0)
97 #else
98 # define TEST1(func,arg1,result) if (func (arg1) != result) abort ()
99 # define TEST2(func,arg1,arg2,result) if (func (arg1, arg2) != result) abort ()
100 # define TEST_CMP(func,low,high,lt_res,eq_res,gt_res) \
101 if ( (func (low, high) != lt_res) \
102 || (func (high, low) != gt_res) \
103 || (func (low, low) != eq_res)) \
104 abort ();
105 #endif
106
107
108 int
main(void)109 main (void)
110 {
111 #ifdef DEBUG
112 printf ("Tests starting\n");
113 #endif
114
115 TEST1 (_COM_CONVf32s, -2.0f, -2);
116 TEST1 (_COM_CONVf32u, -2.0f, (unsigned) -2);
117 TEST1 (_COM_CONV32sf, -2, -2.0f);
118 TEST1 (_COM_CONV32uf, 2, 2.0f);
119 TEST2 (_COM_ADDf, 1.0f, 2.0f, 3.0f);
120 TEST2 (_COM_SUBf, 3.0f, 2.0f, 1.0f);
121 TEST2 (_COM_MULf, 2.0f, 3.0f, 6.0f);
122 TEST2 (_COM_DIVf, 6.0f, 2.0f, 3.0f);
123 TEST_CMP (_COM_CMPLTf, 1.0f, 2.0f, 1, 0, 0);
124 TEST_CMP (_COM_CMPGTf, 1.0f, 2.0f, 0, 0, 1);
125 TEST_CMP (_COM_CMPLEf, 1.0f, 2.0f, 1, 1, 0);
126 TEST_CMP (_COM_CMPGEf, 1.0f, 2.0f, 0, 1, 1);
127 TEST_CMP (_COM_CMPEQf, 1.0f, 2.0f, 0, 1, 0);
128 TEST_CMP (_COM_CMPNEf, 1.0f, 2.0f, 1, 0, 1);
129
130
131 TEST2 (_COM_MUL64, 2LL, 4LL, 8LL);
132 TEST2 (_COM_DIV64s, 6LL, 3LL, 2LL);
133 TEST2 (_COM_DIV64u, 6ULL, 3ULL, 2ULL);
134 TEST2 (_COM_SHLL64, 6LL, 3, 48LL);
135 TEST2 (_COM_SHLR64, 8LL, 2, 2LL);
136 TEST2 (_COM_SHAR64, -1LL, 2, -1LL);
137 TEST1 (_COM_CONVf64s, -2.0f, -2LL);
138 TEST1 (_COM_CONVf64u, 2.0f, 2ULL);
139 TEST1 (_COM_CONVd64s, -2.0, -2LL);
140 TEST1 (_COM_CONVd64u, 2.0, 2ULL);
141 TEST1 (_COM_CONV64sf, -2LL, -2.0f);
142 TEST1 (_COM_CONV64uf, 2ULL, 2.0f);
143 TEST1 (_COM_CONV64sd, -2LL, -2.0);
144 TEST1 (_COM_CONV64ud, 2ULL, 2.0);
145 TEST2 (_COM_MOD64s, 4LL, 3LL, 1LL);
146 TEST2 (_COM_MOD64u, 4ULL, 3ULL, 1ULL);
147 TEST_CMP (_COM_CMPLT64s, 1LL, 2LL, 1, 0, 0);
148 TEST_CMP (_COM_CMPLT64u, 1ULL, 2ULL, 1, 0, 0);
149 TEST_CMP (_COM_CMPGT64s, 1LL, 2LL, 0, 0, 1);
150 TEST_CMP (_COM_CMPGT64u, 1ULL, 2ULL, 0, 0, 1);
151 TEST_CMP (_COM_CMPLE64s, 1LL, 2LL, 1, 1, 0);
152 TEST_CMP (_COM_CMPLE64u, 1ULL, 2ULL, 1, 1, 0);
153 TEST_CMP (_COM_CMPGE64s, 1LL, 2LL, 0, 1, 1);
154 TEST_CMP (_COM_CMPGE64u, 1ULL, 2ULL, 0, 1, 1);
155 TEST_CMP (_COM_CMPEQ64, 1LL, 2LL, 0, 1, 0);
156 TEST_CMP (_COM_CMPNE64, 1LL, 2LL, 1, 0, 1);
157
158
159 TEST2 (_COM_ADDd, 1.0, 2.0, 3.0);
160 TEST2 (_COM_SUBd, 3.0, 2.0, 1.0);
161 TEST2 (_COM_MULd, 2.0, 3.0, 6.0);
162 TEST2 (_COM_DIVd, 6.0, 2.0, 3.0);
163 TEST1 (_COM_CONVd32s, -2.0, -2);
164 TEST1 (_COM_CONVd32u, -2.0, (unsigned) -2);
165 TEST1 (_COM_CONV32sd, -2, -2.0);
166 TEST1 (_COM_CONV32ud, 2, 2.0);
167 TEST1 (_COM_CONVfd, 2.0f, 2.0);
168 TEST1 (_COM_CONVdf, 2.0, 2.0f);
169 TEST1 (_COM_NEGd, -2.0, 2.0);
170 TEST_CMP (_COM_CMPLTd, 1.0, 2.0, 1, 0, 0);
171 TEST_CMP (_COM_CMPGTd, 1.0, 2.0, 0, 0, 1);
172 TEST_CMP (_COM_CMPLEd, 1.0, 2.0, 1, 1, 0);
173 TEST_CMP (_COM_CMPGEd, 1.0, 2.0, 0, 1, 1);
174 TEST_CMP (_COM_CMPEQd, 1.0, 2.0, 0, 1, 0);
175 TEST_CMP (_COM_CMPNEd, 1.0, 2.0, 1, 0, 1);
176
177 #ifdef DEBUG
178 printf ("Tests finished\n");
179 #endif
180 exit (0);
181 }
182