Debian Codegraph @

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

raw
1 /* Template file for binary 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 first parameter. Must be of type
28 INPUT_TYPE. */
29
30 #ifndef TEST_MSG
31 #define TEST_MSG "unnamed test"
32 #endif
33
34 /* The test framework. */
35
36 #include <stdio.h>
37
38 extern void abort ();
39
40 #define INFF __builtin_inf ()
41
42 /* Stringify a macro. */
43 #define STR0(A) #A
44 #define STR(A) STR0 (A)
45
46 /* Macro concatenation. */
47 #define CAT0(A, B) A##B
48 #define CAT(A, B) CAT0 (A, B)
49
50 /* Format strings for error reporting. */
51 #define FMT16 "0x%04x"
52 #define FMT32 "0x%08x"
53 #define FMT CAT (FMT,OUTPUT_TYPE_SIZE)
54
55 /* Type construction: forms TS_t, where T is the base type and S the size in
56 bits. */
57 #define MK_TYPE0(T, S) T##S##_t
58 #define MK_TYPE(T, S) MK_TYPE0 (T, S)
59
60 /* Convenience types for input and output data. */
61 typedef MK_TYPE (uint, OUTPUT_TYPE_SIZE) output_hex_type;
62
63 /* Conversion between typed values and their hexadecimal representation. */
64 typedef union
65 {
66 OUTPUT_TYPE value;
67 output_hex_type hex;
68 } output_conv_type;
69
70 /* Default input values. */
71
72 float16_t input_1_float16_t[] =
73 {
74 0.0, -0.0,
75 2.0, 3.1,
76 20.0, 0.40,
77 -2.3, 1.33,
78 -7.6, 0.31,
79 0.3353, 0.5,
80 1.0, 13.13,
81 -6.3, 20.0,
82 (float16_t)INFF, (float16_t)-INFF,
83 };
84
85 float16_t input_2_float16_t[] =
86 {
87 1.0, 1.0,
88 -4.33, 100.0,
89 30.0, -0.02,
90 0.5, -7.231,
91 -6.3, 20.0,
92 -7.231, 2.3,
93 -7.6, 5.1,
94 0.31, 0.33353,
95 (float16_t)-INFF, (float16_t)INFF,
96 };
97
98 #ifndef INPUT_1
99 #define INPUT_1 CAT (input_1_,INPUT_TYPE)
100 #endif
101
102 #ifndef INPUT_2
103 #define INPUT_2 CAT (input_2_,INPUT_TYPE)
104 #endif
105
106 /* Support macros and routines for the test function. */
107
108 #define CHECK() \
109 { \
110 output_conv_type actual; \
111 output_conv_type expect; \
112 \
113 expect.hex = ((output_hex_type*)EXPECTED)[index]; \
114 actual.value = INSN_NAME ((INPUT_1)[index], \
115 (INPUT_2)[index]); \
116 \
117 if (actual.hex != expect.hex) \
118 { \
119 fprintf (stderr, \
120 "ERROR in %s (%s line %d), buffer %s, " \
121 "index %d: got " \
122 FMT " != " FMT "\n", \
123 TEST_MSG, __FILE__, __LINE__, \
124 STR (EXPECTED), index, \
125 actual.hex, expect.hex); \
126 abort (); \
127 } \
128 fprintf (stderr, "CHECKED %s %s\n", \
129 STR (EXPECTED), TEST_MSG); \
130 }
131
132 #define FNNAME1(NAME) exec_ ## NAME
133 #define FNNAME(NAME) FNNAME1 (NAME)
134
135 /* The test function. */
136
137 void
138 FNNAME (INSN_NAME) (void)
139 {
140 /* Basic test: y[i] = OP (x[i]), for each INPUT[i], then compare the result
141 against EXPECTED[i]. */
142
143 const int num_tests = sizeof (INPUT_1) / sizeof (INPUT_1[0]);
144 int index;
145
146 for (index = 0; index < num_tests; index++)
147 CHECK ();
148
149 #ifdef EXTRA_TESTS
150 EXTRA_TESTS ();
151 #endif
152 }
153
154 int
155 main (void)
156 {
157 FNNAME (INSN_NAME) ();
158
159 return 0;
160 }