blob: d96f9d2462459c5a9c1dd020500227a1ed3f44d6 [file] [log] [blame]
Christophe Lyon073831a2011-01-24 17:37:40 +01001/*
2
3Copyright (c) 2009, 2010, 2011 STMicroelectronics
4Written 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 Lyon1639b3c2011-02-18 10:37:55 +010033#include <math.h>
Christophe Lyon073831a2011-01-24 17:37:40 +010034
35#define TEST_MSG "VRSQRTE/VRSQRTEQ"
36void 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 */
Christophe Lyonf2053672014-12-16 10:26:00 +010064 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);
Christophe Lyon073831a2011-01-24 17:37:40 +010068
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);
Christophe Lyonbf218262014-07-10 15:53:15 +020076 fprintf (gcc_tests_file, "\n%s output:\n", TEST_MSG);
Christophe Lyon073831a2011-01-24 17:37:40 +010077 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 */
Christophe Lyonf2053672014-12-16 10:26:00 +010085 VDUP(vector, , uint, u, 32, 2, 0xFFFFFFFF);
86 VDUP(vector, q, uint, u, 32, 4, 0x89081234);
Christophe Lyon073831a2011-01-24 17:37:40 +010087
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 */
Christophe Lyonf2053672014-12-16 10:26:00 +010097 VDUP(vector, , uint, u, 32, 2, 0x80000000);
98 VDUP(vector, q, uint, u, 32, 4, 0x4ABCDEF0);
Christophe Lyon073831a2011-01-24 17:37:40 +010099
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);
Christophe Lyon1639b3c2011-02-18 10:37:55 +0100107
108 /* Test FP variants with special input values (NaNs, ...) */
Christophe Lyonf2053672014-12-16 10:26:00 +0100109 VDUP(vector, , float, f, 32, 2, NAN);
110 VDUP(vector, q, float, f, 32, 4, 0.0f);
Christophe Lyon1639b3c2011-02-18 10:37:55 +0100111
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) */
Christophe Lyonf2053672014-12-16 10:26:00 +0100121 VDUP(vector, , float, f, 32, 2, -1.0f);
122 VDUP(vector, q, float, f, 32, 4, HUGE_VALF);
Christophe Lyon1639b3c2011-02-18 10:37:55 +0100123
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) */
Christophe Lyonf2053672014-12-16 10:26:00 +0100133 VDUP(vector, , float, f, 32, 2, -0.0f);
134 VDUP(vector, q, float, f, 32, 4, -HUGE_VALF);
Christophe Lyon1639b3c2011-02-18 10:37:55 +0100135
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);
Christophe Lyon073831a2011-01-24 17:37:40 +0100143}