1*f3782652STreehugger Robot /*
2*f3782652STreehugger Robot
3*f3782652STreehugger Robot Copyright (c) 2009, 2010, 2011 STMicroelectronics
4*f3782652STreehugger Robot Written by Christophe Lyon
5*f3782652STreehugger Robot
6*f3782652STreehugger Robot Permission is hereby granted, free of charge, to any person obtaining a copy
7*f3782652STreehugger Robot of this software and associated documentation files (the "Software"), to deal
8*f3782652STreehugger Robot in the Software without restriction, including without limitation the rights
9*f3782652STreehugger Robot to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10*f3782652STreehugger Robot copies of the Software, and to permit persons to whom the Software is
11*f3782652STreehugger Robot furnished to do so, subject to the following conditions:
12*f3782652STreehugger Robot
13*f3782652STreehugger Robot The above copyright notice and this permission notice shall be included in
14*f3782652STreehugger Robot all copies or substantial portions of the Software.
15*f3782652STreehugger Robot
16*f3782652STreehugger Robot THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*f3782652STreehugger Robot IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*f3782652STreehugger Robot FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*f3782652STreehugger Robot AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*f3782652STreehugger Robot LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21*f3782652STreehugger Robot OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22*f3782652STreehugger Robot THE SOFTWARE.
23*f3782652STreehugger Robot
24*f3782652STreehugger Robot */
25*f3782652STreehugger Robot
26*f3782652STreehugger Robot #if defined(__arm__) || defined(__aarch64__)
27*f3782652STreehugger Robot #include <arm_neon.h>
28*f3782652STreehugger Robot #else
29*f3782652STreehugger Robot #include "stm-arm-neon.h"
30*f3782652STreehugger Robot #endif
31*f3782652STreehugger Robot
32*f3782652STreehugger Robot #include "stm-arm-neon-ref.h"
33*f3782652STreehugger Robot #include <math.h>
34*f3782652STreehugger Robot
35*f3782652STreehugger Robot #define TEST_MSG "VRECPE/VRECPEQ"
exec_vrecpe(void)36*f3782652STreehugger Robot void exec_vrecpe(void)
37*f3782652STreehugger Robot {
38*f3782652STreehugger Robot int i;
39*f3782652STreehugger Robot
40*f3782652STreehugger Robot /* Basic test: y=vrecpe(x), then store the result. */
41*f3782652STreehugger Robot #define TEST_VRECPE(Q, T1, T2, W, N) \
42*f3782652STreehugger Robot VECT_VAR(vector_res, T1, W, N) = \
43*f3782652STreehugger Robot vrecpe##Q##_##T2##W(VECT_VAR(vector, T1, W, N)); \
44*f3782652STreehugger Robot vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N), \
45*f3782652STreehugger Robot VECT_VAR(vector_res, T1, W, N))
46*f3782652STreehugger Robot
47*f3782652STreehugger Robot /* With ARM RVCT, we need to declare variables before any executable
48*f3782652STreehugger Robot statement */
49*f3782652STreehugger Robot
50*f3782652STreehugger Robot /* No need for 64 bits variants */
51*f3782652STreehugger Robot DECL_VARIABLE(vector, uint, 32, 2);
52*f3782652STreehugger Robot DECL_VARIABLE(vector, uint, 32, 4);
53*f3782652STreehugger Robot DECL_VARIABLE(vector, float, 32, 2);
54*f3782652STreehugger Robot DECL_VARIABLE(vector, float, 32, 4);
55*f3782652STreehugger Robot
56*f3782652STreehugger Robot DECL_VARIABLE(vector_res, uint, 32, 2);
57*f3782652STreehugger Robot DECL_VARIABLE(vector_res, uint, 32, 4);
58*f3782652STreehugger Robot DECL_VARIABLE(vector_res, float, 32, 2);
59*f3782652STreehugger Robot DECL_VARIABLE(vector_res, float, 32, 4);
60*f3782652STreehugger Robot
61*f3782652STreehugger Robot clean_results ();
62*f3782652STreehugger Robot
63*f3782652STreehugger Robot /* Choose init value arbitrarily */
64*f3782652STreehugger Robot VDUP(vector, , uint, u, 32, 2, 0x12345678);
65*f3782652STreehugger Robot VDUP(vector, , float, f, 32, 2, 1.9f);
66*f3782652STreehugger Robot VDUP(vector, q, uint, u, 32, 4, 0xABCDEF10);
67*f3782652STreehugger Robot VDUP(vector, q, float, f, 32, 4, 125.0f);
68*f3782652STreehugger Robot
69*f3782652STreehugger Robot /* Apply the operator */
70*f3782652STreehugger Robot TEST_VRECPE(, uint, u, 32, 2);
71*f3782652STreehugger Robot TEST_VRECPE(, float, f, 32, 2);
72*f3782652STreehugger Robot TEST_VRECPE(q, uint, u, 32, 4);
73*f3782652STreehugger Robot TEST_VRECPE(q, float, f, 32, 4);
74*f3782652STreehugger Robot
75*f3782652STreehugger Robot fprintf (ref_file, "\n%s %s output:\n", TEST_MSG, " (positive input)");
76*f3782652STreehugger Robot DUMP(TEST_MSG, uint, 32, 2, PRIx32);
77*f3782652STreehugger Robot DUMP(TEST_MSG, uint, 32, 4, PRIx32);
78*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 2, PRIx32);
79*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 4, PRIx32);
80*f3782652STreehugger Robot
81*f3782652STreehugger Robot /* Choose init value arbitrarily */
82*f3782652STreehugger Robot VDUP(vector, , uint, u, 32, 2, 0xFFFFFFFF);
83*f3782652STreehugger Robot VDUP(vector, , float, f, 32, 2, -10.0f);
84*f3782652STreehugger Robot VDUP(vector, q, uint, u, 32, 4, 0x89081234);
85*f3782652STreehugger Robot VDUP(vector, q, float, f, 32, 4, -125.0f);
86*f3782652STreehugger Robot
87*f3782652STreehugger Robot /* Apply the operator */
88*f3782652STreehugger Robot TEST_VRECPE(, uint, u, 32, 2);
89*f3782652STreehugger Robot TEST_VRECPE(, float, f, 32, 2);
90*f3782652STreehugger Robot TEST_VRECPE(q, uint, u, 32, 4);
91*f3782652STreehugger Robot TEST_VRECPE(q, float, f, 32, 4);
92*f3782652STreehugger Robot
93*f3782652STreehugger Robot fprintf (ref_file, "\n%s %s output:\n", TEST_MSG, " (negative input)");
94*f3782652STreehugger Robot DUMP(TEST_MSG, uint, 32, 2, PRIx32);
95*f3782652STreehugger Robot DUMP(TEST_MSG, uint, 32, 4, PRIx32);
96*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 2, PRIx32);
97*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 4, PRIx32);
98*f3782652STreehugger Robot
99*f3782652STreehugger Robot /* Test FP variants with special input values (NaN, infinity) */
100*f3782652STreehugger Robot VDUP(vector, , float, f, 32, 2, NAN);
101*f3782652STreehugger Robot VDUP(vector, q, float, f, 32, 4, HUGE_VALF);
102*f3782652STreehugger Robot
103*f3782652STreehugger Robot /* Apply the operator */
104*f3782652STreehugger Robot TEST_VRECPE(, float, f, 32, 2);
105*f3782652STreehugger Robot TEST_VRECPE(q, float, f, 32, 4);
106*f3782652STreehugger Robot
107*f3782652STreehugger Robot fprintf (ref_file, "\n%s %s output:\n", TEST_MSG, " FP special (NaN, infinity)");
108*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 2, PRIx32);
109*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 4, PRIx32);
110*f3782652STreehugger Robot
111*f3782652STreehugger Robot /* Test FP variants with special input values (zero, large value) */
112*f3782652STreehugger Robot VDUP(vector, , float, f, 32, 2, 0.0f);
113*f3782652STreehugger Robot VDUP(vector, q, float, f, 32, 4, 9.0e37f);
114*f3782652STreehugger Robot
115*f3782652STreehugger Robot /* Apply the operator */
116*f3782652STreehugger Robot TEST_VRECPE(, float, f, 32, 2);
117*f3782652STreehugger Robot TEST_VRECPE(q, float, f, 32, 4);
118*f3782652STreehugger Robot
119*f3782652STreehugger Robot fprintf (ref_file, "\n%s %s output:\n", TEST_MSG, " FP special (zero, large value)");
120*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 2, PRIx32);
121*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 4, PRIx32);
122*f3782652STreehugger Robot
123*f3782652STreehugger Robot /* Test FP variants with special input values (-0, -infinity) */
124*f3782652STreehugger Robot VDUP(vector, , float, f, 32, 2, -0.0f);
125*f3782652STreehugger Robot VDUP(vector, q, float, f, 32, 4, -HUGE_VALF);
126*f3782652STreehugger Robot
127*f3782652STreehugger Robot /* Apply the operator */
128*f3782652STreehugger Robot TEST_VRECPE(, float, f, 32, 2);
129*f3782652STreehugger Robot TEST_VRECPE(q, float, f, 32, 4);
130*f3782652STreehugger Robot
131*f3782652STreehugger Robot fprintf (ref_file, "\n%s %s output:\n", TEST_MSG, " FP special (-0, -infinity)");
132*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 2, PRIx32);
133*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 4, PRIx32);
134*f3782652STreehugger Robot
135*f3782652STreehugger Robot /* Test FP variants with special input values (large negative value) */
136*f3782652STreehugger Robot VDUP(vector, , float, f, 32, 2, -9.0e37f);
137*f3782652STreehugger Robot
138*f3782652STreehugger Robot /* Apply the operator */
139*f3782652STreehugger Robot TEST_VRECPE(, float, f, 32, 2);
140*f3782652STreehugger Robot
141*f3782652STreehugger Robot fprintf (ref_file, "\n%s %s output:\n", TEST_MSG, " FP special (large negative value)");
142*f3782652STreehugger Robot DUMP_FP(TEST_MSG, float, 32, 2, PRIx32);
143*f3782652STreehugger Robot }
144