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