blob: 9ca503820ee0b6efb4adef0f07bbee12fa3452a3 [file] [log] [blame]
Christophe Lyon073831a2011-01-24 17:37:40 +01001/*
2
Christophe Lyon80902f62013-03-29 16:26:42 +01003Copyright (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 Lyonc8aa0f62011-09-26 18:00:27 +020033#include <math.h>
Christophe Lyon073831a2011-01-24 17:37:40 +010034
35
36#define FNNAME1(NAME) void exec_ ## NAME (void)
37#define FNNAME(NAME) FNNAME1(NAME)
38
39FNNAME (INSN_NAME)
40{
41 int i;
42
43 /* Basic test: y=vcomp(x,x), then store the result. */
44#define TEST_VCOMP1(INSN, Q, T1, T2, T3, W, N) \
45 VECT_VAR(vector_res, T3, W, N) = \
46 INSN##Q##_##T2##W(VECT_VAR(vector, T1, W, N), \
47 VECT_VAR(vector2, T1, W, N)); \
48 vst1##Q##_u##W(VECT_VAR(result, T3, W, N), VECT_VAR(vector_res, T3, W, N))
49
50#define TEST_VCOMP(INSN, Q, T1, T2, T3, W, N) \
51 TEST_VCOMP1(INSN, Q, T1, T2, T3, W, N)
52
53 /* With ARM RVCT, we need to declare variables before any executable
54 statement */
55 /* No need for 64 bits elements */
56 DECL_VARIABLE(vector, int, 8, 8);
57 DECL_VARIABLE(vector, int, 16, 4);
58 DECL_VARIABLE(vector, int, 32, 2);
59 DECL_VARIABLE(vector, uint, 8, 8);
60 DECL_VARIABLE(vector, uint, 16, 4);
61 DECL_VARIABLE(vector, uint, 32, 2);
62 DECL_VARIABLE(vector, float, 32, 2);
63 DECL_VARIABLE(vector, int, 8, 16);
64 DECL_VARIABLE(vector, int, 16, 8);
65 DECL_VARIABLE(vector, int, 32, 4);
66 DECL_VARIABLE(vector, uint, 8, 16);
67 DECL_VARIABLE(vector, uint, 16, 8);
68 DECL_VARIABLE(vector, uint, 32, 4);
69 DECL_VARIABLE(vector, float, 32, 4);
70
71 DECL_VARIABLE(vector2, int, 8, 8);
72 DECL_VARIABLE(vector2, int, 16, 4);
73 DECL_VARIABLE(vector2, int, 32, 2);
74 DECL_VARIABLE(vector2, uint, 8, 8);
75 DECL_VARIABLE(vector2, uint, 16, 4);
76 DECL_VARIABLE(vector2, uint, 32, 2);
77 DECL_VARIABLE(vector2, float, 32, 2);
78 DECL_VARIABLE(vector2, int, 8, 16);
79 DECL_VARIABLE(vector2, int, 16, 8);
80 DECL_VARIABLE(vector2, int, 32, 4);
81 DECL_VARIABLE(vector2, uint, 8, 16);
82 DECL_VARIABLE(vector2, uint, 16, 8);
83 DECL_VARIABLE(vector2, uint, 32, 4);
84 DECL_VARIABLE(vector2, float, 32, 4);
85
86 DECL_VARIABLE(vector_res, uint, 8, 8);
87 DECL_VARIABLE(vector_res, uint, 16, 4);
88 DECL_VARIABLE(vector_res, uint, 32, 2);
89 DECL_VARIABLE(vector_res, uint, 8, 16);
90 DECL_VARIABLE(vector_res, uint, 16, 8);
91 DECL_VARIABLE(vector_res, uint, 32, 4);
92
93 clean_results ();
94
95 /* There is no 64 bits variant, we can't use the generic initializer */
Christophe Lyonf2053672014-12-16 10:26:00 +010096 VLOAD(vector, buffer, , int, s, 8, 8);
97 VLOAD(vector, buffer, , int, s, 16, 4);
98 VLOAD(vector, buffer, , int, s, 32, 2);
99 VLOAD(vector, buffer, , uint, u, 8, 8);
100 VLOAD(vector, buffer, , uint, u, 16, 4);
101 VLOAD(vector, buffer, , uint, u, 32, 2);
102 VLOAD(vector, buffer, , float, f, 32, 2);
Christophe Lyon073831a2011-01-24 17:37:40 +0100103
Christophe Lyonf2053672014-12-16 10:26:00 +0100104 VLOAD(vector, buffer, q, int, s, 8, 16);
105 VLOAD(vector, buffer, q, int, s, 16, 8);
106 VLOAD(vector, buffer, q, int, s, 32, 4);
107 VLOAD(vector, buffer, q, uint, u, 8, 16);
108 VLOAD(vector, buffer, q, uint, u, 16, 8);
109 VLOAD(vector, buffer, q, uint, u, 32, 4);
110 VLOAD(vector, buffer, q, float, f, 32, 4);
Christophe Lyon073831a2011-01-24 17:37:40 +0100111
112 /* Choose init value arbitrarily, will be used for vector
113 comparison */
Christophe Lyonf2053672014-12-16 10:26:00 +0100114 VDUP(vector2, , int, s, 8, 8, -10);
115 VDUP(vector2, , int, s, 16, 4, -14);
116 VDUP(vector2, , int, s, 32, 2, -16);
117 VDUP(vector2, , uint, u, 8, 8, 0xF3);
118 VDUP(vector2, , uint, u, 16, 4, 0xFFF2);
119 VDUP(vector2, , uint, u, 32, 2, 0xFFFFFFF1);
120 VDUP(vector2, , float, f, 32, 2, -15.0f);
Christophe Lyon073831a2011-01-24 17:37:40 +0100121
Christophe Lyonf2053672014-12-16 10:26:00 +0100122 VDUP(vector2, q, int, s, 8, 16, -4);
123 VDUP(vector2, q, int, s, 16, 8, -10);
124 VDUP(vector2, q, int, s, 32, 4, -14);
125 VDUP(vector2, q, uint, u, 8, 16, 0xF4);
126 VDUP(vector2, q, uint, u, 16, 8, 0xFFF6);
127 VDUP(vector2, q, uint, u, 32, 4, 0xFFFFFFF2);
128 VDUP(vector2, q, float, f, 32, 4, -14.0f);
Christophe Lyon073831a2011-01-24 17:37:40 +0100129
130 /* The same result buffers are used multiple times, so output them
131 before overwriting them */
132 fprintf(ref_file, "\n%s output:\n", TEST_MSG);
Christophe Lyonbf218262014-07-10 15:53:15 +0200133 fprintf(gcc_tests_file, "\n%s output:\n", TEST_MSG);
Christophe Lyon073831a2011-01-24 17:37:40 +0100134 TEST_VCOMP(INSN_NAME, , int, s, uint, 8, 8);
135 TEST_VCOMP(INSN_NAME, , int, s, uint, 16, 4);
136 TEST_VCOMP(INSN_NAME, , int, s, uint, 32, 2);
137 DUMP(TEST_MSG, uint, 8, 8, PRIx8);
138 DUMP(TEST_MSG, uint, 16, 4, PRIx16);
139 DUMP(TEST_MSG, uint, 32, 2, PRIx32);
140
141 TEST_VCOMP(INSN_NAME, , uint, u, uint, 8, 8);
142 TEST_VCOMP(INSN_NAME, , uint, u, uint, 16, 4);
143 TEST_VCOMP(INSN_NAME, , uint, u, uint, 32, 2);
144 DUMP(TEST_MSG, uint, 8, 8, PRIx8);
145 DUMP(TEST_MSG, uint, 16, 4, PRIx16);
146 DUMP(TEST_MSG, uint, 32, 2, PRIx32);
147
148 TEST_VCOMP(INSN_NAME, q, int, s, uint, 8, 16);
149 TEST_VCOMP(INSN_NAME, q, int, s, uint, 16, 8);
150 TEST_VCOMP(INSN_NAME, q, int, s, uint, 32, 4);
151 DUMP(TEST_MSG, uint, 8, 16, PRIx8);
152 DUMP(TEST_MSG, uint, 16, 8, PRIx16);
153 DUMP(TEST_MSG, uint, 32, 4, PRIx32);
154
155 TEST_VCOMP(INSN_NAME, q, uint, u, uint, 8, 16);
156 TEST_VCOMP(INSN_NAME, q, uint, u, uint, 16, 8);
157 TEST_VCOMP(INSN_NAME, q, uint, u, uint, 32, 4);
158 DUMP(TEST_MSG, uint, 8, 16, PRIx8);
159 DUMP(TEST_MSG, uint, 16, 8, PRIx16);
160 DUMP(TEST_MSG, uint, 32, 4, PRIx32);
161
162 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
163 DUMP(TEST_MSG, uint, 32, 2, PRIx32);
164
165 TEST_VCOMP(INSN_NAME, q, float, f, uint, 32, 4);
166 DUMP(TEST_MSG, uint, 32, 4, PRIx32);
167
168 /* Extra tests to have 100% coverage on all the variants */
Christophe Lyonf2053672014-12-16 10:26:00 +0100169 VDUP(vector2, , uint, u, 32, 2, 0xFFFFFFF0);
Christophe Lyon073831a2011-01-24 17:37:40 +0100170 TEST_VCOMP(INSN_NAME, , uint, u, uint, 32, 2);
171 DUMP(TEST_MSG, uint, 32, 2, PRIx32);
172
Christophe Lyonf2053672014-12-16 10:26:00 +0100173 VDUP(vector2, , int, s, 32, 2, -15);
Christophe Lyon073831a2011-01-24 17:37:40 +0100174 TEST_VCOMP(INSN_NAME, , int, s, uint, 32, 2);
175 DUMP(TEST_MSG, uint, 32, 2, PRIx32);
176
Christophe Lyonf2053672014-12-16 10:26:00 +0100177 VDUP(vector2, , float, f, 32, 2, -16.0f);
Christophe Lyon073831a2011-01-24 17:37:40 +0100178 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
179 DUMP(TEST_MSG, uint, 32, 2, PRIx32);
Christophe Lyonc8aa0f62011-09-26 18:00:27 +0200180
181
182 /* Extra FP tests with special values (NaN, ....) */
Christophe Lyonf2053672014-12-16 10:26:00 +0100183 VDUP(vector, , float, f, 32, 2, 1.0);
184 VDUP(vector2, , float, f, 32, 2, NAN);
Christophe Lyonc8aa0f62011-09-26 18:00:27 +0200185 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
Christophe Lyon269df922011-10-17 15:53:53 +0200186 DUMP(TEST_MSG " FP special (NaN)", uint, 32, 2, PRIx32);
187
Christophe Lyonf2053672014-12-16 10:26:00 +0100188 VDUP(vector, , float, f, 32, 2, 1.0);
189 VDUP(vector2, , float, f, 32, 2, -NAN);
Christophe Lyon269df922011-10-17 15:53:53 +0200190 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
191 DUMP(TEST_MSG " FP special (-NaN)", uint, 32, 2, PRIx32);
Christophe Lyonc8aa0f62011-09-26 18:00:27 +0200192
Christophe Lyonf2053672014-12-16 10:26:00 +0100193 VDUP(vector, , float, f, 32, 2, NAN);
194 VDUP(vector2, , float, f, 32, 2, 1.0);
Christophe Lyonc8aa0f62011-09-26 18:00:27 +0200195 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
Christophe Lyon269df922011-10-17 15:53:53 +0200196 DUMP(TEST_MSG " FP special (NaN)", uint, 32, 2, PRIx32);
Christophe Lyonc8aa0f62011-09-26 18:00:27 +0200197
Christophe Lyonf2053672014-12-16 10:26:00 +0100198 VDUP(vector, , float, f, 32, 2, 1.0);
199 VDUP(vector2, , float, f, 32, 2, HUGE_VALF);
Christophe Lyonc8aa0f62011-09-26 18:00:27 +0200200 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
201 DUMP(TEST_MSG " FP special (inf)", uint, 32, 2, PRIx32);
202
Christophe Lyonf2053672014-12-16 10:26:00 +0100203 VDUP(vector, , float, f, 32, 2, 1.0);
204 VDUP(vector2, , float, f, 32, 2, -HUGE_VALF);
Christophe Lyon269df922011-10-17 15:53:53 +0200205 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
206 DUMP(TEST_MSG " FP special (-inf)", uint, 32, 2, PRIx32);
207
Christophe Lyonf2053672014-12-16 10:26:00 +0100208 VDUP(vector, , float, f, 32, 2, HUGE_VALF);
209 VDUP(vector2, , float, f, 32, 2, 1.0);
Christophe Lyonc8aa0f62011-09-26 18:00:27 +0200210 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
211 DUMP(TEST_MSG " FP special (inf)", uint, 32, 2, PRIx32);
212
Christophe Lyonf2053672014-12-16 10:26:00 +0100213 VDUP(vector, , float, f, 32, 2, -0.0);
214 VDUP(vector2, , float, f, 32, 2, 0.0);
Christophe Lyonc8aa0f62011-09-26 18:00:27 +0200215 TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
216 DUMP(TEST_MSG " FP special (-0.0)", uint, 32, 2, PRIx32);
Christophe Lyon80902f62013-03-29 16:26:42 +0100217
218#ifdef EXTRA_TESTS
219 EXTRA_TESTS();
220#endif
Christophe Lyon073831a2011-01-24 17:37:40 +0100221}