FreeBSD: add file descriptor tracking for _umtx_op
[valgrind.git] / none / tests / s390x / dfp-2.c
blob39427089a188d5fbcecf1db80dcfde56de1d986c
1 #include "dfp_utils.h"
2 #include <stdint.h>
3 #include <stdio.h>
5 #define ITERATE_0_15(x) \
6 x(0); \
7 x(1); \
8 x(2); \
9 x(3); \
10 x(4); \
11 x(5); \
12 x(6); \
13 x(7); \
14 x(8); \
15 x(9); \
16 x(10); \
17 x(11); \
18 x(12); \
19 x(13); \
20 x(14); \
21 x(15);
23 /* Extract biased exponent; extract significance */
25 #define MAKE_EXTRACT(fun, name, opcode, type) \
26 static void fun(type in) \
27 { \
28 long out; \
29 asm(".insn rre," #opcode "0000, %[out], %[in]" \
30 : [out] "=d"(out) \
31 : [in] "f"(in.f)); \
32 printf("%s ", #name); \
33 DFP_VAL_PRINT(in, type); \
34 printf(" -> %ld\n", out); \
37 MAKE_EXTRACT(eedtr, EEDTR, 0xb3e5, pun_d64)
38 MAKE_EXTRACT(eextr, EEXTR, 0xb3ed, pun_d128)
39 MAKE_EXTRACT(esdtr, ESDTR, 0xb3e7, pun_d64)
40 MAKE_EXTRACT(esxtr, ESXTR, 0xb3ef, pun_d128)
42 /* Insert biased exponent */
44 #define MAKE_INSERT(fun, name, opcode, type) \
45 static void fun(type in, long amount) \
46 { \
47 type out; \
48 asm(".insn rrf," #opcode "0000, %[out], %[amount], %[in], 0" \
49 : [out] "=f"(out.f) \
50 : [in] "f"(in.f), [amount] "d"(amount)); \
51 printf("%s ", #name); \
52 DFP_VAL_PRINT(in, type); \
53 printf(", %ld -> ", amount); \
54 DFP_VAL_PRINT(out, type); \
55 printf("\n"); \
58 MAKE_INSERT(iedtr, IEDTR, 0xb3f6, pun_d64)
59 MAKE_INSERT(iextr, IEXTR, 0xb3fe, pun_d128)
61 /* Load and test */
63 #define MAKE_LOAD_AND_TEST(fun, name, opcode, type) \
64 static void fun(type in) \
65 { \
66 type out; \
67 int cc; \
68 asm(".insn rre," #opcode "0000, %[out], %[in]\n\t" \
69 "ipm %[cc]\n\t" \
70 "srl %[cc],28" \
71 : [out] "=f"(out.f), [cc] "=d"(cc) \
72 : [in] "f"(in.f)); \
73 printf("%s ", #name); \
74 DFP_VAL_PRINT(in, type); \
75 printf(" -> %d\n", cc); \
78 MAKE_LOAD_AND_TEST(ltdtr, LTDTR, 0xb3d6, pun_d64)
79 MAKE_LOAD_AND_TEST(ltxtr, LTXTR, 0xb3de, pun_d128)
81 /* Quantize */
83 #define MAKE_QUANTIZE(fun, name, opcode, type, rm) \
84 static void fun##rm(type op, type quan) \
85 { \
86 type out; \
87 asm(".insn rrf," #opcode "0000, %[out], %[quan], %[op], %[m]" \
88 : [out] "=f"(out.f) \
89 : [op] "f"(op.f), [quan] "f"(quan.f), [m] "i"(rm)); \
90 printf("%s ", #name); \
91 DFP_VAL_PRINT(op, type); \
92 printf(", "); \
93 DFP_VAL_PRINT(quan, type); \
94 printf(", %x -> ", rm); \
95 DFP_VAL_PRINT(out, type); \
96 printf("\n"); \
99 #define MAKE_QADTR(rm) MAKE_QUANTIZE(qadtr, QADTR, 0xb3f5, pun_d64, rm)
100 #define CALL_QADTR(rm) qadtr##rm(op, quan)
102 ITERATE_0_15(MAKE_QADTR)
104 void quantize64(pun_d64 op, pun_d64 quan) { ITERATE_0_15(CALL_QADTR); }
106 #define MAKE_QAXTR(rm) MAKE_QUANTIZE(qaxtr, QAXTR, 0xb3fd, pun_d128, rm)
107 #define CALL_QAXTR(rm) qaxtr##rm(op, quan)
109 ITERATE_0_15(MAKE_QAXTR)
111 void quantize128(pun_d128 op, pun_d128 quan) { ITERATE_0_15(CALL_QAXTR); }
113 /* Reround */
115 #define MAKE_REROUND(fun, name, opcode, type, rm) \
116 static void fun##rm(type op, uint8_t sig) \
118 type out; \
119 asm(".insn rrf," #opcode "0000, %[out], %[sig], %[op], %[m]" \
120 : [out] "=f"(out.f) \
121 : [op] "f"(op.f), [sig] "d"(sig), [m] "i"(rm)); \
122 printf("%s ", #name); \
123 DFP_VAL_PRINT(op, type); \
124 printf(", %d, %x -> ", sig, rm); \
125 DFP_VAL_PRINT(out, type); \
126 printf("\n"); \
129 #define MAKE_RRDTR(rm) MAKE_REROUND(rrdtr, RRDTR, 0xb3f7, pun_d64, rm)
130 #define CALL_RRDTR(rm) rrdtr##rm(op, sig)
132 ITERATE_0_15(MAKE_RRDTR)
134 void reround64(pun_d64 op, uint8_t sig) { ITERATE_0_15(CALL_RRDTR); }
136 #define MAKE_RRXTR(rm) MAKE_REROUND(rrxtr, RRXTR, 0xb3ff, pun_d128, rm)
137 #define CALL_RRXTR(rm) rrxtr##rm(op, sig)
139 ITERATE_0_15(MAKE_RRXTR)
141 void reround128(pun_d128 op, uint8_t sig) { ITERATE_0_15(CALL_RRXTR); }
143 /* Shift significand left/right */
145 #define MAKE_SHIFT(fun, name, opcode, type) \
146 static void fun(type in, unsigned long amount) \
148 type out; \
149 int* shift = (int*)amount; \
150 asm(".insn rxf, " #opcode ", %[out], %[in], 0(%[amount])" \
151 : [out] "=f"(out.f) \
152 : [in] "f"(in.f), [amount] "a"(shift)); \
153 printf("%s ", #name); \
154 DFP_VAL_PRINT(in, type); \
155 printf(" -> "); \
156 DFP_VAL_PRINT(out, type); \
157 printf("\n"); \
160 MAKE_SHIFT(sldt, SLDT, 0xed0000000040, pun_d64)
161 MAKE_SHIFT(slxt, SLXT, 0xed0000000048, pun_d128)
162 MAKE_SHIFT(srdt, SRDT, 0xed0000000041, pun_d64)
163 MAKE_SHIFT(srxt, SRXT, 0xed0000000049, pun_d128)
165 /* 64-bit decimal constants */
166 static const pun_d64 dd_0 = {0x2238000000000000}; /* 0.DD */
167 static const pun_d64 dd_00 = {0x2234000000000000}; /* 0.0DD */
168 static const pun_d64 dd_m0 = {0xa238000000000000}; /* -0.DD */
169 static const pun_d64 dd_1 = {0x2238000000000001}; /* 1.DD */
170 static const pun_d64 dd_A = {0x22280000000a0005}; /* 50.0005DD */
171 static const pun_d64 dd_mA = {0xa2280000000a0005}; /* -50.0005DD */
172 static const pun_d64 dd_B = {0x2224014d2e7971a1}; /* 12345678.54321DD */
173 static const pun_d64 dd_mB = {0xa224014d2e7971a1}; /* -12345678.54321DD */
174 static const pun_d64 dd_C = {0x2220000000500005}; /* 5.000005DD */
175 static const pun_d64 dd_mC = {0xa220000000500005}; /* -5.000005DD */
176 static const pun_d64 dd_D = {0x222000000023c534}; /* 2.171234DD */
177 static const pun_d64 dd_mD = {0xa22000000023c534}; /* -2.171234DD */
178 static const pun_d64 dd_DQ = {0x222c000000000001}; /* 0.001DD */
179 static const pun_d64 dd_E = {0x222000000023d2de}; /* 2.174598DD */
180 static const pun_d64 dd_mE = {0xa22000000023d2de}; /* -2.174598DD */
182 /* 128-bit versions of the same constants, except:
183 dl_D = 26365343648.171234DL
184 dl_DQ = 230.01DL */
185 static const pun_d128 dl_0 = {{0x2208000000000000, 0x0000000000000000}};
186 static const pun_d128 dl_00 = {{0x2207c00000000000, 0x0000000000000000}};
187 static const pun_d128 dl_m0 = {{0xa208000000000000, 0x0000000000000000}};
188 static const pun_d128 dl_1 = {{0x2208000000000000, 0x0000000000000001}};
189 static const pun_d128 dl_A = {{0x2207000000000000, 0x00000000000a0005}};
190 static const pun_d128 dl_mA = {{0xa207000000000000, 0x00000000000a0005}};
191 static const pun_d128 dl_B = {{0x2206c00000000000, 0x0000014d2e7971a1}};
192 static const pun_d128 dl_mB = {{0xa206c00000000000, 0x0000014d2e7971a1}};
193 static const pun_d128 dl_C = {{0x2206800000000000, 0x0000000000500005}};
194 static const pun_d128 dl_mC = {{0xa206800000000000, 0x0000000000500005}};
195 static const pun_d128 dl_D = {{0x2206800000000000, 0x0099e570f483c534}};
196 static const pun_d128 dl_mD = {{0xa206800000000000, 0x0099e570f483c534}};
197 static const pun_d128 dl_DQ = {{0x2207800000000000, 0x0000000000008c01}};
198 static const pun_d128 dl_E = {{0x2206800000000000, 0x000000000023d2de}};
199 static const pun_d128 dl_mE = {{0xa206800000000000, 0x000000000023d2de}};
201 int main()
203 eedtr(dd_A);
204 eedtr(dd_mA);
205 eedtr(dd_0);
206 eextr(dl_A);
207 eextr(dl_mA);
208 eextr(dl_0);
210 esdtr(dd_A);
211 esdtr(dd_mA);
212 esdtr(dd_0);
213 esxtr(dl_A);
214 esxtr(dl_mA);
215 esxtr(dl_0);
217 ltdtr(dd_A);
218 ltdtr(dd_mA);
219 ltdtr(dd_00);
220 ltxtr(dl_A);
221 ltxtr(dl_mA);
222 ltxtr(dl_00);
224 sldt(dd_B, 10);
225 sldt(dd_mB, 2);
226 sldt(dd_0, 2);
227 sldt(dd_m0, 2);
229 srdt(dd_B, 5);
230 srdt(dd_mB, 2);
231 srdt(dd_0, 2);
232 srdt(dd_m0, 2);
234 slxt(dl_B, 10);
235 slxt(dl_mB, 2);
236 slxt(dl_0, 2);
237 slxt(dl_m0, 2);
239 srxt(dl_B, 10);
240 srxt(dl_mB, 2);
241 srxt(dl_0, 2);
242 srxt(dl_m0, 2);
244 iedtr(dd_C, 391);
245 iedtr(dd_C, 392);
246 iedtr(dd_C, 393);
247 iedtr(dd_mC, 391);
248 iedtr(dd_mC, 392);
249 iedtr(dd_mC, 393);
250 iedtr(dd_0, 393);
251 iedtr(dd_m0, 393);
252 iedtr(dd_1, 393);
254 iextr(dl_C, 6169);
255 iextr(dl_C, 6170);
256 iextr(dl_C, 6171);
257 iextr(dl_mC, 6169);
258 iextr(dl_mC, 6170);
259 iextr(dl_mC, 6171);
260 iextr(dl_0, 6171);
261 iextr(dl_m0, 6171);
262 iextr(dl_1, 6171);
264 quantize64(dd_D, dd_DQ);
265 quantize64(dd_mD, dd_DQ);
266 quantize64(dd_mD, dd_0);
267 quantize64(dd_0, dd_DQ);
269 quantize128(dl_D, dl_DQ);
270 quantize128(dl_mD, dl_DQ);
271 quantize128(dl_D, dl_0);
272 quantize128(dl_m0, dl_DQ);
274 reround64(dd_E, 3);
275 reround64(dd_E, 4);
276 reround64(dd_E, 5);
277 reround64(dd_mE, 3);
278 reround64(dd_mE, 4);
279 reround64(dd_mE, 5);
280 reround64(dd_0, 0);
282 reround128(dl_E, 3);
283 reround128(dl_E, 4);
284 reround128(dl_E, 5);
285 reround128(dl_mE, 3);
286 reround128(dl_mE, 4);
287 reround128(dl_mE, 5);
288 reround128(dl_0, 0);
290 return 0;