Debian Codegraph @

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

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