4 #define PFPO_F32_TO_D32 0x01080500
5 #define PFPO_D32_TO_F32 0x01050800
6 #define PFPO_F32_TO_D64 0x01090500
7 #define PFPO_D32_TO_F64 0x01060800
8 #define PFPO_F32_TO_D128 0x010A0500
9 #define PFPO_D32_TO_F128 0x01070800
10 #define PFPO_F64_TO_D32 0x01080600
11 #define PFPO_D64_TO_F32 0x01050900
12 #define PFPO_F64_TO_D64 0x01090600
13 #define PFPO_D64_TO_F64 0x01060900
14 #define PFPO_F64_TO_D128 0x010A0600
15 #define PFPO_D64_TO_F128 0x01070900
16 #define PFPO_D128_TO_F64 0x01060A00
17 #define PFPO_F128_TO_D32 0x01080700
18 #define PFPO_D128_TO_F32 0x01050A00
19 #define PFPO_F128_TO_D64 0x01090700
20 #define PFPO_D128_TO_F64 0x01060A00
21 #define PFPO_F128_TO_D128 0x010A0700
22 #define PFPO_D128_TO_F128 0x01070A00
24 static const pun_d32 f32_in
[] = {
26 {.f
= 0x1.fffffep
+127}, /* FLT_MAX */
27 {.f
= 0x1p
-126}, /* FLT_MIN */
30 static const pun_d64 f64_in
[] = {
31 {.f
= 123456789999.5656789},
32 {.f
= 0x1p
-1022}, /* DBL_MIN */
33 {.f
= 0x1.fffffffffffffp
+1023}, /* DBL_MAX */
36 static const pun_d128 f128_in
[] = {
37 {.f
= 1234567812345678912345678912.5656789L},
38 {.f
= 0x1p
-16382L}, /* LDBL_MIN */
39 {.f
= 0x1.ffffffffffffffffffffffffffffp
+16383L}, /* LDBL_MAX */
42 static const pun_d32 d32_in
[] = {
43 {0x2614d757}, /* 123.5656789DF */
44 {0x77f3fcff}, /* DEC32_MAX */
45 {0x00600001}, /* DEC32_MAX */
48 static const pun_d64 d64_in
[] = {
49 {0x262934b9c7fa7f57}, /* 123456789999.5656789DD */
50 {0x003c000000000001}, /* DEC64_MIN */
51 {0x77fcff3fcff3fcff}, /* DEC64_MAX */
54 static const pun_d128 d128_in
[] = {
55 {{0x2606934b9d1c7177, 0x8671c5de19cb9779}},
56 {{0x0008400000000000, 0x0000000000000001}},
57 {{0x77ffcff3fcff3fcf, 0xf3fcff3fcff3fcff}},
60 #define PFPO(initial, src_type, dst_type, fn_code, round, ret_code, cc) \
63 register reg_##src_type src_reg asm("f4") = initial.f; \
64 register reg_##dst_type dst_reg asm("f0"); \
65 register unsigned long fn asm("0") = fn_code | (round & 0xf); \
66 register unsigned int ret asm("1"); \
67 asm(".insn e,0x010a\n\t" \
70 : "=f"(dst_reg), "=d"(ret), "=d"(cc) \
71 : "f"(src_reg), "d"(fn) \
78 #define TEST_TO_DEC(in_bits, out_bits, flg, round) \
80 pun_d##out_bits result; \
81 for (unsigned j = 0; j < 3; j++) { \
82 printf("f" #in_bits " -> d" #out_bits ": round=%x ", round); \
83 printf("%" flg "a -> ", f##in_bits##_in[j].f); \
84 result = PFPO(f##in_bits##_in[j], d##in_bits, d##out_bits, \
85 PFPO_F##in_bits##_TO_D##out_bits, round, ret_code, cc); \
86 DFP_VAL_PRINT(result, pun_d##out_bits); \
87 printf(" ret=%d cc=%d\n", ret_code, cc); \
91 #define TEST_FROM_DEC(in_bits, out_bits, flg, round) \
93 pun_d##out_bits result; \
94 for (unsigned j = 0; j < 3; j++) { \
95 printf("d" #in_bits " -> f" #out_bits ": round=%x ", round); \
96 DFP_VAL_PRINT(d##in_bits##_in[j], pun_d##in_bits); \
97 result = PFPO(d##in_bits##_in[j], d##in_bits, d##out_bits, \
98 PFPO_D##in_bits##_TO_F##out_bits, round, ret_code, cc); \
99 printf(" -> %" flg "a", result.f); \
100 printf(" ret=%d cc=%d\n", ret_code, cc); \
104 /* Test BFP <-> DFP conversions */
109 static const pun_d64 f64_zero
= {.f
= 0.};
111 /* valid function code */
112 PFPO(f64_zero
, d64
, d64
, 0x81090600, 0, ret_code
, cc
);
113 printf("pfpo test: function=%x ret=%d cc=%d\n", 0x81090600, ret_code
, cc
);
115 /* invalid function code */
116 PFPO(f64_zero
, d64
, d64
, 0x81990600, 0, ret_code
, cc
);
117 printf("pfpo test: function=%x ret=%d cc=%d\n", 0x81990600, ret_code
, cc
);
119 for (unsigned i
= 0; i
< 16; i
++) {
120 if (i
< 2 || i
> 7) {
121 TEST_TO_DEC(32, 32, "", i
);
122 TEST_TO_DEC(32, 64, "", i
);
123 TEST_TO_DEC(32, 128, "", i
);
124 TEST_TO_DEC(64, 32, "", i
);
125 TEST_TO_DEC(64, 64, "", i
);
126 TEST_TO_DEC(64, 128, "", i
);
127 TEST_TO_DEC(128, 32, "L", i
);
128 TEST_TO_DEC(128, 64, "L", i
);
129 TEST_TO_DEC(128, 128, "L", i
);
131 TEST_FROM_DEC(32, 32, "", i
);
132 TEST_FROM_DEC(32, 64, "", i
);
133 TEST_FROM_DEC(32, 128, "L", i
);
134 TEST_FROM_DEC(64, 32, "", i
);
135 TEST_FROM_DEC(64, 64, "", i
);
136 TEST_FROM_DEC(64, 128, "L", i
);
137 TEST_FROM_DEC(128, 32, "", i
);
138 TEST_FROM_DEC(128, 64, "", i
);
139 TEST_FROM_DEC(128, 128, "L", i
);