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 #ifndef INSN_NAME
36 #define INSN_NAME vmax
37 #define TEST_MSG "VMAX/VMAXQ"
38 #endif
39
40 /* Can't use the standard ref_v_binary_op.c template because vmax has
41 no 64 bits variant */
42 #define FNNAME1(NAME) void exec_ ## NAME (void)
43 #define FNNAME(NAME) FNNAME1(NAME)
44
FNNAME(INSN_NAME)45 FNNAME (INSN_NAME)
46 {
47 int i;
48
49 /* Basic test: y=OP(x,x), then store the result. */
50 #define TEST_BINARY_OP1(INSN, Q, T1, T2, W, N) \
51 VECT_VAR(vector_res, T1, W, N) = \
52 INSN##Q##_##T2##W(VECT_VAR(vector, T1, W, N), \
53 VECT_VAR(vector2, T1, W, N)); \
54 vst1##Q##_##T2##W(VECT_VAR(result, T1, W, N), VECT_VAR(vector_res, T1, W, N))
55
56 #define TEST_BINARY_OP(INSN, Q, T1, T2, W, N) \
57 TEST_BINARY_OP1(INSN, Q, T1, T2, W, N) \
58
59 /* With ARM RVCT, we need to declare variables before any executable
60 statement */
61 DECL_VARIABLE_ALL_VARIANTS(vector);
62 DECL_VARIABLE_ALL_VARIANTS(vector2);
63 DECL_VARIABLE_ALL_VARIANTS(vector_res);
64
65 clean_results ();
66
67 /* Initialize input "vector" from "buffer" */
68 TEST_MACRO_ALL_VARIANTS_2_5(VLOAD, vector, buffer);
69 #ifndef NO_FLOAT_VARIANT
70 VLOAD(vector, buffer, , float, f, 32, 2);
71 VLOAD(vector, buffer, q, float, f, 32, 4);
72 #endif
73
74 /* Choose init value arbitrarily, will be used as comparison value */
75 VDUP(vector2, , int, s, 8, 8, -13);
76 VDUP(vector2, , int, s, 16, 4, -14);
77 VDUP(vector2, , int, s, 32, 2, -16);
78 VDUP(vector2, , uint, u, 8, 8, 0xf3);
79 VDUP(vector2, , uint, u, 16, 4, 0xfff1);
80 VDUP(vector2, , uint, u, 32, 2, 0xfffffff0);
81 VDUP(vector2, q, int, s, 8, 16, -12);
82 VDUP(vector2, q, int, s, 16, 8, -13);
83 VDUP(vector2, q, int, s, 32, 4, -15);
84 VDUP(vector2, q, uint, u, 8, 16, 0xf9);
85 VDUP(vector2, q, uint, u, 16, 8, 0xfff2);
86 VDUP(vector2, q, uint, u, 32, 4, 0xfffffff1);
87 #ifndef NO_FLOAT_VARIANT
88 VDUP(vector2, , float, f, 32, 2, -15.5f);
89 VDUP(vector2, q, float, f, 32, 4, -14.5f);
90 #endif
91
92 #ifndef NO_FLOAT_VARIANT
93 #define FLOAT_VARIANT(MACRO, VAR) \
94 MACRO(VAR, , float, f, 32, 2); \
95 MACRO(VAR, q, float, f, 32, 4)
96 #else
97 #define FLOAT_VARIANT(MACRO, VAR)
98 #endif
99
100 #define TEST_MACRO_NO64BIT_VARIANT_1_5(MACRO, VAR) \
101 MACRO(VAR, , int, s, 8, 8); \
102 MACRO(VAR, , int, s, 16, 4); \
103 MACRO(VAR, , int, s, 32, 2); \
104 MACRO(VAR, , uint, u, 8, 8); \
105 MACRO(VAR, , uint, u, 16, 4); \
106 MACRO(VAR, , uint, u, 32, 2); \
107 MACRO(VAR, q, int, s, 8, 16); \
108 MACRO(VAR, q, int, s, 16, 8); \
109 MACRO(VAR, q, int, s, 32, 4); \
110 MACRO(VAR, q, uint, u, 8, 16); \
111 MACRO(VAR, q, uint, u, 16, 8); \
112 MACRO(VAR, q, uint, u, 32, 4); \
113 FLOAT_VARIANT(MACRO, VAR)
114
115 /* Apply a binary operator named INSN_NAME */
116 TEST_MACRO_NO64BIT_VARIANT_1_5(TEST_BINARY_OP, INSN_NAME);
117
118 dump_results_hex (TEST_MSG);
119
120
121 #ifndef NO_FLOAT_VARIANT
122 /* Extra FP tests with special values (NaN, ....) */
123 VDUP(vector, q, float, f, 32, 4, 1.0f);
124 VDUP(vector2, q, float, f, 32, 4, NAN);
125 TEST_BINARY_OP(INSN_NAME, q, float, f, 32, 4);
126 DUMP_FP(TEST_MSG " FP special (NaN)", float, 32, 4, PRIx32);
127
128 VDUP(vector, q, float, f, 32, 4, -NAN);
129 VDUP(vector2, q, float, f, 32, 4, 1.0f);
130 TEST_BINARY_OP(INSN_NAME, q, float, f, 32, 4);
131 DUMP_FP(TEST_MSG " FP special (-NaN)", float, 32, 4, PRIx32);
132
133 VDUP(vector, q, float, f, 32, 4, 1.0f);
134 VDUP(vector2, q, float, f, 32, 4, HUGE_VALF);
135 TEST_BINARY_OP(INSN_NAME, q, float, f, 32, 4);
136 DUMP_FP(TEST_MSG " FP special (inf)", float, 32, 4, PRIx32);
137
138 VDUP(vector, q, float, f, 32, 4, -HUGE_VALF);
139 VDUP(vector2, q, float, f, 32, 4, 1.0f);
140 TEST_BINARY_OP(INSN_NAME, q, float, f, 32, 4);
141 DUMP_FP(TEST_MSG " FP special (-inf)", float, 32, 4, PRIx32);
142
143 VDUP(vector, q, float, f, 32, 4, 0.0f);
144 VDUP(vector2, q, float, f, 32, 4, -0.0f);
145 TEST_BINARY_OP(INSN_NAME, q, float, f, 32, 4);
146 DUMP_FP(TEST_MSG " FP special (-0.0)", float, 32, 4, PRIx32);
147
148 VDUP(vector, q, float, f, 32, 4, -0.0f);
149 VDUP(vector2, q, float, f, 32, 4, 0.0f);
150 TEST_BINARY_OP(INSN_NAME, q, float, f, 32, 4);
151 DUMP_FP(TEST_MSG " FP special (-0.0)", float, 32, 4, PRIx32);
152 #endif
153 }
154