1*f3782652STreehugger Robot /*
2*f3782652STreehugger Robot
3*f3782652STreehugger Robot Copyright (c) 2009, 2010, 2011 STMicroelectronics
4*f3782652STreehugger Robot Written by Christophe Lyon
5*f3782652STreehugger Robot
6*f3782652STreehugger Robot Permission is hereby granted, free of charge, to any person obtaining a copy
7*f3782652STreehugger Robot of this software and associated documentation files (the "Software"), to deal
8*f3782652STreehugger Robot in the Software without restriction, including without limitation the rights
9*f3782652STreehugger Robot to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10*f3782652STreehugger Robot copies of the Software, and to permit persons to whom the Software is
11*f3782652STreehugger Robot furnished to do so, subject to the following conditions:
12*f3782652STreehugger Robot
13*f3782652STreehugger Robot The above copyright notice and this permission notice shall be included in
14*f3782652STreehugger Robot all copies or substantial portions of the Software.
15*f3782652STreehugger Robot
16*f3782652STreehugger Robot THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*f3782652STreehugger Robot IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*f3782652STreehugger Robot FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*f3782652STreehugger Robot AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*f3782652STreehugger Robot LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21*f3782652STreehugger Robot OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22*f3782652STreehugger Robot THE SOFTWARE.
23*f3782652STreehugger Robot
24*f3782652STreehugger Robot */
25*f3782652STreehugger Robot
26*f3782652STreehugger Robot #if defined(__arm__) || defined(__aarch64__)
27*f3782652STreehugger Robot #include <arm_neon.h>
28*f3782652STreehugger Robot #else
29*f3782652STreehugger Robot #include "stm-arm-neon.h"
30*f3782652STreehugger Robot #endif
31*f3782652STreehugger Robot
32*f3782652STreehugger Robot #include "stm-arm-neon-ref.h"
33*f3782652STreehugger Robot
34*f3782652STreehugger Robot #define INSN vqrshrun_n
35*f3782652STreehugger Robot #define TEST_MSG "VQRSHRUN_N"
36*f3782652STreehugger Robot
37*f3782652STreehugger Robot #define FNNAME1(NAME) void exec_ ## NAME (void)
38*f3782652STreehugger Robot #define FNNAME(NAME) FNNAME1(NAME)
39*f3782652STreehugger Robot
FNNAME(INSN)40*f3782652STreehugger Robot FNNAME (INSN)
41*f3782652STreehugger Robot {
42*f3782652STreehugger Robot /* Basic test: y=vqrshrun_n(x,v), then store the result. */
43*f3782652STreehugger Robot #define TEST_VQRSHRUN_N2(INSN, T1, T2, W, W2, N, V) \
44*f3782652STreehugger Robot Set_Neon_Cumulative_Sat(0, VECT_VAR(vector_res, uint, W2, N)); \
45*f3782652STreehugger Robot VECT_VAR(vector_res, uint, W2, N) = \
46*f3782652STreehugger Robot INSN##_##T2##W(VECT_VAR(vector, T1, W, N), \
47*f3782652STreehugger Robot V); \
48*f3782652STreehugger Robot vst1_u##W2(VECT_VAR(result, uint, W2, N), \
49*f3782652STreehugger Robot VECT_VAR(vector_res, uint, W2, N)); \
50*f3782652STreehugger Robot dump_neon_cumulative_sat(TEST_MSG, xSTR(INSN##_##T2##W), \
51*f3782652STreehugger Robot xSTR(T1), W, N)
52*f3782652STreehugger Robot
53*f3782652STreehugger Robot /* Two auxliary macros are necessary to expand INSN */
54*f3782652STreehugger Robot #define TEST_VQRSHRUN_N1(INSN, T1, T2, W, W2, N, V) \
55*f3782652STreehugger Robot TEST_VQRSHRUN_N2(INSN, T1, T2, W, W2, N, V)
56*f3782652STreehugger Robot
57*f3782652STreehugger Robot #define TEST_VQRSHRUN_N(T1, T2, W, W2, N, V) \
58*f3782652STreehugger Robot TEST_VQRSHRUN_N1(INSN, T1, T2, W, W2, N, V)
59*f3782652STreehugger Robot
60*f3782652STreehugger Robot
61*f3782652STreehugger Robot /* With ARM RVCT, we need to declare variables before any executable
62*f3782652STreehugger Robot statement */
63*f3782652STreehugger Robot
64*f3782652STreehugger Robot /* vector is twice as large as vector_res */
65*f3782652STreehugger Robot DECL_VARIABLE(vector, int, 16, 8);
66*f3782652STreehugger Robot DECL_VARIABLE(vector, int, 32, 4);
67*f3782652STreehugger Robot DECL_VARIABLE(vector, int, 64, 2);
68*f3782652STreehugger Robot
69*f3782652STreehugger Robot DECL_VARIABLE(vector_res, uint, 8, 8);
70*f3782652STreehugger Robot DECL_VARIABLE(vector_res, uint, 16, 4);
71*f3782652STreehugger Robot DECL_VARIABLE(vector_res, uint, 32, 2);
72*f3782652STreehugger Robot
73*f3782652STreehugger Robot clean_results ();
74*f3782652STreehugger Robot
75*f3782652STreehugger Robot /* Fill input vector with negative values, to check saturation on limits */
76*f3782652STreehugger Robot VDUP(vector, q, int, s, 16, 8, -2);
77*f3782652STreehugger Robot VDUP(vector, q, int, s, 32, 4, -3);
78*f3782652STreehugger Robot VDUP(vector, q, int, s, 64, 2, -4);
79*f3782652STreehugger Robot
80*f3782652STreehugger Robot /* Choose shift amount arbitrarily */
81*f3782652STreehugger Robot fprintf(ref_file, "\n%s cumulative saturation output:\n",
82*f3782652STreehugger Robot TEST_MSG " (negative input)");
83*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 16, 8, 8, 3);
84*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 32, 16, 4, 4);
85*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 64, 32, 2, 2);
86*f3782652STreehugger Robot
87*f3782652STreehugger Robot /* FIXME: only a few result buffers are used, but we output all of them */
88*f3782652STreehugger Robot dump_results_hex2 (TEST_MSG, " (negative input)");
89*f3782652STreehugger Robot
90*f3782652STreehugger Robot /* Fill input vector with max value, to check saturation on limits */
91*f3782652STreehugger Robot VDUP(vector, q, int, s, 16, 8, 0x7FFF);
92*f3782652STreehugger Robot VDUP(vector, q, int, s, 32, 4, 0x7FFFFFFF);
93*f3782652STreehugger Robot VDUP(vector, q, int, s, 64, 2, 0x7FFFFFFFFFFFFFFFLL);
94*f3782652STreehugger Robot
95*f3782652STreehugger Robot /* shift by 1 */
96*f3782652STreehugger Robot fprintf(ref_file, "\n%s cumulative saturation output:\n",
97*f3782652STreehugger Robot TEST_MSG " (check cumulative saturation: shift by 1)");
98*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 16, 8, 8, 1);
99*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 32, 16, 4, 1);
100*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 64, 32, 2, 1);
101*f3782652STreehugger Robot
102*f3782652STreehugger Robot dump_results_hex2 (TEST_MSG, " (check cumulative saturation: shift by 1)");
103*f3782652STreehugger Robot
104*f3782652STreehugger Robot /* shift by max */
105*f3782652STreehugger Robot fprintf(ref_file, "\n%s cumulative saturation output:\n",
106*f3782652STreehugger Robot TEST_MSG " (check cumulative saturation: shift by max, positive input)");
107*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 16, 8, 8, 8);
108*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 32, 16, 4, 16);
109*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 64, 32, 2, 32);
110*f3782652STreehugger Robot
111*f3782652STreehugger Robot dump_results_hex2 (TEST_MSG,
112*f3782652STreehugger Robot " (check cumulative saturation: shift by max, positive input)");
113*f3782652STreehugger Robot
114*f3782652STreehugger Robot
115*f3782652STreehugger Robot /* Fill input vector with min value, to check saturation on limits */
116*f3782652STreehugger Robot VDUP(vector, q, int, s, 16, 8, 0x8000);
117*f3782652STreehugger Robot VDUP(vector, q, int, s, 32, 4, 0x80000000);
118*f3782652STreehugger Robot VDUP(vector, q, int, s, 64, 2, 0x8000000000000000LL);
119*f3782652STreehugger Robot
120*f3782652STreehugger Robot /* shift by max */
121*f3782652STreehugger Robot fprintf(ref_file, "\n%s cumulative saturation output:\n",
122*f3782652STreehugger Robot TEST_MSG " (check cumulative saturation: shift by max, negative input)");
123*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 16, 8, 8, 8);
124*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 32, 16, 4, 16);
125*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 64, 32, 2, 32);
126*f3782652STreehugger Robot
127*f3782652STreehugger Robot dump_results_hex2 (TEST_MSG,
128*f3782652STreehugger Robot " (check cumulative saturation: shift by max, negative input)");
129*f3782652STreehugger Robot
130*f3782652STreehugger Robot /* Fill input vector with positive values, to check normal case */
131*f3782652STreehugger Robot VDUP(vector, q, int, s, 16, 8, 0x1234);
132*f3782652STreehugger Robot VDUP(vector, q, int, s, 32, 4, 0x87654321);
133*f3782652STreehugger Robot VDUP(vector, q, int, s, 64, 2, 0xDEADBEEF);
134*f3782652STreehugger Robot
135*f3782652STreehugger Robot /* shift arbitrary amount */
136*f3782652STreehugger Robot fprintf(ref_file, "\n%s cumulative saturation output:\n", TEST_MSG);
137*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 16, 8, 8, 6);
138*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 32, 16, 4, 7);
139*f3782652STreehugger Robot TEST_VQRSHRUN_N(int, s, 64, 32, 2, 8);
140*f3782652STreehugger Robot
141*f3782652STreehugger Robot dump_results_hex (TEST_MSG);
142*f3782652STreehugger Robot }
143