9 /* Test "fixbr" with rounding mode given in insn (m3 field)
10 Covers all generally available rounding modes that can be mapped to
11 IRRoundingMode. As a consequence m3=1 which is "round to nearest with
12 ties away from 0" is not tested here.
16 rtext(unsigned m3_round
)
19 case 0: return "[-> per fpc]";
20 case 1: return "[-> nearest away]";
21 case 3: return "[-> prepare short]"; // floating point extension fac needed
22 case 4: return "[-> nearest even]";
23 case 5: return "[-> 0]";
24 case 6: return "[-> +inf]";
25 case 7: return "[-> -inf]";
30 #define round_to_int(value,round) \
32 long double src = value; \
35 __asm__ volatile ("fixbr %[dst]," #round ",%[src]\n\t" \
39 printf("fixbr %.5Lf\t-> %Lg %s\n", \
40 src, dst, rtext(round)); \
43 #define fixbr(value,round) round_to_int(value,round)
46 set_rounding_mode(unsigned mode
)
48 register unsigned r
asm("1") = mode
;
49 __asm__
volatile ( SFPC(1) : : "d"(r
) );
56 static const long double dval
[] = {
57 1.25, 1.5, 2.5, 1.75, -1.25, -1.5, -2.5, -1.75, 0.0,
60 assert(sizeof(long double) == 16);
62 /* f128 -> f128, round to int */
63 for (j
= 0; j
< sizeof dval
/ sizeof dval
[0]; ++j
) {
64 set_rounding_mode(FPC_BFP_ROUND_ZERO
);
65 fixbr(dval
[j
], M3_BFP_ROUND_NEAREST_EVEN
);
66 set_rounding_mode(FPC_BFP_ROUND_NEAREST_EVEN
);
67 fixbr(dval
[j
], M3_BFP_ROUND_ZERO
);
68 fixbr(dval
[j
], M3_BFP_ROUND_POSINF
);
69 fixbr(dval
[j
], M3_BFP_ROUND_NEGINF
);