18c2ecf20Sopenharmony_ci/* Machine-dependent software floating-point definitions. PPC version. 28c2ecf20Sopenharmony_ci Copyright (C) 1997 Free Software Foundation, Inc. 38c2ecf20Sopenharmony_ci This file is part of the GNU C Library. 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci The GNU C Library is free software; you can redistribute it and/or 68c2ecf20Sopenharmony_ci modify it under the terms of the GNU Library General Public License as 78c2ecf20Sopenharmony_ci published by the Free Software Foundation; either version 2 of the 88c2ecf20Sopenharmony_ci License, or (at your option) any later version. 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci The GNU C Library is distributed in the hope that it will be useful, 118c2ecf20Sopenharmony_ci but WITHOUT ANY WARRANTY; without even the implied warranty of 128c2ecf20Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 138c2ecf20Sopenharmony_ci Library General Public License for more details. 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci You should have received a copy of the GNU Library General Public 168c2ecf20Sopenharmony_ci License along with the GNU C Library; see the file COPYING.LIB. If 178c2ecf20Sopenharmony_ci not, write to the Free Software Foundation, Inc., 188c2ecf20Sopenharmony_ci 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci Actually, this is a PPC (32bit) version, written based on the 218c2ecf20Sopenharmony_ci i386, sparc, and sparc64 versions, by me, 228c2ecf20Sopenharmony_ci Peter Maydell (pmaydell@chiark.greenend.org.uk). 238c2ecf20Sopenharmony_ci Comments are by and large also mine, although they may be inaccurate. 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci In picking out asm fragments I've gone with the lowest common 268c2ecf20Sopenharmony_ci denominator, which also happens to be the hardware I have :-> 278c2ecf20Sopenharmony_ci That is, a SPARC without hardware multiply and divide. 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* basic word size definitions */ 318c2ecf20Sopenharmony_ci#define _FP_W_TYPE_SIZE 32 328c2ecf20Sopenharmony_ci#define _FP_W_TYPE unsigned int 338c2ecf20Sopenharmony_ci#define _FP_WS_TYPE signed int 348c2ecf20Sopenharmony_ci#define _FP_I_TYPE int 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2)) 378c2ecf20Sopenharmony_ci#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1)) 388c2ecf20Sopenharmony_ci#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2)) 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* You can optionally code some things like addition in asm. For 418c2ecf20Sopenharmony_ci * example, i386 defines __FP_FRAC_ADD_2 as asm. If you don't 428c2ecf20Sopenharmony_ci * then you get a fragment of C code [if you change an #ifdef 0 438c2ecf20Sopenharmony_ci * in op-2.h] or a call to add_ssaaaa (see below). 448c2ecf20Sopenharmony_ci * Good places to look for asm fragments to use are gcc and glibc. 458c2ecf20Sopenharmony_ci * gcc's longlong.h is useful. 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* We need to know how to multiply and divide. If the host word size 498c2ecf20Sopenharmony_ci * is >= 2*fracbits you can use FP_MUL_MEAT_n_imm(t,R,X,Y) which 508c2ecf20Sopenharmony_ci * codes the multiply with whatever gcc does to 'a * b'. 518c2ecf20Sopenharmony_ci * _FP_MUL_MEAT_n_wide(t,R,X,Y,f) is used when you have an asm 528c2ecf20Sopenharmony_ci * function that can multiply two 1W values and get a 2W result. 538c2ecf20Sopenharmony_ci * Otherwise you're stuck with _FP_MUL_MEAT_n_hard(t,R,X,Y) which 548c2ecf20Sopenharmony_ci * does bitshifting to avoid overflow. 558c2ecf20Sopenharmony_ci * For division there is FP_DIV_MEAT_n_imm(t,R,X,Y,f) for word size 568c2ecf20Sopenharmony_ci * >= 2*fracbits, where f is either _FP_DIV_HELP_imm or 578c2ecf20Sopenharmony_ci * _FP_DIV_HELP_ldiv (see op-1.h). 588c2ecf20Sopenharmony_ci * _FP_DIV_MEAT_udiv() is if you have asm to do 2W/1W => (1W, 1W). 598c2ecf20Sopenharmony_ci * [GCC and glibc have longlong.h which has the asm macro udiv_qrnnd 608c2ecf20Sopenharmony_ci * to do this.] 618c2ecf20Sopenharmony_ci * In general, 'n' is the number of words required to hold the type, 628c2ecf20Sopenharmony_ci * and 't' is either S, D or Q for single/double/quad. 638c2ecf20Sopenharmony_ci * -- PMM 648c2ecf20Sopenharmony_ci */ 658c2ecf20Sopenharmony_ci/* Example: SPARC64: 668c2ecf20Sopenharmony_ci * #define _FP_MUL_MEAT_S(R,X,Y) _FP_MUL_MEAT_1_imm(S,R,X,Y) 678c2ecf20Sopenharmony_ci * #define _FP_MUL_MEAT_D(R,X,Y) _FP_MUL_MEAT_1_wide(D,R,X,Y,umul_ppmm) 688c2ecf20Sopenharmony_ci * #define _FP_MUL_MEAT_Q(R,X,Y) _FP_MUL_MEAT_2_wide(Q,R,X,Y,umul_ppmm) 698c2ecf20Sopenharmony_ci * 708c2ecf20Sopenharmony_ci * #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_imm(S,R,X,Y,_FP_DIV_HELP_imm) 718c2ecf20Sopenharmony_ci * #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_1_udiv(D,R,X,Y) 728c2ecf20Sopenharmony_ci * #define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_2_udiv_64(Q,R,X,Y) 738c2ecf20Sopenharmony_ci * 748c2ecf20Sopenharmony_ci * Example: i386: 758c2ecf20Sopenharmony_ci * #define _FP_MUL_MEAT_S(R,X,Y) _FP_MUL_MEAT_1_wide(S,R,X,Y,_i386_mul_32_64) 768c2ecf20Sopenharmony_ci * #define _FP_MUL_MEAT_D(R,X,Y) _FP_MUL_MEAT_2_wide(D,R,X,Y,_i386_mul_32_64) 778c2ecf20Sopenharmony_ci * 788c2ecf20Sopenharmony_ci * #define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv(S,R,X,Y,_i386_div_64_32) 798c2ecf20Sopenharmony_ci * #define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv_64(D,R,X,Y) 808c2ecf20Sopenharmony_ci */ 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci#define _FP_MUL_MEAT_S(R,X,Y) _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm) 838c2ecf20Sopenharmony_ci#define _FP_MUL_MEAT_D(R,X,Y) _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm) 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv_norm(S,R,X,Y) 868c2ecf20Sopenharmony_ci#define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y) 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* These macros define what NaN looks like. They're supposed to expand to 898c2ecf20Sopenharmony_ci * a comma-separated set of 32bit unsigned ints that encode NaN. 908c2ecf20Sopenharmony_ci */ 918c2ecf20Sopenharmony_ci#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1) 928c2ecf20Sopenharmony_ci#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1 938c2ecf20Sopenharmony_ci#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1 948c2ecf20Sopenharmony_ci#define _FP_NANSIGN_S 0 958c2ecf20Sopenharmony_ci#define _FP_NANSIGN_D 0 968c2ecf20Sopenharmony_ci#define _FP_NANSIGN_Q 0 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#define _FP_KEEPNANFRACP 1 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci#ifdef FP_EX_BOOKE_E500_SPE 1018c2ecf20Sopenharmony_ci#define FP_EX_INEXACT (1 << 21) 1028c2ecf20Sopenharmony_ci#define FP_EX_INVALID (1 << 20) 1038c2ecf20Sopenharmony_ci#define FP_EX_DIVZERO (1 << 19) 1048c2ecf20Sopenharmony_ci#define FP_EX_UNDERFLOW (1 << 18) 1058c2ecf20Sopenharmony_ci#define FP_EX_OVERFLOW (1 << 17) 1068c2ecf20Sopenharmony_ci#define FP_INHIBIT_RESULTS 0 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#define __FPU_FPSCR (current->thread.spefscr) 1098c2ecf20Sopenharmony_ci#define __FPU_ENABLED_EXC \ 1108c2ecf20Sopenharmony_ci({ \ 1118c2ecf20Sopenharmony_ci (__FPU_FPSCR >> 2) & 0x1f; \ 1128c2ecf20Sopenharmony_ci}) 1138c2ecf20Sopenharmony_ci#else 1148c2ecf20Sopenharmony_ci/* Exception flags. We use the bit positions of the appropriate bits 1158c2ecf20Sopenharmony_ci in the FPSCR, which also correspond to the FE_* bits. This makes 1168c2ecf20Sopenharmony_ci everything easier ;-). */ 1178c2ecf20Sopenharmony_ci#define FP_EX_INVALID (1 << (31 - 2)) 1188c2ecf20Sopenharmony_ci#define FP_EX_INVALID_SNAN EFLAG_VXSNAN 1198c2ecf20Sopenharmony_ci#define FP_EX_INVALID_ISI EFLAG_VXISI 1208c2ecf20Sopenharmony_ci#define FP_EX_INVALID_IDI EFLAG_VXIDI 1218c2ecf20Sopenharmony_ci#define FP_EX_INVALID_ZDZ EFLAG_VXZDZ 1228c2ecf20Sopenharmony_ci#define FP_EX_INVALID_IMZ EFLAG_VXIMZ 1238c2ecf20Sopenharmony_ci#define FP_EX_OVERFLOW (1 << (31 - 3)) 1248c2ecf20Sopenharmony_ci#define FP_EX_UNDERFLOW (1 << (31 - 4)) 1258c2ecf20Sopenharmony_ci#define FP_EX_DIVZERO (1 << (31 - 5)) 1268c2ecf20Sopenharmony_ci#define FP_EX_INEXACT (1 << (31 - 6)) 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#define __FPU_FPSCR (current->thread.fp_state.fpscr) 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/* We only actually write to the destination register 1318c2ecf20Sopenharmony_ci * if exceptions signalled (if any) will not trap. 1328c2ecf20Sopenharmony_ci */ 1338c2ecf20Sopenharmony_ci#define __FPU_ENABLED_EXC \ 1348c2ecf20Sopenharmony_ci({ \ 1358c2ecf20Sopenharmony_ci (__FPU_FPSCR >> 3) & 0x1f; \ 1368c2ecf20Sopenharmony_ci}) 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci#endif 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci/* 1418c2ecf20Sopenharmony_ci * If one NaN is signaling and the other is not, 1428c2ecf20Sopenharmony_ci * we choose that one, otherwise we choose X. 1438c2ecf20Sopenharmony_ci */ 1448c2ecf20Sopenharmony_ci#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \ 1458c2ecf20Sopenharmony_ci do { \ 1468c2ecf20Sopenharmony_ci if ((_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs) \ 1478c2ecf20Sopenharmony_ci && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \ 1488c2ecf20Sopenharmony_ci { \ 1498c2ecf20Sopenharmony_ci R##_s = X##_s; \ 1508c2ecf20Sopenharmony_ci _FP_FRAC_COPY_##wc(R,X); \ 1518c2ecf20Sopenharmony_ci } \ 1528c2ecf20Sopenharmony_ci else \ 1538c2ecf20Sopenharmony_ci { \ 1548c2ecf20Sopenharmony_ci R##_s = Y##_s; \ 1558c2ecf20Sopenharmony_ci _FP_FRAC_COPY_##wc(R,Y); \ 1568c2ecf20Sopenharmony_ci } \ 1578c2ecf20Sopenharmony_ci R##_c = FP_CLS_NAN; \ 1588c2ecf20Sopenharmony_ci } while (0) 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci#include <linux/kernel.h> 1628c2ecf20Sopenharmony_ci#include <linux/sched.h> 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci#define __FPU_TRAP_P(bits) \ 1658c2ecf20Sopenharmony_ci ((__FPU_ENABLED_EXC & (bits)) != 0) 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci#define __FP_PACK_S(val,X) \ 1688c2ecf20Sopenharmony_ci({ int __exc = _FP_PACK_CANONICAL(S,1,X); \ 1698c2ecf20Sopenharmony_ci if(!__exc || !__FPU_TRAP_P(__exc)) \ 1708c2ecf20Sopenharmony_ci _FP_PACK_RAW_1_P(S,val,X); \ 1718c2ecf20Sopenharmony_ci __exc; \ 1728c2ecf20Sopenharmony_ci}) 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci#define __FP_PACK_D(val,X) \ 1758c2ecf20Sopenharmony_ci do { \ 1768c2ecf20Sopenharmony_ci _FP_PACK_CANONICAL(D, 2, X); \ 1778c2ecf20Sopenharmony_ci if (!FP_CUR_EXCEPTIONS || !__FPU_TRAP_P(FP_CUR_EXCEPTIONS)) \ 1788c2ecf20Sopenharmony_ci _FP_PACK_RAW_2_P(D, val, X); \ 1798c2ecf20Sopenharmony_ci } while (0) 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci#define __FP_PACK_DS(val,X) \ 1828c2ecf20Sopenharmony_ci do { \ 1838c2ecf20Sopenharmony_ci FP_DECL_S(__X); \ 1848c2ecf20Sopenharmony_ci FP_CONV(S, D, 1, 2, __X, X); \ 1858c2ecf20Sopenharmony_ci _FP_PACK_CANONICAL(S, 1, __X); \ 1868c2ecf20Sopenharmony_ci if (!FP_CUR_EXCEPTIONS || !__FPU_TRAP_P(FP_CUR_EXCEPTIONS)) { \ 1878c2ecf20Sopenharmony_ci _FP_UNPACK_CANONICAL(S, 1, __X); \ 1888c2ecf20Sopenharmony_ci FP_CONV(D, S, 2, 1, X, __X); \ 1898c2ecf20Sopenharmony_ci _FP_PACK_CANONICAL(D, 2, X); \ 1908c2ecf20Sopenharmony_ci if (!FP_CUR_EXCEPTIONS || !__FPU_TRAP_P(FP_CUR_EXCEPTIONS)) \ 1918c2ecf20Sopenharmony_ci _FP_PACK_RAW_2_P(D, val, X); \ 1928c2ecf20Sopenharmony_ci } \ 1938c2ecf20Sopenharmony_ci } while (0) 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci/* Obtain the current rounding mode. */ 1968c2ecf20Sopenharmony_ci#define FP_ROUNDMODE \ 1978c2ecf20Sopenharmony_ci({ \ 1988c2ecf20Sopenharmony_ci __FPU_FPSCR & 0x3; \ 1998c2ecf20Sopenharmony_ci}) 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci/* the asm fragments go here: all these are taken from glibc-2.0.5's 2028c2ecf20Sopenharmony_ci * stdlib/longlong.h 2038c2ecf20Sopenharmony_ci */ 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci#include <linux/types.h> 2068c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci/* add_ssaaaa is used in op-2.h and should be equivalent to 2098c2ecf20Sopenharmony_ci * #define add_ssaaaa(sh,sl,ah,al,bh,bl) (sh = ah+bh+ (( sl = al+bl) < al)) 2108c2ecf20Sopenharmony_ci * add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1, 2118c2ecf20Sopenharmony_ci * high_addend_2, low_addend_2) adds two UWtype integers, composed by 2128c2ecf20Sopenharmony_ci * HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2 2138c2ecf20Sopenharmony_ci * respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow 2148c2ecf20Sopenharmony_ci * (i.e. carry out) is not stored anywhere, and is lost. 2158c2ecf20Sopenharmony_ci */ 2168c2ecf20Sopenharmony_ci#define add_ssaaaa(sh, sl, ah, al, bh, bl) \ 2178c2ecf20Sopenharmony_ci do { \ 2188c2ecf20Sopenharmony_ci if (__builtin_constant_p (bh) && (bh) == 0) \ 2198c2ecf20Sopenharmony_ci __asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2" \ 2208c2ecf20Sopenharmony_ci : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\ 2218c2ecf20Sopenharmony_ci else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \ 2228c2ecf20Sopenharmony_ci __asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2" \ 2238c2ecf20Sopenharmony_ci : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\ 2248c2ecf20Sopenharmony_ci else \ 2258c2ecf20Sopenharmony_ci __asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3" \ 2268c2ecf20Sopenharmony_ci : "=r" (sh), "=&r" (sl) \ 2278c2ecf20Sopenharmony_ci : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \ 2288c2ecf20Sopenharmony_ci } while (0) 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci/* sub_ddmmss is used in op-2.h and udivmodti4.c and should be equivalent to 2318c2ecf20Sopenharmony_ci * #define sub_ddmmss(sh, sl, ah, al, bh, bl) (sh = ah-bh - ((sl = al-bl) > al)) 2328c2ecf20Sopenharmony_ci * sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend, 2338c2ecf20Sopenharmony_ci * high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers, 2348c2ecf20Sopenharmony_ci * composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and 2358c2ecf20Sopenharmony_ci * LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE 2368c2ecf20Sopenharmony_ci * and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere, 2378c2ecf20Sopenharmony_ci * and is lost. 2388c2ecf20Sopenharmony_ci */ 2398c2ecf20Sopenharmony_ci#define sub_ddmmss(sh, sl, ah, al, bh, bl) \ 2408c2ecf20Sopenharmony_ci do { \ 2418c2ecf20Sopenharmony_ci if (__builtin_constant_p (ah) && (ah) == 0) \ 2428c2ecf20Sopenharmony_ci __asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2" \ 2438c2ecf20Sopenharmony_ci : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\ 2448c2ecf20Sopenharmony_ci else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0) \ 2458c2ecf20Sopenharmony_ci __asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2" \ 2468c2ecf20Sopenharmony_ci : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\ 2478c2ecf20Sopenharmony_ci else if (__builtin_constant_p (bh) && (bh) == 0) \ 2488c2ecf20Sopenharmony_ci __asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2" \ 2498c2ecf20Sopenharmony_ci : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\ 2508c2ecf20Sopenharmony_ci else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \ 2518c2ecf20Sopenharmony_ci __asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2" \ 2528c2ecf20Sopenharmony_ci : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\ 2538c2ecf20Sopenharmony_ci else \ 2548c2ecf20Sopenharmony_ci __asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2" \ 2558c2ecf20Sopenharmony_ci : "=r" (sh), "=&r" (sl) \ 2568c2ecf20Sopenharmony_ci : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \ 2578c2ecf20Sopenharmony_ci } while (0) 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci/* asm fragments for mul and div */ 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci/* umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two 2628c2ecf20Sopenharmony_ci * UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype 2638c2ecf20Sopenharmony_ci * word product in HIGH_PROD and LOW_PROD. 2648c2ecf20Sopenharmony_ci */ 2658c2ecf20Sopenharmony_ci#define umul_ppmm(ph, pl, m0, m1) \ 2668c2ecf20Sopenharmony_ci do { \ 2678c2ecf20Sopenharmony_ci USItype __m0 = (m0), __m1 = (m1); \ 2688c2ecf20Sopenharmony_ci __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \ 2698c2ecf20Sopenharmony_ci (pl) = __m0 * __m1; \ 2708c2ecf20Sopenharmony_ci } while (0) 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci/* udiv_qrnnd(quotient, remainder, high_numerator, low_numerator, 2738c2ecf20Sopenharmony_ci * denominator) divides a UDWtype, composed by the UWtype integers 2748c2ecf20Sopenharmony_ci * HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient 2758c2ecf20Sopenharmony_ci * in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less 2768c2ecf20Sopenharmony_ci * than DENOMINATOR for correct operation. If, in addition, the most 2778c2ecf20Sopenharmony_ci * significant bit of DENOMINATOR must be 1, then the pre-processor symbol 2788c2ecf20Sopenharmony_ci * UDIV_NEEDS_NORMALIZATION is defined to 1. 2798c2ecf20Sopenharmony_ci */ 2808c2ecf20Sopenharmony_ci#define udiv_qrnnd(q, r, n1, n0, d) \ 2818c2ecf20Sopenharmony_ci do { \ 2828c2ecf20Sopenharmony_ci UWtype __d1, __d0, __q1, __q0; \ 2838c2ecf20Sopenharmony_ci UWtype __r1, __r0, __m; \ 2848c2ecf20Sopenharmony_ci __d1 = __ll_highpart (d); \ 2858c2ecf20Sopenharmony_ci __d0 = __ll_lowpart (d); \ 2868c2ecf20Sopenharmony_ci \ 2878c2ecf20Sopenharmony_ci __r1 = (n1) % __d1; \ 2888c2ecf20Sopenharmony_ci __q1 = (n1) / __d1; \ 2898c2ecf20Sopenharmony_ci __m = (UWtype) __q1 * __d0; \ 2908c2ecf20Sopenharmony_ci __r1 = __r1 * __ll_B | __ll_highpart (n0); \ 2918c2ecf20Sopenharmony_ci if (__r1 < __m) \ 2928c2ecf20Sopenharmony_ci { \ 2938c2ecf20Sopenharmony_ci __q1--, __r1 += (d); \ 2948c2ecf20Sopenharmony_ci if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\ 2958c2ecf20Sopenharmony_ci if (__r1 < __m) \ 2968c2ecf20Sopenharmony_ci __q1--, __r1 += (d); \ 2978c2ecf20Sopenharmony_ci } \ 2988c2ecf20Sopenharmony_ci __r1 -= __m; \ 2998c2ecf20Sopenharmony_ci \ 3008c2ecf20Sopenharmony_ci __r0 = __r1 % __d1; \ 3018c2ecf20Sopenharmony_ci __q0 = __r1 / __d1; \ 3028c2ecf20Sopenharmony_ci __m = (UWtype) __q0 * __d0; \ 3038c2ecf20Sopenharmony_ci __r0 = __r0 * __ll_B | __ll_lowpart (n0); \ 3048c2ecf20Sopenharmony_ci if (__r0 < __m) \ 3058c2ecf20Sopenharmony_ci { \ 3068c2ecf20Sopenharmony_ci __q0--, __r0 += (d); \ 3078c2ecf20Sopenharmony_ci if (__r0 >= (d)) \ 3088c2ecf20Sopenharmony_ci if (__r0 < __m) \ 3098c2ecf20Sopenharmony_ci __q0--, __r0 += (d); \ 3108c2ecf20Sopenharmony_ci } \ 3118c2ecf20Sopenharmony_ci __r0 -= __m; \ 3128c2ecf20Sopenharmony_ci \ 3138c2ecf20Sopenharmony_ci (q) = (UWtype) __q1 * __ll_B | __q0; \ 3148c2ecf20Sopenharmony_ci (r) = __r0; \ 3158c2ecf20Sopenharmony_ci } while (0) 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci#define UDIV_NEEDS_NORMALIZATION 1 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci#define abort() \ 3208c2ecf20Sopenharmony_ci return 0 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN 3238c2ecf20Sopenharmony_ci#define __BYTE_ORDER __BIG_ENDIAN 3248c2ecf20Sopenharmony_ci#else 3258c2ecf20Sopenharmony_ci#define __BYTE_ORDER __LITTLE_ENDIAN 3268c2ecf20Sopenharmony_ci#endif 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci/* Exception flags. */ 3298c2ecf20Sopenharmony_ci#define EFLAG_INVALID (1 << (31 - 2)) 3308c2ecf20Sopenharmony_ci#define EFLAG_OVERFLOW (1 << (31 - 3)) 3318c2ecf20Sopenharmony_ci#define EFLAG_UNDERFLOW (1 << (31 - 4)) 3328c2ecf20Sopenharmony_ci#define EFLAG_DIVZERO (1 << (31 - 5)) 3338c2ecf20Sopenharmony_ci#define EFLAG_INEXACT (1 << (31 - 6)) 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci#define EFLAG_VXSNAN (1 << (31 - 7)) 3368c2ecf20Sopenharmony_ci#define EFLAG_VXISI (1 << (31 - 8)) 3378c2ecf20Sopenharmony_ci#define EFLAG_VXIDI (1 << (31 - 9)) 3388c2ecf20Sopenharmony_ci#define EFLAG_VXZDZ (1 << (31 - 10)) 3398c2ecf20Sopenharmony_ci#define EFLAG_VXIMZ (1 << (31 - 11)) 3408c2ecf20Sopenharmony_ci#define EFLAG_VXVC (1 << (31 - 12)) 3418c2ecf20Sopenharmony_ci#define EFLAG_VXSOFT (1 << (31 - 21)) 3428c2ecf20Sopenharmony_ci#define EFLAG_VXSQRT (1 << (31 - 22)) 3438c2ecf20Sopenharmony_ci#define EFLAG_VXCVI (1 << (31 - 23)) 344