regtest: broaden none/tests/linux/bug498317 suppression for PPC
[valgrind.git] / none / tests / arm64 / frinta_frintn.cpp
blobc0803688f698a746aec96c20ab8872987e880d5c
1 /*
2 * An extra testcase for bug484426
3 * The testcase supplied only tests single precision frinta
4 */
6 #include <type_traits>
7 #include <cassert>
9 template<typename T>
10 void test_frinta(T input, T expected)
12 T result;
13 T* rp(&result);
14 T* ip(&input);
15 if constexpr (std::is_same_v<double, T> == true)
17 __asm__ __volatile__(
18 "ldr d0, [%1];\n"
19 "frinta d0, d0;\n"
20 "str d0, [%0];\n"
21 : "+rm" (rp)
22 : "r" (ip)
23 : "memory", "d0");
24 assert(result == expected);
26 else
28 __asm__ __volatile__(
29 "ldr s0, [%1];\n"
30 "frinta s0, s0;\n"
31 "str s0, [%0];\n"
32 : "+rm" (rp)
33 : "r" (ip)
34 : "memory", "s0");
35 assert(result == expected);
39 template<typename T>
40 void test_frinta_fullvec(T* input, T* expected)
42 T result[2*sizeof(double)/sizeof(T)];
43 T* rp = result;
44 if constexpr (std::is_same_v<double, T> == true)
46 __asm__ __volatile__(
47 "ldr q23, [%1];\n"
48 "frinta v22.2d, v23.2d;\n"
49 "str q22, [%0];\n"
50 : "+rm" (rp)
51 : "r" (input)
52 : "memory", "v22", "v23");
53 assert(result[0] == expected[0]);
54 assert(result[1] == expected[1]);
56 else
58 __asm__ __volatile__(
59 "ldr q23, [%1];\n"
60 "frinta v22.4s, v23.4s;\n"
61 "str q22, [%0];\n"
62 : "+rm" (rp)
63 : "r" (input)
64 : "memory", "v22", "v23");
65 assert(result[0] == expected[0]);
66 assert(result[1] == expected[1]);
67 assert(result[2] == expected[2]);
68 assert(result[3] == expected[3]);
72 void test_frinta_halfvec(float* input, float* expected)
74 float result[2];
75 float* rp = result;
76 __asm__ __volatile__(
77 "ldr d23, [%1];\n"
78 "frinta v22.2s, v23.2s;\n"
79 "str d22, [%0];\n"
80 : "+rm" (rp)
81 : "r" (input)
82 : "memory", "v22", "v23");
83 assert(result[0] == expected[0]);
84 assert(result[1] == expected[1]);
88 template<typename T>
89 void test_frintn(T input, T expected)
91 T result;
92 T* rp(&result);
93 T* ip(&input);
94 if constexpr (std::is_same_v<double, T> == true)
96 __asm__ __volatile__(
97 "ldr d0, [%1];\n"
98 "frintn d0, d0;\n"
99 "str d0, [%0];\n"
100 : "+rm" (rp)
101 : "r" (ip)
102 : "memory", "d0");
103 assert(result == expected);
105 else
107 __asm__ __volatile__(
108 "ldr s0, [%1];\n"
109 "frintn s0, s0;\n"
110 "str s0, [%0];\n"
111 : "+rm" (rp)
112 : "r" (ip)
113 : "memory", "s0");
114 assert(result == expected);
118 template<typename T>
119 void test_frintn_fullvec(T* input, T* expected)
121 T result[2*sizeof(double)/sizeof(T)];
122 T* rp = result;
123 if constexpr (std::is_same_v<double, T> == true)
125 __asm__ __volatile__(
126 "ldr q23, [%1];\n"
127 "frintn v22.2d, v23.2d;\n"
128 "str q22, [%0];\n"
129 : "+rm" (rp)
130 : "r" (input)
131 : "memory", "v22", "v23");
132 assert(result[0] == expected[0]);
133 assert(result[1] == expected[1]);
135 else
137 __asm__ __volatile__(
138 "ldr q23, [%1];\n"
139 "frintn v22.4s, v23.4s;\n"
140 "str q22, [%0];\n"
141 : "+rm" (rp)
142 : "r" (input)
143 : "memory", "v22", "v23");
144 assert(result[0] == expected[0]);
145 assert(result[1] == expected[1]);
146 assert(result[2] == expected[2]);
147 assert(result[3] == expected[3]);
151 void test_frintn_halfvec(float* input, float* expected)
153 float result[2];
154 float* rp = result;
155 __asm__ __volatile__(
156 "ldr d23, [%1];\n"
157 "frintn v22.2s, v23.2s;\n"
158 "str d22, [%0];\n"
159 : "+rm" (rp)
160 : "r" (input)
161 : "memory", "v22", "v23");
162 assert(result[0] == expected[0]);
163 assert(result[1] == expected[1]);
166 int main()
168 // round "away from zero"
169 test_frinta(1.5, 2.0);
170 test_frinta(2.5, 3.0);
171 test_frinta(-1.5, -2.0);
172 test_frinta(-2.5, -3.0);
173 test_frinta(1.5F, 2.0F);
174 test_frinta(2.5F, 3.0F);
175 test_frinta(-1.5F, -2.0F);
176 test_frinta(-2.5F, -3.0F);
178 double in1[] = {1.5, 1.5};
179 double out1[] = {2.0, 2,0};
180 test_frinta_fullvec(in1, out1);
181 double in2[] = {2.5, 2.5};
182 double out2[] = {3.0, 3,0};
183 test_frinta_fullvec(in2, out2);
184 double in3[] = {-1.5, -1.5};
185 double out3[] = {-2.0, -2,0};
186 test_frinta_fullvec(in3, out3);
187 double in4[] = {-2.5, -2.5};
188 double out4[] = {-3.0, -3,0};
189 test_frinta_fullvec(in4, out4);
191 float in1f[] = {1.5F, 1.5F, 1.5F, 1.5F};
192 float out1f[] = {2.0F, 2.0F, 2.0F, 2.0F};
193 test_frinta_fullvec(in1f, out1f);
194 test_frinta_halfvec(in1f, out1f);
195 float in2f[] = {2.5F, 2.5F, 2.5F, 2.5F};
196 float out2f[] = {3.0F, 3.0F, 3.0F, 3.0F};
197 test_frinta_fullvec(in2f, out2f);
198 test_frinta_halfvec(in2f, out2f);
199 float in3f[] = {-1.5F, -1.5F, -1.5F, -1.5F};
200 float out3f[] = {-2.0F, -2.0F, -2.0F, -2.0F};
201 test_frinta_fullvec(in3f, out3f);
202 test_frinta_halfvec(in3f, out3f);
203 float in4f[] = {-2.5F, -2.5F, -2.5F, -2.5F};
204 float out4f[] = {-3.0F, -3.0F, -3.0F, -3.0F};
205 test_frinta_fullvec(in4f, out4f);
206 test_frinta_halfvec(in4f, out4f);
208 // round "to even"
209 test_frintn(1.5, 2.0);
210 test_frintn(2.5, 2.0);
211 test_frintn(-1.5, -2.0);
212 test_frintn(-2.5, -2.0);
213 test_frintn(1.5F, 2.0F);
214 test_frintn(2.5F, 2.0F);
215 test_frintn(-1.5F, -2.0F);
216 test_frintn(-2.5F, -2.0F);
218 test_frintn_fullvec(in1, out1);
219 test_frintn_fullvec(in2, out1);
220 test_frintn_fullvec(in3, out3);
221 test_frintn_fullvec(in4, out3);
223 test_frintn_fullvec(in1f, out1f);
224 test_frintn_halfvec(in1f, out1f);
225 test_frintn_fullvec(in2f, out1f);
226 test_frintn_halfvec(in2f, out1f);
227 test_frintn_fullvec(in3f, out3f);
228 test_frintn_halfvec(in3f, out3f);
229 test_frintn_fullvec(in4f, out3f);
230 test_frintn_halfvec(in4f, out3f);