1*4882a593Smuzhiyun /* Machine-dependent software floating-point definitions. PPC version. 2*4882a593Smuzhiyun Copyright (C) 1997 Free Software Foundation, Inc. 3*4882a593Smuzhiyun This file is part of the GNU C Library. 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun The GNU C Library is free software; you can redistribute it and/or 6*4882a593Smuzhiyun modify it under the terms of the GNU Library General Public License as 7*4882a593Smuzhiyun published by the Free Software Foundation; either version 2 of the 8*4882a593Smuzhiyun License, or (at your option) any later version. 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun The GNU C Library is distributed in the hope that it will be useful, 11*4882a593Smuzhiyun but WITHOUT ANY WARRANTY; without even the implied warranty of 12*4882a593Smuzhiyun MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13*4882a593Smuzhiyun Library General Public License for more details. 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun You should have received a copy of the GNU Library General Public 16*4882a593Smuzhiyun License along with the GNU C Library; see the file COPYING.LIB. If 17*4882a593Smuzhiyun not, write to the Free Software Foundation, Inc., 18*4882a593Smuzhiyun 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun Actually, this is a PPC (32bit) version, written based on the 21*4882a593Smuzhiyun i386, sparc, and sparc64 versions, by me, 22*4882a593Smuzhiyun Peter Maydell (pmaydell@chiark.greenend.org.uk). 23*4882a593Smuzhiyun Comments are by and large also mine, although they may be inaccurate. 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun In picking out asm fragments I've gone with the lowest common 26*4882a593Smuzhiyun denominator, which also happens to be the hardware I have :-> 27*4882a593Smuzhiyun That is, a SPARC without hardware multiply and divide. 28*4882a593Smuzhiyun */ 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun /* basic word size definitions */ 31*4882a593Smuzhiyun #define _FP_W_TYPE_SIZE 32 32*4882a593Smuzhiyun #define _FP_W_TYPE unsigned int 33*4882a593Smuzhiyun #define _FP_WS_TYPE signed int 34*4882a593Smuzhiyun #define _FP_I_TYPE int 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2)) 37*4882a593Smuzhiyun #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1)) 38*4882a593Smuzhiyun #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2)) 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun /* You can optionally code some things like addition in asm. For 41*4882a593Smuzhiyun * example, i386 defines __FP_FRAC_ADD_2 as asm. If you don't 42*4882a593Smuzhiyun * then you get a fragment of C code [if you change an #ifdef 0 43*4882a593Smuzhiyun * in op-2.h] or a call to add_ssaaaa (see below). 44*4882a593Smuzhiyun * Good places to look for asm fragments to use are gcc and glibc. 45*4882a593Smuzhiyun * gcc's longlong.h is useful. 46*4882a593Smuzhiyun */ 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun /* We need to know how to multiply and divide. If the host word size 49*4882a593Smuzhiyun * is >= 2*fracbits you can use FP_MUL_MEAT_n_imm(t,R,X,Y) which 50*4882a593Smuzhiyun * codes the multiply with whatever gcc does to 'a * b'. 51*4882a593Smuzhiyun * _FP_MUL_MEAT_n_wide(t,R,X,Y,f) is used when you have an asm 52*4882a593Smuzhiyun * function that can multiply two 1W values and get a 2W result. 53*4882a593Smuzhiyun * Otherwise you're stuck with _FP_MUL_MEAT_n_hard(t,R,X,Y) which 54*4882a593Smuzhiyun * does bitshifting to avoid overflow. 55*4882a593Smuzhiyun * For division there is FP_DIV_MEAT_n_imm(t,R,X,Y,f) for word size 56*4882a593Smuzhiyun * >= 2*fracbits, where f is either _FP_DIV_HELP_imm or 57*4882a593Smuzhiyun * _FP_DIV_HELP_ldiv (see op-1.h). 58*4882a593Smuzhiyun * _FP_DIV_MEAT_udiv() is if you have asm to do 2W/1W => (1W, 1W). 59*4882a593Smuzhiyun * [GCC and glibc have longlong.h which has the asm macro udiv_qrnnd 60*4882a593Smuzhiyun * to do this.] 61*4882a593Smuzhiyun * In general, 'n' is the number of words required to hold the type, 62*4882a593Smuzhiyun * and 't' is either S, D or Q for single/double/quad. 63*4882a593Smuzhiyun * -- PMM 64*4882a593Smuzhiyun */ 65*4882a593Smuzhiyun /* Example: SPARC64: 66*4882a593Smuzhiyun * #define _FP_MUL_MEAT_S(R,X,Y) _FP_MUL_MEAT_1_imm(S,R,X,Y) 67*4882a593Smuzhiyun * #define _FP_MUL_MEAT_D(R,X,Y) _FP_MUL_MEAT_1_wide(D,R,X,Y,umul_ppmm) 68*4882a593Smuzhiyun * #define _FP_MUL_MEAT_Q(R,X,Y) _FP_MUL_MEAT_2_wide(Q,R,X,Y,umul_ppmm) 69*4882a593Smuzhiyun * 70*4882a593Smuzhiyun * #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_imm(S,R,X,Y,_FP_DIV_HELP_imm) 71*4882a593Smuzhiyun * #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_1_udiv(D,R,X,Y) 72*4882a593Smuzhiyun * #define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_2_udiv_64(Q,R,X,Y) 73*4882a593Smuzhiyun * 74*4882a593Smuzhiyun * Example: i386: 75*4882a593Smuzhiyun * #define _FP_MUL_MEAT_S(R,X,Y) _FP_MUL_MEAT_1_wide(S,R,X,Y,_i386_mul_32_64) 76*4882a593Smuzhiyun * #define _FP_MUL_MEAT_D(R,X,Y) _FP_MUL_MEAT_2_wide(D,R,X,Y,_i386_mul_32_64) 77*4882a593Smuzhiyun * 78*4882a593Smuzhiyun * #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv(S,R,X,Y,_i386_div_64_32) 79*4882a593Smuzhiyun * #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv_64(D,R,X,Y) 80*4882a593Smuzhiyun */ 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun #define _FP_MUL_MEAT_S(R,X,Y) _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm) 83*4882a593Smuzhiyun #define _FP_MUL_MEAT_D(R,X,Y) _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm) 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv_norm(S,R,X,Y) 86*4882a593Smuzhiyun #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y) 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun /* These macros define what NaN looks like. They're supposed to expand to 89*4882a593Smuzhiyun * a comma-separated set of 32bit unsigned ints that encode NaN. 90*4882a593Smuzhiyun */ 91*4882a593Smuzhiyun #define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1) 92*4882a593Smuzhiyun #define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1 93*4882a593Smuzhiyun #define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1 94*4882a593Smuzhiyun #define _FP_NANSIGN_S 0 95*4882a593Smuzhiyun #define _FP_NANSIGN_D 0 96*4882a593Smuzhiyun #define _FP_NANSIGN_Q 0 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun #define _FP_KEEPNANFRACP 1 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun #ifdef FP_EX_BOOKE_E500_SPE 101*4882a593Smuzhiyun #define FP_EX_INEXACT (1 << 21) 102*4882a593Smuzhiyun #define FP_EX_INVALID (1 << 20) 103*4882a593Smuzhiyun #define FP_EX_DIVZERO (1 << 19) 104*4882a593Smuzhiyun #define FP_EX_UNDERFLOW (1 << 18) 105*4882a593Smuzhiyun #define FP_EX_OVERFLOW (1 << 17) 106*4882a593Smuzhiyun #define FP_INHIBIT_RESULTS 0 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun #define __FPU_FPSCR (current->thread.spefscr) 109*4882a593Smuzhiyun #define __FPU_ENABLED_EXC \ 110*4882a593Smuzhiyun ({ \ 111*4882a593Smuzhiyun (__FPU_FPSCR >> 2) & 0x1f; \ 112*4882a593Smuzhiyun }) 113*4882a593Smuzhiyun #else 114*4882a593Smuzhiyun /* Exception flags. We use the bit positions of the appropriate bits 115*4882a593Smuzhiyun in the FPSCR, which also correspond to the FE_* bits. This makes 116*4882a593Smuzhiyun everything easier ;-). */ 117*4882a593Smuzhiyun #define FP_EX_INVALID (1 << (31 - 2)) 118*4882a593Smuzhiyun #define FP_EX_INVALID_SNAN EFLAG_VXSNAN 119*4882a593Smuzhiyun #define FP_EX_INVALID_ISI EFLAG_VXISI 120*4882a593Smuzhiyun #define FP_EX_INVALID_IDI EFLAG_VXIDI 121*4882a593Smuzhiyun #define FP_EX_INVALID_ZDZ EFLAG_VXZDZ 122*4882a593Smuzhiyun #define FP_EX_INVALID_IMZ EFLAG_VXIMZ 123*4882a593Smuzhiyun #define FP_EX_OVERFLOW (1 << (31 - 3)) 124*4882a593Smuzhiyun #define FP_EX_UNDERFLOW (1 << (31 - 4)) 125*4882a593Smuzhiyun #define FP_EX_DIVZERO (1 << (31 - 5)) 126*4882a593Smuzhiyun #define FP_EX_INEXACT (1 << (31 - 6)) 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun #define __FPU_FPSCR (current->thread.fp_state.fpscr) 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun /* We only actually write to the destination register 131*4882a593Smuzhiyun * if exceptions signalled (if any) will not trap. 132*4882a593Smuzhiyun */ 133*4882a593Smuzhiyun #define __FPU_ENABLED_EXC \ 134*4882a593Smuzhiyun ({ \ 135*4882a593Smuzhiyun (__FPU_FPSCR >> 3) & 0x1f; \ 136*4882a593Smuzhiyun }) 137*4882a593Smuzhiyun 138*4882a593Smuzhiyun #endif 139*4882a593Smuzhiyun 140*4882a593Smuzhiyun /* 141*4882a593Smuzhiyun * If one NaN is signaling and the other is not, 142*4882a593Smuzhiyun * we choose that one, otherwise we choose X. 143*4882a593Smuzhiyun */ 144*4882a593Smuzhiyun #define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \ 145*4882a593Smuzhiyun do { \ 146*4882a593Smuzhiyun if ((_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs) \ 147*4882a593Smuzhiyun && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \ 148*4882a593Smuzhiyun { \ 149*4882a593Smuzhiyun R##_s = X##_s; \ 150*4882a593Smuzhiyun _FP_FRAC_COPY_##wc(R,X); \ 151*4882a593Smuzhiyun } \ 152*4882a593Smuzhiyun else \ 153*4882a593Smuzhiyun { \ 154*4882a593Smuzhiyun R##_s = Y##_s; \ 155*4882a593Smuzhiyun _FP_FRAC_COPY_##wc(R,Y); \ 156*4882a593Smuzhiyun } \ 157*4882a593Smuzhiyun R##_c = FP_CLS_NAN; \ 158*4882a593Smuzhiyun } while (0) 159*4882a593Smuzhiyun 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun #include <linux/kernel.h> 162*4882a593Smuzhiyun #include <linux/sched.h> 163*4882a593Smuzhiyun 164*4882a593Smuzhiyun #define __FPU_TRAP_P(bits) \ 165*4882a593Smuzhiyun ((__FPU_ENABLED_EXC & (bits)) != 0) 166*4882a593Smuzhiyun 167*4882a593Smuzhiyun #define __FP_PACK_S(val,X) \ 168*4882a593Smuzhiyun ({ int __exc = _FP_PACK_CANONICAL(S,1,X); \ 169*4882a593Smuzhiyun if(!__exc || !__FPU_TRAP_P(__exc)) \ 170*4882a593Smuzhiyun _FP_PACK_RAW_1_P(S,val,X); \ 171*4882a593Smuzhiyun __exc; \ 172*4882a593Smuzhiyun }) 173*4882a593Smuzhiyun 174*4882a593Smuzhiyun #define __FP_PACK_D(val,X) \ 175*4882a593Smuzhiyun do { \ 176*4882a593Smuzhiyun _FP_PACK_CANONICAL(D, 2, X); \ 177*4882a593Smuzhiyun if (!FP_CUR_EXCEPTIONS || !__FPU_TRAP_P(FP_CUR_EXCEPTIONS)) \ 178*4882a593Smuzhiyun _FP_PACK_RAW_2_P(D, val, X); \ 179*4882a593Smuzhiyun } while (0) 180*4882a593Smuzhiyun 181*4882a593Smuzhiyun #define __FP_PACK_DS(val,X) \ 182*4882a593Smuzhiyun do { \ 183*4882a593Smuzhiyun FP_DECL_S(__X); \ 184*4882a593Smuzhiyun FP_CONV(S, D, 1, 2, __X, X); \ 185*4882a593Smuzhiyun _FP_PACK_CANONICAL(S, 1, __X); \ 186*4882a593Smuzhiyun if (!FP_CUR_EXCEPTIONS || !__FPU_TRAP_P(FP_CUR_EXCEPTIONS)) { \ 187*4882a593Smuzhiyun _FP_UNPACK_CANONICAL(S, 1, __X); \ 188*4882a593Smuzhiyun FP_CONV(D, S, 2, 1, X, __X); \ 189*4882a593Smuzhiyun _FP_PACK_CANONICAL(D, 2, X); \ 190*4882a593Smuzhiyun if (!FP_CUR_EXCEPTIONS || !__FPU_TRAP_P(FP_CUR_EXCEPTIONS)) \ 191*4882a593Smuzhiyun _FP_PACK_RAW_2_P(D, val, X); \ 192*4882a593Smuzhiyun } \ 193*4882a593Smuzhiyun } while (0) 194*4882a593Smuzhiyun 195*4882a593Smuzhiyun /* Obtain the current rounding mode. */ 196*4882a593Smuzhiyun #define FP_ROUNDMODE \ 197*4882a593Smuzhiyun ({ \ 198*4882a593Smuzhiyun __FPU_FPSCR & 0x3; \ 199*4882a593Smuzhiyun }) 200*4882a593Smuzhiyun 201*4882a593Smuzhiyun /* the asm fragments go here: all these are taken from glibc-2.0.5's 202*4882a593Smuzhiyun * stdlib/longlong.h 203*4882a593Smuzhiyun */ 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun #include <linux/types.h> 206*4882a593Smuzhiyun #include <asm/byteorder.h> 207*4882a593Smuzhiyun 208*4882a593Smuzhiyun /* add_ssaaaa is used in op-2.h and should be equivalent to 209*4882a593Smuzhiyun * #define add_ssaaaa(sh,sl,ah,al,bh,bl) (sh = ah+bh+ (( sl = al+bl) < al)) 210*4882a593Smuzhiyun * add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1, 211*4882a593Smuzhiyun * high_addend_2, low_addend_2) adds two UWtype integers, composed by 212*4882a593Smuzhiyun * HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2 213*4882a593Smuzhiyun * respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow 214*4882a593Smuzhiyun * (i.e. carry out) is not stored anywhere, and is lost. 215*4882a593Smuzhiyun */ 216*4882a593Smuzhiyun #define add_ssaaaa(sh, sl, ah, al, bh, bl) \ 217*4882a593Smuzhiyun do { \ 218*4882a593Smuzhiyun if (__builtin_constant_p (bh) && (bh) == 0) \ 219*4882a593Smuzhiyun __asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2" \ 220*4882a593Smuzhiyun : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\ 221*4882a593Smuzhiyun else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \ 222*4882a593Smuzhiyun __asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2" \ 223*4882a593Smuzhiyun : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\ 224*4882a593Smuzhiyun else \ 225*4882a593Smuzhiyun __asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3" \ 226*4882a593Smuzhiyun : "=r" (sh), "=&r" (sl) \ 227*4882a593Smuzhiyun : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \ 228*4882a593Smuzhiyun } while (0) 229*4882a593Smuzhiyun 230*4882a593Smuzhiyun /* sub_ddmmss is used in op-2.h and udivmodti4.c and should be equivalent to 231*4882a593Smuzhiyun * #define sub_ddmmss(sh, sl, ah, al, bh, bl) (sh = ah-bh - ((sl = al-bl) > al)) 232*4882a593Smuzhiyun * sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend, 233*4882a593Smuzhiyun * high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers, 234*4882a593Smuzhiyun * composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and 235*4882a593Smuzhiyun * LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE 236*4882a593Smuzhiyun * and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere, 237*4882a593Smuzhiyun * and is lost. 238*4882a593Smuzhiyun */ 239*4882a593Smuzhiyun #define sub_ddmmss(sh, sl, ah, al, bh, bl) \ 240*4882a593Smuzhiyun do { \ 241*4882a593Smuzhiyun if (__builtin_constant_p (ah) && (ah) == 0) \ 242*4882a593Smuzhiyun __asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2" \ 243*4882a593Smuzhiyun : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\ 244*4882a593Smuzhiyun else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0) \ 245*4882a593Smuzhiyun __asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2" \ 246*4882a593Smuzhiyun : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\ 247*4882a593Smuzhiyun else if (__builtin_constant_p (bh) && (bh) == 0) \ 248*4882a593Smuzhiyun __asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2" \ 249*4882a593Smuzhiyun : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\ 250*4882a593Smuzhiyun else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \ 251*4882a593Smuzhiyun __asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2" \ 252*4882a593Smuzhiyun : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\ 253*4882a593Smuzhiyun else \ 254*4882a593Smuzhiyun __asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2" \ 255*4882a593Smuzhiyun : "=r" (sh), "=&r" (sl) \ 256*4882a593Smuzhiyun : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \ 257*4882a593Smuzhiyun } while (0) 258*4882a593Smuzhiyun 259*4882a593Smuzhiyun /* asm fragments for mul and div */ 260*4882a593Smuzhiyun 261*4882a593Smuzhiyun /* umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two 262*4882a593Smuzhiyun * UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype 263*4882a593Smuzhiyun * word product in HIGH_PROD and LOW_PROD. 264*4882a593Smuzhiyun */ 265*4882a593Smuzhiyun #define umul_ppmm(ph, pl, m0, m1) \ 266*4882a593Smuzhiyun do { \ 267*4882a593Smuzhiyun USItype __m0 = (m0), __m1 = (m1); \ 268*4882a593Smuzhiyun __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ 269*4882a593Smuzhiyun (pl) = __m0 * __m1; \ 270*4882a593Smuzhiyun } while (0) 271*4882a593Smuzhiyun 272*4882a593Smuzhiyun /* udiv_qrnnd(quotient, remainder, high_numerator, low_numerator, 273*4882a593Smuzhiyun * denominator) divides a UDWtype, composed by the UWtype integers 274*4882a593Smuzhiyun * HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient 275*4882a593Smuzhiyun * in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less 276*4882a593Smuzhiyun * than DENOMINATOR for correct operation. If, in addition, the most 277*4882a593Smuzhiyun * significant bit of DENOMINATOR must be 1, then the pre-processor symbol 278*4882a593Smuzhiyun * UDIV_NEEDS_NORMALIZATION is defined to 1. 279*4882a593Smuzhiyun */ 280*4882a593Smuzhiyun #define udiv_qrnnd(q, r, n1, n0, d) \ 281*4882a593Smuzhiyun do { \ 282*4882a593Smuzhiyun UWtype __d1, __d0, __q1, __q0; \ 283*4882a593Smuzhiyun UWtype __r1, __r0, __m; \ 284*4882a593Smuzhiyun __d1 = __ll_highpart (d); \ 285*4882a593Smuzhiyun __d0 = __ll_lowpart (d); \ 286*4882a593Smuzhiyun \ 287*4882a593Smuzhiyun __r1 = (n1) % __d1; \ 288*4882a593Smuzhiyun __q1 = (n1) / __d1; \ 289*4882a593Smuzhiyun __m = (UWtype) __q1 * __d0; \ 290*4882a593Smuzhiyun __r1 = __r1 * __ll_B | __ll_highpart (n0); \ 291*4882a593Smuzhiyun if (__r1 < __m) \ 292*4882a593Smuzhiyun { \ 293*4882a593Smuzhiyun __q1--, __r1 += (d); \ 294*4882a593Smuzhiyun if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\ 295*4882a593Smuzhiyun if (__r1 < __m) \ 296*4882a593Smuzhiyun __q1--, __r1 += (d); \ 297*4882a593Smuzhiyun } \ 298*4882a593Smuzhiyun __r1 -= __m; \ 299*4882a593Smuzhiyun \ 300*4882a593Smuzhiyun __r0 = __r1 % __d1; \ 301*4882a593Smuzhiyun __q0 = __r1 / __d1; \ 302*4882a593Smuzhiyun __m = (UWtype) __q0 * __d0; \ 303*4882a593Smuzhiyun __r0 = __r0 * __ll_B | __ll_lowpart (n0); \ 304*4882a593Smuzhiyun if (__r0 < __m) \ 305*4882a593Smuzhiyun { \ 306*4882a593Smuzhiyun __q0--, __r0 += (d); \ 307*4882a593Smuzhiyun if (__r0 >= (d)) \ 308*4882a593Smuzhiyun if (__r0 < __m) \ 309*4882a593Smuzhiyun __q0--, __r0 += (d); \ 310*4882a593Smuzhiyun } \ 311*4882a593Smuzhiyun __r0 -= __m; \ 312*4882a593Smuzhiyun \ 313*4882a593Smuzhiyun (q) = (UWtype) __q1 * __ll_B | __q0; \ 314*4882a593Smuzhiyun (r) = __r0; \ 315*4882a593Smuzhiyun } while (0) 316*4882a593Smuzhiyun 317*4882a593Smuzhiyun #define UDIV_NEEDS_NORMALIZATION 1 318*4882a593Smuzhiyun 319*4882a593Smuzhiyun #define abort() \ 320*4882a593Smuzhiyun return 0 321*4882a593Smuzhiyun 322*4882a593Smuzhiyun #ifdef __BIG_ENDIAN 323*4882a593Smuzhiyun #define __BYTE_ORDER __BIG_ENDIAN 324*4882a593Smuzhiyun #else 325*4882a593Smuzhiyun #define __BYTE_ORDER __LITTLE_ENDIAN 326*4882a593Smuzhiyun #endif 327*4882a593Smuzhiyun 328*4882a593Smuzhiyun /* Exception flags. */ 329*4882a593Smuzhiyun #define EFLAG_INVALID (1 << (31 - 2)) 330*4882a593Smuzhiyun #define EFLAG_OVERFLOW (1 << (31 - 3)) 331*4882a593Smuzhiyun #define EFLAG_UNDERFLOW (1 << (31 - 4)) 332*4882a593Smuzhiyun #define EFLAG_DIVZERO (1 << (31 - 5)) 333*4882a593Smuzhiyun #define EFLAG_INEXACT (1 << (31 - 6)) 334*4882a593Smuzhiyun 335*4882a593Smuzhiyun #define EFLAG_VXSNAN (1 << (31 - 7)) 336*4882a593Smuzhiyun #define EFLAG_VXISI (1 << (31 - 8)) 337*4882a593Smuzhiyun #define EFLAG_VXIDI (1 << (31 - 9)) 338*4882a593Smuzhiyun #define EFLAG_VXZDZ (1 << (31 - 10)) 339*4882a593Smuzhiyun #define EFLAG_VXIMZ (1 << (31 - 11)) 340*4882a593Smuzhiyun #define EFLAG_VXVC (1 << (31 - 12)) 341*4882a593Smuzhiyun #define EFLAG_VXSOFT (1 << (31 - 21)) 342*4882a593Smuzhiyun #define EFLAG_VXSQRT (1 << (31 - 22)) 343*4882a593Smuzhiyun #define EFLAG_VXCVI (1 << (31 - 23)) 344