]>
Commit | Line | Data |
---|---|---|
7b0c0d66 TM |
1 | /* |
2 | * PowerPC Decimal Floating Point (DPF) emulation helpers for QEMU. | |
3 | * | |
4 | * Copyright (c) 2014 IBM Corporation. | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include "cpu.h" | |
21 | #include "exec/helper-proto.h" | |
22 | ||
23 | #define DECNUMDIGITS 34 | |
24 | #include "libdecnumber/decContext.h" | |
25 | #include "libdecnumber/decNumber.h" | |
26 | #include "libdecnumber/dpd/decimal32.h" | |
27 | #include "libdecnumber/dpd/decimal64.h" | |
28 | #include "libdecnumber/dpd/decimal128.h" | |
29 | ||
30 | #if defined(HOST_WORDS_BIGENDIAN) | |
31 | #define HI_IDX 0 | |
32 | #define LO_IDX 1 | |
33 | #else | |
34 | #define HI_IDX 1 | |
35 | #define LO_IDX 0 | |
36 | #endif | |
37 | ||
38 | struct PPC_DFP { | |
39 | CPUPPCState *env; | |
40 | uint64_t t64[2], a64[2], b64[2]; | |
41 | decNumber t, a, b; | |
42 | decContext context; | |
43 | uint8_t crbf; | |
44 | }; | |
45 | ||
46 | static void dfp_prepare_rounding_mode(decContext *context, uint64_t fpscr) | |
47 | { | |
48 | enum rounding rnd; | |
49 | ||
50 | switch ((fpscr >> 32) & 0x7) { | |
51 | case 0: | |
52 | rnd = DEC_ROUND_HALF_EVEN; | |
53 | break; | |
54 | case 1: | |
55 | rnd = DEC_ROUND_DOWN; | |
56 | break; | |
57 | case 2: | |
58 | rnd = DEC_ROUND_CEILING; | |
59 | break; | |
60 | case 3: | |
61 | rnd = DEC_ROUND_FLOOR; | |
62 | break; | |
63 | case 4: | |
64 | rnd = DEC_ROUND_HALF_UP; | |
65 | break; | |
66 | case 5: | |
67 | rnd = DEC_ROUND_HALF_DOWN; | |
68 | break; | |
69 | case 6: | |
70 | rnd = DEC_ROUND_UP; | |
71 | break; | |
72 | case 7: | |
73 | rnd = DEC_ROUND_05UP; | |
74 | break; | |
75 | default: | |
76 | g_assert_not_reached(); | |
77 | } | |
78 | ||
79 | decContextSetRounding(context, rnd); | |
80 | } | |
81 | ||
7b0c0d66 TM |
82 | static void dfp_prepare_decimal64(struct PPC_DFP *dfp, uint64_t *a, |
83 | uint64_t *b, CPUPPCState *env) | |
84 | { | |
85 | decContextDefault(&dfp->context, DEC_INIT_DECIMAL64); | |
86 | dfp_prepare_rounding_mode(&dfp->context, env->fpscr); | |
87 | dfp->env = env; | |
88 | ||
89 | if (a) { | |
90 | dfp->a64[0] = *a; | |
91 | decimal64ToNumber((decimal64 *)dfp->a64, &dfp->a); | |
92 | } else { | |
93 | dfp->a64[0] = 0; | |
94 | decNumberZero(&dfp->a); | |
95 | } | |
96 | ||
97 | if (b) { | |
98 | dfp->b64[0] = *b; | |
99 | decimal64ToNumber((decimal64 *)dfp->b64, &dfp->b); | |
100 | } else { | |
101 | dfp->b64[0] = 0; | |
102 | decNumberZero(&dfp->b); | |
103 | } | |
104 | } | |
105 | ||
7b0c0d66 TM |
106 | static void dfp_prepare_decimal128(struct PPC_DFP *dfp, uint64_t *a, |
107 | uint64_t *b, CPUPPCState *env) | |
108 | { | |
109 | decContextDefault(&dfp->context, DEC_INIT_DECIMAL128); | |
110 | dfp_prepare_rounding_mode(&dfp->context, env->fpscr); | |
111 | dfp->env = env; | |
112 | ||
113 | if (a) { | |
114 | dfp->a64[0] = a[HI_IDX]; | |
115 | dfp->a64[1] = a[LO_IDX]; | |
116 | decimal128ToNumber((decimal128 *)dfp->a64, &dfp->a); | |
117 | } else { | |
118 | dfp->a64[0] = dfp->a64[1] = 0; | |
119 | decNumberZero(&dfp->a); | |
120 | } | |
121 | ||
122 | if (b) { | |
123 | dfp->b64[0] = b[HI_IDX]; | |
124 | dfp->b64[1] = b[LO_IDX]; | |
125 | decimal128ToNumber((decimal128 *)dfp->b64, &dfp->b); | |
126 | } else { | |
127 | dfp->b64[0] = dfp->b64[1] = 0; | |
128 | decNumberZero(&dfp->b); | |
129 | } | |
130 | } | |
27722744 TM |
131 | |
132 | #define FP_FX (1ull << FPSCR_FX) | |
133 | #define FP_FEX (1ull << FPSCR_FEX) | |
134 | #define FP_OX (1ull << FPSCR_OX) | |
135 | #define FP_OE (1ull << FPSCR_OE) | |
136 | #define FP_UX (1ull << FPSCR_UX) | |
137 | #define FP_UE (1ull << FPSCR_UE) | |
138 | #define FP_XX (1ull << FPSCR_XX) | |
139 | #define FP_XE (1ull << FPSCR_XE) | |
140 | #define FP_ZX (1ull << FPSCR_ZX) | |
141 | #define FP_ZE (1ull << FPSCR_ZE) | |
142 | #define FP_VX (1ull << FPSCR_VX) | |
143 | #define FP_VXSNAN (1ull << FPSCR_VXSNAN) | |
144 | #define FP_VXISI (1ull << FPSCR_VXISI) | |
145 | #define FP_VXIMZ (1ull << FPSCR_VXIMZ) | |
146 | #define FP_VXZDZ (1ull << FPSCR_VXZDZ) | |
147 | #define FP_VXIDI (1ull << FPSCR_VXIDI) | |
148 | #define FP_VXVC (1ull << FPSCR_VXVC) | |
149 | #define FP_VXCVI (1ull << FPSCR_VXCVI) | |
150 | #define FP_VE (1ull << FPSCR_VE) | |
151 | #define FP_FI (1ull << FPSCR_FI) | |
152 | ||
27722744 TM |
153 | static void dfp_set_FPSCR_flag(struct PPC_DFP *dfp, uint64_t flag, |
154 | uint64_t enabled) | |
155 | { | |
156 | dfp->env->fpscr |= (flag | FP_FX); | |
157 | if (dfp->env->fpscr & enabled) { | |
158 | dfp->env->fpscr |= FP_FEX; | |
159 | } | |
160 | } | |
a9d7ba03 TM |
161 | |
162 | static void dfp_set_FPRF_from_FRT_with_context(struct PPC_DFP *dfp, | |
163 | decContext *context) | |
164 | { | |
165 | uint64_t fprf = 0; | |
166 | ||
167 | /* construct FPRF */ | |
168 | switch (decNumberClass(&dfp->t, context)) { | |
169 | case DEC_CLASS_SNAN: | |
170 | fprf = 0x01; | |
171 | break; | |
172 | case DEC_CLASS_QNAN: | |
173 | fprf = 0x11; | |
174 | break; | |
175 | case DEC_CLASS_NEG_INF: | |
176 | fprf = 0x09; | |
177 | break; | |
178 | case DEC_CLASS_NEG_NORMAL: | |
179 | fprf = 0x08; | |
180 | break; | |
181 | case DEC_CLASS_NEG_SUBNORMAL: | |
182 | fprf = 0x18; | |
183 | break; | |
184 | case DEC_CLASS_NEG_ZERO: | |
185 | fprf = 0x12; | |
186 | break; | |
187 | case DEC_CLASS_POS_ZERO: | |
188 | fprf = 0x02; | |
189 | break; | |
190 | case DEC_CLASS_POS_SUBNORMAL: | |
191 | fprf = 0x14; | |
192 | break; | |
193 | case DEC_CLASS_POS_NORMAL: | |
194 | fprf = 0x04; | |
195 | break; | |
196 | case DEC_CLASS_POS_INF: | |
197 | fprf = 0x05; | |
198 | break; | |
199 | default: | |
200 | assert(0); /* should never get here */ | |
201 | } | |
202 | dfp->env->fpscr &= ~(0x1F << 12); | |
203 | dfp->env->fpscr |= (fprf << 12); | |
204 | } | |
205 | ||
206 | static void dfp_set_FPRF_from_FRT(struct PPC_DFP *dfp) | |
207 | { | |
208 | dfp_set_FPRF_from_FRT_with_context(dfp, &dfp->context); | |
209 | } | |
210 | ||
211 | static void dfp_check_for_OX(struct PPC_DFP *dfp) | |
212 | { | |
213 | if (dfp->context.status & DEC_Overflow) { | |
214 | dfp_set_FPSCR_flag(dfp, FP_OX, FP_OE); | |
215 | } | |
216 | } | |
217 | ||
218 | static void dfp_check_for_UX(struct PPC_DFP *dfp) | |
219 | { | |
220 | if (dfp->context.status & DEC_Underflow) { | |
221 | dfp_set_FPSCR_flag(dfp, FP_UX, FP_UE); | |
222 | } | |
223 | } | |
224 | ||
225 | static void dfp_check_for_XX(struct PPC_DFP *dfp) | |
226 | { | |
227 | if (dfp->context.status & DEC_Inexact) { | |
228 | dfp_set_FPSCR_flag(dfp, FP_XX | FP_FI, FP_XE); | |
229 | } | |
230 | } | |
231 | ||
9024ff40 TM |
232 | static void dfp_check_for_ZX(struct PPC_DFP *dfp) |
233 | { | |
234 | if (dfp->context.status & DEC_Division_by_zero) { | |
235 | dfp_set_FPSCR_flag(dfp, FP_ZX, FP_ZE); | |
236 | } | |
237 | } | |
238 | ||
a9d7ba03 TM |
239 | static void dfp_check_for_VXSNAN(struct PPC_DFP *dfp) |
240 | { | |
241 | if (dfp->context.status & DEC_Invalid_operation) { | |
242 | if (decNumberIsSNaN(&dfp->a) || decNumberIsSNaN(&dfp->b)) { | |
243 | dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXSNAN, FP_VE); | |
244 | } | |
245 | } | |
246 | } | |
247 | ||
248 | static void dfp_check_for_VXISI(struct PPC_DFP *dfp, int testForSameSign) | |
249 | { | |
250 | if (dfp->context.status & DEC_Invalid_operation) { | |
251 | if (decNumberIsInfinite(&dfp->a) && decNumberIsInfinite(&dfp->b)) { | |
252 | int same = decNumberClass(&dfp->a, &dfp->context) == | |
253 | decNumberClass(&dfp->b, &dfp->context); | |
254 | if ((same && testForSameSign) || (!same && !testForSameSign)) { | |
255 | dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXISI, FP_VE); | |
256 | } | |
257 | } | |
258 | } | |
259 | } | |
260 | ||
261 | static void dfp_check_for_VXISI_add(struct PPC_DFP *dfp) | |
262 | { | |
263 | dfp_check_for_VXISI(dfp, 0); | |
264 | } | |
265 | ||
2128f8a5 TM |
266 | static void dfp_check_for_VXISI_subtract(struct PPC_DFP *dfp) |
267 | { | |
268 | dfp_check_for_VXISI(dfp, 1); | |
269 | } | |
270 | ||
8de6a1cc TM |
271 | static void dfp_check_for_VXIMZ(struct PPC_DFP *dfp) |
272 | { | |
273 | if (dfp->context.status & DEC_Invalid_operation) { | |
274 | if ((decNumberIsInfinite(&dfp->a) && decNumberIsZero(&dfp->b)) || | |
275 | (decNumberIsInfinite(&dfp->b) && decNumberIsZero(&dfp->a))) { | |
276 | dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXIMZ, FP_VE); | |
277 | } | |
278 | } | |
279 | } | |
280 | ||
9024ff40 TM |
281 | static void dfp_check_for_VXZDZ(struct PPC_DFP *dfp) |
282 | { | |
283 | if (dfp->context.status & DEC_Division_undefined) { | |
284 | dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXZDZ, FP_VE); | |
285 | } | |
286 | } | |
287 | ||
288 | static void dfp_check_for_VXIDI(struct PPC_DFP *dfp) | |
289 | { | |
290 | if (dfp->context.status & DEC_Invalid_operation) { | |
291 | if (decNumberIsInfinite(&dfp->a) && decNumberIsInfinite(&dfp->b)) { | |
292 | dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXIDI, FP_VE); | |
293 | } | |
294 | } | |
295 | } | |
296 | ||
5833505b TM |
297 | static void dfp_check_for_VXVC(struct PPC_DFP *dfp) |
298 | { | |
299 | if (decNumberIsNaN(&dfp->a) || decNumberIsNaN(&dfp->b)) { | |
300 | dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXVC, FP_VE); | |
301 | } | |
302 | } | |
303 | ||
304 | static void dfp_set_CRBF_from_T(struct PPC_DFP *dfp) | |
305 | { | |
306 | if (decNumberIsNaN(&dfp->t)) { | |
307 | dfp->crbf = 1; | |
308 | } else if (decNumberIsZero(&dfp->t)) { | |
309 | dfp->crbf = 2; | |
310 | } else if (decNumberIsNegative(&dfp->t)) { | |
311 | dfp->crbf = 8; | |
312 | } else { | |
313 | dfp->crbf = 4; | |
314 | } | |
315 | } | |
316 | ||
317 | static void dfp_set_FPCC_from_CRBF(struct PPC_DFP *dfp) | |
318 | { | |
319 | dfp->env->fpscr &= ~(0xF << 12); | |
320 | dfp->env->fpscr |= (dfp->crbf << 12); | |
321 | } | |
322 | ||
a9d7ba03 TM |
323 | #define DFP_HELPER_TAB(op, dnop, postprocs, size) \ |
324 | void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *a, uint64_t *b) \ | |
325 | { \ | |
326 | struct PPC_DFP dfp; \ | |
327 | dfp_prepare_decimal##size(&dfp, a, b, env); \ | |
328 | dnop(&dfp.t, &dfp.a, &dfp.b, &dfp.context); \ | |
329 | decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, &dfp.context); \ | |
330 | postprocs(&dfp); \ | |
331 | if (size == 64) { \ | |
332 | t[0] = dfp.t64[0]; \ | |
333 | } else if (size == 128) { \ | |
334 | t[0] = dfp.t64[HI_IDX]; \ | |
335 | t[1] = dfp.t64[LO_IDX]; \ | |
336 | } \ | |
337 | } | |
338 | ||
339 | static void ADD_PPs(struct PPC_DFP *dfp) | |
340 | { | |
341 | dfp_set_FPRF_from_FRT(dfp); | |
342 | dfp_check_for_OX(dfp); | |
343 | dfp_check_for_UX(dfp); | |
344 | dfp_check_for_XX(dfp); | |
345 | dfp_check_for_VXSNAN(dfp); | |
346 | dfp_check_for_VXISI_add(dfp); | |
347 | } | |
348 | ||
349 | DFP_HELPER_TAB(dadd, decNumberAdd, ADD_PPs, 64) | |
350 | DFP_HELPER_TAB(daddq, decNumberAdd, ADD_PPs, 128) | |
2128f8a5 TM |
351 | |
352 | static void SUB_PPs(struct PPC_DFP *dfp) | |
353 | { | |
354 | dfp_set_FPRF_from_FRT(dfp); | |
355 | dfp_check_for_OX(dfp); | |
356 | dfp_check_for_UX(dfp); | |
357 | dfp_check_for_XX(dfp); | |
358 | dfp_check_for_VXSNAN(dfp); | |
359 | dfp_check_for_VXISI_subtract(dfp); | |
360 | } | |
361 | ||
362 | DFP_HELPER_TAB(dsub, decNumberSubtract, SUB_PPs, 64) | |
363 | DFP_HELPER_TAB(dsubq, decNumberSubtract, SUB_PPs, 128) | |
8de6a1cc TM |
364 | |
365 | static void MUL_PPs(struct PPC_DFP *dfp) | |
366 | { | |
367 | dfp_set_FPRF_from_FRT(dfp); | |
368 | dfp_check_for_OX(dfp); | |
369 | dfp_check_for_UX(dfp); | |
370 | dfp_check_for_XX(dfp); | |
371 | dfp_check_for_VXSNAN(dfp); | |
372 | dfp_check_for_VXIMZ(dfp); | |
373 | } | |
374 | ||
375 | DFP_HELPER_TAB(dmul, decNumberMultiply, MUL_PPs, 64) | |
376 | DFP_HELPER_TAB(dmulq, decNumberMultiply, MUL_PPs, 128) | |
9024ff40 TM |
377 | |
378 | static void DIV_PPs(struct PPC_DFP *dfp) | |
379 | { | |
380 | dfp_set_FPRF_from_FRT(dfp); | |
381 | dfp_check_for_OX(dfp); | |
382 | dfp_check_for_UX(dfp); | |
383 | dfp_check_for_ZX(dfp); | |
384 | dfp_check_for_XX(dfp); | |
385 | dfp_check_for_VXSNAN(dfp); | |
386 | dfp_check_for_VXZDZ(dfp); | |
387 | dfp_check_for_VXIDI(dfp); | |
388 | } | |
389 | ||
390 | DFP_HELPER_TAB(ddiv, decNumberDivide, DIV_PPs, 64) | |
391 | DFP_HELPER_TAB(ddivq, decNumberDivide, DIV_PPs, 128) | |
5833505b TM |
392 | |
393 | #define DFP_HELPER_BF_AB(op, dnop, postprocs, size) \ | |
394 | uint32_t helper_##op(CPUPPCState *env, uint64_t *a, uint64_t *b) \ | |
395 | { \ | |
396 | struct PPC_DFP dfp; \ | |
397 | dfp_prepare_decimal##size(&dfp, a, b, env); \ | |
398 | dnop(&dfp.t, &dfp.a, &dfp.b, &dfp.context); \ | |
399 | decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, &dfp.context); \ | |
400 | postprocs(&dfp); \ | |
401 | return dfp.crbf; \ | |
402 | } | |
403 | ||
404 | static void CMPU_PPs(struct PPC_DFP *dfp) | |
405 | { | |
406 | dfp_set_CRBF_from_T(dfp); | |
407 | dfp_set_FPCC_from_CRBF(dfp); | |
408 | dfp_check_for_VXSNAN(dfp); | |
409 | } | |
410 | ||
411 | DFP_HELPER_BF_AB(dcmpu, decNumberCompare, CMPU_PPs, 64) | |
412 | DFP_HELPER_BF_AB(dcmpuq, decNumberCompare, CMPU_PPs, 128) | |
413 | ||
414 | static void CMPO_PPs(struct PPC_DFP *dfp) | |
415 | { | |
416 | dfp_set_CRBF_from_T(dfp); | |
417 | dfp_set_FPCC_from_CRBF(dfp); | |
418 | dfp_check_for_VXSNAN(dfp); | |
419 | dfp_check_for_VXVC(dfp); | |
420 | } | |
421 | ||
422 | DFP_HELPER_BF_AB(dcmpo, decNumberCompare, CMPO_PPs, 64) | |
423 | DFP_HELPER_BF_AB(dcmpoq, decNumberCompare, CMPO_PPs, 128) | |
e601c1ee TM |
424 | |
425 | #define DFP_HELPER_TSTDC(op, size) \ | |
426 | uint32_t helper_##op(CPUPPCState *env, uint64_t *a, uint32_t dcm) \ | |
427 | { \ | |
428 | struct PPC_DFP dfp; \ | |
429 | int match = 0; \ | |
430 | \ | |
431 | dfp_prepare_decimal##size(&dfp, a, 0, env); \ | |
432 | \ | |
433 | match |= (dcm & 0x20) && decNumberIsZero(&dfp.a); \ | |
434 | match |= (dcm & 0x10) && decNumberIsSubnormal(&dfp.a, &dfp.context); \ | |
435 | match |= (dcm & 0x08) && decNumberIsNormal(&dfp.a, &dfp.context); \ | |
436 | match |= (dcm & 0x04) && decNumberIsInfinite(&dfp.a); \ | |
437 | match |= (dcm & 0x02) && decNumberIsQNaN(&dfp.a); \ | |
438 | match |= (dcm & 0x01) && decNumberIsSNaN(&dfp.a); \ | |
439 | \ | |
440 | if (decNumberIsNegative(&dfp.a)) { \ | |
441 | dfp.crbf = match ? 0xA : 0x8; \ | |
442 | } else { \ | |
443 | dfp.crbf = match ? 0x2 : 0x0; \ | |
444 | } \ | |
445 | \ | |
446 | dfp_set_FPCC_from_CRBF(&dfp); \ | |
447 | return dfp.crbf; \ | |
448 | } | |
449 | ||
450 | DFP_HELPER_TSTDC(dtstdc, 64) | |
451 | DFP_HELPER_TSTDC(dtstdcq, 128) | |
1bf9c0e1 TM |
452 | |
453 | #define DFP_HELPER_TSTDG(op, size) \ | |
454 | uint32_t helper_##op(CPUPPCState *env, uint64_t *a, uint32_t dcm) \ | |
455 | { \ | |
456 | struct PPC_DFP dfp; \ | |
457 | int minexp, maxexp, nzero_digits, nzero_idx, is_negative, is_zero, \ | |
458 | is_extreme_exp, is_subnormal, is_normal, leftmost_is_nonzero, \ | |
459 | match; \ | |
460 | \ | |
461 | dfp_prepare_decimal##size(&dfp, a, 0, env); \ | |
462 | \ | |
463 | if ((size) == 64) { \ | |
464 | minexp = -398; \ | |
465 | maxexp = 369; \ | |
466 | nzero_digits = 16; \ | |
467 | nzero_idx = 5; \ | |
468 | } else if ((size) == 128) { \ | |
469 | minexp = -6176; \ | |
470 | maxexp = 6111; \ | |
471 | nzero_digits = 34; \ | |
472 | nzero_idx = 11; \ | |
473 | } \ | |
474 | \ | |
475 | is_negative = decNumberIsNegative(&dfp.a); \ | |
476 | is_zero = decNumberIsZero(&dfp.a); \ | |
477 | is_extreme_exp = (dfp.a.exponent == maxexp) || \ | |
478 | (dfp.a.exponent == minexp); \ | |
479 | is_subnormal = decNumberIsSubnormal(&dfp.a, &dfp.context); \ | |
480 | is_normal = decNumberIsNormal(&dfp.a, &dfp.context); \ | |
481 | leftmost_is_nonzero = (dfp.a.digits == nzero_digits) && \ | |
482 | (dfp.a.lsu[nzero_idx] != 0); \ | |
483 | match = 0; \ | |
484 | \ | |
485 | match |= (dcm & 0x20) && is_zero && !is_extreme_exp; \ | |
486 | match |= (dcm & 0x10) && is_zero && is_extreme_exp; \ | |
487 | match |= (dcm & 0x08) && \ | |
488 | (is_subnormal || (is_normal && is_extreme_exp)); \ | |
489 | match |= (dcm & 0x04) && is_normal && !is_extreme_exp && \ | |
490 | !leftmost_is_nonzero; \ | |
491 | match |= (dcm & 0x02) && is_normal && !is_extreme_exp && \ | |
492 | leftmost_is_nonzero; \ | |
493 | match |= (dcm & 0x01) && decNumberIsSpecial(&dfp.a); \ | |
494 | \ | |
495 | if (is_negative) { \ | |
496 | dfp.crbf = match ? 0xA : 0x8; \ | |
497 | } else { \ | |
498 | dfp.crbf = match ? 0x2 : 0x0; \ | |
499 | } \ | |
500 | \ | |
501 | dfp_set_FPCC_from_CRBF(&dfp); \ | |
502 | return dfp.crbf; \ | |
503 | } | |
504 | ||
505 | DFP_HELPER_TSTDG(dtstdg, 64) | |
506 | DFP_HELPER_TSTDG(dtstdgq, 128) | |
f3d2b0bc TM |
507 | |
508 | #define DFP_HELPER_TSTEX(op, size) \ | |
509 | uint32_t helper_##op(CPUPPCState *env, uint64_t *a, uint64_t *b) \ | |
510 | { \ | |
511 | struct PPC_DFP dfp; \ | |
512 | int expa, expb, a_is_special, b_is_special; \ | |
513 | \ | |
514 | dfp_prepare_decimal##size(&dfp, a, b, env); \ | |
515 | \ | |
516 | expa = dfp.a.exponent; \ | |
517 | expb = dfp.b.exponent; \ | |
518 | a_is_special = decNumberIsSpecial(&dfp.a); \ | |
519 | b_is_special = decNumberIsSpecial(&dfp.b); \ | |
520 | \ | |
521 | if (a_is_special || b_is_special) { \ | |
522 | int atype = a_is_special ? (decNumberIsNaN(&dfp.a) ? 4 : 2) : 1; \ | |
523 | int btype = b_is_special ? (decNumberIsNaN(&dfp.b) ? 4 : 2) : 1; \ | |
524 | dfp.crbf = (atype ^ btype) ? 0x1 : 0x2; \ | |
525 | } else if (expa < expb) { \ | |
526 | dfp.crbf = 0x8; \ | |
527 | } else if (expa > expb) { \ | |
528 | dfp.crbf = 0x4; \ | |
529 | } else { \ | |
530 | dfp.crbf = 0x2; \ | |
531 | } \ | |
532 | \ | |
533 | dfp_set_FPCC_from_CRBF(&dfp); \ | |
534 | return dfp.crbf; \ | |
535 | } | |
536 | ||
537 | DFP_HELPER_TSTEX(dtstex, 64) | |
538 | DFP_HELPER_TSTEX(dtstexq, 128) | |
f6022a76 TM |
539 | |
540 | #define DFP_HELPER_TSTSF(op, size) \ | |
541 | uint32_t helper_##op(CPUPPCState *env, uint64_t *a, uint64_t *b) \ | |
542 | { \ | |
543 | struct PPC_DFP dfp; \ | |
544 | unsigned k; \ | |
545 | \ | |
546 | dfp_prepare_decimal##size(&dfp, 0, b, env); \ | |
547 | \ | |
548 | k = *a & 0x3F; \ | |
549 | \ | |
550 | if (unlikely(decNumberIsSpecial(&dfp.b))) { \ | |
551 | dfp.crbf = 1; \ | |
552 | } else if (k == 0) { \ | |
553 | dfp.crbf = 4; \ | |
554 | } else if (unlikely(decNumberIsZero(&dfp.b))) { \ | |
555 | /* Zero has no sig digits */ \ | |
556 | dfp.crbf = 4; \ | |
557 | } else { \ | |
558 | unsigned nsd = dfp.b.digits; \ | |
559 | if (k < nsd) { \ | |
560 | dfp.crbf = 8; \ | |
561 | } else if (k > nsd) { \ | |
562 | dfp.crbf = 4; \ | |
563 | } else { \ | |
564 | dfp.crbf = 2; \ | |
565 | } \ | |
566 | } \ | |
567 | \ | |
568 | dfp_set_FPCC_from_CRBF(&dfp); \ | |
569 | return dfp.crbf; \ | |
570 | } | |
571 | ||
572 | DFP_HELPER_TSTSF(dtstsf, 64) | |
573 | DFP_HELPER_TSTSF(dtstsfq, 128) |