3 * Copyright (C) 2016-2017 Will Schmidt <will_schmidt@vnet.ibm.com>
5 * This file contains helper functions for the ISA 3.0 test suite.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License V2
11 * as published by the Free Software Foundation
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "tests/malloc.h" // memalign32
24 typedef uint64_t HWord_t
;
26 #if defined (DEBUG_ARGS_BUILD)
27 #define AB_DPRINTF(fmt, args...) do { fprintf(stderr, fmt , ##args); } while (0)
29 #define AB_DPRINTF(fmt, args...) do { } while (0)
33 * Due to the excessive size of the test results, allow a #ifdef to
34 * enable/disable most of the input values.
37 // #define EXHAUSTIVE_TESTS 1
40 #define ALLCR "cr0","cr1","cr2","cr3","cr4","cr5","cr6","cr7"
42 #define SET_CR(_arg) \
43 __asm__ __volatile__ ("mtcr %0" : : "b"(_arg) : ALLCR );
45 #define SET_CR0_FIELD(_arg) __asm__ __volatile__ ("mtocrf 0x80,%0 " : : "b" (_arg):"cr0");
46 #define SET_CR1_FIELD(_arg) __asm__ __volatile__ ("mtocrf 0x40,%0 " : : "b" (_arg):"cr1");
47 #define SET_CR2_FIELD(_arg) __asm__ __volatile__ ("mtocrf 0x20,%0 " : : "b" (_arg):"cr2");
48 #define SET_CR3_FIELD(_arg) __asm__ __volatile__ ("mtocrf 0x10,%0 " : : "b" (_arg):"cr3");
49 #define SET_CR4_FIELD(_arg) __asm__ __volatile__ ("mtocrf 0x08,%0 " : : "r" (_arg):"cr4");
50 #define SET_CR5_FIELD(_arg) __asm__ __volatile__ ("mtocrf 0x04,%0 " : : "r" (_arg):"cr5");
51 #define SET_CR6_FIELD(_arg) __asm__ __volatile__ ("mtocrf 0x02,%0 " : : "r" (_arg):"cr6");
52 #define SET_CR7_FIELD(_arg) __asm__ __volatile__ ("mtocrf 0x01,%0 " : : "r" (_arg):"cr7");
54 #define SET_XER(_arg) \
55 __asm__ __volatile__ ("mtxer %0" : : "b"(_arg) : "xer" );
57 #define GET_CR(_lval) \
58 __asm__ __volatile__ ("mfcr %0" : "=b"(_lval) )
60 #define GET_XER(_lval) \
61 __asm__ __volatile__ ("mfxer %0" : "=b"(_lval) )
66 #define SET_FPSCR_ZERO \
69 __asm__ __volatile__ ("mtfsf 0xFF, %0" : : "f"(_d) ); \
72 #define GET_FPSCR(_arg) \
73 __asm__ __volatile__ ("mffs %0" : "=f"(_arg) );
75 /* The bit definitions for the FPSCR are as follows.
78 32 Floating-Point Exception Summary (FX)
79 33 Floating-Point Enabled Exception Summary (FEX)
80 34 Floating-Point Invalid Operation Exception Summary (VX)
81 35 Floating-Point Overflow Exception (OX)
82 36 Floating-Point Underflow Exception (UX)
83 37 Floating-Point Zero Divide Exception (ZX)
84 38 Floating-Point Inexact Exception (XX)
85 39 Floating-Point Invalid Operation Exception (SNaN) (VXSNAN)
86 40 Floating-Point Invalid Operation Exception (∞ - ∞) (VXISI)
87 41 Floating-Point Invalid Operation Exception (∞ ÷ ∞) (VXIDI)
88 42 Floating-Point Invalid Operation Exception (0 ÷ 0) (VXZDZ)
89 43 Floating-Point Invalid Operation Exception (∞ × 0) (VXIMZ)
90 44 Floating-Point Invalid Operation Exception (Invalid Compare) (VXVC)
91 45 Floating-Point Fraction Rounded (FR)
92 46 Floating-Point Fraction Inexact (FI)
93 47:51 Floating-Point Result Flags (FPRF)
94 47 Floating-Point Result Class Descriptor (C)
95 48:51 Floating-Point Condition Code (FPCC)
96 48 Floating-Point Less Than or Negative (FL or <)
97 49 Floating-Point Greater Than or Positive (FG or >)
98 50 Floating-Point Equal or Zero (FE or =)
99 51 Floating-Point Unordered or NaN (FU or ?)
101 53 Floating-Point Invalid Operation Exception (Software-Defined Condition) (VXSOFT)
102 54 Floating-Point Invalid Operation Exception (Invalid Square Root) (VXSQRT)
103 55 Floating-Point Invalid Operation Exception (Invalid Integer Convert) (VXCVI)
104 56 Floating-Point Invalid Operation Exception Enable (VE)
105 57 Floating-Point Overflow Exception Enable (OE)
106 58 Floating-Point Underflow Exception Enable (UE)
107 59 Floating-Point Zero Divide Exception Enable (ZE)
108 60 Floating-Point Inexact Exception Enable (XE)
109 61 Floating-Point Non-IEEE Mode (NI)
110 62:63 Floating-Point Rounding Control (RN)
113 10 Round toward +Infinity
114 11 Round toward -Infinity
116 /* NOTE, currently Valgrind only tracks the rounding mode, C and FPCC fields in the
120 static char * fpscr_strings
[] = {
121 " 0-RSVD", " 1-RSVD", " 2-RSVD", " 3-RSVD", " 4-RSVD", " 5-RSVD", " 6-RSVD",
122 " 7-RSVD", " 8-RSVD", " 9-RSVD", "10-RSVD", "11-RSVD", "12-RSVD", "13-RSVD",
123 "14-RSVD", "15-RSVD", "16-RSVD", "17-RSVD", "18-RSVD", "19-RSVD", "20-RSVD",
124 "21-RSVD", "22-RSVD", "23-RSVD", "24-RSVD", "25-RSVD", "26-RSVD", "27-RSVD",
125 "28-RSVD", "29-DRN0", "30-DRN1", "31-DRN2",
126 /* 32 */ "FX", "FEX", "VX",
127 /* 35 */ "OX", "UX", "ZX", "XX", "VXSNAN",
128 /* 40 */ "VXISI (inf-inf)", "VXIDI (inf/inf)", "VXZDZ (0/0)",
129 /* 43 */ "VXIMZ (inf*0)", "VXVC",
131 /* 47 */ "FPRF-C", "FPCC-FL", "FPCC-FG",
132 /* 50 */ "FPCC-FE", "FPCC-FU",
133 /* 52 */ "52-RSVD", "FXSOFT", "VXSQRT",
134 /* 55 */ "VXCVI", "VE", "OE", "UE", "ZE",
135 /* 60 */ "XE", "NI", "RN-bit62", "RN-bit63"
138 #define FPCC_C_BIT (0x1 << (63-47))
139 #define FPCC_FL_BIT (0x1 << (63-48))
140 #define FPCC_FG_BIT (0x1 << (63-49))
141 #define FPCC_FE_BIT (0x1 << (63-50))
142 #define FPCC_FU_BIT (0x1 << (63-51))
143 #define FPCC_FPRF_MASK FPCC_C_BIT|FPCC_FL_BIT|FPCC_FG_BIT|FPCC_FE_BIT|FPCC_FU_BIT
145 #define FPSCR_RN_BIT62 (0x1 << (63-62))
146 #define FPSCR_RN_BIT63 (0x1 << (63-63))
148 #define CRFIELD_BIT0 0x8
149 #define CRFIELD_BIT1 0x4
150 #define CRFIELD_BIT2 0x2
151 #define CRFIELD_BIT3 0x1
154 * display the condition register bits in a
155 * human readable format.
158 static inline int cr_overflow_set(unsigned this_cr
) {
159 return (this_cr
& CRFIELD_BIT3
);
162 static inline int cr_zero_set(unsigned this_cr
) {
163 return (this_cr
& CRFIELD_BIT2
);
166 static inline int cr_positive_set(unsigned this_cr
) {
167 return (this_cr
& CRFIELD_BIT1
);
170 static inline int cr_negative_set(unsigned this_cr
) {
171 return (this_cr
& CRFIELD_BIT0
);
174 /* __dissect_cr takes a bitfield directly, not the full condition register.
175 * This is a helper for dissect_cr_rn.
177 inline static void __dissect_cr(unsigned this_cr
) {
178 if (cr_negative_set(this_cr
))
179 printf("%s(LT)", verbose
? " 0x1=Negative" : "");
181 if (cr_positive_set(this_cr
))
182 printf("%s(GT)", verbose
? " 0x2=Positive" : "");
184 if (cr_zero_set(this_cr
))
185 printf("%s(EQ)", verbose
? " 0x4=Zero" : "");
187 if (cr_overflow_set(this_cr
))
188 printf("%s(SO)", verbose
? " 0x8=Overflow" : "");
191 /* Extract one CR field */
192 static int extract_cr_rn(unsigned long local_cr
,unsigned long rn
) {
193 unsigned int masked_cr
;
194 unsigned long shifted_value
;
196 shifted_value
= local_cr
>> ( ( (7 - rn
) * 4 ) );
197 masked_cr
= shifted_value
& 0xf;
201 /* Display one CR field */
202 static void dissect_cr_rn(unsigned long local_cr
, unsigned long rn
) {
203 unsigned int masked_cr
;
205 masked_cr
= extract_cr_rn(local_cr
, rn
);
206 __dissect_cr(masked_cr
);
209 /* Display all of the CR fields... */
210 static void dissect_cr(unsigned long local_cr
) {
213 for (crn
= 0; crn
< 8; crn
++) {
214 dissect_cr_rn(local_cr
, crn
);
218 /* dissect the fpscr bits that are valid under valgrind.
219 * Valgrind tracks the C (FPSCR[47]), FPCC (FPSCR[48:51)
220 * DRN (FPSCR[29:31]) and RN (FPSCR[62:63]).
222 static void dissect_fpscr_valgrind(unsigned long local_fpscr
) {
226 /* Print DRN fields */
227 for (i
= 29; i
< 32; i
++) {
228 mybit
= 1LL << (63 - i
);
229 if (mybit
& local_fpscr
) {
230 printf(" %s",fpscr_strings
[i
]);
234 /* Print C and FPCC fields */
235 for (i
= 47; i
< 52; i
++) {
236 mybit
= 1LL << (63 - i
);
237 if (mybit
& local_fpscr
) {
238 printf(" %s",fpscr_strings
[i
]);
243 for (i
= 62; i
< 64; i
++) {
244 mybit
= 1LL << (63 - i
);
245 if (mybit
& local_fpscr
) {
246 printf(" %s",fpscr_strings
[i
]);
251 /* dissect the fpscr bits.
252 * This prints the entire FPSCR field. This is only called under higher
253 * verbosities, as valgrind does not track most of these bits.
255 static void dissect_fpscr_raw(unsigned long local_fpscr
) {
256 /* Due to the additional involved logic, the rounding mode (RN) bits 61-62
257 * are handled within dissect_fpscr_rounding_mode(). */
261 for (i
= 0; i
< 61; i
++) {
262 /* also note that the bit numbering is backwards. */
263 mybit
= 1LL << (63 - i
);
264 if (mybit
& local_fpscr
) {
265 printf(" %s", fpscr_strings
[i
]);
270 static void dissect_fpscr(unsigned long local_fpscr
) {
272 printf(" [[ fpscr:%lx ]] ", local_fpscr
);
273 dissect_fpscr_raw(local_fpscr
);
275 dissect_fpscr_valgrind(local_fpscr
);
279 /* Display the rounding mode */
280 static void dissect_fpscr_rounding_mode(unsigned long local_fpscr
) {
281 /* special case handing for the rounding mode round-nearest (RN) bits. 62:63 */
282 printf("Rounding Mode: ");
284 if (local_fpscr
& FPSCR_RN_BIT62
)
285 if (local_fpscr
& FPSCR_RN_BIT63
)
286 /* 0b11 */ printf("RN-to--INF");
288 /* 0b10 */ printf("RN-to-+INF");
290 if (local_fpscr
& FPSCR_RN_BIT63
)
291 /* 0b01 */ printf("RN-to-Nearest");
293 /* 0b00 */ printf("RN-to-Zero");
297 * Arithmetic, rounding, and Convert From Integer instructions will set
298 * bits in the FPCC field to indicate the class of the result.
299 * The table is described as follows;
300 flags / Result value class
304 0 1 0 0 0 -Normalized Number
305 1 1 0 0 0 -Denormalized Number
308 1 0 1 0 0 +Denormalized Number
309 0 0 1 0 0 +Normalized Number
313 static void dissect_fpscr_result_value_class(unsigned long local_fpscr
) {
314 if (local_fpscr
& FPCC_C_BIT
) {
315 if (local_fpscr
& FPCC_FL_BIT
)
316 printf("-Denormalized");
318 else if (local_fpscr
& FPCC_FG_BIT
)
319 printf("+Denormalized");
321 else if (local_fpscr
& FPCC_FE_BIT
)
324 else if (local_fpscr
& FPCC_FU_BIT
)
325 printf("Quiet NaN ");
328 if (local_fpscr
& FPCC_FL_BIT
) {
329 if (local_fpscr
& FPCC_FU_BIT
)
330 printf("-Infinity ");
333 printf("-Normalized ");
335 } else if (local_fpscr
& FPCC_FG_BIT
) {
336 if (local_fpscr
& FPCC_FU_BIT
)
337 printf("+Infinity ");
340 printf("+Normalized ");
342 if (local_fpscr
& FPCC_FE_BIT
)
348 /* Interpret the fields in the FPCC as they apply to the DCMX checks.
349 * The 'Match' indicator will typically be evaluated by the caller.
352 * DCMX bit / 0x value / Data Class
360 * 7 0x7f ALL bits set.
363 static void dissect_fpscr_dcmx_indicator(unsigned long local_fpscr
) {
364 if (verbose
> 2) printf("fpscr_cc:%lx ", local_fpscr
& (FPCC_FPRF_MASK
) );
366 // See if the data class of the src value matches the set DCMX bits.
367 if (verbose
> 1) printf("%s ", (local_fpscr
&FPCC_FE_BIT
) ? "Match":"");
369 // Display the sign bit of the src value.
370 if (verbose
> 1) printf("SRC sign:%s ", (local_fpscr
&FPCC_FL_BIT
) ? "-" : "+");
372 // The src value can be either a SP or DP value, this indicates
373 // if it is a valid SP value.
374 if (verbose
> 1) printf("%s ", (local_fpscr
&FPCC_FE_BIT
) ? "SP" : "");
377 /* dissect_xer helpers*/
378 static char * xer_strings
[] = {
379 " 0-RSVD", " 1-RSVD", " 2-RSVD", " 3-RSVD", " 4-RSVD", " 5-RSVD", " 6-RSVD",
380 " 7-RSVD", " 8-RSVD", " 9-RSVD", "10-RSVD", "11-RSVD", "12-RSVD", "13-RSVD",
381 "14-RSVD", "15-RSVD", "16-RSVD", "17-RSVD", "18-RSVD", "19-RSVD",
382 "20-RSVD", "21-RSVD", "22-RSVD", "23-RSVD", "24-RSVD", "25-RSVD",
383 "26-RSVD", "27-RSVD", "28-RSVD", "29-RSVD", "30-RSVD", "31-RSVD",
384 /* 32 */ "SO", "OV", "CA",
385 /* 35 */ "35-RSVD", "36-RSVD", "37-RSVD", "38-RSVD", "39-RSVD",
386 /* 40 */ "40-RSVD", "41-RSVD", "42-RSVD", "43-RSVD",
387 /* 44 */ "OV32", "CA32",
388 /* 46 */ "46-RSVD", "47-RSVD", "48-RSVD", "49-RSVD", "50-RSVD", "51-RSVD",
389 "52-RSVD", "53-RSVD", "54-RSVD", "55-RSVD", "56-RSVD",
390 /* 57:63 # bytes transferred by a Load/Store String Indexed instruction. */
391 "LSI/SSI-0", "LSI/SSI-1", "LSI/SSI-2", "LSI/SSI-3",
392 "LSI/SSI-4", "LSI/SSI-5", "LSI/SSI-6",
395 /* Dissect the XER register contents.
397 static void dissect_xer_raw(unsigned long local_xer
) {
401 for (i
= 0; i
<= 63; i
++) {
402 mybit
= 1ULL << (63 - i
); /* compensate for reversed bit numbering. */
403 if (mybit
& local_xer
)
404 printf(" %s", xer_strings
[i
]);
407 /* Display only the XER contents that are relevant for our tests.
408 * this is currently the OV and OV32 bits. */
409 static void dissect_xer_valgrind(unsigned long local_xer
) {
413 mybit
= 1ULL << (63 - i
);
414 if (mybit
& local_xer
) printf(" %s", xer_strings
[i
]);
416 mybit
= 1ULL << (63 - i
);
417 if (mybit
& local_xer
) printf(" %s", xer_strings
[i
]);
422 static void dissect_xer(unsigned long local_xer
) {
424 printf(" [[ xer:%lx ]]", local_xer
);
426 dissect_xer_raw(local_xer
);
428 dissect_xer_valgrind(local_xer
);
432 /* DFP helpers for bcd-to-dpd, dpd-to-bcd, misc.
433 * pulled from vex/.../host_generic_simd64.c
435 /*------------------------------------------------------------------*/
436 /* Decimal Floating Point (DFP) helper functions */
437 /*------------------------------------------------------------------*/
438 #define NOT( x ) ( ( ( x ) == 0) ? 1 : 0)
439 #define GET( x, y ) ( ( ( x ) & ( 0x1UL << ( y ) ) ) >> ( y ) )
440 #define PUT( x, y ) ( ( x )<< ( y ) )
442 static unsigned long dpb_to_bcd( unsigned long chunk
)
444 int a
, b
, c
, d
, e
, f
, g
, h
, i
, j
, k
, m
;
445 int p
, q
, r
, s
, t
, u
, v
, w
, x
, y
;
448 /* convert 10 bit densely packed BCD to BCD */
460 /* The BCD bit values are given by the following boolean equations.*/
461 a
= ( NOT(s
) & v
& w
) | ( t
& v
& w
& s
) | ( v
& w
& NOT(x
) );
462 b
= ( p
& s
& x
& NOT(t
) ) | ( p
& NOT(w
) ) | ( p
& NOT(v
) );
463 c
= ( q
& s
& x
& NOT(t
) ) | ( q
& NOT(w
) ) | ( q
& NOT(v
) );
465 e
= ( v
& NOT(w
) & x
) | ( s
& v
& w
& x
) | ( NOT(t
) & v
& x
& w
);
466 f
= ( p
& t
& v
& w
& x
& NOT(s
) ) | ( s
& NOT(x
) & v
) | ( s
& NOT(v
) );
467 g
= ( q
& t
& w
& v
& x
& NOT(s
) ) | ( t
& NOT(x
) & v
) | ( t
& NOT(v
) );
469 i
= ( t
& v
& w
& x
) | ( s
& v
& w
& x
) | ( v
& NOT(w
) & NOT(x
) );
470 j
= ( p
& NOT(s
) & NOT(t
) & w
& v
) | ( s
& v
& NOT(w
) & x
)
471 | ( p
& w
& NOT(x
) & v
) | ( w
& NOT(v
) );
472 k
= ( q
& NOT(s
) & NOT(t
) & v
& w
) | ( t
& v
& NOT(w
) & x
)
473 | ( q
& v
& w
& NOT(x
) ) | ( x
& NOT(v
) );
476 value
= PUT(a
, 11) | PUT(b
, 10) | PUT(c
, 9) | PUT(d
, 8) | PUT(e
, 7)
477 | PUT(f
, 6) | PUT(g
, 5) | PUT(h
, 4) | PUT(i
, 3) | PUT(j
, 2)
478 | PUT(k
, 1) | PUT(m
, 0);
486 typedef union dfp_union
{
487 _Decimal128 dec_val128
;
489 #if defined(VGP_ppc64le_linux)
499 /* Based on and enhanced from the dfp128_vals table in test_dfp5.c.
500 * Todo: Refine/refactor and turn into a build_table function.
503 static unsigned long dfp128_vals
[] = {
504 #ifdef EXHAUSTIVE_TESTS
505 // Some finite numbers
506 0x2208000000000000ULL
, 0x0000000000000001ULL
, // 1 *10^0
507 0xa208800000000000ULL
, 0x0000000000000001ULL
, // -1 *10^1
508 0x0000000000000000ULL
, 0x0000000000000001ULL
, // 1 *10^-6176. (smallest exp)
509 0x43ffc00000000000ULL
, 0x0000000000000001ULL
, // 1 *10^6111
510 0x6fffc00000000000ULL
, 0x0000000000000001ULL
, // foo *10^2015.
511 0x67ffc00000000000ULL
, 0x0000000000000001ULL
, // foo *10^-2081.
512 0x77ffc00000000000ULL
, 0x0000000000000001ULL
, // 1 *10^6111 (largest exp)
513 0x77ffffffffffffffULL
, 0xffffffffffffffffULL
, // max possible value *10^6111 (largest exp)
514 0x0000000000000000ULL
, 0x0000000000000001ULL
, // min possible value 1 *10^-6176. (smallest exp)
515 0x8000000000000000ULL
, 0x0000000000000001ULL
, // -1 *10^-6176. (smallest exp)
517 /* data bits sprinkled across the significand field. */
518 0xa208800001000000ULL
, 0x0000000000010000ULL
, //-foo *10^1
519 0xa208800000000100ULL
, 0x0000000000000100ULL
, //-foo *10^1
520 0xa208800000000000ULL
, 0x0000100000000000ULL
, //-foo *10^1
521 0xa208800000000000ULL
, 0x0000000001000000ULL
, //-foo *10^1
522 0xa208800000000000ULL
, 0x0000000000000001ULL
, //-foo *10^1
524 // pre-existing dfp128 values:
525 0x2207c00000000000ULL
, 0x0000000000000e50ULL
, // foo * 10^-1
526 0x2207c00000000000ULL
, 0x000000000014c000ULL
, // foo * 10^-1
527 0xa207c00000000000ULL
, 0x00000000000000e0ULL
, // foo * 10^-1
528 0x2206c00000000000ULL
, 0x00000000000000cfULL
, // foo * 10^-5
529 0xa205c00000000000ULL
, 0x000000010a395bcfULL
, // foo * 10^-9
530 0x6209400000fd0000ULL
, 0x00253f1f534acdd4ULL
, // foo * 10^-4091
531 0x000400000089b000ULL
, 0x0a6000d000000049ULL
, // very small number // foo * 10^-6160
534 0x2208000000000000ULL
, 0x0000000000000000ULL
, // 0*10^256
535 0xa208000000000000ULL
, 0x0000000000000000ULL
, // -0*10^0
536 0xa248000000000000ULL
, 0x0000000000000000ULL
, // 0*10^256
539 0x7c00000000000000ULL
, 0x0000000000000000ULL
, // quiet
540 0xfc00000000000000ULL
, 0xc00100035b007700ULL
, // NAN
541 0x7e00000000000000ULL
, 0xfe000000d0e0a0d0ULL
, // signaling NAN
543 // flavors of Infinity
544 0x7800000000000000ULL
, 0x0000000000000000ULL
, // +inf
545 0xf800000000000000ULL
, 0x0000000000000000ULL
, // -inf
546 0xf900000000000000ULL
, 0x0000000000000000ULL
// -inf
548 0x2208000000000000ULL
, 0x0000000000000001ULL
, // 1 *10^0
549 0x77ffffffffffffffULL
, 0xffffffffffffffffULL
, // max possible value *10^6111 (largest exp)
550 0xa208000000000000ULL
, 0x0000000000000000ULL
, // -0*10^0
551 0xfc00000000000000ULL
, 0xc00100035b007700ULL
, // NAN
552 0x7e00000000000000ULL
, 0xfe000000d0e0a0d0ULL
, // signaling NAN
553 0xf800000000000000ULL
, 0x0000000000000000ULL
, // -inf
557 #define NUM_DFP128_VALS (sizeof(dfp128_vals) / sizeof(unsigned long))
558 unsigned long nb_dfp128_vals
= NUM_DFP128_VALS
;
560 /* Todo: update dfp64_vals to match dfp128_vals content. */
562 static unsigned long dfp64_vals
[] = {
563 #ifdef EXHAUSTIVE_TESTS
564 0x77fcffffffffffffULL
, // max possible value 9..9 *10^369 (largest exp)
565 0x0000000000000001ULL
, // min possible nonzero value 1 *10^-398. (smallest exp)
566 0x4248000000000001ULL
, // 1*10^260
567 0x2234000000000e50ULL
, // foo*10^-1
568 0x223400000014c000ULL
, //
569 0xa2340000000000e0ULL
, //
570 0x22240000000000cfULL
, // foo*10^-5
571 0xa21400010a395bcfULL
, // negative -foo*10^-9
572 0x6e4d3f1f534acdd4ULL
, // huge number foo*10^5
573 0x000400000089b000ULL
, // very small number foo*10^-397
576 0x2238000000000000ULL
,
577 0xa238000000000000ULL
, // 0 * 10 ^0
578 0x4248000000000000ULL
, // 0 * 10 ^260
581 0x7e34000000000111ULL
, //signaling NaN
582 0xfe000000d0e0a0d0ULL
, //signaling NaN
583 0xfc00000000000000ULL
, //quiet NaN
585 // flavors of Infinity
586 0x7800000000000000ULL
, //+Inf
587 0xf800000000000000ULL
, //-Inf
588 0x7a34000000000000ULL
, //+Inf
590 0x77fcffffffffffffULL
, // max possible value 9..9 *10^369 (largest exp)
591 0x4248000000000000ULL
, // 0 * 10 ^260
592 0xfe000000d0e0a0d0ULL
, //signaling NaN
593 0xf800000000000000ULL
, //-Inf
597 #define NUM_DFP64_VALS (sizeof(dfp64_vals) / sizeof(unsigned long))
598 unsigned long nb_dfp64_vals
= NUM_DFP64_VALS
;
606 static uint64_t shift_amounts
[] = {
611 #define SHIFT_ARRAY_SIZE 4
614 /* vector splat helpers */
621 static uint64_t splat_values
[] = {
627 #define SPLAT_ARRAY_SIZE 5
630 /* a small memory range used to test load-from and store-to vsx */
631 #define BUFFER_SIZE 4
632 #define MAX_BUFFER_PATTERNS 6
633 unsigned long buffer
[BUFFER_SIZE
];
635 static void initialize_buffer(int t
)
639 for (x
= 0; x
< BUFFER_SIZE
; x
++)
640 /* Don't want each of the 32-bit chunks to be identical. Loads of a
641 * byte from the wrong 32-bit chuck are not detectable if the chunks
644 switch((t
+x
)%BUFFER_SIZE
) {
646 buffer
[x
] = 0xffffffffffffffff;
649 buffer
[x
] = 0x0001020304050607;
652 buffer
[x
] = 0x5555555555555555;
655 buffer
[x
] = 0x0000000000000000;
658 buffer
[x
] = 0x5a05a05a05a05a05;
661 buffer
[x
] = 0x0102030405060708;
664 buffer
[x
] = 0x1010101010101010;
669 #define PATTERN_SIZE 5
670 unsigned long pattern
[PATTERN_SIZE
] = {
679 static void dump_small_buffer(void) {
684 for (x
= 0; x
< BUFFER_SIZE
; x
++)
685 printf("%016lx ", buffer
[x
] );
690 /* value to be shifted */
691 static uint64_t values_to_shift
[] = {
759 #define SHIFT_VALUES_SIZE 66
762 /* DFP related helper functions: */
764 /* For DFP finite numbers, the combination field (G field) is a
765 * combination of the exponent and the LMD (Left Most Digit) of the
766 * significand. The fields are encoded/decoded as described in the
768 * 00 01 10 -< Exponent bits.
769 * 0: 00000 01000 10000
771 * 7: 00111 01111 10111
772 * 8: 11000 11010 11100
773 * 9: 11001 11011 11101 (encoded special field).
777 #define DFP_GFIELD_MASK 0x7c00000000000000UL
778 #define DFP_GFIELD_SHIFT 58
780 static unsigned int special_field_LMD(uint64_t dword1
) {
781 unsigned long g_field_specials
;
783 int right_three_bits
;
785 g_field_specials
= (dword1
& DFP_GFIELD_MASK
) >> DFP_GFIELD_SHIFT
;
786 left_two_bits
= (g_field_specials
& 0x18) >> 3;
787 right_three_bits
= g_field_specials
& 0x07;
789 /* The LMD result maps directly to the right_three_bits value as
790 * long as the left two bits are 0b00,0b01,0b10. So a compare
791 * against 3 is sufficient to determine if we can return the right
792 * three bits directly. (LMD values 0..7).
794 if (left_two_bits
< 3) {
795 return (right_three_bits
);
798 /* LMD values of 8 or 9 require a bit of swizzle, but a check of
799 * the right-most bit is sufficient to determine whether LMD value
802 if (right_three_bits
& 0x1)
808 /* Returns the exponent bits, as decoded from the G field. */
809 static inline int special_field_exponent_bits(unsigned long dword1
) {
810 unsigned long g_field_specials
;
812 int right_three_bits
;
814 g_field_specials
= (dword1
& DFP_GFIELD_MASK
) >> DFP_GFIELD_SHIFT
;
815 left_two_bits
= (g_field_specials
& 0x18) >> 3;
816 right_three_bits
= g_field_specials
& 0x07;
818 /* The special field exponent bits maps directly to the left_two_bits
819 * value as long as the left two bits are 0b00,0b01,0b10. So a compare
820 * against 3 is sufficient for those values.
822 if (left_two_bits
< 3) {
823 return (left_two_bits
);
826 switch(right_three_bits
) {
833 case 6: /* Infinity */ return 0x0;
834 case 7: /* NaN */ return 0x0;
836 return -1; /* should never hit this */
839 /* get_declet(). Return a 10-bit declet, beginning at the 'start'
842 * | dword1 | dword0 |
845 #define TEN_BITS 0x03ffULL
847 static inline int get_declet(int start
, uint64_t dword1
, uint64_t dword0
) {
848 unsigned long local_declet
;
849 unsigned int dword0_shift
;
850 unsigned int dword1_shift
;
852 dword1_shift
= 63 - (start
+ 9);
853 dword0_shift
= 127 - (start
+ 9);
855 if (verbose
>5) printf("\n%s (%d) %016lx %016lx",
856 __FUNCTION__
, start
, dword1
, dword0
);
858 if ((start
+ 9) < 63) { /* fully within dword1 */
859 local_declet
= (dword1
>> dword1_shift
) & TEN_BITS
;
861 } else if (start
>= 65) {/* fully within dword0 */
862 local_declet
= (dword0
>> dword0_shift
) & TEN_BITS
;
864 } else { /* straddling the two dwords*/
865 unsigned long mask_dword0
;
866 unsigned long mask_dword1
;
868 mask_dword1
= TEN_BITS
>> (64 - dword0_shift
);
869 mask_dword0
= TEN_BITS
<< (dword0_shift
);
871 ((dword1
& mask_dword1
) << (64-dword0_shift
)) +
872 ((dword0
& mask_dword0
) >> dword0_shift
);
877 static int get_bcd_digit_from_dpd(int start
, uint64_t dword1
,
882 declet
= get_declet(start
, dword1
, dword0
);
883 bcd_digit
= dpb_to_bcd(declet
);
888 /* The 'exponent left' shift is for moving the leftmost two bits
889 * of the exponent down to where they can be easily merged with the
890 * rest of the exponent.
892 #define DFP128_EXPONENT_RIGHT_MASK 0x03ffc00000000000
893 #define DFP64_EXPONENT_RIGHT_MASK 0x03fc000000000000
894 #define DFP128_EXPONENT_RIGHT_MASK_SHIFT 46
895 #define DFP64_EXPONENT_RIGHT_MASK_SHIFT 50
896 #define DFP128_EXPONENT_LEFT_SHIFT 12
897 #define DFP64_EXPONENT_LEFT_SHIFT 8
901 #define DFP_SIGNALING_NAN_BIT 0x0200000000000000
903 /* Start of the Trailing Significand field is at bit # .. */
904 #define DFP128_T_START 18
905 #define DFP64_T_START 14
907 //The exponent bias value is 101 for DFP Short, 398
908 //for DFP Long, and 6176 for DFP Extended.
909 #define DFP128_EXPONENT_BIAS 6176
910 #define DFP64_EXPONENT_BIAS 398
912 /* return the dfp exponent from the leading dword. */
913 static inline signed long dfp128_exponent(unsigned long dword1
) {
914 unsigned long exponent_left
;
915 unsigned long exponent_right
;
916 unsigned long biased_exponent
;
917 signed long exponent
;
919 exponent_left
= special_field_exponent_bits(dword1
);
920 exponent_right
= (dword1
& DFP128_EXPONENT_RIGHT_MASK
);
921 biased_exponent
= (exponent_left
<< DFP128_EXPONENT_LEFT_SHIFT
) +
922 (exponent_right
>> DFP128_EXPONENT_RIGHT_MASK_SHIFT
);
924 /* Unbias the exponent. */
925 exponent
= biased_exponent
- DFP128_EXPONENT_BIAS
;
930 /* Interpret the paired 64-bit values as a extended (quad) 128 bit DFP.
932 * | Significand | Combination Field/ | |
933 * | sign bit | Encoded Exponent | remainder of significand |
935 * ^ (bit0) Significand sign bit.
936 * ^ (bit 1:17) Combination field. Contains high bits of
937 * exponent (encoded), LMD of significand (encoded),
938 * and the remainder of the exponent. First five bits
939 * will indicate special cases NAN or INF.
940 * ^ (bit 18:127) Remainder of the
944 #define DFP128_COMBINATION_MASK 0x7fffc
945 #define DFP64_COMBINATION_MASK 0x7ffc
946 #define DFP128_COMBINATION_SHIFT 46
947 #define DFP64_COMBINATION_SHIFT 50
948 #define DFP_SPECIAL_SYMBOLS_MASK 0x1f
949 #define DFP_SPECIAL_SYMBOLS_SHIFT 58
951 static inline void dissect_dfp128_float(uint64_t dword1
, uint64_t dword0
) {
953 signed long exponent
;
954 unsigned long gfield_special_symbols
;
955 unsigned long lmd_digit
;
956 unsigned long bcd_digits
[13];
958 int silent
=0; // suppress leading zeros from the output.
960 if (verbose
> 5) printf("RAW128: %016lx %016lx ", dword1
, dword0
);
962 signbit
= (dword1
>> 63);
964 if (signbit
) printf("-");
967 gfield_special_symbols
=
968 ((dword1
>> DFP_SPECIAL_SYMBOLS_SHIFT
) & DFP_SPECIAL_SYMBOLS_MASK
);
970 switch (gfield_special_symbols
) {
976 if (dword1
& DFP_SIGNALING_NAN_BIT
)
984 exponent
= dfp128_exponent(dword1
);
985 lmd_digit
= special_field_LMD(dword1
);
987 for (i
= 0; i
< 11; i
++) {
988 bcd_digits
[i
] = get_bcd_digit_from_dpd((DFP128_T_START
989 + 10 * i
), dword1
, dword0
);
994 printf("%01lx", lmd_digit
);
1000 for (i
= 0; i
< 11; i
++) {
1001 if (bcd_digits
[i
] || silent
) {
1003 printf("%03lx", bcd_digits
[i
]);
1006 /* always print at least the last zero */
1015 printf("%ld ", exponent
);
1019 /* Interpret the 64-bit values as a 64 bit DFP.
1021 * | Significand | Combination Field/ | |
1022 * | sign bit | Encoded Exponent | remainder of significand |
1024 * ^ (bit0) Significand sign bit.
1025 * ^ (bit 1:13) Combination field. Contains high bits of
1026 * exponent (encoded), LMD of significand (encoded),
1027 * and the remainder of the exponent. First five bits
1028 * will indicate special cases NAN or INF.
1029 * ^ (bit 14:63) Remainder of the
1033 /* return the dfp exponent from the leading dword. */
1034 static inline signed long dfp64_exponent(unsigned long dword1
) {
1035 unsigned long exponent_left
;
1036 unsigned long exponent_right
;
1037 unsigned long biased_exponent
;
1038 signed long exponent
;
1040 exponent_left
= special_field_exponent_bits(dword1
);
1041 exponent_right
= (dword1
& DFP64_EXPONENT_RIGHT_MASK
);
1042 biased_exponent
= (exponent_left
<< DFP64_EXPONENT_LEFT_SHIFT
) +
1043 (exponent_right
>> DFP64_EXPONENT_RIGHT_MASK_SHIFT
);
1045 /* Unbias the exponent. */
1046 exponent
= biased_exponent
- DFP64_EXPONENT_BIAS
;
1050 static inline void dissect_dfp64_float(uint64_t dword1
) {
1052 signed long exponent
;
1053 unsigned long gfield_special_symbols
;
1054 unsigned long lmd_digit
;
1055 unsigned long bcd_digits
[13];
1057 int silent
=0; // suppress leading zeros from the output.
1059 if (verbose
> 5) printf("RAW64: %016lx ", dword1
);
1061 signbit
= (dword1
>> 63);
1063 if (signbit
) printf("-");
1066 gfield_special_symbols
=
1067 ((dword1
>> DFP_SPECIAL_SYMBOLS_SHIFT
) & DFP_SPECIAL_SYMBOLS_MASK
);
1069 switch (gfield_special_symbols
) {
1075 if (dword1
& DFP_SIGNALING_NAN_BIT
)
1083 exponent
= dfp64_exponent(dword1
);
1084 lmd_digit
= special_field_LMD(dword1
);
1086 for (i
= 0; i
< 5; i
++)
1087 bcd_digits
[i
] = get_bcd_digit_from_dpd((DFP64_T_START
+ 10 * i
),
1092 printf("%01lx", lmd_digit
);
1098 for (i
= 0; i
< 5; i
++) {
1099 if (bcd_digits
[i
] || silent
) {
1101 printf("%03lx", bcd_digits
[i
]);
1103 } else { // suppress leading zeros.
1104 /* always print at least the last zero */
1113 printf("%ld ", exponent
);
1117 static void dump_dfp128_table(void) {
1120 printf("DFP 128 table:\n");
1122 for (i
= 0; i
< nb_dfp128_vals
; i
+= 2) {
1123 printf("i=:%2d ", i
);
1124 dissect_dfp128_float(dfp128_vals
[i
], dfp128_vals
[i
+1]);
1129 static void dump_dfp64_table(void) {
1132 printf("DFP 64 table:\n");
1134 for (i
= 0; i
<nb_dfp64_vals
; i
++) {
1135 printf("i=:%2d ", i
);
1136 dissect_dfp64_float(dfp64_vals
[i
]);
1142 /* Data Formats for floating point.
1143 * Floating point values include the following:
1144 * -INF -NOR -DEN -0 +0 +DEN +NOR +INF
1145 * INFinite: When the biased exponent is the MAX possible value, and
1146 * the fraction field is 0.
1147 * ZERo. biased exponent is zero, fraction is 0.
1148 * DENormalized. biased exponent is 0, and fraction is non-zero.
1149 * NORmalized. All other values that are neither Zero, Denormalized,
1150 * or Infinite. Biased exponent=1..MAX-1.
1154 * | Sign | EXPonent+Bias | FRACTION/Mantissa |
1156 * exponent is 15 bits. ranging from: 0x0000 .. 0x7fff
1157 * 0 = (zero if fraction==0, DeNormal if fraction !=0 )
1158 * 1...0x7ffe = normalized
1159 * 7fff = (infinite if fraction==0, NaN if fraction !=0)
1161 #define QUAD_EXP_MASK 0x7fff
1163 /* This assumes we are working on the top half of a quad stored in a 64-bit
1166 #define QUAD_EXP_SHIFT 48
1167 #define QUAD_MANTISSA_MASK 0x0000ffffffffffff
1168 static inline unsigned long build_binary128_float(unsigned long signbit
,
1169 unsigned long exponent
,
1170 unsigned long mantissa
) {
1171 unsigned long thevalue
;
1173 thevalue
= (unsigned long) (signbit
<< 63) |
1174 ((exponent
& QUAD_EXP_MASK
) << QUAD_EXP_SHIFT
) |
1175 (mantissa
& QUAD_MANTISSA_MASK
);
1178 printf("%s %lx \n", __FUNCTION__
, (unsigned long)thevalue
);
1184 * | Sign | EXPonent+Bias | FRACTION/Mantissa |
1186 * exponent is 11 bits. ranging from: 0x000 .. 0x7ff
1187 * 0 = (zero if fraction==0, DeNormal if fraction !=0 )
1188 * 1...0x7fe = normalized
1189 * 7ff = (infinite if fraction==0, NaN if fraction !=0)
1191 #define DOUBLE_EXP_MASK 0x7ff
1192 #define DOUBLE_EXP_SHIFT 52
1193 #define DOUBLE_MANTISSA_MASK 0x000fffffffffffff
1195 static inline unsigned long build_binary64_float(unsigned long signbit
,
1196 unsigned long exponent
,
1197 unsigned long mantissa
) {
1198 unsigned long thevalue
;
1200 thevalue
= (unsigned long ) (signbit
<< 63) |
1201 ((exponent
& DOUBLE_EXP_MASK
) << DOUBLE_EXP_SHIFT
) |
1202 (mantissa
& DOUBLE_MANTISSA_MASK
);
1205 printf("%s %lx \n", __FUNCTION__
, (unsigned long)thevalue
);
1210 /* floating point single (32bit):
1211 * | Sign | EXPonent+Bias | FRACTION/Mantissa |
1213 * exponent is 8 bits. ranging from: 0x00 .. 0xff
1214 * 0 = (zero if fraction==0, DeNormal if fraction !=0 )
1215 * 1...0x7e = normalized
1216 * 7f = (infinite if fraction==0, NaN if fraction !=0) */
1217 #define SINGLE_EXP_MASK 0xff
1218 #define SINGLE_EXP_SHIFT 23
1219 #define SINGLE_MANTISSA_MASK 0x007fffff
1221 /* This is building the 32-bit float. */
1222 static inline unsigned long build_binary32_float(unsigned long signbit
,
1223 unsigned long exponent
,
1224 unsigned long mantissa
) {
1225 unsigned long thevalue
;
1226 unsigned long local_signbit
;
1227 unsigned long local_exponent
;
1228 unsigned long local_mantissa
;
1230 local_signbit
= (signbit
!= 0) << 31;
1231 local_exponent
= ((exponent
& SINGLE_EXP_MASK
) << SINGLE_EXP_SHIFT
);
1232 local_mantissa
= (mantissa
& SINGLE_MANTISSA_MASK
);
1234 thevalue
= (unsigned long) (local_signbit
) |
1239 printf("%s %lx \n", __FUNCTION__
, (unsigned long)thevalue
);
1244 /* floating point half (16bit):
1245 * | Sign | EXPonent+Bias | FRACTION/Mantissa |
1247 * exponent is 6 bits. 0x00 .. 0x7e masked with EXP_MASK
1248 * 0 = (zero if fraction==0, DeNormal if fraction !=0 )
1249 * 1...0x7d = normalized
1250 * 7e = (infinite if fraction==0, NaN if fraction !=0) */
1251 /* when extracting the exponent from the 16-bit half-word, use this mask. */
1252 #define HALF_EXP_MASK 0x7e00
1254 /* when building the 16-bit half-word, mask against this,
1255 * then shift into place
1257 #define HALF_EXP_MASK_NORMALIZED 0x3f
1258 #define HALF_EXP_SHIFT 9
1259 #define HALF_MANTISSA_MASK 0x01ff
1261 /* This is building the 16-bit float. */
1262 static inline unsigned long build_binary16_float(unsigned long in_signbit
,
1263 unsigned long exponent
,
1264 unsigned mantissa
) {
1265 unsigned long thevalue
;
1266 unsigned long local_signbit
;
1267 unsigned long local_exponent
;
1268 unsigned long local_mantissa
;
1270 local_signbit
= (in_signbit
!= 0) << 15;
1272 local_exponent
= ((exponent
& HALF_EXP_MASK_NORMALIZED
) << HALF_EXP_SHIFT
);
1273 local_mantissa
= (mantissa
& HALF_MANTISSA_MASK
);
1275 thevalue
= (unsigned long) (local_signbit
) | (local_exponent
)
1279 printf("%s %lx \n", __FUNCTION__
, (unsigned long)thevalue
);
1284 /* dissect_binary128_float:
1285 * Interpret the (high half) 64-bit value as normal/denormal/inf/NaN.
1286 * This is as it would be interpreted as the MSB portion of
1287 * a 128-bit wide QUAD.
1289 static inline void dissect_binary128_float(uint64_t value
) {
1290 unsigned long signbit
;
1291 unsigned long exponent
;
1292 unsigned long mantissa
;
1294 signbit
= (value
>> 63);
1295 exponent
= ( QUAD_EXP_MASK
& (value
>> QUAD_EXP_SHIFT
));
1296 mantissa
= ( QUAD_MANTISSA_MASK
& value
);
1298 if (verbose
> 4) printf("128 bit:");
1300 if (signbit
) printf("-");
1305 if (mantissa
== 0) printf("zero ");
1306 else printf("denormal ");
1310 if (mantissa
== 0) printf("inf ");
1311 else printf("NaN ");
1314 default: printf("Normal ");
1318 printf("%lx %4lx %16lx %16lx \n", signbit
, exponent
, mantissa
, value
);
1321 /* Interpret the 64-bit value as normal/denormal/inf/NaN
1322 * this is as interpreted as the 64-bit float
1324 static inline void dissect_binary64_float(uint64_t value
) {
1325 unsigned long signbit
;
1326 unsigned long exponent
;
1327 unsigned long mantissa
;
1329 signbit
= (value
>> 63); // bit0
1330 exponent
= ( DOUBLE_EXP_MASK
& (value
>> DOUBLE_EXP_SHIFT
));
1331 mantissa
= ( DOUBLE_MANTISSA_MASK
& value
);
1333 if (verbose
> 4) printf(" 64 bit:");
1335 if (signbit
) printf("-");
1340 if (mantissa
== 0) printf("zero ");
1341 else printf("denormal ");
1344 case DOUBLE_EXP_MASK
:
1345 if (mantissa
== 0) printf("inf ");
1346 else printf("NaN ");
1349 default: printf("Normal ");
1353 printf("%lx %4lx %16lx %16lx\n", signbit
, exponent
, mantissa
, value
);
1356 /* interpret the 32-bit value as normal/denormal/inf/NaN.
1357 * Note that the value is stored in the upper half of a
1358 * 64-bit, which is itself in the upper half of a quad.
1360 static inline void dissect_binary32_float(uint64_t value
) {
1361 unsigned long signbit
;
1362 unsigned long exponent
;
1363 unsigned long mantissa
;
1364 unsigned long adj_value
;
1366 /* shift down to where the offsets make more sense.*/
1367 adj_value
= value
; //>>32;
1368 signbit
= (adj_value
>> 31);
1369 exponent
= ( SINGLE_EXP_MASK
& (adj_value
>> SINGLE_EXP_SHIFT
));
1370 mantissa
= ( SINGLE_MANTISSA_MASK
& adj_value
);
1372 if (verbose
> 4) printf(" 32 bit:");
1374 if (signbit
) printf("-");
1379 if (mantissa
== 0) printf("zero ");
1380 else printf("denormal ");
1383 case SINGLE_EXP_MASK
:
1384 if (mantissa
== 0) printf("inf ");
1385 else printf("NaN ");
1388 default: printf("Normal ");
1392 printf("%lx %4lx %16lx %16lx \n", signbit
, exponent
, mantissa
, adj_value
);
1395 /* Interpret the 16-bit value as normal/denormal/inf/NaN. */
1396 static inline void dissect_binary16_float(uint64_t value
) {
1397 unsigned long signbit
;
1398 unsigned long exponent
;
1399 unsigned long mantissa
;
1400 unsigned long adj_value
;
1402 adj_value
= (value
& 0xffff);
1403 signbit
= ((adj_value
& 0x8000) > 1);
1404 exponent
= ((adj_value
& HALF_EXP_MASK
) >> HALF_EXP_SHIFT
) ;
1405 mantissa
= (adj_value
& HALF_MANTISSA_MASK
);
1407 if (verbose
> 4) printf(" 16 bit:");
1409 if (signbit
) printf("-");
1414 if (mantissa
== 0) printf("zero ");
1415 else printf("denormal ");
1419 if (mantissa
== 0) printf("inf ");
1420 else printf("NaN ");
1423 default: printf("Normal ");
1427 printf("%lx %4lx %16lx %16lx \n",
1428 signbit
, exponent
>>HALF_EXP_SHIFT
, mantissa
, adj_value
);
1431 #define dissect_double_as_32s(vec_foo) \
1433 dissect_binary16_float((vec_foo & 0xffffffff)); \
1435 dissect_binary16_float((vec_foo >> 32) & 0xffffffff);
1437 #define dissect_double_as_16s(vec_foo) \
1439 dissect_binary16_float((vec_foo&0xffff)); \
1441 dissect_binary16_float((vec_foo>>16)&0xffff); \
1443 dissect_binary16_float((vec_foo>>32)&0xffff); \
1445 dissect_binary16_float((vec_foo>>48)&0xffff);
1447 /* a table of exponent values for use in the float precision tests. */
1448 unsigned long exponent_table
[] = {
1449 #ifdef EXHAUSTIVE_TESTS
1450 0x0000, /* +/-0 or +/-DENormalized, depending on associated mantissa. */
1451 0x1a, /* within NORmalized for 16,32,64,128-bit. */
1452 0x1f, /* +/-INF or +/-NaN for 16bit, NORmalized for 32,64,128 */
1453 0xff, /* +/-INF or +/-NaN for 32bit, NORmalized for 64,128 */
1454 0x7ff, /* +/-INF or +/-NaN for 32 and 64bit, NORmalized for 128 */
1455 0x7fff, /* +/-INF or +/-NaN for 128bit. */
1457 0x0000, /* +/-0 or +/-DENormalized, depending on associated mantissa. */
1458 0xff, /* +/-INF or +/-NaN for 32bit, NORmalized for 64,128 */
1459 0x7ff, /* +/-INF or +/-NaN for 32 and 64bit, NORmalized for 128 */
1460 0x7fff, /* +/-INF or +/-NaN for 128bit. */
1463 #define MAX_EXPONENTS (sizeof(exponent_table) / sizeof(unsigned long))
1465 unsigned long mantissa_table
[] = {
1466 #ifdef EXHAUSTIVE_TESTS
1467 0xbeefbeefbeef, /* NOR or DEN or NaN */
1468 0x000000000000, /* ZERO or INF */
1469 0x7fffffffffff, /* NOR or DEN or NaN */
1471 0x000000000000, /* ZERO or INF */
1472 0x7fffffffffff, /* NOR or DEN or NaN */
1475 #define MAX_MANTISSAS (sizeof(mantissa_table) / sizeof(unsigned long))
1477 /* build in 64-bit chunks, low doubleword is zero. */
1478 static unsigned long * float_vsxargs
;
1479 static unsigned long * binary128_float_vsxargs
= NULL
;
1480 static unsigned long * binary64_float_vsxargs
= NULL
;
1481 static unsigned long * binary32_float_vsxargs
= NULL
;
1482 static unsigned long * binary16_float_vsxargs
= NULL
;
1484 unsigned long nb_float_vsxargs
;
1486 #define MAX_FLOAT_VSX_ARRAY_SIZE (((MAX_EXPONENTS * MAX_MANTISSAS) * 2 + 1) * 2)
1488 void build_float_vsx_tables (void)
1491 unsigned long signbit
;
1492 unsigned long exponent
;
1493 unsigned long mantissa
;/* also referred to as FRACTION in the ISA.*/
1494 unsigned long exponent_index
;
1495 unsigned long mantissa_index
;
1497 if (verbose
> 2) printf("%s\n", __FUNCTION__
);
1499 binary128_float_vsxargs
= malloc(MAX_FLOAT_VSX_ARRAY_SIZE
1500 * sizeof(unsigned long));
1502 float_vsxargs
= binary128_float_vsxargs
;
1504 binary64_float_vsxargs
= malloc(MAX_FLOAT_VSX_ARRAY_SIZE
1505 * sizeof(unsigned long));
1507 binary32_float_vsxargs
= malloc(MAX_FLOAT_VSX_ARRAY_SIZE
1508 * sizeof(unsigned long));
1509 binary16_float_vsxargs
= malloc(MAX_FLOAT_VSX_ARRAY_SIZE
1510 * sizeof(unsigned long));
1512 for (signbit
= 0; signbit
< 2; signbit
++) {
1513 for (exponent_index
= 0; exponent_index
< MAX_EXPONENTS
;
1516 for (mantissa_index
= 0; mantissa_index
< MAX_MANTISSAS
;
1519 exponent
= exponent_table
[exponent_index
];
1520 mantissa
= mantissa_table
[mantissa_index
];
1523 printf("signbit:%lx ", signbit
);
1524 printf("exponent:%4lx ", exponent
);
1525 printf("mantissa:%lx ", mantissa
);
1529 binary128_float_vsxargs
[i
] = build_binary128_float(signbit
, exponent
,
1532 binary128_float_vsxargs
[i
+1] = 0;
1534 binary64_float_vsxargs
[i
] = build_binary64_float(signbit
, exponent
,
1537 binary64_float_vsxargs
[i
+1] = build_binary64_float(signbit
, exponent
,
1540 binary32_float_vsxargs
[i
] = build_binary32_float(signbit
, exponent
,
1543 binary32_float_vsxargs
[i
+1] = build_binary32_float(signbit
, exponent
,
1546 binary16_float_vsxargs
[i
] = build_binary16_float(signbit
, exponent
,
1549 binary16_float_vsxargs
[i
+1] = build_binary16_float(signbit
, exponent
,
1555 nb_float_vsxargs
= i
;
1558 /* Display entries stored in the float_vsx table. These are used as
1559 * quad/double/singles, stored as quads. */
1560 void dump_float_vsx_table (void) {
1563 printf("Float VSX Table:");
1564 printf("128-bit (quad):\n");
1566 for (i
= 0; i
< nb_float_vsxargs
; i
+= 2) {
1567 printf("i =: %2d ", i
);
1568 dissect_binary128_float(binary128_float_vsxargs
[i
]);
1571 printf("64-bit (double):\n");
1573 for (i
= 0; i
< nb_float_vsxargs
; i
+= 2) {
1574 printf("i = %2d ", i
);
1575 dissect_binary64_float(binary64_float_vsxargs
[i
]);
1578 printf("32-bit (single):\n");
1580 for (i
= 0; i
< nb_float_vsxargs
; i
+= 2) {
1581 printf("i = %2d ", i
);
1582 dissect_binary32_float(binary32_float_vsxargs
[i
]);
1585 printf("16-bit (half):\n");
1587 for (i
= 0; i
< nb_float_vsxargs
; i
+= 2) {
1588 printf("i =% 2d ", i
);
1589 dissect_binary16_float(binary16_float_vsxargs
[i
]);
1595 static void print_dcmx_field(unsigned long local_dcmx
) {
1596 /* Note - this splats out the local_dxmc field from the form used to
1597 * globally pass it, with a single set bit, into the functions that use
1598 * it. The actual DCMX field is a bit-field from 0x00 to 0x3f. If
1599 * multiple bits are ever set, this function and the way it is passed
1600 * into the users will need to be updated. This does not handle
1601 * multiple bits being set.
1606 switch(local_dcmx
) {
1607 case 0: printf("ALL"); break;
1608 case 1: printf("NaN"); break;
1609 case 2: printf("+inf"); break;
1610 case 3: printf("-inf"); break;
1611 case 4: printf("+zero"); break;
1612 case 5: printf("-zero"); break;
1613 case 6: printf("+denormal"); break;
1614 case 7: printf("-denormal"); break;
1615 default: printf("other"); break;
1619 printf(" %lx", local_dcmx
);
1624 #define MAX_CHAR_ARGS_ARRAY_SIZE 128
1626 static unsigned char * char_args
;
1627 unsigned long nb_char_args
;
1629 static void build_char_table(void) {
1633 char_args
= memalign(32, MAX_CHAR_ARGS_ARRAY_SIZE
* sizeof(char));
1635 #ifdef EXHAUSTIVE_TESTS
1636 for (ichar
= 'a'; ichar
<= 'z'; ichar
++) { char_args
[i
++] = ichar
; }
1637 for (ichar
= '0'; ichar
<= '9'; ichar
++) { char_args
[i
++] = ichar
; }
1638 for (ichar
= 'A'; ichar
<= 'Z'; ichar
++) { char_args
[i
++] = ichar
; }
1640 for (ichar
= 'a'; ichar
<= 'z'; ichar
+=6) { char_args
[i
++] = ichar
; }
1641 for (ichar
= '0'; ichar
<= '9'; ichar
+=6) { char_args
[i
++] = ichar
; }
1642 for (ichar
= 'A'; ichar
<= 'Z'; ichar
+=6) { char_args
[i
++] = ichar
; }
1645 char_args
[i
++] = ' ';
1646 char_args
[i
++] = '+';
1647 char_args
[i
++] = '-';
1648 char_args
[i
++] = '/';
1649 char_args
[i
++] = '[';
1650 char_args
[i
++] = ']';
1651 char_args
[i
++] = '`';
1652 char_args
[i
++] = '_';
1656 static void dump_char_table() {
1659 printf("Char Table:");
1661 for (i
= 0; i
<nb_char_args
; i
++)
1662 printf("%c ", char_args
[i
]);
1667 #define MAX_CHAR_RANGES_SIZE 128
1669 static unsigned char * char_ranges
;
1670 unsigned long nb_char_ranges
;
1672 static void build_char_range_table(void) {
1673 /* ... in groups of four. */
1676 char char_start
, char_end
;
1678 char_ranges
= memalign(32, MAX_CHAR_RANGES_SIZE
* sizeof(char));
1681 char_ranges
[i
++] = char_start
;
1682 char_ranges
[i
++] = char_end
;
1686 char_ranges
[i
++] = char_start
;
1687 char_ranges
[i
++] = char_end
;
1691 char_ranges
[i
++] = char_start
;
1692 char_ranges
[i
++] = char_end
;
1696 char_ranges
[i
++] = char_start
;
1697 char_ranges
[i
++] = char_end
;
1701 char_ranges
[i
++] = char_start
;
1702 char_ranges
[i
++] = char_end
;
1706 char_ranges
[i
++] = char_start
;
1707 char_ranges
[i
++] = char_end
;
1712 static void dump_char_range_table()
1716 printf("Char Range Table:");
1718 for (i
= 0; i
< nb_char_ranges
; i
+= 4) {
1719 printf(" [ %c-%c %c-%c ] ",
1720 char_ranges
[i
], char_ranges
[i
+1],
1721 char_ranges
[i
+2], char_ranges
[i
+3] );
1727 static HWord_t
*iargs
= NULL
;
1728 static int nb_iargs
= 0;
1730 static void build_iargs_table (void) {
1734 iargs
= malloc(20 * sizeof(HWord_t
));
1736 for (tmp
= 0; ; tmp
= 123456789*tmp
+ 123456789999) {
1738 tmp
= 0xFFFFFFFFFFFFFFFFULL
;
1741 AB_DPRINTF("val %016lx\n", tmp
);
1743 if (tmp
== 0xFFFFFFFFFFFFFFFFULL
)
1747 AB_DPRINTF("Registered %d iargs values\n", i
);
1751 static unsigned long * vsxargs
= NULL
;
1752 unsigned long nb_vargs
;
1754 #define MAX_VSX_ARRAY_SIZE 42
1756 static void build_vsx_table (void)
1759 // A VSX register is 128-bits wide.
1760 // We build contents here using pairs of 64-bit longs.
1761 // Permutes work against two (non-paired) VSX regs, so these are
1762 // also grouped by twos.
1763 vsxargs
= memalign(16, MAX_VSX_ARRAY_SIZE
* sizeof(unsigned long));
1764 #ifdef EXHAUSTIVE_TESTS
1765 vsxargs
[i
++] = 0x0000000000000000UL
; vsxargs
[i
++] = 0x0000000000000000UL
;
1766 vsxargs
[i
++] = 0x0102030405060708UL
; vsxargs
[i
++] = 0x0102010201020102UL
;
1768 vsxargs
[i
++] = 0xaaaaaaaaaaaaaaaaUL
; vsxargs
[i
++] = 0xaaaaaaaaaaaaaaaaUL
;
1769 vsxargs
[i
++] = 0x5555555555555555UL
; vsxargs
[i
++] = 0x5555555555555555UL
;
1771 vsxargs
[i
++] = 0x08090a0b0c0d0e0fUL
; vsxargs
[i
++] = 0x0102010201020102UL
;
1772 vsxargs
[i
++] = 0xf0f1f2f3f4f5f6f7UL
; vsxargs
[i
++] = 0xf8f9fafbfcfdfeffUL
;
1774 vsxargs
[i
++] = 0x7ea1a5a7abadb0baUL
; vsxargs
[i
++] = 0x070d111d1e555e70UL
;
1775 vsxargs
[i
++] = 0xe5e7ecedeff0f1faUL
; vsxargs
[i
++] = 0xbeb1c0caced0dbdeUL
;
1777 vsxargs
[i
++] = 0x00115e7eadbabec0UL
; vsxargs
[i
++] = 0xced0deede5ecef00UL
;
1778 vsxargs
[i
++] = 0x00111e7ea5abadb1UL
; vsxargs
[i
++] = 0xbecad0deedeffe00UL
;
1780 vsxargs
[i
++] = 0x0011223344556677UL
; vsxargs
[i
++] = 0x8899aabbccddeeffUL
;
1781 vsxargs
[i
++] = 0xf0e0d0c0b0a09080UL
; vsxargs
[i
++] = 0x7060504030201000UL
;
1783 vsxargs
[i
++] = 0x0000000000000000UL
; vsxargs
[i
++] = 0x0000000000000000UL
;
1784 vsxargs
[i
++] = 0x0102030405060708UL
; vsxargs
[i
++] = 0x0102010201020102UL
;
1786 vsxargs
[i
++] = 0x0011223344556677UL
; vsxargs
[i
++] = 0x8899aabbccddeeffUL
;
1787 vsxargs
[i
++] = 0xf0e0d0c0b0a09080UL
; vsxargs
[i
++] = 0x7060504030201000UL
;
1790 // these next three groups are specific for vector rotate tests.
1791 // bits 11:15,19:23,27:31 of each 32-bit word contain mb,me,sh values.
1792 vsxargs
[i
++] = 0x0000100000001002ULL
; vsxargs
[i
++] = 0x0000100800001010ULL
;
1793 vsxargs
[i
++] = 0x0010100000101002ULL
; vsxargs
[i
++] = 0x0010100800101010ULL
;
1795 // vector rotate special...
1796 vsxargs
[i
++] = 0x00001c0000001c02ULL
; vsxargs
[i
++] = 0x00001c0800001c10ULL
;
1797 vsxargs
[i
++] = 0x00101c0000101c02ULL
; vsxargs
[i
++] = 0x00101c0800101c10ULL
;
1799 // vector rotate special...
1800 vsxargs
[i
++] = 0x00001f0000001f02ULL
; vsxargs
[i
++] = 0x00001f0800001f10ULL
;
1801 vsxargs
[i
++] = 0x00101f0000101f02ULL
; vsxargs
[i
++] = 0x00101f0800101f10ULL
;
1803 AB_DPRINTF("Registered %d vargs values\n", i
/2);
1807 /* VPCV = Vector Permute Control Vector */
1808 unsigned long nb_vpcv
;
1809 static unsigned long * vpcv
= NULL
;
1811 #define MAX_VPCV_SIZE 20
1813 static void build_vector_permute_table(void)
1817 vpcv
= memalign(16, MAX_VPCV_SIZE
* sizeof(unsigned long));
1819 #ifdef EXHAUSTIVE_TESTS
1820 /* These two lines are complementary pairs of each other. */
1821 vpcv
[i
++]=0x12021a0817141317ULL
; vpcv
[i
++]=0x100d1b05070f0205ULL
;
1822 vpcv
[i
++]=0x0d1d0517080b0c08ULL
; vpcv
[i
++]=0x0f12041a18101d1cULL
;
1823 vpcv
[i
++]=0x100d1b070f020505ULL
; vpcv
[i
++]=0x0e201f1400130105ULL
;
1824 vpcv
[i
++]=0x0705030a0b01ea0cULL
; vpcv
[i
++]=0x0e0c09010602080dULL
;
1826 vpcv
[i
++]=0x12021a0817141317ULL
; vpcv
[i
++]=0x100d1b05070f0205ULL
;
1827 vpcv
[i
++]=0x0705030a0b01ea0cULL
; vpcv
[i
++]=0x0e0c09010602080dULL
;
1830 AB_DPRINTF("Registered %d permute control vectors \n", nb_vpcv
);
1832 if (i
>= MAX_VPCV_SIZE
)
1833 printf("Warning! Exceeded size of table building the vector permute control . \n");
1836 /* Decimal Encodings...
1837 * Packed, National, Zoned decimal content follows.
1838 * Note: Watch the conversions in and out of the
1839 * dwords / vectors for reverses with respect to
1840 * top/bottom low/high
1844 * A valid encoding of a packed decimal integer value requires the following
1846 * – Each of the 31 4-bit digits of the operand’s magnitude (bits 0:123)
1847 * must be in the range 0-9.
1848 * – The sign code (bits 124:127) must be in the range 10-15. (0xa-0xf).
1849 * Source operands with sign codes of 0b1010, 0b1100, 0b1110, and 0b1111 are
1850 * interpreted as positive values. Source operands with sign codes of
1851 * 0b1011 and 0b1101 are interpreted as negative values.
1852 * Positive and zero results are encoded with a either sign code of
1853 * 0b1100 or 0b1111, depending on the preferred sign (indicated as an
1854 * immediate operand). Negative results are encoded with a sign code
1856 * PS - This is the 'preferred sign' bit encoded in some BCD associated
1860 // Note: table content is limited to values encoded, not interpreted.
1861 unsigned int packed_decimal_sign_codes
[] = {
1862 /* positive operands */
1863 0xc, 0xf, // 0b1100, 0b1111
1865 /* negative operands */
1869 #define NR_PACKED_DECIMAL_SIGNS 3
1870 #define MAX_PACKED_DECIMAL_TABLE_SIZE 8 * 16 * 2 + 20
1872 static unsigned long * packed_decimal_table
;
1874 /* build into a pair of doubles */
1875 unsigned long nb_packed_decimal_entries
;
1877 static void dissect_packed_decimal_sign(unsigned long local_sign
) {
1878 switch(local_sign
) {
1879 case 0xa: /*0b1010:*/ printf("[ + ]"); break;
1880 case 0xb: /*0b1011:*/ printf("[ - ]"); break;
1881 case 0xc: /*0b1100:*/ printf("(+|0)"); break;
1882 case 0xd: /*0b1101:*/ printf("( - )"); break;
1883 case 0xe: /*0b1110:*/ printf("[ + ]"); break;
1884 case 0xf: /*0b1111:*/ printf("(+|0)"); break;
1885 default: printf("(?%02lx)", local_sign
);
1889 int extract_packed_decimal_sign(unsigned long dword1
, unsigned long dword0
) {
1890 return (dword1
& 0xf);
1893 static void dissect_packed_decimal(unsigned long dword1
,unsigned long dword0
)
1899 local_sign
= extract_packed_decimal_sign(dword1
, dword0
);
1900 printf("packed_decimal: [");
1902 for (i
= 60; i
>= 0; i
-= 4) {
1903 nibble
=(dword1
>> (i
)) & 0xf;
1904 printf(" %x", nibble
);
1907 for (i
= 60; i
>= 0; i
-= 4) {
1908 nibble
=(dword0
>> (i
)) & 0xf;
1909 printf(" %x", nibble
);
1913 dissect_packed_decimal_sign(local_sign
);
1917 static void build_packed_decimal_table(void)
1921 unsigned long i
= 0;
1922 unsigned long value
;
1923 #ifdef EXHAUSTIVE_TESTS
1927 if (verbose
) printf("%s\n", __FUNCTION__
);
1929 packed_decimal_table
= malloc((MAX_PACKED_DECIMAL_TABLE_SIZE
+ 2)
1930 * sizeof (unsigned long));
1932 for (sign_index
= 0; sign_index
< NR_PACKED_DECIMAL_SIGNS
; sign_index
++) {
1933 sign_value
= packed_decimal_sign_codes
[sign_index
];
1935 for (value
= 0; value
<= 9; value
++) {
1936 packed_decimal_table
[i
] = 0x1111111111111111 * value
;
1937 packed_decimal_table
[i
+1] = sign_value
;
1938 packed_decimal_table
[i
+1] += 0x1111111111111110 * value
;
1940 if (verbose
>3) dissect_packed_decimal(packed_decimal_table
[i
+1],
1941 packed_decimal_table
[i
]);
1942 if (verbose
>3) printf("\n");
1946 #ifdef EXHAUSTIVE_TESTS
1947 for (scramble
= 1; scramble
<= 4; scramble
++) {
1948 packed_decimal_table
[i
] = 0x3210321032103210 * scramble
;
1949 packed_decimal_table
[i
+1] = sign_value
;
1950 packed_decimal_table
[i
+1] += 0x0123012301230120 * scramble
;
1952 if (verbose
>3) dissect_packed_decimal(packed_decimal_table
[i
+1],
1953 packed_decimal_table
[i
]);
1954 if (verbose
>3) printf("\n");
1959 /* Add some entries that will provide interesting output from
1960 * the convert TO tests.
1962 packed_decimal_table
[i
] = 0x0000000000000000;
1963 packed_decimal_table
[i
+1] = sign_value
;
1964 packed_decimal_table
[i
+1] += 0x0000000012345670;
1966 if (verbose
> 3) dissect_packed_decimal(packed_decimal_table
[i
+1],
1967 packed_decimal_table
[i
]);
1969 if (verbose
>3) printf("\n");
1973 #ifdef EXHAUSTIVE_TESTS
1974 packed_decimal_table
[i
] = 0x0000000000000000;
1975 packed_decimal_table
[i
+1] = sign_value
;
1976 packed_decimal_table
[i
+1] += 0x0000000098765430;
1978 if (verbose
> 3) dissect_packed_decimal(packed_decimal_table
[i
+1],
1979 packed_decimal_table
[i
]);
1981 if (verbose
> 3) printf("\n");
1985 packed_decimal_table
[i
] = 0x000000000000000b;
1986 packed_decimal_table
[i
+1] = sign_value
;
1987 packed_decimal_table
[i
+1] += 0x0000000000000000;
1989 if (verbose
> 3) dissect_packed_decimal(packed_decimal_table
[i
+1],
1990 packed_decimal_table
[i
]);
1992 if (verbose
>3) printf("\n");
1997 packed_decimal_table
[i
] = 0x0030000000000000;
1998 packed_decimal_table
[i
+1] = sign_value
;
1999 packed_decimal_table
[i
+1] += 0x0000000000000000;
2001 if (verbose
> 3) dissect_packed_decimal(packed_decimal_table
[i
+1],
2002 packed_decimal_table
[i
]);
2004 if (verbose
> 3) printf("\n");
2009 if (verbose
>2) printf("\n");
2011 nb_packed_decimal_entries
= i
;
2014 static void dump_packed_decimal_table(void) {
2017 printf("packed_decimal_table:\n");
2019 for (i
= 0; i
< nb_packed_decimal_entries
; i
+= 2) {
2020 printf("i =: %2d ", i
);
2021 dissect_packed_decimal(packed_decimal_table
[i
+1],
2022 packed_decimal_table
[i
]);
2027 /* National decimals:
2028 * A valid encoding of a national decimal value requires the following.
2029 * – The contents of halfword 7 (sign code) must be
2030 * either 0x002B or 0x002D.
2031 * – The contents of halfwords 0 to 6 must be in the
2032 * range 0x0030 to 0x0039.
2033 * National decimal values having a sign code of 0x002B
2034 * are interpreted as positive values.
2035 * National decimal values having a sign code of 0x002D
2036 * are interpreted as negative values.
2038 unsigned int national_decimal_sign_codes
[] = {
2039 /* positive */ 0x002b,
2040 /* negative */ 0x002d
2043 #define NR_NATIONAL_DECIMAL_SIGNS 2
2045 unsigned int national_decimal_values
[] = {
2046 #ifdef EXHAUSTIVE_TESTS
2047 0x0030, 0x0031, 0x0032, 0x0033, 0x0034,
2048 0x0035, 0x0036, 0x0037, 0x0038, 0x0039
2055 #define NR_NATIONAL_DECIMAL_VALUES (sizeof(national_decimal_values) / sizeof(unsigned int))
2057 static unsigned long * national_decimal_table
;
2059 #define MAX_NATIONAL_DECIMAL_TABLE_SIZE 10 * NR_NATIONAL_DECIMAL_VALUES * NR_NATIONAL_DECIMAL_SIGNS
2061 unsigned long nb_national_decimal_entries
;
2063 static void dissect_national_decimal_sign(unsigned long local_sign
) {
2064 switch(local_sign
) {
2073 default: printf("unhandled sign value: %lx", local_sign
);
2077 int extract_national_decimal_sign(unsigned long dword1
, unsigned long dword0
) {
2078 return (dword1
& 0x0ff);
2081 static void dissect_national_decimal(unsigned long dword1
,
2082 unsigned long dword0
)
2088 printf("national_decimal: [");
2090 if (verbose
>4) printf("raw: [%016lx %016lx] ", dword1
, dword0
);
2092 for (i
= 48;i
>= 0; i
-= 16) {
2093 hword
= dword1
>> (i
) & 0x00ff;
2095 /* validity of national decimal value */
2096 /* the i>0 clause skips the validity check against the sign value. */
2097 if (((i
> 0) && (hword
< 0x30)) || (hword
> 0x39)) printf("!");
2099 printf("%04lx ", hword
);
2102 for (i
= 48; i
>= 0; i
-= 16) {
2103 hword
= dword0
>> (i
) & 0x00ff;
2105 if ((hword
< 0x30) || (hword
> 0x39)) printf("!");
2107 printf("%04lx ", hword
);
2110 local_sign
= extract_national_decimal_sign(dword1
, dword0
);
2111 dissect_national_decimal_sign(local_sign
);
2115 static void build_national_decimal_table(void)
2119 unsigned long i
= 0;
2121 unsigned long value
;
2123 if (verbose
) printf("%s\n",__FUNCTION__
);
2124 national_decimal_table
= malloc(MAX_NATIONAL_DECIMAL_TABLE_SIZE
2125 * sizeof (unsigned long));
2127 for (sign_index
= 0; sign_index
< NR_NATIONAL_DECIMAL_SIGNS
; sign_index
++) {
2128 sign_value
= national_decimal_sign_codes
[sign_index
];
2130 for (index
= 0; index
< NR_NATIONAL_DECIMAL_VALUES
; index
++) {
2131 value
= national_decimal_values
[index
];
2133 national_decimal_table
[i
] = 0x0001000100010001 * value
;
2134 national_decimal_table
[i
+1] = 0x0001000100010000 * value
;
2135 national_decimal_table
[i
+1] += sign_value
;
2138 dissect_national_decimal(national_decimal_table
[i
+1],
2139 national_decimal_table
[i
]);
2144 #ifdef EXHAUSTIVE_TESTS
2145 { /* a few more for fun */
2146 national_decimal_table
[i
] = 0x0031003200330034;
2147 national_decimal_table
[i
+1] = 0x0035003600370000;
2148 national_decimal_table
[i
+1] += sign_value
;
2151 dissect_national_decimal(national_decimal_table
[i
+1],
2152 national_decimal_table
[i
]);
2157 national_decimal_table
[i
] = 0x0031003200330034;
2158 national_decimal_table
[i
+1] = 0x0035003600370000;
2159 national_decimal_table
[i
+1] += sign_value
;
2162 dissect_national_decimal(national_decimal_table
[i
+1],
2163 national_decimal_table
[i
]);
2171 if (verbose
> 2) printf("\n");
2173 nb_national_decimal_entries
= i
;
2176 static void dump_national_decimal_table(void) {
2179 printf("national_decimal_table:\n");
2181 for (i
= 0; i
< nb_national_decimal_entries
; i
+= 2) {
2183 dissect_national_decimal(national_decimal_table
[i
+1],
2184 national_decimal_table
[i
]);
2192 * When PS=0, do the following.
2193 * A valid encoding of a zoned decimal value requires the following.
2194 * – The contents of bits 0:3 of byte 15 (sign code) can be any
2195 * value in the range 0x0 to 0xF.
2196 * – The contents of bits 0:3 of bytes 0 to 14 (zone) must
2198 * – The contents of bits 4:7 of bytes 0 to 15 must
2199 * be a value in the range 0x0 to 0x9.
2200 * Zoned decimal values having a sign code of 0x0, 0x1, 0x2, 0x3,
2201 * 0x8, 0x9, 0xA, or 0xB are interpreted as positive values.
2202 * Zoned decimal values having a sign code of 0x4, 0x5, 0x6, 0x7,
2203 * 0xC, 0xD, 0xE, or 0xF are interpreted as negative values.
2204 :: 0,1,2,3, 8,9,a,b, are interpreted as positive.
2205 :: 4,5,6,7, c,d,e,f are interpreted as negative.
2206 * When PS=1, do the following.
2207 * A valid encoding of a zoned decimal source operand requires the following.
2208 * – The contents of bits 0:3 of byte 15 (sign code) must be a value in the
2210 * – The contents of bits 0:3 of bytes 0 to 14 (zone) must be the value 0xF.
2211 * – The contents of bits 4:7 of bytes 0 to 15 must be a value in the
2213 * Zoned decimal source operands having a sign code of 0xA, 0xC, 0xE,
2214 * or 0xF are interpreted as positive values.
2215 * Zoned decimal source operands having a sign code of 0xB or 0xD are
2216 * interpreted as negative values.
2217 :: a, c, e,f are interpreted as positive.
2218 :: b, d, are interpreted as negative.
2221 /* a valid sign is anything in range 0-9,a-f,
2222 * For coverage that does not overwhelm, we have chosen to use 0,1,4,a,b,f. */
2223 #define NM_ZONED_DECIMAL_SIGNS 6
2224 #define NM_ZONED_VALUES 5 /* 0,2,4,6,9 */
2225 #define NM_PS_VALUES 2 /* 0,1 */
2226 #define NM_ZONED_ADDITIONAL_PATTERNS 4
2227 #define MAX_ZONED_DECIMAL_TABLE_SIZE NM_ZONED_DECIMAL_SIGNS * NM_ZONED_VALUES * NM_ZONED_ADDITIONAL_PATTERNS * NM_PS_VALUES + 10
2229 static unsigned long zoned_decimal_table_
[MAX_ZONED_DECIMAL_TABLE_SIZE
];
2230 static unsigned long * zoned_decimal_table
;
2231 unsigned long nb_zoned_decimal_entries
;
2233 static void dissect_zoned_decimal_sign(unsigned long local_sign
, int ps
) {
2235 switch(local_sign
) {
2236 case 0x0: case 0x1: case 0x2: case 0x3:
2237 case 0x8: case 0x9: case 0xa: case 0xb:
2241 case 0x4: case 0x5: case 0x6: case 0x7:
2242 case 0xc: case 0xd: case 0xe: case 0xf:
2245 default: printf("zoned decimal (ps=%d). Unhandled sign value: %lx",
2251 switch(local_sign
) {
2252 case 0xa: case 0xc: case 0xe: case 0xf:
2260 default: printf("zoned decimal (ps=%d). Unhandled sign value: %lx",
2266 /* Valid byte values within a zoned decimal are in the ranges of
2267 * 0x30..0x39 when PS==0, or 0xf0..0xff when PS==1.
2269 static void check_zoned_byte_validity(int byte
, int ps
) {
2271 /* check the zone */
2272 if (((byte
& 0x30) != 0x30))
2275 } else { /* ps==1 */
2276 if (((byte
& 0xf0) != 0xf0))
2277 printf("%x !=f0 ", byte
);
2280 /* check the numeric value */
2281 if ((byte
& 0x0f) > 0x9)
2285 int extract_zoned_decimal_sign(unsigned long dword1
, unsigned long dword0
) {
2286 return ((dword1
& 0xf0) >> 4);
2289 static void dissect_zoned_decimal(unsigned long dword1
, unsigned long dword0
,
2296 printf("zoned_decimal: [");
2298 for (i
= 56; i
>= 0; i
-= 8) {
2299 byte
= (dword1
>> (i
)) & 0xff;
2300 check_zoned_byte_validity(byte
, ps
);
2301 printf(" %02x", byte
);
2304 for (i
= 56; i
>= 0; i
-= 8) {
2305 byte
= (dword0
>> (i
)) & 0x00ff;
2306 check_zoned_byte_validity(byte
, ps
);
2308 if ((byte
& 0xf) > 0x9) printf(" !(>9)");
2309 printf(" %02x", byte
);
2312 local_sign
= extract_zoned_decimal_sign(dword1
, dword0
);
2313 dissect_zoned_decimal_sign(local_sign
, ps
);
2317 #ifdef EXHAUSTIVE_TESTS
2318 // Randomly chosen exhaustive coverage for k includes values: 0,2,4,7,9
2319 # define SELECTIVE_INCREMENT_ZONED(k) \
2320 if (k == 7) k = 9; \
2321 else if (k == 4) k = 7; \
2322 else if (k == 2) k = 4; \
2323 else if (k == 0) k = 2; \
2325 // Randomly chosen exhaustive coverage for signs includes values: 0,1,4,a,b,f
2326 # define SELECTIVE_INCREMENT_SIGNS(signs) \
2327 if (signs == 0x0) signs = 0x1; \
2328 else if (signs == 0x1) signs = 0x4; \
2329 else if (signs == 0x4) signs = 0xa; \
2330 else if (signs == 0xa) signs = 0xb; \
2331 else if (signs == 0xb) signs = 0xf; \
2334 // Randomly chosen coverage for k includes values: 0,7,9
2335 # define SELECTIVE_INCREMENT_ZONED(k) \
2336 if (k == 7) k = 9; \
2337 else if (k == 0) k = 7; \
2339 // Randomly chosen coverage for signs includes values: 0,4,b,f
2340 # define SELECTIVE_INCREMENT_SIGNS(signs) \
2341 if (signs == 0x0) signs = 0x4; \
2342 else if (signs == 0x4) signs = 0xb; \
2343 else if (signs == 0xb) signs = 0xf; \
2348 static void build_zoned_decimal_table(void)
2350 unsigned long signs
;
2354 int signs_start
,signs_end
;
2356 if (verbose
) printf("%s\n", __FUNCTION__
);
2358 zoned_decimal_table
= zoned_decimal_table_
;
2361 for (ps
= 0; ps
<= 1; ps
++) {
2371 for (signs
= signs_start
;
2372 signs
<= signs_end
; /* signs selectively updated below */) {
2374 if (verbose
> 2) printf("ps=%d sign:%lx\n", ps
, signs
);
2376 for (k
= 0 ; k
< 9; /* k selectively updated below */) {
2378 zoned_decimal_table
[i
] = 0x3030303030303030; // set bits 0:3 of bytes 0..7.
2379 zoned_decimal_table
[i
+1] = 0x3030303030303000; // bits 0:3 of bytes 8..14 must be 0x3
2382 zoned_decimal_table
[i
] = 0xf0f0f0f0f0f0f0f0; // set bits 0:3 of bytes 0..7.
2383 zoned_decimal_table
[i
+1] = 0xf0f0f0f0f0f0f000; // bits 0:3 of bytes 8..14 must be 0x3
2386 zoned_decimal_table
[i
] += 0x010101010101010 * k
; // set bits 4..7 of bytes 0..7.
2387 zoned_decimal_table
[i
+1] += 0x010101010101000 * k
; // bits 4:7 of bytes 8..15 must be 0..9.
2388 zoned_decimal_table
[i
+1] += (signs
<< 4); // bits 0:3 of byte 15 is the sign.
2390 dissect_zoned_decimal(zoned_decimal_table
[i
+1],
2391 zoned_decimal_table
[i
], ps
);
2395 SELECTIVE_INCREMENT_ZONED(k
)
2398 /* add a few more patterns outside of the k patterns. */
2400 zoned_decimal_table
[i
] = 0x3030303030303030;
2401 zoned_decimal_table
[i
+1] = 0x3030303030303000;
2404 zoned_decimal_table
[i
] = 0xf0f0f0f0f0f0f0f0;
2405 zoned_decimal_table
[i
+1] = 0xf0f0f0f0f0f0f000;
2408 zoned_decimal_table
[i
] += 0x0908070605040302;
2409 zoned_decimal_table
[i
+1] += 0x0102030405060700;
2410 zoned_decimal_table
[i
+1] += (signs
<<4); // bits 0:3 of byte 15.
2413 dissect_zoned_decimal(zoned_decimal_table
[i
+1],
2414 zoned_decimal_table
[i
], ps
);
2419 SELECTIVE_INCREMENT_SIGNS(signs
)
2423 nb_zoned_decimal_entries
= i
;
2426 static void dump_zoned_decimal_table(void) {
2430 for (ps
= 0; ps
<= 1; ps
++) {
2431 printf("zoned_decimal_table ps=%d:\n", ps
);
2433 for (i
= 0; i
< nb_zoned_decimal_entries
; i
+= 2) {
2435 dissect_zoned_decimal(zoned_decimal_table
[i
+1],
2436 zoned_decimal_table
[i
], ps
);
2442 /* Build table containing shift and truncate values */
2443 #define MAX_DECIMAL_SHIFT_TABLE_SIZE 64
2445 static unsigned long * decimal_shift_table
;
2446 unsigned long nb_decimal_shift_entries
;
2448 static void build_decimal_shift_table(void) {
2449 unsigned long i
= 0;
2450 unsigned long value
;
2452 if (verbose
) printf("%s\n",__FUNCTION__
);
2454 decimal_shift_table
= malloc(MAX_DECIMAL_SHIFT_TABLE_SIZE
2455 * sizeof (unsigned long));
2457 for (value
= 0; value
<= 31; value
++) {
2458 decimal_shift_table
[i
] = value
;
2459 decimal_shift_table
[i
+1] = 0;
2463 if (verbose
>2) printf("\n");
2465 nb_decimal_shift_entries
= i
;
2468 static void dump_decimal_shift_table(void) {
2471 printf("decimal_shift_table:\n");
2473 for (i
= 0; i
< nb_decimal_shift_entries
; i
+= 2) {
2474 printf("i=:%2d ", i
);
2475 printf(" 0x%2lx 0x%2lx ", decimal_shift_table
[i
],
2476 decimal_shift_table
[i
+1]);