1 /* Machine-dependent software floating-point definitions.
2 Sparc userland (_Q_*) version.
3 Copyright (C) 1997,1998,1999, 2002, 2006 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Richard Henderson (rth@cygnus.com),
6 Jakub Jelinek (jj@ultra.linux.cz) and
7 David S. Miller (davem@redhat.com).
9 The GNU C Library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
14 The GNU C Library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with the GNU C Library; if not, write to the Free
21 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #include <fpu_control.h>
27 #define _FP_W_TYPE_SIZE 32
28 #define _FP_W_TYPE unsigned long
29 #define _FP_WS_TYPE signed long
30 #define _FP_I_TYPE long
32 #define _FP_MUL_MEAT_S(R,X,Y) \
33 _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm)
34 #define _FP_MUL_MEAT_D(R,X,Y) \
35 _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
36 #define _FP_MUL_MEAT_Q(R,X,Y) \
37 _FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
39 #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv(S,R,X,Y)
40 #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y)
41 #define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_4_udiv(Q,R,X,Y)
43 #define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
44 #define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1
45 #define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1
46 #define _FP_NANSIGN_S 0
47 #define _FP_NANSIGN_D 0
48 #define _FP_NANSIGN_Q 0
50 #define _FP_KEEPNANFRACP 1
52 /* If one NaN is signaling and the other is not,
53 * we choose that one, otherwise we choose X.
55 /* For _Qp_* and _Q_*, this should prefer X, for
56 * CPU instruction emulation this should prefer Y.
57 * (see SPAMv9 B.2.2 section).
59 #define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
61 if ((_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs) \
62 && !(_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs)) \
65 _FP_FRAC_COPY_##wc(R,Y); \
70 _FP_FRAC_COPY_##wc(R,X); \
75 /* Some assembly to speed things up. */
76 #define __FP_FRAC_ADD_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \
77 __asm__ ("addcc %r7,%8,%2\n\
80 : "=r" ((USItype)(r2)), \
81 "=&r" ((USItype)(r1)), \
82 "=&r" ((USItype)(r0)) \
83 : "%rJ" ((USItype)(x2)), \
84 "rI" ((USItype)(y2)), \
85 "%rJ" ((USItype)(x1)), \
86 "rI" ((USItype)(y1)), \
87 "%rJ" ((USItype)(x0)), \
88 "rI" ((USItype)(y0)) \
91 #define __FP_FRAC_SUB_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \
92 __asm__ ("subcc %r7,%8,%2\n\
95 : "=r" ((USItype)(r2)), \
96 "=&r" ((USItype)(r1)), \
97 "=&r" ((USItype)(r0)) \
98 : "%rJ" ((USItype)(x2)), \
99 "rI" ((USItype)(y2)), \
100 "%rJ" ((USItype)(x1)), \
101 "rI" ((USItype)(y1)), \
102 "%rJ" ((USItype)(x0)), \
103 "rI" ((USItype)(y0)) \
106 #define __FP_FRAC_ADD_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \
108 /* We need to fool gcc, as we need to pass more than 10 \
110 register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \
111 __asm__ __volatile__ ("\
114 addxcc %r4,%5,%%g2\n\
116 : "=&r" ((USItype)(r1)), \
117 "=&r" ((USItype)(r0)) \
118 : "%rJ" ((USItype)(x3)), \
119 "rI" ((USItype)(y3)), \
120 "%rJ" ((USItype)(x2)), \
121 "rI" ((USItype)(y2)), \
122 "%rJ" ((USItype)(x1)), \
123 "rI" ((USItype)(y1)), \
124 "%rJ" ((USItype)(x0)), \
125 "rI" ((USItype)(y0)) \
126 : "cc", "g1", "g2"); \
127 __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \
128 r3 = _t1; r2 = _t2; \
131 #define __FP_FRAC_SUB_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \
133 /* We need to fool gcc, as we need to pass more than 10 \
135 register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \
136 __asm__ __volatile__ ("\
139 subxcc %r4,%5,%%g2\n\
141 : "=&r" ((USItype)(r1)), \
142 "=&r" ((USItype)(r0)) \
143 : "%rJ" ((USItype)(x3)), \
144 "rI" ((USItype)(y3)), \
145 "%rJ" ((USItype)(x2)), \
146 "rI" ((USItype)(y2)), \
147 "%rJ" ((USItype)(x1)), \
148 "rI" ((USItype)(y1)), \
149 "%rJ" ((USItype)(x0)), \
150 "rI" ((USItype)(y0)) \
151 : "cc", "g1", "g2"); \
152 __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \
153 r3 = _t1; r2 = _t2; \
156 #define __FP_FRAC_DEC_3(x2,x1,x0,y2,y1,y0) __FP_FRAC_SUB_3(x2,x1,x0,x2,x1,x0,y2,y1,y0)
158 #define __FP_FRAC_DEC_4(x3,x2,x1,x0,y3,y2,y1,y0) __FP_FRAC_SUB_4(x3,x2,x1,x0,x3,x2,x1,x0,y3,y2,y1,y0)
160 #define __FP_FRAC_ADDI_4(x3,x2,x1,x0,i) \
161 __asm__ ("addcc %3,%4,%3\n\
165 : "=&r" ((USItype)(x3)), \
166 "=&r" ((USItype)(x2)), \
167 "=&r" ((USItype)(x1)), \
168 "=&r" ((USItype)(x0)) \
169 : "rI" ((USItype)(i)), \
170 "0" ((USItype)(x3)), \
171 "1" ((USItype)(x2)), \
172 "2" ((USItype)(x1)), \
173 "3" ((USItype)(x0)) \
176 /* Obtain the current rounding mode. */
178 #define FP_ROUNDMODE ((_fcw >> 30) & 0x3)
181 /* Exception flags. */
182 #define FP_EX_INVALID (1 << 4)
183 #define FP_EX_OVERFLOW (1 << 3)
184 #define FP_EX_UNDERFLOW (1 << 2)
185 #define FP_EX_DIVZERO (1 << 1)
186 #define FP_EX_INEXACT (1 << 0)
188 #define _FP_DECL_EX fpu_control_t _fcw
190 #define FP_INIT_ROUNDMODE \
195 /* Simulate exceptions using double arithmetics. */
196 extern double ___Q_simulate_exceptions(int exc
);
198 #define FP_HANDLE_EXCEPTIONS \
202 /* This is the common case, so we do it inline. \
203 * We need to clear cexc bits if any. \
205 extern unsigned long long ___Q_numbers[]; \
206 __asm__ __volatile__("\
208 faddd %%f30, %%f30, %%f30\
209 " : : "r" (___Q_numbers) : "f30"); \
212 ___Q_simulate_exceptions (_fex); \