qmp: add ACPI_DEVICE_OST event handling
[qemu.git] / target-ppc / dfp_helper.c
blob773803a28559dde6ab81b4b78bbec3439fe94b9a
1 /*
2 * PowerPC Decimal Floating Point (DPF) emulation helpers for QEMU.
4 * Copyright (c) 2014 IBM Corporation.
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.
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.
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/>.
20 #include "cpu.h"
21 #include "exec/helper-proto.h"
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"
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
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;
46 static void dfp_prepare_rounding_mode(decContext *context, uint64_t fpscr)
48 enum rounding rnd;
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();
79 decContextSetRounding(context, rnd);
82 static void dfp_set_round_mode_from_immediate(uint8_t r, uint8_t rmc,
83 struct PPC_DFP *dfp)
85 enum rounding rnd;
86 if (r == 0) {
87 switch (rmc & 3) {
88 case 0:
89 rnd = DEC_ROUND_HALF_EVEN;
90 break;
91 case 1:
92 rnd = DEC_ROUND_DOWN;
93 break;
94 case 2:
95 rnd = DEC_ROUND_HALF_UP;
96 break;
97 case 3: /* use FPSCR rounding mode */
98 return;
99 default:
100 assert(0); /* cannot get here */
102 } else { /* r == 1 */
103 switch (rmc & 3) {
104 case 0:
105 rnd = DEC_ROUND_CEILING;
106 break;
107 case 1:
108 rnd = DEC_ROUND_FLOOR;
109 break;
110 case 2:
111 rnd = DEC_ROUND_UP;
112 break;
113 case 3:
114 rnd = DEC_ROUND_HALF_DOWN;
115 break;
116 default:
117 assert(0); /* cannot get here */
120 decContextSetRounding(&dfp->context, rnd);
123 static void dfp_prepare_decimal64(struct PPC_DFP *dfp, uint64_t *a,
124 uint64_t *b, CPUPPCState *env)
126 decContextDefault(&dfp->context, DEC_INIT_DECIMAL64);
127 dfp_prepare_rounding_mode(&dfp->context, env->fpscr);
128 dfp->env = env;
130 if (a) {
131 dfp->a64[0] = *a;
132 decimal64ToNumber((decimal64 *)dfp->a64, &dfp->a);
133 } else {
134 dfp->a64[0] = 0;
135 decNumberZero(&dfp->a);
138 if (b) {
139 dfp->b64[0] = *b;
140 decimal64ToNumber((decimal64 *)dfp->b64, &dfp->b);
141 } else {
142 dfp->b64[0] = 0;
143 decNumberZero(&dfp->b);
147 static void dfp_prepare_decimal128(struct PPC_DFP *dfp, uint64_t *a,
148 uint64_t *b, CPUPPCState *env)
150 decContextDefault(&dfp->context, DEC_INIT_DECIMAL128);
151 dfp_prepare_rounding_mode(&dfp->context, env->fpscr);
152 dfp->env = env;
154 if (a) {
155 dfp->a64[0] = a[HI_IDX];
156 dfp->a64[1] = a[LO_IDX];
157 decimal128ToNumber((decimal128 *)dfp->a64, &dfp->a);
158 } else {
159 dfp->a64[0] = dfp->a64[1] = 0;
160 decNumberZero(&dfp->a);
163 if (b) {
164 dfp->b64[0] = b[HI_IDX];
165 dfp->b64[1] = b[LO_IDX];
166 decimal128ToNumber((decimal128 *)dfp->b64, &dfp->b);
167 } else {
168 dfp->b64[0] = dfp->b64[1] = 0;
169 decNumberZero(&dfp->b);
173 #define FP_FX (1ull << FPSCR_FX)
174 #define FP_FEX (1ull << FPSCR_FEX)
175 #define FP_OX (1ull << FPSCR_OX)
176 #define FP_OE (1ull << FPSCR_OE)
177 #define FP_UX (1ull << FPSCR_UX)
178 #define FP_UE (1ull << FPSCR_UE)
179 #define FP_XX (1ull << FPSCR_XX)
180 #define FP_XE (1ull << FPSCR_XE)
181 #define FP_ZX (1ull << FPSCR_ZX)
182 #define FP_ZE (1ull << FPSCR_ZE)
183 #define FP_VX (1ull << FPSCR_VX)
184 #define FP_VXSNAN (1ull << FPSCR_VXSNAN)
185 #define FP_VXISI (1ull << FPSCR_VXISI)
186 #define FP_VXIMZ (1ull << FPSCR_VXIMZ)
187 #define FP_VXZDZ (1ull << FPSCR_VXZDZ)
188 #define FP_VXIDI (1ull << FPSCR_VXIDI)
189 #define FP_VXVC (1ull << FPSCR_VXVC)
190 #define FP_VXCVI (1ull << FPSCR_VXCVI)
191 #define FP_VE (1ull << FPSCR_VE)
192 #define FP_FI (1ull << FPSCR_FI)
194 static void dfp_set_FPSCR_flag(struct PPC_DFP *dfp, uint64_t flag,
195 uint64_t enabled)
197 dfp->env->fpscr |= (flag | FP_FX);
198 if (dfp->env->fpscr & enabled) {
199 dfp->env->fpscr |= FP_FEX;
203 static void dfp_set_FPRF_from_FRT_with_context(struct PPC_DFP *dfp,
204 decContext *context)
206 uint64_t fprf = 0;
208 /* construct FPRF */
209 switch (decNumberClass(&dfp->t, context)) {
210 case DEC_CLASS_SNAN:
211 fprf = 0x01;
212 break;
213 case DEC_CLASS_QNAN:
214 fprf = 0x11;
215 break;
216 case DEC_CLASS_NEG_INF:
217 fprf = 0x09;
218 break;
219 case DEC_CLASS_NEG_NORMAL:
220 fprf = 0x08;
221 break;
222 case DEC_CLASS_NEG_SUBNORMAL:
223 fprf = 0x18;
224 break;
225 case DEC_CLASS_NEG_ZERO:
226 fprf = 0x12;
227 break;
228 case DEC_CLASS_POS_ZERO:
229 fprf = 0x02;
230 break;
231 case DEC_CLASS_POS_SUBNORMAL:
232 fprf = 0x14;
233 break;
234 case DEC_CLASS_POS_NORMAL:
235 fprf = 0x04;
236 break;
237 case DEC_CLASS_POS_INF:
238 fprf = 0x05;
239 break;
240 default:
241 assert(0); /* should never get here */
243 dfp->env->fpscr &= ~(0x1F << 12);
244 dfp->env->fpscr |= (fprf << 12);
247 static void dfp_set_FPRF_from_FRT(struct PPC_DFP *dfp)
249 dfp_set_FPRF_from_FRT_with_context(dfp, &dfp->context);
252 static void dfp_set_FPRF_from_FRT_short(struct PPC_DFP *dfp)
254 decContext shortContext;
255 decContextDefault(&shortContext, DEC_INIT_DECIMAL32);
256 dfp_set_FPRF_from_FRT_with_context(dfp, &shortContext);
259 static void dfp_set_FPRF_from_FRT_long(struct PPC_DFP *dfp)
261 decContext longContext;
262 decContextDefault(&longContext, DEC_INIT_DECIMAL64);
263 dfp_set_FPRF_from_FRT_with_context(dfp, &longContext);
266 static void dfp_check_for_OX(struct PPC_DFP *dfp)
268 if (dfp->context.status & DEC_Overflow) {
269 dfp_set_FPSCR_flag(dfp, FP_OX, FP_OE);
273 static void dfp_check_for_UX(struct PPC_DFP *dfp)
275 if (dfp->context.status & DEC_Underflow) {
276 dfp_set_FPSCR_flag(dfp, FP_UX, FP_UE);
280 static void dfp_check_for_XX(struct PPC_DFP *dfp)
282 if (dfp->context.status & DEC_Inexact) {
283 dfp_set_FPSCR_flag(dfp, FP_XX | FP_FI, FP_XE);
287 static void dfp_check_for_ZX(struct PPC_DFP *dfp)
289 if (dfp->context.status & DEC_Division_by_zero) {
290 dfp_set_FPSCR_flag(dfp, FP_ZX, FP_ZE);
294 static void dfp_check_for_VXSNAN(struct PPC_DFP *dfp)
296 if (dfp->context.status & DEC_Invalid_operation) {
297 if (decNumberIsSNaN(&dfp->a) || decNumberIsSNaN(&dfp->b)) {
298 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXSNAN, FP_VE);
303 static void dfp_check_for_VXSNAN_and_convert_to_QNaN(struct PPC_DFP *dfp)
305 if (decNumberIsSNaN(&dfp->t)) {
306 dfp->t.bits &= ~DECSNAN;
307 dfp->t.bits |= DECNAN;
308 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXSNAN, FP_VE);
312 static void dfp_check_for_VXISI(struct PPC_DFP *dfp, int testForSameSign)
314 if (dfp->context.status & DEC_Invalid_operation) {
315 if (decNumberIsInfinite(&dfp->a) && decNumberIsInfinite(&dfp->b)) {
316 int same = decNumberClass(&dfp->a, &dfp->context) ==
317 decNumberClass(&dfp->b, &dfp->context);
318 if ((same && testForSameSign) || (!same && !testForSameSign)) {
319 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXISI, FP_VE);
325 static void dfp_check_for_VXISI_add(struct PPC_DFP *dfp)
327 dfp_check_for_VXISI(dfp, 0);
330 static void dfp_check_for_VXISI_subtract(struct PPC_DFP *dfp)
332 dfp_check_for_VXISI(dfp, 1);
335 static void dfp_check_for_VXIMZ(struct PPC_DFP *dfp)
337 if (dfp->context.status & DEC_Invalid_operation) {
338 if ((decNumberIsInfinite(&dfp->a) && decNumberIsZero(&dfp->b)) ||
339 (decNumberIsInfinite(&dfp->b) && decNumberIsZero(&dfp->a))) {
340 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXIMZ, FP_VE);
345 static void dfp_check_for_VXZDZ(struct PPC_DFP *dfp)
347 if (dfp->context.status & DEC_Division_undefined) {
348 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXZDZ, FP_VE);
352 static void dfp_check_for_VXIDI(struct PPC_DFP *dfp)
354 if (dfp->context.status & DEC_Invalid_operation) {
355 if (decNumberIsInfinite(&dfp->a) && decNumberIsInfinite(&dfp->b)) {
356 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXIDI, FP_VE);
361 static void dfp_check_for_VXVC(struct PPC_DFP *dfp)
363 if (decNumberIsNaN(&dfp->a) || decNumberIsNaN(&dfp->b)) {
364 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXVC, FP_VE);
368 static void dfp_check_for_VXCVI(struct PPC_DFP *dfp)
370 if ((dfp->context.status & DEC_Invalid_operation) &&
371 (!decNumberIsSNaN(&dfp->a)) &&
372 (!decNumberIsSNaN(&dfp->b))) {
373 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXCVI, FP_VE);
377 static void dfp_set_CRBF_from_T(struct PPC_DFP *dfp)
379 if (decNumberIsNaN(&dfp->t)) {
380 dfp->crbf = 1;
381 } else if (decNumberIsZero(&dfp->t)) {
382 dfp->crbf = 2;
383 } else if (decNumberIsNegative(&dfp->t)) {
384 dfp->crbf = 8;
385 } else {
386 dfp->crbf = 4;
390 static void dfp_set_FPCC_from_CRBF(struct PPC_DFP *dfp)
392 dfp->env->fpscr &= ~(0xF << 12);
393 dfp->env->fpscr |= (dfp->crbf << 12);
396 static inline void dfp_makeQNaN(decNumber *dn)
398 dn->bits &= ~DECSPECIAL;
399 dn->bits |= DECNAN;
402 static inline int dfp_get_digit(decNumber *dn, int n)
404 assert(DECDPUN == 3);
405 int unit = n / DECDPUN;
406 int dig = n % DECDPUN;
407 switch (dig) {
408 case 0:
409 return dn->lsu[unit] % 10;
410 case 1:
411 return (dn->lsu[unit] / 10) % 10;
412 case 2:
413 return dn->lsu[unit] / 100;
414 default:
415 assert(0);
419 #define DFP_HELPER_TAB(op, dnop, postprocs, size) \
420 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *a, uint64_t *b) \
422 struct PPC_DFP dfp; \
423 dfp_prepare_decimal##size(&dfp, a, b, env); \
424 dnop(&dfp.t, &dfp.a, &dfp.b, &dfp.context); \
425 decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, &dfp.context); \
426 postprocs(&dfp); \
427 if (size == 64) { \
428 t[0] = dfp.t64[0]; \
429 } else if (size == 128) { \
430 t[0] = dfp.t64[HI_IDX]; \
431 t[1] = dfp.t64[LO_IDX]; \
435 static void ADD_PPs(struct PPC_DFP *dfp)
437 dfp_set_FPRF_from_FRT(dfp);
438 dfp_check_for_OX(dfp);
439 dfp_check_for_UX(dfp);
440 dfp_check_for_XX(dfp);
441 dfp_check_for_VXSNAN(dfp);
442 dfp_check_for_VXISI_add(dfp);
445 DFP_HELPER_TAB(dadd, decNumberAdd, ADD_PPs, 64)
446 DFP_HELPER_TAB(daddq, decNumberAdd, ADD_PPs, 128)
448 static void SUB_PPs(struct PPC_DFP *dfp)
450 dfp_set_FPRF_from_FRT(dfp);
451 dfp_check_for_OX(dfp);
452 dfp_check_for_UX(dfp);
453 dfp_check_for_XX(dfp);
454 dfp_check_for_VXSNAN(dfp);
455 dfp_check_for_VXISI_subtract(dfp);
458 DFP_HELPER_TAB(dsub, decNumberSubtract, SUB_PPs, 64)
459 DFP_HELPER_TAB(dsubq, decNumberSubtract, SUB_PPs, 128)
461 static void MUL_PPs(struct PPC_DFP *dfp)
463 dfp_set_FPRF_from_FRT(dfp);
464 dfp_check_for_OX(dfp);
465 dfp_check_for_UX(dfp);
466 dfp_check_for_XX(dfp);
467 dfp_check_for_VXSNAN(dfp);
468 dfp_check_for_VXIMZ(dfp);
471 DFP_HELPER_TAB(dmul, decNumberMultiply, MUL_PPs, 64)
472 DFP_HELPER_TAB(dmulq, decNumberMultiply, MUL_PPs, 128)
474 static void DIV_PPs(struct PPC_DFP *dfp)
476 dfp_set_FPRF_from_FRT(dfp);
477 dfp_check_for_OX(dfp);
478 dfp_check_for_UX(dfp);
479 dfp_check_for_ZX(dfp);
480 dfp_check_for_XX(dfp);
481 dfp_check_for_VXSNAN(dfp);
482 dfp_check_for_VXZDZ(dfp);
483 dfp_check_for_VXIDI(dfp);
486 DFP_HELPER_TAB(ddiv, decNumberDivide, DIV_PPs, 64)
487 DFP_HELPER_TAB(ddivq, decNumberDivide, DIV_PPs, 128)
489 #define DFP_HELPER_BF_AB(op, dnop, postprocs, size) \
490 uint32_t helper_##op(CPUPPCState *env, uint64_t *a, uint64_t *b) \
492 struct PPC_DFP dfp; \
493 dfp_prepare_decimal##size(&dfp, a, b, env); \
494 dnop(&dfp.t, &dfp.a, &dfp.b, &dfp.context); \
495 decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, &dfp.context); \
496 postprocs(&dfp); \
497 return dfp.crbf; \
500 static void CMPU_PPs(struct PPC_DFP *dfp)
502 dfp_set_CRBF_from_T(dfp);
503 dfp_set_FPCC_from_CRBF(dfp);
504 dfp_check_for_VXSNAN(dfp);
507 DFP_HELPER_BF_AB(dcmpu, decNumberCompare, CMPU_PPs, 64)
508 DFP_HELPER_BF_AB(dcmpuq, decNumberCompare, CMPU_PPs, 128)
510 static void CMPO_PPs(struct PPC_DFP *dfp)
512 dfp_set_CRBF_from_T(dfp);
513 dfp_set_FPCC_from_CRBF(dfp);
514 dfp_check_for_VXSNAN(dfp);
515 dfp_check_for_VXVC(dfp);
518 DFP_HELPER_BF_AB(dcmpo, decNumberCompare, CMPO_PPs, 64)
519 DFP_HELPER_BF_AB(dcmpoq, decNumberCompare, CMPO_PPs, 128)
521 #define DFP_HELPER_TSTDC(op, size) \
522 uint32_t helper_##op(CPUPPCState *env, uint64_t *a, uint32_t dcm) \
524 struct PPC_DFP dfp; \
525 int match = 0; \
527 dfp_prepare_decimal##size(&dfp, a, 0, env); \
529 match |= (dcm & 0x20) && decNumberIsZero(&dfp.a); \
530 match |= (dcm & 0x10) && decNumberIsSubnormal(&dfp.a, &dfp.context); \
531 match |= (dcm & 0x08) && decNumberIsNormal(&dfp.a, &dfp.context); \
532 match |= (dcm & 0x04) && decNumberIsInfinite(&dfp.a); \
533 match |= (dcm & 0x02) && decNumberIsQNaN(&dfp.a); \
534 match |= (dcm & 0x01) && decNumberIsSNaN(&dfp.a); \
536 if (decNumberIsNegative(&dfp.a)) { \
537 dfp.crbf = match ? 0xA : 0x8; \
538 } else { \
539 dfp.crbf = match ? 0x2 : 0x0; \
542 dfp_set_FPCC_from_CRBF(&dfp); \
543 return dfp.crbf; \
546 DFP_HELPER_TSTDC(dtstdc, 64)
547 DFP_HELPER_TSTDC(dtstdcq, 128)
549 #define DFP_HELPER_TSTDG(op, size) \
550 uint32_t helper_##op(CPUPPCState *env, uint64_t *a, uint32_t dcm) \
552 struct PPC_DFP dfp; \
553 int minexp, maxexp, nzero_digits, nzero_idx, is_negative, is_zero, \
554 is_extreme_exp, is_subnormal, is_normal, leftmost_is_nonzero, \
555 match; \
557 dfp_prepare_decimal##size(&dfp, a, 0, env); \
559 if ((size) == 64) { \
560 minexp = -398; \
561 maxexp = 369; \
562 nzero_digits = 16; \
563 nzero_idx = 5; \
564 } else if ((size) == 128) { \
565 minexp = -6176; \
566 maxexp = 6111; \
567 nzero_digits = 34; \
568 nzero_idx = 11; \
571 is_negative = decNumberIsNegative(&dfp.a); \
572 is_zero = decNumberIsZero(&dfp.a); \
573 is_extreme_exp = (dfp.a.exponent == maxexp) || \
574 (dfp.a.exponent == minexp); \
575 is_subnormal = decNumberIsSubnormal(&dfp.a, &dfp.context); \
576 is_normal = decNumberIsNormal(&dfp.a, &dfp.context); \
577 leftmost_is_nonzero = (dfp.a.digits == nzero_digits) && \
578 (dfp.a.lsu[nzero_idx] != 0); \
579 match = 0; \
581 match |= (dcm & 0x20) && is_zero && !is_extreme_exp; \
582 match |= (dcm & 0x10) && is_zero && is_extreme_exp; \
583 match |= (dcm & 0x08) && \
584 (is_subnormal || (is_normal && is_extreme_exp)); \
585 match |= (dcm & 0x04) && is_normal && !is_extreme_exp && \
586 !leftmost_is_nonzero; \
587 match |= (dcm & 0x02) && is_normal && !is_extreme_exp && \
588 leftmost_is_nonzero; \
589 match |= (dcm & 0x01) && decNumberIsSpecial(&dfp.a); \
591 if (is_negative) { \
592 dfp.crbf = match ? 0xA : 0x8; \
593 } else { \
594 dfp.crbf = match ? 0x2 : 0x0; \
597 dfp_set_FPCC_from_CRBF(&dfp); \
598 return dfp.crbf; \
601 DFP_HELPER_TSTDG(dtstdg, 64)
602 DFP_HELPER_TSTDG(dtstdgq, 128)
604 #define DFP_HELPER_TSTEX(op, size) \
605 uint32_t helper_##op(CPUPPCState *env, uint64_t *a, uint64_t *b) \
607 struct PPC_DFP dfp; \
608 int expa, expb, a_is_special, b_is_special; \
610 dfp_prepare_decimal##size(&dfp, a, b, env); \
612 expa = dfp.a.exponent; \
613 expb = dfp.b.exponent; \
614 a_is_special = decNumberIsSpecial(&dfp.a); \
615 b_is_special = decNumberIsSpecial(&dfp.b); \
617 if (a_is_special || b_is_special) { \
618 int atype = a_is_special ? (decNumberIsNaN(&dfp.a) ? 4 : 2) : 1; \
619 int btype = b_is_special ? (decNumberIsNaN(&dfp.b) ? 4 : 2) : 1; \
620 dfp.crbf = (atype ^ btype) ? 0x1 : 0x2; \
621 } else if (expa < expb) { \
622 dfp.crbf = 0x8; \
623 } else if (expa > expb) { \
624 dfp.crbf = 0x4; \
625 } else { \
626 dfp.crbf = 0x2; \
629 dfp_set_FPCC_from_CRBF(&dfp); \
630 return dfp.crbf; \
633 DFP_HELPER_TSTEX(dtstex, 64)
634 DFP_HELPER_TSTEX(dtstexq, 128)
636 #define DFP_HELPER_TSTSF(op, size) \
637 uint32_t helper_##op(CPUPPCState *env, uint64_t *a, uint64_t *b) \
639 struct PPC_DFP dfp; \
640 unsigned k; \
642 dfp_prepare_decimal##size(&dfp, 0, b, env); \
644 k = *a & 0x3F; \
646 if (unlikely(decNumberIsSpecial(&dfp.b))) { \
647 dfp.crbf = 1; \
648 } else if (k == 0) { \
649 dfp.crbf = 4; \
650 } else if (unlikely(decNumberIsZero(&dfp.b))) { \
651 /* Zero has no sig digits */ \
652 dfp.crbf = 4; \
653 } else { \
654 unsigned nsd = dfp.b.digits; \
655 if (k < nsd) { \
656 dfp.crbf = 8; \
657 } else if (k > nsd) { \
658 dfp.crbf = 4; \
659 } else { \
660 dfp.crbf = 2; \
664 dfp_set_FPCC_from_CRBF(&dfp); \
665 return dfp.crbf; \
668 DFP_HELPER_TSTSF(dtstsf, 64)
669 DFP_HELPER_TSTSF(dtstsfq, 128)
671 static void QUA_PPs(struct PPC_DFP *dfp)
673 dfp_set_FPRF_from_FRT(dfp);
674 dfp_check_for_XX(dfp);
675 dfp_check_for_VXSNAN(dfp);
676 dfp_check_for_VXCVI(dfp);
679 static void dfp_quantize(uint8_t rmc, struct PPC_DFP *dfp)
681 dfp_set_round_mode_from_immediate(0, rmc, dfp);
682 decNumberQuantize(&dfp->t, &dfp->b, &dfp->a, &dfp->context);
683 if (decNumberIsSNaN(&dfp->a)) {
684 dfp->t = dfp->a;
685 dfp_makeQNaN(&dfp->t);
686 } else if (decNumberIsSNaN(&dfp->b)) {
687 dfp->t = dfp->b;
688 dfp_makeQNaN(&dfp->t);
689 } else if (decNumberIsQNaN(&dfp->a)) {
690 dfp->t = dfp->a;
691 } else if (decNumberIsQNaN(&dfp->b)) {
692 dfp->t = dfp->b;
696 #define DFP_HELPER_QUAI(op, size) \
697 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *b, \
698 uint32_t te, uint32_t rmc) \
700 struct PPC_DFP dfp; \
702 dfp_prepare_decimal##size(&dfp, 0, b, env); \
704 decNumberFromUInt32(&dfp.a, 1); \
705 dfp.a.exponent = (int32_t)((int8_t)(te << 3) >> 3); \
707 dfp_quantize(rmc, &dfp); \
708 decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, \
709 &dfp.context); \
710 QUA_PPs(&dfp); \
712 if (size == 64) { \
713 t[0] = dfp.t64[0]; \
714 } else if (size == 128) { \
715 t[0] = dfp.t64[HI_IDX]; \
716 t[1] = dfp.t64[LO_IDX]; \
720 DFP_HELPER_QUAI(dquai, 64)
721 DFP_HELPER_QUAI(dquaiq, 128)
723 #define DFP_HELPER_QUA(op, size) \
724 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *a, \
725 uint64_t *b, uint32_t rmc) \
727 struct PPC_DFP dfp; \
729 dfp_prepare_decimal##size(&dfp, a, b, env); \
731 dfp_quantize(rmc, &dfp); \
732 decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, \
733 &dfp.context); \
734 QUA_PPs(&dfp); \
736 if (size == 64) { \
737 t[0] = dfp.t64[0]; \
738 } else if (size == 128) { \
739 t[0] = dfp.t64[HI_IDX]; \
740 t[1] = dfp.t64[LO_IDX]; \
744 DFP_HELPER_QUA(dqua, 64)
745 DFP_HELPER_QUA(dquaq, 128)
747 static void _dfp_reround(uint8_t rmc, int32_t ref_sig, int32_t xmax,
748 struct PPC_DFP *dfp)
750 int msd_orig, msd_rslt;
752 if (unlikely((ref_sig == 0) || (dfp->b.digits <= ref_sig))) {
753 dfp->t = dfp->b;
754 if (decNumberIsSNaN(&dfp->b)) {
755 dfp_makeQNaN(&dfp->t);
756 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXSNAN, FPSCR_VE);
758 return;
761 /* Reround is equivalent to quantizing b with 1**E(n) where */
762 /* n = exp(b) + numDigits(b) - reference_significance. */
764 decNumberFromUInt32(&dfp->a, 1);
765 dfp->a.exponent = dfp->b.exponent + dfp->b.digits - ref_sig;
767 if (unlikely(dfp->a.exponent > xmax)) {
768 dfp->t.digits = 0;
769 dfp->t.bits &= ~DECNEG;
770 dfp_makeQNaN(&dfp->t);
771 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXCVI, FPSCR_VE);
772 return;
775 dfp_quantize(rmc, dfp);
777 msd_orig = dfp_get_digit(&dfp->b, dfp->b.digits-1);
778 msd_rslt = dfp_get_digit(&dfp->t, dfp->t.digits-1);
780 /* If the quantization resulted in rounding up to the next magnitude, */
781 /* then we need to shift the significand and adjust the exponent. */
783 if (unlikely((msd_orig == 9) && (msd_rslt == 1))) {
785 decNumber negone;
787 decNumberFromInt32(&negone, -1);
788 decNumberShift(&dfp->t, &dfp->t, &negone, &dfp->context);
789 dfp->t.exponent++;
791 if (unlikely(dfp->t.exponent > xmax)) {
792 dfp_makeQNaN(&dfp->t);
793 dfp->t.digits = 0;
794 dfp_set_FPSCR_flag(dfp, FP_VX | FP_VXCVI, FP_VE);
795 /* Inhibit XX in this case */
796 decContextClearStatus(&dfp->context, DEC_Inexact);
801 #define DFP_HELPER_RRND(op, size) \
802 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *a, \
803 uint64_t *b, uint32_t rmc) \
805 struct PPC_DFP dfp; \
806 int32_t ref_sig = *a & 0x3F; \
807 int32_t xmax = ((size) == 64) ? 369 : 6111; \
809 dfp_prepare_decimal##size(&dfp, 0, b, env); \
811 _dfp_reround(rmc, ref_sig, xmax, &dfp); \
812 decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, \
813 &dfp.context); \
814 QUA_PPs(&dfp); \
816 if (size == 64) { \
817 t[0] = dfp.t64[0]; \
818 } else if (size == 128) { \
819 t[0] = dfp.t64[HI_IDX]; \
820 t[1] = dfp.t64[LO_IDX]; \
824 DFP_HELPER_RRND(drrnd, 64)
825 DFP_HELPER_RRND(drrndq, 128)
827 #define DFP_HELPER_RINT(op, postprocs, size) \
828 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *b, \
829 uint32_t r, uint32_t rmc) \
831 struct PPC_DFP dfp; \
833 dfp_prepare_decimal##size(&dfp, 0, b, env); \
835 dfp_set_round_mode_from_immediate(r, rmc, &dfp); \
836 decNumberToIntegralExact(&dfp.t, &dfp.b, &dfp.context); \
837 decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, &dfp.context); \
838 postprocs(&dfp); \
840 if (size == 64) { \
841 t[0] = dfp.t64[0]; \
842 } else if (size == 128) { \
843 t[0] = dfp.t64[HI_IDX]; \
844 t[1] = dfp.t64[LO_IDX]; \
848 static void RINTX_PPs(struct PPC_DFP *dfp)
850 dfp_set_FPRF_from_FRT(dfp);
851 dfp_check_for_XX(dfp);
852 dfp_check_for_VXSNAN(dfp);
855 DFP_HELPER_RINT(drintx, RINTX_PPs, 64)
856 DFP_HELPER_RINT(drintxq, RINTX_PPs, 128)
858 static void RINTN_PPs(struct PPC_DFP *dfp)
860 dfp_set_FPRF_from_FRT(dfp);
861 dfp_check_for_VXSNAN(dfp);
864 DFP_HELPER_RINT(drintn, RINTN_PPs, 64)
865 DFP_HELPER_RINT(drintnq, RINTN_PPs, 128)
867 void helper_dctdp(CPUPPCState *env, uint64_t *t, uint64_t *b)
869 struct PPC_DFP dfp;
870 uint32_t b_short = *b;
871 dfp_prepare_decimal64(&dfp, 0, 0, env);
872 decimal32ToNumber((decimal32 *)&b_short, &dfp.t);
873 decimal64FromNumber((decimal64 *)t, &dfp.t, &dfp.context);
874 dfp_set_FPRF_from_FRT(&dfp);
877 void helper_dctqpq(CPUPPCState *env, uint64_t *t, uint64_t *b)
879 struct PPC_DFP dfp;
880 dfp_prepare_decimal128(&dfp, 0, 0, env);
881 decimal64ToNumber((decimal64 *)b, &dfp.t);
883 dfp_check_for_VXSNAN_and_convert_to_QNaN(&dfp);
884 dfp_set_FPRF_from_FRT(&dfp);
886 decimal128FromNumber((decimal128 *)&dfp.t64, &dfp.t, &dfp.context);
887 t[0] = dfp.t64[HI_IDX];
888 t[1] = dfp.t64[LO_IDX];
891 void helper_drsp(CPUPPCState *env, uint64_t *t, uint64_t *b)
893 struct PPC_DFP dfp;
894 uint32_t t_short = 0;
895 dfp_prepare_decimal64(&dfp, 0, b, env);
896 decimal32FromNumber((decimal32 *)&t_short, &dfp.b, &dfp.context);
897 decimal32ToNumber((decimal32 *)&t_short, &dfp.t);
899 dfp_set_FPRF_from_FRT_short(&dfp);
900 dfp_check_for_OX(&dfp);
901 dfp_check_for_UX(&dfp);
902 dfp_check_for_XX(&dfp);
904 *t = t_short;
907 void helper_drdpq(CPUPPCState *env, uint64_t *t, uint64_t *b)
909 struct PPC_DFP dfp;
910 dfp_prepare_decimal128(&dfp, 0, b, env);
911 decimal64FromNumber((decimal64 *)&dfp.t64, &dfp.b, &dfp.context);
912 decimal64ToNumber((decimal64 *)&dfp.t64, &dfp.t);
914 dfp_check_for_VXSNAN_and_convert_to_QNaN(&dfp);
915 dfp_set_FPRF_from_FRT_long(&dfp);
916 dfp_check_for_OX(&dfp);
917 dfp_check_for_UX(&dfp);
918 dfp_check_for_XX(&dfp);
920 decimal64FromNumber((decimal64 *)dfp.t64, &dfp.t, &dfp.context);
921 t[0] = dfp.t64[0];
922 t[1] = 0;
925 #define DFP_HELPER_CFFIX(op, size) \
926 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *b) \
928 struct PPC_DFP dfp; \
929 dfp_prepare_decimal##size(&dfp, 0, b, env); \
930 decNumberFromInt64(&dfp.t, (int64_t)(*b)); \
931 decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, &dfp.context); \
932 CFFIX_PPs(&dfp); \
934 if (size == 64) { \
935 t[0] = dfp.t64[0]; \
936 } else if (size == 128) { \
937 t[0] = dfp.t64[HI_IDX]; \
938 t[1] = dfp.t64[LO_IDX]; \
942 static void CFFIX_PPs(struct PPC_DFP *dfp)
944 dfp_set_FPRF_from_FRT(dfp);
945 dfp_check_for_XX(dfp);
948 DFP_HELPER_CFFIX(dcffix, 64)
949 DFP_HELPER_CFFIX(dcffixq, 128)
951 #define DFP_HELPER_CTFIX(op, size) \
952 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *b) \
954 struct PPC_DFP dfp; \
955 dfp_prepare_decimal##size(&dfp, 0, b, env); \
957 if (unlikely(decNumberIsSpecial(&dfp.b))) { \
958 uint64_t invalid_flags = FP_VX | FP_VXCVI; \
959 if (decNumberIsInfinite(&dfp.b)) { \
960 dfp.t64[0] = decNumberIsNegative(&dfp.b) ? INT64_MIN : INT64_MAX; \
961 } else { /* NaN */ \
962 dfp.t64[0] = INT64_MIN; \
963 if (decNumberIsSNaN(&dfp.b)) { \
964 invalid_flags |= FP_VXSNAN; \
967 dfp_set_FPSCR_flag(&dfp, invalid_flags, FP_VE); \
968 } else if (unlikely(decNumberIsZero(&dfp.b))) { \
969 dfp.t64[0] = 0; \
970 } else { \
971 decNumberToIntegralExact(&dfp.b, &dfp.b, &dfp.context); \
972 dfp.t64[0] = decNumberIntegralToInt64(&dfp.b, &dfp.context); \
973 if (decContextTestStatus(&dfp.context, DEC_Invalid_operation)) { \
974 dfp.t64[0] = decNumberIsNegative(&dfp.b) ? INT64_MIN : INT64_MAX; \
975 dfp_set_FPSCR_flag(&dfp, FP_VX | FP_VXCVI, FP_VE); \
976 } else { \
977 dfp_check_for_XX(&dfp); \
981 *t = dfp.t64[0]; \
984 DFP_HELPER_CTFIX(dctfix, 64)
985 DFP_HELPER_CTFIX(dctfixq, 128)
987 static inline void dfp_set_bcd_digit_64(uint64_t *t, uint8_t digit,
988 unsigned n)
990 *t |= ((uint64_t)(digit & 0xF) << (n << 2));
993 static inline void dfp_set_bcd_digit_128(uint64_t *t, uint8_t digit,
994 unsigned n)
996 t[(n & 0x10) ? HI_IDX : LO_IDX] |=
997 ((uint64_t)(digit & 0xF) << ((n & 15) << 2));
1000 static inline void dfp_set_sign_64(uint64_t *t, uint8_t sgn)
1002 *t <<= 4;
1003 *t |= (sgn & 0xF);
1006 static inline void dfp_set_sign_128(uint64_t *t, uint8_t sgn)
1008 t[HI_IDX] <<= 4;
1009 t[HI_IDX] |= (t[LO_IDX] >> 60);
1010 t[LO_IDX] <<= 4;
1011 t[LO_IDX] |= (sgn & 0xF);
1014 #define DFP_HELPER_DEDPD(op, size) \
1015 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *b, uint32_t sp) \
1017 struct PPC_DFP dfp; \
1018 uint8_t digits[34]; \
1019 int i, N; \
1021 dfp_prepare_decimal##size(&dfp, 0, b, env); \
1023 decNumberGetBCD(&dfp.b, digits); \
1024 dfp.t64[0] = dfp.t64[1] = 0; \
1025 N = dfp.b.digits; \
1027 for (i = 0; (i < N) && (i < (size)/4); i++) { \
1028 dfp_set_bcd_digit_##size(dfp.t64, digits[N-i-1], i); \
1031 if (sp & 2) { \
1032 uint8_t sgn; \
1034 if (decNumberIsNegative(&dfp.b)) { \
1035 sgn = 0xD; \
1036 } else { \
1037 sgn = ((sp & 1) ? 0xF : 0xC); \
1039 dfp_set_sign_##size(dfp.t64, sgn); \
1042 if (size == 64) { \
1043 t[0] = dfp.t64[0]; \
1044 } else if (size == 128) { \
1045 t[0] = dfp.t64[HI_IDX]; \
1046 t[1] = dfp.t64[LO_IDX]; \
1050 DFP_HELPER_DEDPD(ddedpd, 64)
1051 DFP_HELPER_DEDPD(ddedpdq, 128)
1053 static inline uint8_t dfp_get_bcd_digit_64(uint64_t *t, unsigned n)
1055 return *t >> ((n << 2) & 63) & 15;
1058 static inline uint8_t dfp_get_bcd_digit_128(uint64_t *t, unsigned n)
1060 return t[(n & 0x10) ? HI_IDX : LO_IDX] >> ((n << 2) & 63) & 15;
1063 #define DFP_HELPER_ENBCD(op, size) \
1064 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *b, uint32_t s) \
1066 struct PPC_DFP dfp; \
1067 uint8_t digits[32]; \
1068 int n = 0, offset = 0, sgn = 0, nonzero = 0; \
1070 dfp_prepare_decimal##size(&dfp, 0, b, env); \
1072 decNumberZero(&dfp.t); \
1074 if (s) { \
1075 uint8_t sgnNibble = dfp_get_bcd_digit_##size(dfp.b64, offset++); \
1076 switch (sgnNibble) { \
1077 case 0xD: \
1078 case 0xB: \
1079 sgn = 1; \
1080 break; \
1081 case 0xC: \
1082 case 0xF: \
1083 case 0xA: \
1084 case 0xE: \
1085 sgn = 0; \
1086 break; \
1087 default: \
1088 dfp_set_FPSCR_flag(&dfp, FP_VX | FP_VXCVI, FPSCR_VE); \
1089 return; \
1093 while (offset < (size)/4) { \
1094 n++; \
1095 digits[(size)/4-n] = dfp_get_bcd_digit_##size(dfp.b64, offset++); \
1096 if (digits[(size)/4-n] > 10) { \
1097 dfp_set_FPSCR_flag(&dfp, FP_VX | FP_VXCVI, FPSCR_VE); \
1098 return; \
1099 } else { \
1100 nonzero |= (digits[(size)/4-n] > 0); \
1104 if (nonzero) { \
1105 decNumberSetBCD(&dfp.t, digits+((size)/4)-n, n); \
1108 if (s && sgn) { \
1109 dfp.t.bits |= DECNEG; \
1111 decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, \
1112 &dfp.context); \
1113 dfp_set_FPRF_from_FRT(&dfp); \
1114 if ((size) == 64) { \
1115 t[0] = dfp.t64[0]; \
1116 } else if ((size) == 128) { \
1117 t[0] = dfp.t64[HI_IDX]; \
1118 t[1] = dfp.t64[LO_IDX]; \
1122 DFP_HELPER_ENBCD(denbcd, 64)
1123 DFP_HELPER_ENBCD(denbcdq, 128)
1125 #define DFP_HELPER_XEX(op, size) \
1126 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *b) \
1128 struct PPC_DFP dfp; \
1130 dfp_prepare_decimal##size(&dfp, 0, b, env); \
1132 if (unlikely(decNumberIsSpecial(&dfp.b))) { \
1133 if (decNumberIsInfinite(&dfp.b)) { \
1134 *t = -1; \
1135 } else if (decNumberIsSNaN(&dfp.b)) { \
1136 *t = -3; \
1137 } else if (decNumberIsQNaN(&dfp.b)) { \
1138 *t = -2; \
1139 } else { \
1140 assert(0); \
1142 } else { \
1143 if ((size) == 64) { \
1144 *t = dfp.b.exponent + 398; \
1145 } else if ((size) == 128) { \
1146 *t = dfp.b.exponent + 6176; \
1147 } else { \
1148 assert(0); \
1153 DFP_HELPER_XEX(dxex, 64)
1154 DFP_HELPER_XEX(dxexq, 128)
1156 static void dfp_set_raw_exp_64(uint64_t *t, uint64_t raw)
1158 *t &= 0x8003ffffffffffffULL;
1159 *t |= (raw << (63-13));
1162 static void dfp_set_raw_exp_128(uint64_t *t, uint64_t raw)
1164 t[HI_IDX] &= 0x80003fffffffffffULL;
1165 t[HI_IDX] |= (raw << (63-17));
1168 #define DFP_HELPER_IEX(op, size) \
1169 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *a, uint64_t *b) \
1171 struct PPC_DFP dfp; \
1172 uint64_t raw_qnan, raw_snan, raw_inf, max_exp; \
1173 int bias; \
1174 int64_t exp = *((int64_t *)a); \
1176 dfp_prepare_decimal##size(&dfp, 0, b, env); \
1178 if ((size) == 64) { \
1179 max_exp = 767; \
1180 raw_qnan = 0x1F00; \
1181 raw_snan = 0x1F80; \
1182 raw_inf = 0x1E00; \
1183 bias = 398; \
1184 } else if ((size) == 128) { \
1185 max_exp = 12287; \
1186 raw_qnan = 0x1f000; \
1187 raw_snan = 0x1f800; \
1188 raw_inf = 0x1e000; \
1189 bias = 6176; \
1190 } else { \
1191 assert(0); \
1194 if (unlikely((exp < 0) || (exp > max_exp))) { \
1195 dfp.t64[0] = dfp.b64[0]; \
1196 dfp.t64[1] = dfp.b64[1]; \
1197 if (exp == -1) { \
1198 dfp_set_raw_exp_##size(dfp.t64, raw_inf); \
1199 } else if (exp == -3) { \
1200 dfp_set_raw_exp_##size(dfp.t64, raw_snan); \
1201 } else { \
1202 dfp_set_raw_exp_##size(dfp.t64, raw_qnan); \
1204 } else { \
1205 dfp.t = dfp.b; \
1206 if (unlikely(decNumberIsSpecial(&dfp.t))) { \
1207 dfp.t.bits &= ~DECSPECIAL; \
1209 dfp.t.exponent = exp - bias; \
1210 decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, \
1211 &dfp.context); \
1213 if (size == 64) { \
1214 t[0] = dfp.t64[0]; \
1215 } else if (size == 128) { \
1216 t[0] = dfp.t64[HI_IDX]; \
1217 t[1] = dfp.t64[LO_IDX]; \
1221 DFP_HELPER_IEX(diex, 64)
1222 DFP_HELPER_IEX(diexq, 128)
1224 static void dfp_clear_lmd_from_g5msb(uint64_t *t)
1227 /* The most significant 5 bits of the PowerPC DFP format combine bits */
1228 /* from the left-most decimal digit (LMD) and the biased exponent. */
1229 /* This routine clears the LMD bits while preserving the exponent */
1230 /* bits. See "Figure 80: Encoding of bits 0:4 of the G field for */
1231 /* Finite Numbers" in the Power ISA for additional details. */
1233 uint64_t g5msb = (*t >> 58) & 0x1F;
1235 if ((g5msb >> 3) < 3) { /* LMD in [0-7] ? */
1236 *t &= ~(7ULL << 58);
1237 } else {
1238 switch (g5msb & 7) {
1239 case 0:
1240 case 1:
1241 g5msb = 0;
1242 break;
1243 case 2:
1244 case 3:
1245 g5msb = 0x8;
1246 break;
1247 case 4:
1248 case 5:
1249 g5msb = 0x10;
1250 break;
1251 case 6:
1252 g5msb = 0x1E;
1253 break;
1254 case 7:
1255 g5msb = 0x1F;
1256 break;
1259 *t &= ~(0x1fULL << 58);
1260 *t |= (g5msb << 58);
1264 #define DFP_HELPER_SHIFT(op, size, shift_left) \
1265 void helper_##op(CPUPPCState *env, uint64_t *t, uint64_t *a, \
1266 uint32_t sh) \
1268 struct PPC_DFP dfp; \
1269 unsigned max_digits = ((size) == 64) ? 16 : 34; \
1271 dfp_prepare_decimal##size(&dfp, a, 0, env); \
1273 if (sh <= max_digits) { \
1275 decNumber shd; \
1276 unsigned special = dfp.a.bits & DECSPECIAL; \
1278 if (shift_left) { \
1279 decNumberFromUInt32(&shd, sh); \
1280 } else { \
1281 decNumberFromInt32(&shd, -((int32_t)sh)); \
1284 dfp.a.bits &= ~DECSPECIAL; \
1285 decNumberShift(&dfp.t, &dfp.a, &shd, &dfp.context); \
1287 dfp.t.bits |= special; \
1288 if (special && (dfp.t.digits >= max_digits)) { \
1289 dfp.t.digits = max_digits - 1; \
1292 decimal##size##FromNumber((decimal##size *)dfp.t64, &dfp.t, \
1293 &dfp.context); \
1294 } else { \
1295 if ((size) == 64) { \
1296 dfp.t64[0] = dfp.a64[0] & 0xFFFC000000000000ULL; \
1297 dfp_clear_lmd_from_g5msb(dfp.t64); \
1298 } else { \
1299 dfp.t64[HI_IDX] = dfp.a64[HI_IDX] & \
1300 0xFFFFC00000000000ULL; \
1301 dfp_clear_lmd_from_g5msb(dfp.t64 + HI_IDX); \
1302 dfp.t64[LO_IDX] = 0; \
1306 if ((size) == 64) { \
1307 t[0] = dfp.t64[0]; \
1308 } else { \
1309 t[0] = dfp.t64[HI_IDX]; \
1310 t[1] = dfp.t64[LO_IDX]; \
1314 DFP_HELPER_SHIFT(dscli, 64, 1)
1315 DFP_HELPER_SHIFT(dscliq, 128, 1)
1316 DFP_HELPER_SHIFT(dscri, 64, 0)
1317 DFP_HELPER_SHIFT(dscriq, 128, 0)