]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/powerpc/powerpc64/le/fpu/sfp-machine.h
[powerpc] Use __builtin_{mffs,mtfsf}
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc64 / le / fpu / sfp-machine.h
CommitLineData
f819dbea
PM
1#define _FP_W_TYPE_SIZE 64
2#define _FP_W_TYPE unsigned long long
3#define _FP_WS_TYPE signed long long
4#define _FP_I_TYPE long long
5
6typedef int TItype __attribute__ ((mode (TI)));
7typedef unsigned int UTItype __attribute__ ((mode (TI)));
8
462e83a4 9#define TI_BITS (__CHAR_BIT__ * (int) sizeof (TItype))
f819dbea
PM
10
11/* The type of the result of a floating point comparison. This must
12 match `__libgcc_cmp_return__' in GCC for the target. */
13typedef int __gcc_CMPtype __attribute__ ((mode (__libgcc_cmp_return__)));
14#define CMPtype __gcc_CMPtype
15
16#define _FP_MUL_MEAT_S(R,X,Y) \
17 _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm)
18
19#define _FP_MUL_MEAT_D(R,X,Y) \
20 _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
21#define _FP_MUL_MEAT_Q(R,X,Y) \
22 _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
23
24#define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_loop(S,R,X,Y)
25
26#define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_1_udiv(D,R,X,Y)
27#define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_2_udiv(Q,R,X,Y)
28
29#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
30
31#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1)
32#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1
33
34#define _FP_NANSIGN_S 0
35#define _FP_NANSIGN_D 0
36#define _FP_NANSIGN_Q 0
37
38#define _FP_KEEPNANFRACP 1
39#define _FP_QNANNEGATEDP 0
40
41/* Someone please check this. */
42#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
43 do { \
44 if ((_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs) \
45 && !(_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs)) \
46 { \
47 R##_s = Y##_s; \
48 _FP_FRAC_COPY_##wc(R,Y); \
49 } \
50 else \
51 { \
52 R##_s = X##_s; \
53 _FP_FRAC_COPY_##wc(R,X); \
54 } \
55 R##_c = FP_CLS_NAN; \
56 } while (0)
57
58#define _FP_TININESS_AFTER_ROUNDING 0
59
60#define __LITTLE_ENDIAN 1234
61#define __BIG_ENDIAN 4321
62#define __BYTE_ORDER __LITTLE_ENDIAN
63
64/* Only provide exception support if we have hardware floating point using
65 floating point registers and we can execute the mtfsf instruction. This
66 would only be true if we are using the emulation routines for IEEE 128-bit
67 floating point on pre-ISA 3.0 machines without the IEEE 128-bit floating
68 point support. */
69
70#ifdef __FLOAT128__
71#define ISA_BIT(x) (1LL << (63 - x))
72
73/* Use the same bits of the FPSCR. */
74# define FP_EX_INVALID ISA_BIT(34)
75# define FP_EX_OVERFLOW ISA_BIT(35)
76# define FP_EX_UNDERFLOW ISA_BIT(36)
77# define FP_EX_DIVZERO ISA_BIT(37)
78# define FP_EX_INEXACT ISA_BIT(38)
79# define FP_EX_ALL (FP_EX_INVALID | FP_EX_OVERFLOW \
80 | FP_EX_UNDERFLOW | FP_EX_DIVZERO \
81 | FP_EX_INEXACT)
82
83void __sfp_handle_exceptions (int);
84
85# define FP_HANDLE_EXCEPTIONS \
86 do { \
87 if (__builtin_expect (_fex, 0)) \
88 __sfp_handle_exceptions (_fex); \
89 } while (0);
90
91/* The FP_EX_* bits track whether the exception has occurred. This macro
92 must set the FP_EX_* bits of those exceptions which are configured to
93 trap. The FPSCR bit which indicates this is 22 ISA bits above the
94 respective FP_EX_* bit. Note, the ISA labels bits from msb to lsb,
95 so 22 ISA bits above is 22 bits below when counted from the lsb. */
96# define FP_TRAPPING_EXCEPTIONS ((_fpscr.i << 22) & FP_EX_ALL)
97
98# define FP_RND_NEAREST 0x0
99# define FP_RND_ZERO 0x1
100# define FP_RND_PINF 0x2
101# define FP_RND_MINF 0x3
102# define FP_RND_MASK 0x3
103
104# define _FP_DECL_EX \
105 union { unsigned long long i; double d; } _fpscr __attribute__ ((unused)) = \
106 { .i = FP_RND_NEAREST }
107
108#define FP_INIT_ROUNDMODE \
109 do { \
10cce669 110 _fpscr.d = __builtin_mffs (); \
f819dbea
PM
111 } while (0)
112
113# define FP_ROUNDMODE (_fpscr.i & FP_RND_MASK)
114#endif /* !__FLOAT128__ */