6 #define CRF_LT (1 << 3)
7 #define CRF_GT (1 << 2)
8 #define CRF_EQ (1 << 1)
9 #define CRF_SO (1 << 0)
13 #if !__has_builtin(__builtin_bcdsub)
14 #define NO_BUILTIN_BCDSUB
18 #ifdef NO_BUILTIN_BCDSUB
19 #define BCDSUB(T, A, B, PS) \
20 ".long 4 << 26 | (" #T ") << 21 | (" #A ") << 16 | (" #B ") << 11" \
21 " | 1 << 10 | (" #PS ") << 9 | 65\n\t"
23 #define BCDSUB(T, A, B, PS) "bcdsub. " #T ", " #A ", " #B ", " #PS "\n\t"
26 #define TEST(AH, AL, BH, BL, PS, TH, TL, CR6) \
31 * Use GPR pairs to load the VSR values and place the resulting VSR and\
32 * CR6 in th, tl, and cr. Note that we avoid newer instructions (e.g., \
33 * mtvsrdd/mfvsrld) so we can run this test on POWER8 machines. \
35 asm ("mtvsrd 32, %3\n\t" \
37 "xxmrghd 32, 32, 33\n\t" \
40 "xxmrghd 33, 33, 34\n\t" \
42 "mfocrf %0, 0b10\n\t" \
44 "xxswapd 32, 32\n\t" \
46 : "=r" (cr), "=r" (th), "=r" (tl) \
47 : "r" (AH), "r" (AL), "r" (BH), "r" (BL) \
48 : "v0", "v1", "v2"); \
49 if (TH != UNDEF || TL != UNDEF) { \
53 assert((cr >> 4) == CR6); \
57 * Unbounded result is equal to zero:
58 * sign = (PS) ? 0b1111 : 0b1100
61 void test_bcdsub_eq(void)
63 /* maximum positive BCD value */
64 TEST(0x9999999999999999, 0x999999999999999c,
65 0x9999999999999999, 0x999999999999999c,
67 TEST(0x9999999999999999, 0x999999999999999c,
68 0x9999999999999999, 0x999999999999999c,
73 * Unbounded result is greater than zero:
74 * sign = (PS) ? 0b1111 : 0b1100
75 * CR6 = (overflow) ? 0b0101 : 0b0100
77 void test_bcdsub_gt(void)
79 /* maximum positive and negative one BCD values */
80 TEST(0x9999999999999999, 0x999999999999999c, 0x0, 0x1d, 0,
81 0x0, 0xc, (CRF_GT
| CRF_SO
));
82 TEST(0x9999999999999999, 0x999999999999999c, 0x0, 0x1d, 1,
83 0x0, 0xf, (CRF_GT
| CRF_SO
));
85 TEST(0x9999999999999999, 0x999999999999998c, 0x0, 0x1d, 0,
86 0x9999999999999999, 0x999999999999999c, CRF_GT
);
87 TEST(0x9999999999999999, 0x999999999999998c, 0x0, 0x1d, 1,
88 0x9999999999999999, 0x999999999999999f, CRF_GT
);
92 * Unbounded result is less than zero:
94 * CR6 = (overflow) ? 0b1001 : 0b1000
96 void test_bcdsub_lt(void)
98 /* positive zero and positive one BCD values */
99 TEST(0x0, 0xc, 0x0, 0x1c, 0, 0x0, 0x1d, CRF_LT
);
100 TEST(0x0, 0xc, 0x0, 0x1c, 1, 0x0, 0x1d, CRF_LT
);
102 /* maximum negative and positive one BCD values */
103 TEST(0x9999999999999999, 0x999999999999999d, 0x0, 0x1c, 0,
104 0x0, 0xd, (CRF_LT
| CRF_SO
));
105 TEST(0x9999999999999999, 0x999999999999999d, 0x0, 0x1c, 1,
106 0x0, 0xd, (CRF_LT
| CRF_SO
));
109 void test_bcdsub_invalid(void)
111 TEST(0x0, 0x1c, 0x0, 0xf00, 0, UNDEF
, UNDEF
, CRF_SO
);
112 TEST(0x0, 0x1c, 0x0, 0xf00, 1, UNDEF
, UNDEF
, CRF_SO
);
114 TEST(0x0, 0xf00, 0x0, 0x1c, 0, UNDEF
, UNDEF
, CRF_SO
);
115 TEST(0x0, 0xf00, 0x0, 0x1c, 1, UNDEF
, UNDEF
, CRF_SO
);
117 TEST(0x0, 0xbad, 0x0, 0xf00, 0, UNDEF
, UNDEF
, CRF_SO
);
118 TEST(0x0, 0xbad, 0x0, 0xf00, 1, UNDEF
, UNDEF
, CRF_SO
);
123 struct sigaction action
;
125 action
.sa_handler
= _exit
;
126 sigaction(SIGABRT
, &action
, NULL
);
131 test_bcdsub_invalid();