1 #include <arm_neon.h>
2 #include "arm-neon-ref.h"
3 #include "compute-ref-data.h"
4 #include <math.h>
5 
6 /* Expected results with positive input.  */
7 VECT_VAR_DECL(expected_positive,uint,32,2) [] = { 0xffffffff, 0xffffffff };
8 VECT_VAR_DECL(expected_positive,uint,32,4) [] = { 0xbf000000, 0xbf000000,
9 						  0xbf000000, 0xbf000000 };
10 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
11 VECT_VAR_DECL(expected_positive, hfloat, 16, 4) [] = { 0x3834, 0x3834,
12 						       0x3834, 0x3834 };
13 VECT_VAR_DECL(expected_positive, hfloat, 16, 8) [] = { 0x2018, 0x2018,
14 						       0x2018, 0x2018,
15 						       0x2018, 0x2018,
16 						       0x2018, 0x2018 };
17 #endif
18 VECT_VAR_DECL(expected_positive,hfloat,32,2) [] = { 0x3f068000, 0x3f068000 };
19 VECT_VAR_DECL(expected_positive,hfloat,32,4) [] = { 0x3c030000, 0x3c030000,
20 						    0x3c030000, 0x3c030000 };
21 
22 /* Expected results with negative input.  */
23 VECT_VAR_DECL(expected_negative,uint,32,2) [] = { 0x80000000, 0x80000000 };
24 VECT_VAR_DECL(expected_negative,uint,32,4) [] = { 0xee800000, 0xee800000,
25 						  0xee800000, 0xee800000 };
26 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
27 VECT_VAR_DECL(expected_negative, hfloat, 16, 4) [] = { 0xae64, 0xae64,
28 						       0xae64, 0xae64 };
29 VECT_VAR_DECL(expected_negative, hfloat, 16, 8) [] = { 0xa018, 0xa018,
30 						       0xa018, 0xa018,
31 						       0xa018, 0xa018,
32 						       0xa018, 0xa018 };
33 #endif
34 VECT_VAR_DECL(expected_negative,hfloat,32,2) [] = { 0xbdcc8000, 0xbdcc8000 };
35 VECT_VAR_DECL(expected_negative,hfloat,32,4) [] = { 0xbc030000, 0xbc030000,
36 						    0xbc030000, 0xbc030000 };
37 
38 /* Expected results with FP special values (NaN, infinity).  */
39 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
40 VECT_VAR_DECL(expected_fp1, hfloat, 16, 4) [] = { 0x7e00, 0x7e00,
41 						  0x7e00, 0x7e00 };
42 VECT_VAR_DECL(expected_fp1, hfloat, 16, 8) [] = { 0x0, 0x0, 0x0, 0x0,
43 						  0x0, 0x0, 0x0, 0x0 };
44 #endif
45 VECT_VAR_DECL(expected_fp1,hfloat,32,2) [] = { 0x7fc00000, 0x7fc00000 };
46 VECT_VAR_DECL(expected_fp1,hfloat,32,4) [] = { 0x0, 0x0, 0x0, 0x0 };
47 
48 /* Expected results with FP special values (zero, large value).  */
49 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
50 VECT_VAR_DECL(expected_fp2, hfloat, 16, 4) [] = { 0x7c00, 0x7c00,
51 						  0x7c00, 0x7c00 };
52 VECT_VAR_DECL(expected_fp2, hfloat, 16, 8) [] = { 0x0, 0x0, 0x0, 0x0,
53 						  0x0, 0x0, 0x0, 0x0 };
54 #endif
55 VECT_VAR_DECL(expected_fp2,hfloat,32,2) [] = { 0x7f800000, 0x7f800000 };
56 VECT_VAR_DECL(expected_fp2,hfloat,32,4) [] = { 0x0, 0x0, 0x0, 0x0 };
57 
58 /* Expected results with FP special values (-0, -infinity).  */
59 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
60 VECT_VAR_DECL(expected_fp3, hfloat, 16, 4) [] = { 0xfc00, 0xfc00,
61 						  0xfc00, 0xfc00};
62 VECT_VAR_DECL(expected_fp3, hfloat, 16, 8) [] = { 0x8000, 0x8000,
63 						  0x8000, 0x8000,
64 						  0x8000, 0x8000,
65 						  0x8000, 0x8000 };
66 #endif
67 VECT_VAR_DECL(expected_fp3,hfloat,32,2) [] = { 0xff800000, 0xff800000 };
68 VECT_VAR_DECL(expected_fp3,hfloat,32,4) [] = { 0x80000000, 0x80000000,
69 					       0x80000000, 0x80000000 };
70 
71 /* Expected results with FP special large negative value.  */
72 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
73 VECT_VAR_DECL(expected_fp4, hfloat, 16, 4) [] = { 0x8000, 0x8000,
74 						  0x8000, 0x8000 };
75 #endif
76 VECT_VAR_DECL(expected_fp4,hfloat,32,2) [] = { 0x80000000, 0x80000000 };
77 
78 #define TEST_MSG "VRECPE/VRECPEQ"
exec_vrecpe(void)79 void exec_vrecpe(void)
80 {
81   int i;
82 
83   /* Basic test: y=vrecpe(x), then store the result.  */
84 #define TEST_VRECPE(Q, T1, T2, W, N)			\
85   VECT_VAR(vector_res, T1, W, N) =			\
86     vrecpe##Q##_##T2##W(VECT_VAR(vector, T1, W, N));	\
87   vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N),		\
88 		    VECT_VAR(vector_res, T1, W, N))
89 
90   /* No need for 64 bits variants.  */
91   DECL_VARIABLE(vector, uint, 32, 2);
92   DECL_VARIABLE(vector, uint, 32, 4);
93 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
94   DECL_VARIABLE(vector, float, 16, 4);
95   DECL_VARIABLE(vector, float, 16, 8);
96 #endif
97   DECL_VARIABLE(vector, float, 32, 2);
98   DECL_VARIABLE(vector, float, 32, 4);
99 
100   DECL_VARIABLE(vector_res, uint, 32, 2);
101   DECL_VARIABLE(vector_res, uint, 32, 4);
102 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
103   DECL_VARIABLE(vector_res, float, 16, 4);
104   DECL_VARIABLE(vector_res, float, 16, 8);
105 #endif
106   DECL_VARIABLE(vector_res, float, 32, 2);
107   DECL_VARIABLE(vector_res, float, 32, 4);
108 
109   clean_results ();
110 
111   /* Choose init value arbitrarily, positive.  */
112   VDUP(vector, , uint, u, 32, 2, 0x12345678);
113 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
114   VDUP(vector, , float, f, 16, 4, 1.9f);
115 #endif
116   VDUP(vector, , float, f, 32, 2, 1.9f);
117 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
118   VDUP(vector, q, float, f, 16, 8, 125.0f);
119 #endif
120   VDUP(vector, q, uint, u, 32, 4, 0xABCDEF10);
121   VDUP(vector, q, float, f, 32, 4, 125.0f);
122 
123   /* Apply the operator.  */
124   TEST_VRECPE(, uint, u, 32, 2);
125 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
126   TEST_VRECPE(, float, f, 16, 4);
127 #endif
128   TEST_VRECPE(, float, f, 32, 2);
129   TEST_VRECPE(q, uint, u, 32, 4);
130 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
131   TEST_VRECPE(q, float, f, 16, 8);
132 #endif
133   TEST_VRECPE(q, float, f, 32, 4);
134 
135 #define CMT " (positive input)"
136   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_positive, CMT);
137   CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_positive, CMT);
138 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
139   CHECK_FP(TEST_MSG, float, 16, 4, PRIx16, expected_positive, CMT);
140   CHECK_FP(TEST_MSG, float, 16, 8, PRIx16, expected_positive, CMT);
141 #endif
142   CHECK_FP(TEST_MSG, float, 32, 2, PRIx32, expected_positive, CMT);
143   CHECK_FP(TEST_MSG, float, 32, 4, PRIx32, expected_positive, CMT);
144 
145   /* Choose init value arbitrarily,negative.  */
146   VDUP(vector, , uint, u, 32, 2, 0xFFFFFFFF);
147 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
148   VDUP(vector, , float, f, 16, 4, -10.0f);
149 #endif
150   VDUP(vector, , float, f, 32, 2, -10.0f);
151   VDUP(vector, q, uint, u, 32, 4, 0x89081234);
152 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
153   VDUP(vector, q, float, f, 16, 8, -125.0f);
154 #endif
155   VDUP(vector, q, float, f, 32, 4, -125.0f);
156 
157   /* Apply the operator.  */
158   TEST_VRECPE(, uint, u, 32, 2);
159 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
160   TEST_VRECPE(, float, f, 16, 4);
161 #endif
162   TEST_VRECPE(, float, f, 32, 2);
163   TEST_VRECPE(q, uint, u, 32, 4);
164 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
165   TEST_VRECPE(q, float, f, 16, 8);
166 #endif
167   TEST_VRECPE(q, float, f, 32, 4);
168 
169 #undef CMT
170 #define CMT " (negative input)"
171   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_negative, CMT);
172   CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_negative, CMT);
173 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
174   CHECK_FP(TEST_MSG, float, 16, 4, PRIx16, expected_negative, CMT);
175   CHECK_FP(TEST_MSG, float, 16, 8, PRIx16, expected_negative, CMT);
176 #endif
177   CHECK_FP(TEST_MSG, float, 32, 2, PRIx32, expected_negative, CMT);
178   CHECK_FP(TEST_MSG, float, 32, 4, PRIx32, expected_negative, CMT);
179 
180   /* Test FP variants with special input values (NaN, infinity).  */
181 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
182   VDUP(vector, , float, f, 16, 4, NAN);
183   VDUP(vector, q, float, f, 16, 8, HUGE_VALF);
184 #endif
185   VDUP(vector, , float, f, 32, 2, NAN);
186   VDUP(vector, q, float, f, 32, 4, HUGE_VALF);
187 
188   /* Apply the operator.  */
189 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
190   TEST_VRECPE(, float, f, 16, 4);
191   TEST_VRECPE(q, float, f, 16, 8);
192 #endif
193   TEST_VRECPE(, float, f, 32, 2);
194   TEST_VRECPE(q, float, f, 32, 4);
195 
196 #undef CMT
197 #define CMT " FP special (NaN, infinity)"
198 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
199   CHECK_FP(TEST_MSG, float, 16, 4, PRIx16, expected_fp1, CMT);
200   CHECK_FP(TEST_MSG, float, 16, 8, PRIx16, expected_fp1, CMT);
201 #endif
202   CHECK_FP(TEST_MSG, float, 32, 2, PRIx32, expected_fp1, CMT);
203   CHECK_FP(TEST_MSG, float, 32, 4, PRIx32, expected_fp1, CMT);
204 
205   /* Test FP variants with special input values (zero, large value).  */
206 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
207   VDUP(vector, , float, f, 16, 4, 0.0f);
208   VDUP(vector, q, float, f, 16, 8, 8.97229e37f /*9.0e37f*/);
209 #endif
210   VDUP(vector, , float, f, 32, 2, 0.0f);
211   VDUP(vector, q, float, f, 32, 4, 8.97229e37f /*9.0e37f*/);
212 
213   /* Apply the operator.  */
214 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
215   TEST_VRECPE(, float, f, 16, 4);
216   TEST_VRECPE(q, float, f, 16, 8);
217 #endif
218   TEST_VRECPE(, float, f, 32, 2);
219   TEST_VRECPE(q, float, f, 32, 4);
220 
221 #undef CMT
222 #define CMT " FP special (zero, large value)"
223 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
224   CHECK_FP(TEST_MSG, float, 16, 4, PRIx16, expected_fp2, CMT);
225   CHECK_FP(TEST_MSG, float, 16, 8, PRIx16, expected_fp2, CMT);
226 #endif
227   CHECK_FP(TEST_MSG, float, 32, 2, PRIx32, expected_fp2, CMT);
228   CHECK_FP(TEST_MSG, float, 32, 4, PRIx32, expected_fp2, CMT);
229 
230   /* Test FP variants with special input values (-0, -infinity).  */
231 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
232   VDUP(vector, , float, f, 16, 4, -0.0f);
233   VDUP(vector, q, float, f, 16, 8, -HUGE_VALF);
234 #endif
235   VDUP(vector, , float, f, 32, 2, -0.0f);
236   VDUP(vector, q, float, f, 32, 4, -HUGE_VALF);
237 
238   /* Apply the operator.  */
239 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
240   TEST_VRECPE(, float, f, 16, 4);
241   TEST_VRECPE(q, float, f, 16, 8);
242 #endif
243   TEST_VRECPE(, float, f, 32, 2);
244   TEST_VRECPE(q, float, f, 32, 4);
245 
246 #undef CMT
247 #define CMT " FP special (-0, -infinity)"
248 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
249   CHECK_FP(TEST_MSG, float, 16, 4, PRIx16, expected_fp3, CMT);
250   CHECK_FP(TEST_MSG, float, 16, 8, PRIx16, expected_fp3, CMT);
251 #endif
252   CHECK_FP(TEST_MSG, float, 32, 2, PRIx32, expected_fp3, CMT);
253   CHECK_FP(TEST_MSG, float, 32, 4, PRIx32, expected_fp3, CMT);
254 
255   /* Test FP variants with special input values (large negative value).  */
256 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
257   VDUP(vector, , float, f, 16, 4, -9.0e37f);
258 #endif
259   VDUP(vector, , float, f, 32, 2, -9.0e37f);
260 
261   /* Apply the operator.  */
262 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
263   TEST_VRECPE(, float, f, 16, 4);
264 #endif
265   TEST_VRECPE(, float, f, 32, 2);
266 
267 #undef CMT
268 #define CMT " FP special (large negative value)"
269 #if defined (__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
270   CHECK_FP(TEST_MSG, float, 16, 4, PRIx16, expected_fp4, CMT);
271 #endif
272   CHECK_FP(TEST_MSG, float, 32, 2, PRIx32, expected_fp4, CMT);
273 }
274 
main(void)275 int main (void)
276 {
277   exec_vrecpe ();
278   return 0;
279 }
280