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 "VRSQRTE/VRSQRTEQ"
exec_vrsqrte(void)36 void exec_vrsqrte(void)
37 {
38 int i;
39
40 /* Basic test: y=vrsqrte(x), then store the result. */
41 #define TEST_VRSQRTE(Q, T1, T2, W, N) \
42 VECT_VAR(vector_res, T1, W, N) = \
43 vrsqrte##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, float, 32, 2);
53 DECL_VARIABLE(vector, uint, 32, 4);
54 DECL_VARIABLE(vector, float, 32, 4);
55
56 DECL_VARIABLE(vector_res, uint, 32, 2);
57 DECL_VARIABLE(vector_res, float, 32, 2);
58 DECL_VARIABLE(vector_res, uint, 32, 4);
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, 25.799999f);
66 VDUP(vector, q, uint, u, 32, 4, 0xABCDEF10);
67 VDUP(vector, q, float, f, 32, 4, 18.2f);
68
69 /* Apply the operator */
70 TEST_VRSQRTE(, uint, u, 32, 2);
71 TEST_VRSQRTE(, float, f, 32, 2);
72 TEST_VRSQRTE(q, uint, u, 32, 4);
73 TEST_VRSQRTE(q, float, f, 32, 4);
74
75 fprintf (ref_file, "\n%s output:\n", TEST_MSG);
76 fprintf (gcc_tests_file, "\n%s output:\n", TEST_MSG);
77 DUMP(TEST_MSG, uint, 32, 2, PRIx32);
78 DUMP(TEST_MSG, uint, 32, 4, PRIx32);
79 DUMP_FP(TEST_MSG, float, 32, 2, PRIx32);
80 DUMP_FP(TEST_MSG, float, 32, 4, PRIx32);
81
82 /* Don't test FP variants with negative inputs: the result depends
83 on the platform */
84 /* Choose init value arbitrarily */
85 VDUP(vector, , uint, u, 32, 2, 0xFFFFFFFF);
86 VDUP(vector, q, uint, u, 32, 4, 0x89081234);
87
88 /* Apply the operator */
89 TEST_VRSQRTE(, uint, u, 32, 2);
90 TEST_VRSQRTE(q, uint, u, 32, 4);
91
92 fprintf (ref_file, "\n%s output:\n", TEST_MSG " (2)");
93 DUMP(TEST_MSG, uint, 32, 2, PRIx32);
94 DUMP(TEST_MSG, uint, 32, 4, PRIx32);
95
96 /* Choose init value arbitrarily */
97 VDUP(vector, , uint, u, 32, 2, 0x80000000);
98 VDUP(vector, q, uint, u, 32, 4, 0x4ABCDEF0);
99
100 /* Apply the operator */
101 TEST_VRSQRTE(, uint, u, 32, 2);
102 TEST_VRSQRTE(q, uint, u, 32, 4);
103
104 fprintf (ref_file, "\n%s output:\n", TEST_MSG " (3)");
105 DUMP(TEST_MSG, uint, 32, 2, PRIx32);
106 DUMP(TEST_MSG, uint, 32, 4, PRIx32);
107
108 /* Test FP variants with special input values (NaNs, ...) */
109 VDUP(vector, , float, f, 32, 2, NAN);
110 VDUP(vector, q, float, f, 32, 4, 0.0f);
111
112 /* Apply the operator */
113 TEST_VRSQRTE(, float, f, 32, 2);
114 TEST_VRSQRTE(q, float, f, 32, 4);
115
116 fprintf (ref_file, "\n%s output:\n", TEST_MSG " FP special (NaN, 0)");
117 DUMP_FP(TEST_MSG, float, 32, 2, PRIx32);
118 DUMP_FP(TEST_MSG, float, 32, 4, PRIx32);
119
120 /* Test FP variants with special input values (negative, infinity) */
121 VDUP(vector, , float, f, 32, 2, -1.0f);
122 VDUP(vector, q, float, f, 32, 4, HUGE_VALF);
123
124 /* Apply the operator */
125 TEST_VRSQRTE(, float, f, 32, 2);
126 TEST_VRSQRTE(q, float, f, 32, 4);
127
128 fprintf (ref_file, "\n%s output:\n", TEST_MSG " FP special (negative, infinity)");
129 DUMP_FP(TEST_MSG, float, 32, 2, PRIx32);
130 DUMP_FP(TEST_MSG, float, 32, 4, PRIx32);
131
132 /* Test FP variants with special input values (-0, -infinity) */
133 VDUP(vector, , float, f, 32, 2, -0.0f);
134 VDUP(vector, q, float, f, 32, 4, -HUGE_VALF);
135
136 /* Apply the operator */
137 TEST_VRSQRTE(, float, f, 32, 2);
138 TEST_VRSQRTE(q, float, f, 32, 4);
139
140 fprintf (ref_file, "\n%s output:\n", TEST_MSG " FP special (-0, -infinity)");
141 DUMP_FP(TEST_MSG, float, 32, 2, PRIx32);
142 DUMP_FP(TEST_MSG, float, 32, 4, PRIx32);
143 }
144