blob: a22613fb006b2d345a95b908a018a565cccddf51 [file] [log] [blame]
Christophe Lyon073831a2011-01-24 17:37:40 +01001/*
2
Christophe Lyon34adaf62013-04-11 15:05:18 +02003Copyright (c) 2009, 2010, 2011, 2013 STMicroelectronics
Christophe Lyon073831a2011-01-24 17:37:40 +01004Written by Christophe Lyon
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22THE SOFTWARE.
23
24*/
25
Christophe Lyon1775be02014-07-10 13:46:54 +020026#if defined(__arm__) || defined(__aarch64__)
Christophe Lyon073831a2011-01-24 17:37:40 +010027#include <arm_neon.h>
28#else
Christophe Lyon0dab5f72011-07-19 17:14:09 +020029#include "stm-arm-neon.h"
Christophe Lyon073831a2011-01-24 17:37:40 +010030#endif
31
32#include "stm-arm-neon-ref.h"
Christophe Lyon34adaf62013-04-11 15:05:18 +020033#include <math.h>
Christophe Lyon073831a2011-01-24 17:37:40 +010034
35#define TEST_MSG "VCVT/VCVTQ"
36void exec_vcvt (void)
37{
38 int i;
39
40 /* Basic test: y=vcvt(x), then store the result. */
41#define TEST_VCVT(Q, T1, T2, W, N, TS1, TS2) \
42 VECT_VAR(vector_res, T1, W, N) = \
43 vcvt##Q##_##T2##W##_##TS2##W(VECT_VAR(vector, TS1, W, N)); \
44 vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N), \
45 VECT_VAR(vector_res, T1, W, N)); \
46 DUMP(TEST_MSG, T1, W, N, PRIx##W);
47
48#define TEST_VCVT_FP(Q, T1, T2, W, N, TS1, TS2) \
49 VECT_VAR(vector_res, T1, W, N) = \
50 vcvt##Q##_##T2##W##_##TS2##W(VECT_VAR(vector, TS1, W, N)); \
51 vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N), \
52 VECT_VAR(vector_res, T1, W, N)); \
53 DUMP_FP(TEST_MSG, T1, W, N, PRIx##W);
54
Christophe Lyond98beba2016-08-24 18:02:41 +020055#if defined(__ARM_FP16_FORMAT_IEEE) && ( ((__ARM_FP & 0x2) != 0) || ((__ARM_NEON_FP16_INTRINSICS & 1) != 0) )
Christophe Lyon34adaf62013-04-11 15:05:18 +020056#define TEST_VCVT_FP16(T1, T2, W1, W2, N) \
57 VECT_VAR(vector_res, T1, W1, N) = \
58 vcvt_##T2##W1##_##T2##W2(VECT_VAR(vector, T1, W2, N)); \
59 vst1q_##T2##W1(VECT_VAR(result, T1, W1, N), \
60 VECT_VAR(vector_res, T1, W1, N)); \
61 DUMP_FP(TEST_MSG, T1, W1, N, PRIx##W1);
62
63#define TEST_VCVT_2FP16(T1, T2, W1, W2, N) \
64 VECT_VAR(vector_res, T1, W1, N) = \
65 vcvt_##T2##W1##_##T2##W2(VECT_VAR(vector, T1, W2, N)); \
66 vst1_##T2##W1(VECT_VAR(result, T1, W1, N), \
67 VECT_VAR(vector_res, T1, W1, N)); \
68 DUMP_FP16(TEST_MSG, T1, W1, N, PRIx##W1);
69#endif
70
Christophe Lyon073831a2011-01-24 17:37:40 +010071#define TEST_VCVT_N(Q, T1, T2, W, N, TS1, TS2, V) \
72 VECT_VAR(vector_res, T1, W, N) = \
73 vcvt##Q##_n_##T2##W##_##TS2##W(VECT_VAR(vector, TS1, W, N), V); \
74 vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N), \
75 VECT_VAR(vector_res, T1, W, N)); \
76 DUMP(TEST_MSG, T1, W, N, PRIx##W);
77
78#define TEST_VCVT_N_FP(Q, T1, T2, W, N, TS1, TS2, V) \
79 VECT_VAR(vector_res, T1, W, N) = \
80 vcvt##Q##_n_##T2##W##_##TS2##W(VECT_VAR(vector, TS1, W, N), V); \
81 vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N), \
82 VECT_VAR(vector_res, T1, W, N)); \
83 DUMP_FP(TEST_MSG, T1, W, N, PRIx##W);
84
85 /* With ARM RVCT, we need to declare variables before any executable
86 statement */
87 DECL_VARIABLE_ALL_VARIANTS(vector);
88 DECL_VARIABLE_ALL_VARIANTS(vector_res);
Christophe Lyond98beba2016-08-24 18:02:41 +020089#if defined(__ARM_FP16_FORMAT_IEEE) && ( ((__ARM_FP & 0x2) != 0) || ((__ARM_NEON_FP16_INTRINSICS & 1) != 0) )
Christophe Lyon34adaf62013-04-11 15:05:18 +020090 DECL_VARIABLE(vector_init, uint, 16, 4);
91 DECL_VARIABLE(vector_init, uint, 16, 8);
92 DECL_VARIABLE(vector, float, 16, 4);
93 DECL_VARIABLE(vector, float, 16, 8);
94 DECL_VARIABLE(vector_res, float, 16, 4);
95 DECL_VARIABLE(vector_res, float, 16, 8);
96#endif
Christophe Lyon073831a2011-01-24 17:37:40 +010097
98 clean_results ();
99
100
101 /* Initialize input "vector" from "buffer" */
Christophe Lyonf2053672014-12-16 10:26:00 +0100102 TEST_MACRO_ALL_VARIANTS_2_5(VLOAD, vector, buffer);
103 VLOAD(vector, buffer, , float, f, 32, 2);
104 VLOAD(vector, buffer, q, float, f, 32, 4);
Christophe Lyond98beba2016-08-24 18:02:41 +0200105#if defined(__ARM_FP16_FORMAT_IEEE) && ( ((__ARM_FP & 0x2) != 0) || ((__ARM_NEON_FP16_INTRINSICS & 1) != 0) )
Christophe Lyonf2053672014-12-16 10:26:00 +0100106 VLOAD(vector, buffer, , float, f, 16, 4);
107 VLOAD(vector, buffer, q, float, f, 16, 8);
Christophe Lyon34adaf62013-04-11 15:05:18 +0200108#endif
Christophe Lyon073831a2011-01-24 17:37:40 +0100109
110 /* Make sure some elements have a fractional part, to exercise
111 integer conversions */
Christophe Lyonbd9ecf42011-07-19 16:30:50 +0200112 TEST_VSET_LANE(vector, , float, f, 32, 2, 0, -15.3f);
113 TEST_VSET_LANE(vector, , float, f, 32, 2, 1, 5.3f);
114 TEST_VSET_LANE(vector, q, float, f, 32, 4, 2, -15.3f);
115 TEST_VSET_LANE(vector, q, float, f, 32, 4, 3, 5.3f);
Christophe Lyon073831a2011-01-24 17:37:40 +0100116
Christophe Lyond98beba2016-08-24 18:02:41 +0200117#if defined(__ARM_FP16_FORMAT_IEEE) && ( ((__ARM_FP & 0x2) != 0) || ((__ARM_NEON_FP16_INTRINSICS & 1) != 0) )
Christophe Lyon34adaf62013-04-11 15:05:18 +0200118 /* FP16 tests. */
119 /* There is no vdup_n_f16, so we need another initialization
120 method. */
121 /* Use all lanes with values of different types: first, a "standard"
122 positive number, a "standard" negative one, and +0 and -0. */
123 TEST_VSET_LANE(vector_init, , uint, u, 16, 4, 0, 0x4b90 /* 15.125 */);
124 TEST_VSET_LANE(vector_init, , uint, u, 16, 4, 1, 0xcb90 /* -15.125 */);
125 TEST_VSET_LANE(vector_init, , uint, u, 16, 4, 2, 0 /* 0 */);
126 TEST_VSET_LANE(vector_init, , uint, u, 16, 4, 3, 0x8000 /* -0 */);
127 VECT_VAR(vector, float, 16, 4) =
128 vreinterpret_f16_u16(VECT_VAR(vector_init, uint, 16, 4));
129#endif
130
Christophe Lyon073831a2011-01-24 17:37:40 +0100131 /* The same result buffers are used multiple times, so we output
132 them before overwriting them */
133 fprintf(ref_file, "\n%s output:\n", TEST_MSG);
Christophe Lyonbf218262014-07-10 15:53:15 +0200134 fprintf(gcc_tests_file, "\n%s output:\n", TEST_MSG);
Christophe Lyon073831a2011-01-24 17:37:40 +0100135
136 /* vcvt_f32_xx */
137 TEST_VCVT_FP(, float, f, 32, 2, int, s);
138 TEST_VCVT_FP(, float, f, 32, 2, uint, u);
Christophe Lyond98beba2016-08-24 18:02:41 +0200139#if defined(__ARM_FP16_FORMAT_IEEE) && ( ((__ARM_FP & 0x2) != 0) || ((__ARM_NEON_FP16_INTRINSICS & 1) != 0) )
Christophe Lyon34adaf62013-04-11 15:05:18 +0200140 TEST_VCVT_FP16(float, f, 32, 16, 4);
141#endif
Christophe Lyon073831a2011-01-24 17:37:40 +0100142
143 /* vcvtq_f32_xx */
144 TEST_VCVT_FP(q, float, f, 32, 4, int, s);
145 TEST_VCVT_FP(q, float, f, 32, 4, uint, u);
146
147 /* vcvt_xx_f32 */
148 TEST_VCVT(, int, s, 32, 2, float, f);
149 TEST_VCVT(, uint, u, 32, 2, float, f);
150
Christophe Lyon34adaf62013-04-11 15:05:18 +0200151 TEST_VSET_LANE(vector, q, float, f, 32, 4, 0, 0.0f);
152 TEST_VSET_LANE(vector, q, float, f, 32, 4, 1, -0.0f);
153 TEST_VSET_LANE(vector, q, float, f, 32, 4, 2, 15.12f);
154 TEST_VSET_LANE(vector, q, float, f, 32, 4, 3, -15.12f);
Christophe Lyond98beba2016-08-24 18:02:41 +0200155#if defined(__ARM_FP16_FORMAT_IEEE) && ( ((__ARM_FP & 0x2) != 0) || ((__ARM_NEON_FP16_INTRINSICS & 1) != 0) )
Christophe Lyon34adaf62013-04-11 15:05:18 +0200156 TEST_VCVT_2FP16(float, f, 16, 32, 4);
157#endif
158
Christophe Lyon073831a2011-01-24 17:37:40 +0100159 /* vcvtq_xx_f32 */
160 TEST_VCVT(q, int, s, 32, 4, float, f);
161 TEST_VCVT(q, uint, u, 32, 4, float, f);
162
163 /* The same result buffers are used multiple times, so output them
164 before overwriting them */
165#undef TEST_MSG
166#define TEST_MSG "VCVT_N/VCVTQ_N"
167 fprintf(ref_file, "\n%s output:\n", TEST_MSG);
Christophe Lyonbf218262014-07-10 15:53:15 +0200168 fprintf(gcc_tests_file, "\n%s output:\n", TEST_MSG);
Christophe Lyon073831a2011-01-24 17:37:40 +0100169
170 /* vcvt_n_f32_xx */
171 TEST_VCVT_N_FP(, float, f, 32, 2, int, s, 2);
172 TEST_VCVT_N_FP(, float, f, 32, 2, uint, u, 7);
173
174 /* vcvtq_n_f32_xx */
175 TEST_VCVT_N_FP(q, float, f, 32, 4, int, s, 30);
176 TEST_VCVT_N_FP(q, float, f, 32, 4, uint, u, 12);
177
178 /* vcvt_n_xx_f32 */
179 TEST_VCVT_N(, int, s, 32, 2, float, f, 20);
180 TEST_VCVT_N(, uint, u, 32, 2, float, f, 2);
181
182 /* vcvtq_n_xx_f32 */
183 TEST_VCVT_N(q, int, s, 32, 4, float, f, 13);
184 TEST_VCVT_N(q, uint, u, 32, 4, float, f, 1);
185
186 /* Check rounding */
187#undef TEST_MSG
188#define TEST_MSG "VCVT/VCVTQ"
189 fprintf(ref_file, "\n%s output:\n", TEST_MSG " (check rounding)");
Christophe Lyonf2053672014-12-16 10:26:00 +0100190 VDUP(vector, , float, f, 32, 2, 10.4f);
191 VDUP(vector, q, float, f, 32, 4, 125.9f);
Christophe Lyon073831a2011-01-24 17:37:40 +0100192 /* vcvt_xx_f32 */
193 TEST_VCVT(, int, s, 32, 2, float, f);
194 TEST_VCVT(, uint, u, 32, 2, float, f);
195 /* vcvtq_xx_f32 */
196 TEST_VCVT(q, int, s, 32, 4, float, f);
197 TEST_VCVT(q, uint, u, 32, 4, float, f);
198
199#undef TEST_MSG
200#define TEST_MSG "VCVT_N/VCVTQ_N"
201 fprintf(ref_file, "\n%s output:\n", TEST_MSG " (check rounding)");
202 /* vcvt_n_xx_f32 */
203 TEST_VCVT_N(, int, s, 32, 2, float, f, 20);
204 TEST_VCVT_N(, uint, u, 32, 2, float, f, 20);
205 /* vcvtq_n_xx_f32 */
206 TEST_VCVT_N(q, int, s, 32, 4, float, f, 13);
207 TEST_VCVT_N(q, uint, u, 32, 4, float, f, 13);
208
209#undef TEST_MSG
210#define TEST_MSG "VCVT_N/VCVTQ_N"
211 fprintf(ref_file, "\n%s output:\n", TEST_MSG " (check saturation)");
212 /* vcvt_n_xx_f32 */
213 TEST_VCVT_N(, int, s, 32, 2, float, f, 31);
214 /* vcvtq_n_xx_f32 */
215 TEST_VCVT_N(q, int, s, 32, 4, float, f, 31);
Christophe Lyon34adaf62013-04-11 15:05:18 +0200216
Christophe Lyond98beba2016-08-24 18:02:41 +0200217#if defined(__ARM_FP16_FORMAT_IEEE) && ( ((__ARM_FP & 0x2) != 0) || ((__ARM_NEON_FP16_INTRINSICS & 1) != 0) )
Christophe Lyon34adaf62013-04-11 15:05:18 +0200218#undef TEST_MSG
219#define TEST_MSG "VCVT FP16"
220 fprintf(ref_file, "\n%s output:\n", TEST_MSG " (check fp16-fp32 inf/nan/denormal)");
221 TEST_VSET_LANE(vector_init, , uint, u, 16, 4, 0, 0x0390 /* DENORMAL */);
222 TEST_VSET_LANE(vector_init, , uint, u, 16, 4, 1, 0x7c00 /* inf */);
223 TEST_VSET_LANE(vector_init, , uint, u, 16, 4, 2, 0x7e00 /* nan */);
224 TEST_VSET_LANE(vector_init, , uint, u, 16, 4, 3, 0xfc00 /* -inf */);
225 VECT_VAR(vector, float, 16, 4) =
226 vreinterpret_f16_u16(VECT_VAR(vector_init, uint, 16, 4));
227 TEST_VCVT_FP16(float, f, 32, 16, 4);
228
229 fprintf(ref_file, "\n%s output:\n", TEST_MSG " (check fp32-fp16 inf/nan)");
230 TEST_VSET_LANE(vector, q, float, f, 32, 4, 0, NAN);
231 TEST_VSET_LANE(vector, q, float, f, 32, 4, 1, HUGE_VALF);
232 TEST_VSET_LANE(vector, q, float, f, 32, 4, 2, -HUGE_VALF);
233 TEST_VSET_LANE(vector, q, float, f, 32, 4, 3, -0.0f);
234 TEST_VCVT_2FP16(float, f, 16, 32, 4);
235#endif
Christophe Lyon073831a2011-01-24 17:37:40 +0100236}