Debian Codegraph @

gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/ternary_scalar_op.inc

raw
1 /* Template file for ternary scalar operator validation.
2
3 This file is meant to be included by test files for binary scalar
4 operations. */
5
6 /* Check for required settings. */
7
8 #ifndef INSN_NAME
9 #error INSN_NAME (the intrinsic to test) must be defined.
10 #endif
11
12 #ifndef INPUT_TYPE
13 #error INPUT_TYPE (basic type of an input value) must be defined.
14 #endif
15
16 #ifndef OUTPUT_TYPE
17 #error OUTPUT_TYPE (basic type of an output value) must be defined.
18 #endif
19
20 #ifndef OUTPUT_TYPE_SIZE
21 #error OUTPUT_TYPE_SIZE (size in bits of an output value) must be defined.
22 #endif
23
24 /* Optional settings:
25
26 INPUT_1: Input values for the first parameter. Must be of type INPUT_TYPE.
27 INPUT_2: Input values for the second parameter. Must be of type INPUT_TYPE.
28 INPUT_3: Input values for the third parameter. Must be of type
29 INPUT_TYPE. */
30
31 #ifndef TEST_MSG
32 #define TEST_MSG "unnamed test"
33 #endif
34
35 /* The test framework. */
36
37 #include <stdio.h>
38
39 extern void abort ();
40
41 #define INFF __builtin_inf ()
42
43 /* Stringify a macro. */
44 #define STR0(A) #A
45 #define STR(A) STR0 (A)
46
47 /* Macro concatenation. */
48 #define CAT0(A, B) A##B
49 #define CAT(A, B) CAT0 (A, B)
50
51 /* Format strings for error reporting. */
52 #define FMT16 "0x%04x"
53 #define FMT32 "0x%08x"
54 #define FMT CAT (FMT,OUTPUT_TYPE_SIZE)
55
56 /* Type construction: forms TS_t, where T is the base type and S the size in
57 bits. */
58 #define MK_TYPE0(T, S) T##S##_t
59 #define MK_TYPE(T, S) MK_TYPE0 (T, S)
60
61 /* Convenience types for input and output data. */
62 typedef MK_TYPE (uint, OUTPUT_TYPE_SIZE) output_hex_type;
63
64 /* Conversion between typed values and their hexadecimal representation. */
65 typedef union
66 {
67 OUTPUT_TYPE value;
68 output_hex_type hex;
69 } output_conv_type;
70
71 /* Default input values. */
72
73 float16_t input_1_float16_t[] =
74 {
75 0.0,
76 -0.0,
77 2.0,
78 3.1,
79 20.0,
80 0.40,
81 -2.3,
82 1.33,
83 -7.6,
84 0.31,
85 0.3353,
86 0.5,
87 1.0,
88 13.13,
89 -6.3,
90 20.0,
91 (float16_t)INFF,
92 (float16_t)-INFF,
93 };
94
95 float16_t input_2_float16_t[] =
96 {
97 1.0,
98 1.0,
99 -4.33,
100 100.0,
101 30.0,
102 -0.02,
103 0.5,
104 -7.231,
105 -6.3,
106 20.0,
107 -7.231,
108 2.3,
109 -7.6,
110 5.1,
111 0.31,
112 0.33353,
113 (float16_t)-INFF,
114 (float16_t)INFF,
115 };
116
117 float16_t input_3_float16_t[] =
118 {
119 -0.0,
120 0.0,
121 0.31,
122 -0.31,
123 1.31,
124 2.1,
125 -6.3,
126 1.0,
127 -1.5,
128 5.1,
129 0.3353,
130 9.3,
131 -9.3,
132 -7.231,
133 0.5,
134 -0.33,
135 (float16_t)INFF,
136 (float16_t)INFF,
137 };
138
139 #ifndef INPUT_1
140 #define INPUT_1 CAT (input_1_,INPUT_TYPE)
141 #endif
142
143 #ifndef INPUT_2
144 #define INPUT_2 CAT (input_2_,INPUT_TYPE)
145 #endif
146
147 #ifndef INPUT_3
148 #define INPUT_3 CAT (input_3_,INPUT_TYPE)
149 #endif
150
151 /* Support macros and routines for the test function. */
152
153 #define CHECK() \
154 { \
155 output_conv_type actual; \
156 output_conv_type expect; \
157 \
158 expect.hex = ((output_hex_type*)EXPECTED)[index]; \
159 actual.value = INSN_NAME ((INPUT_1)[index], \
160 (INPUT_2)[index], \
161 (INPUT_3)[index]); \
162 \
163 if (actual.hex != expect.hex) \
164 { \
165 fprintf (stderr, \
166 "ERROR in %s (%s line %d), buffer %s, " \
167 "index %d: got " \
168 FMT " != " FMT "\n", \
169 TEST_MSG, __FILE__, __LINE__, \
170 STR (EXPECTED), index, \
171 actual.hex, expect.hex); \
172 abort (); \
173 } \
174 fprintf (stderr, "CHECKED %s %s\n", \
175 STR (EXPECTED), TEST_MSG); \
176 }
177
178 #define FNNAME1(NAME) exec_ ## NAME
179 #define FNNAME(NAME) FNNAME1 (NAME)
180
181 /* The test function. */
182
183 void
184 FNNAME (INSN_NAME) (void)
185 {
186 /* Basic test: y[i] = OP (x[i]), for each INPUT[i], then compare the result
187 against EXPECTED[i]. */
188
189 const int num_tests = sizeof (INPUT_1) / sizeof (INPUT_1[0]);
190 int index;
191
192 for (index = 0; index < num_tests; index++)
193 CHECK ();
194
195 #ifdef EXTRA_TESTS
196 EXTRA_TESTS ();
197 #endif
198 }
199
200 int
201 main (void)
202 {
203 FNNAME (INSN_NAME) ();
204
205 return 0;
206 }