18c2ecf20Sopenharmony_ci/* Machine-dependent software floating-point definitions. 28c2ecf20Sopenharmony_ci Sparc userland (_Q_*) version. 38c2ecf20Sopenharmony_ci Copyright (C) 1997,1998,1999 Free Software Foundation, Inc. 48c2ecf20Sopenharmony_ci This file is part of the GNU C Library. 58c2ecf20Sopenharmony_ci Contributed by Richard Henderson (rth@cygnus.com), 68c2ecf20Sopenharmony_ci Jakub Jelinek (jj@ultra.linux.cz), 78c2ecf20Sopenharmony_ci David S. Miller (davem@redhat.com) and 88c2ecf20Sopenharmony_ci Peter Maydell (pmaydell@chiark.greenend.org.uk). 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci The GNU C Library is free software; you can redistribute it and/or 118c2ecf20Sopenharmony_ci modify it under the terms of the GNU Library General Public License as 128c2ecf20Sopenharmony_ci published by the Free Software Foundation; either version 2 of the 138c2ecf20Sopenharmony_ci License, or (at your option) any later version. 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci The GNU C Library is distributed in the hope that it will be useful, 168c2ecf20Sopenharmony_ci but WITHOUT ANY WARRANTY; without even the implied warranty of 178c2ecf20Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 188c2ecf20Sopenharmony_ci Library General Public License for more details. 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci You should have received a copy of the GNU Library General Public 218c2ecf20Sopenharmony_ci License along with the GNU C Library; see the file COPYING.LIB. If 228c2ecf20Sopenharmony_ci not, write to the Free Software Foundation, Inc., 238c2ecf20Sopenharmony_ci 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#ifndef _SFP_MACHINE_H 268c2ecf20Sopenharmony_ci#define _SFP_MACHINE_H 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define _FP_W_TYPE_SIZE 32 308c2ecf20Sopenharmony_ci#define _FP_W_TYPE unsigned long 318c2ecf20Sopenharmony_ci#define _FP_WS_TYPE signed long 328c2ecf20Sopenharmony_ci#define _FP_I_TYPE long 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define _FP_MUL_MEAT_S(R,X,Y) \ 358c2ecf20Sopenharmony_ci _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm) 368c2ecf20Sopenharmony_ci#define _FP_MUL_MEAT_D(R,X,Y) \ 378c2ecf20Sopenharmony_ci _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm) 388c2ecf20Sopenharmony_ci#define _FP_MUL_MEAT_Q(R,X,Y) \ 398c2ecf20Sopenharmony_ci _FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm) 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv(S,R,X,Y) 428c2ecf20Sopenharmony_ci#define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y) 438c2ecf20Sopenharmony_ci#define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_4_udiv(Q,R,X,Y) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1) 468c2ecf20Sopenharmony_ci#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1 478c2ecf20Sopenharmony_ci#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1 488c2ecf20Sopenharmony_ci#define _FP_NANSIGN_S 0 498c2ecf20Sopenharmony_ci#define _FP_NANSIGN_D 0 508c2ecf20Sopenharmony_ci#define _FP_NANSIGN_Q 0 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define _FP_KEEPNANFRACP 1 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci/* If one NaN is signaling and the other is not, 558c2ecf20Sopenharmony_ci * we choose that one, otherwise we choose X. 568c2ecf20Sopenharmony_ci */ 578c2ecf20Sopenharmony_ci/* For _Qp_* and _Q_*, this should prefer X, for 588c2ecf20Sopenharmony_ci * CPU instruction emulation this should prefer Y. 598c2ecf20Sopenharmony_ci * (see SPAMv9 B.2.2 section). 608c2ecf20Sopenharmony_ci */ 618c2ecf20Sopenharmony_ci#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \ 628c2ecf20Sopenharmony_ci do { \ 638c2ecf20Sopenharmony_ci if ((_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs) \ 648c2ecf20Sopenharmony_ci && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \ 658c2ecf20Sopenharmony_ci { \ 668c2ecf20Sopenharmony_ci R##_s = X##_s; \ 678c2ecf20Sopenharmony_ci _FP_FRAC_COPY_##wc(R,X); \ 688c2ecf20Sopenharmony_ci } \ 698c2ecf20Sopenharmony_ci else \ 708c2ecf20Sopenharmony_ci { \ 718c2ecf20Sopenharmony_ci R##_s = Y##_s; \ 728c2ecf20Sopenharmony_ci _FP_FRAC_COPY_##wc(R,Y); \ 738c2ecf20Sopenharmony_ci } \ 748c2ecf20Sopenharmony_ci R##_c = FP_CLS_NAN; \ 758c2ecf20Sopenharmony_ci } while (0) 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* Some assembly to speed things up. */ 788c2ecf20Sopenharmony_ci#define __FP_FRAC_ADD_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \ 798c2ecf20Sopenharmony_ci __asm__ ("addcc %r7,%8,%2\n\t" \ 808c2ecf20Sopenharmony_ci "addxcc %r5,%6,%1\n\t" \ 818c2ecf20Sopenharmony_ci "addx %r3,%4,%0\n" \ 828c2ecf20Sopenharmony_ci : "=r" (r2), \ 838c2ecf20Sopenharmony_ci "=&r" (r1), \ 848c2ecf20Sopenharmony_ci "=&r" (r0) \ 858c2ecf20Sopenharmony_ci : "%rJ" ((USItype)(x2)), \ 868c2ecf20Sopenharmony_ci "rI" ((USItype)(y2)), \ 878c2ecf20Sopenharmony_ci "%rJ" ((USItype)(x1)), \ 888c2ecf20Sopenharmony_ci "rI" ((USItype)(y1)), \ 898c2ecf20Sopenharmony_ci "%rJ" ((USItype)(x0)), \ 908c2ecf20Sopenharmony_ci "rI" ((USItype)(y0)) \ 918c2ecf20Sopenharmony_ci : "cc") 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci#define __FP_FRAC_SUB_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \ 948c2ecf20Sopenharmony_ci __asm__ ("subcc %r7,%8,%2\n\t" \ 958c2ecf20Sopenharmony_ci "subxcc %r5,%6,%1\n\t" \ 968c2ecf20Sopenharmony_ci "subx %r3,%4,%0\n" \ 978c2ecf20Sopenharmony_ci : "=r" (r2), \ 988c2ecf20Sopenharmony_ci "=&r" (r1), \ 998c2ecf20Sopenharmony_ci "=&r" (r0) \ 1008c2ecf20Sopenharmony_ci : "%rJ" ((USItype)(x2)), \ 1018c2ecf20Sopenharmony_ci "rI" ((USItype)(y2)), \ 1028c2ecf20Sopenharmony_ci "%rJ" ((USItype)(x1)), \ 1038c2ecf20Sopenharmony_ci "rI" ((USItype)(y1)), \ 1048c2ecf20Sopenharmony_ci "%rJ" ((USItype)(x0)), \ 1058c2ecf20Sopenharmony_ci "rI" ((USItype)(y0)) \ 1068c2ecf20Sopenharmony_ci : "cc") 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#define __FP_FRAC_ADD_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \ 1098c2ecf20Sopenharmony_ci do { \ 1108c2ecf20Sopenharmony_ci /* We need to fool gcc, as we need to pass more than 10 \ 1118c2ecf20Sopenharmony_ci input/outputs. */ \ 1128c2ecf20Sopenharmony_ci register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \ 1138c2ecf20Sopenharmony_ci __asm__ __volatile__ ( \ 1148c2ecf20Sopenharmony_ci "addcc %r8,%9,%1\n\t" \ 1158c2ecf20Sopenharmony_ci "addxcc %r6,%7,%0\n\t" \ 1168c2ecf20Sopenharmony_ci "addxcc %r4,%5,%%g2\n\t" \ 1178c2ecf20Sopenharmony_ci "addx %r2,%3,%%g1\n\t" \ 1188c2ecf20Sopenharmony_ci : "=&r" (r1), \ 1198c2ecf20Sopenharmony_ci "=&r" (r0) \ 1208c2ecf20Sopenharmony_ci : "%rJ" ((USItype)(x3)), \ 1218c2ecf20Sopenharmony_ci "rI" ((USItype)(y3)), \ 1228c2ecf20Sopenharmony_ci "%rJ" ((USItype)(x2)), \ 1238c2ecf20Sopenharmony_ci "rI" ((USItype)(y2)), \ 1248c2ecf20Sopenharmony_ci "%rJ" ((USItype)(x1)), \ 1258c2ecf20Sopenharmony_ci "rI" ((USItype)(y1)), \ 1268c2ecf20Sopenharmony_ci "%rJ" ((USItype)(x0)), \ 1278c2ecf20Sopenharmony_ci "rI" ((USItype)(y0)) \ 1288c2ecf20Sopenharmony_ci : "cc", "g1", "g2"); \ 1298c2ecf20Sopenharmony_ci __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \ 1308c2ecf20Sopenharmony_ci r3 = _t1; r2 = _t2; \ 1318c2ecf20Sopenharmony_ci } while (0) 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#define __FP_FRAC_SUB_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \ 1348c2ecf20Sopenharmony_ci do { \ 1358c2ecf20Sopenharmony_ci /* We need to fool gcc, as we need to pass more than 10 \ 1368c2ecf20Sopenharmony_ci input/outputs. */ \ 1378c2ecf20Sopenharmony_ci register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \ 1388c2ecf20Sopenharmony_ci __asm__ __volatile__ ( \ 1398c2ecf20Sopenharmony_ci "subcc %r8,%9,%1\n\t" \ 1408c2ecf20Sopenharmony_ci "subxcc %r6,%7,%0\n\t" \ 1418c2ecf20Sopenharmony_ci "subxcc %r4,%5,%%g2\n\t" \ 1428c2ecf20Sopenharmony_ci "subx %r2,%3,%%g1\n\t" \ 1438c2ecf20Sopenharmony_ci : "=&r" (r1), \ 1448c2ecf20Sopenharmony_ci "=&r" (r0) \ 1458c2ecf20Sopenharmony_ci : "%rJ" ((USItype)(x3)), \ 1468c2ecf20Sopenharmony_ci "rI" ((USItype)(y3)), \ 1478c2ecf20Sopenharmony_ci "%rJ" ((USItype)(x2)), \ 1488c2ecf20Sopenharmony_ci "rI" ((USItype)(y2)), \ 1498c2ecf20Sopenharmony_ci "%rJ" ((USItype)(x1)), \ 1508c2ecf20Sopenharmony_ci "rI" ((USItype)(y1)), \ 1518c2ecf20Sopenharmony_ci "%rJ" ((USItype)(x0)), \ 1528c2ecf20Sopenharmony_ci "rI" ((USItype)(y0)) \ 1538c2ecf20Sopenharmony_ci : "cc", "g1", "g2"); \ 1548c2ecf20Sopenharmony_ci __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \ 1558c2ecf20Sopenharmony_ci r3 = _t1; r2 = _t2; \ 1568c2ecf20Sopenharmony_ci } while (0) 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci#define __FP_FRAC_DEC_3(x2,x1,x0,y2,y1,y0) __FP_FRAC_SUB_3(x2,x1,x0,x2,x1,x0,y2,y1,y0) 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci#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) 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci#define __FP_FRAC_ADDI_4(x3,x2,x1,x0,i) \ 1638c2ecf20Sopenharmony_ci __asm__ ("addcc %3,%4,%3\n\t" \ 1648c2ecf20Sopenharmony_ci "addxcc %2,%%g0,%2\n\t" \ 1658c2ecf20Sopenharmony_ci "addxcc %1,%%g0,%1\n\t" \ 1668c2ecf20Sopenharmony_ci "addx %0,%%g0,%0\n\t" \ 1678c2ecf20Sopenharmony_ci : "=&r" (x3), \ 1688c2ecf20Sopenharmony_ci "=&r" (x2), \ 1698c2ecf20Sopenharmony_ci "=&r" (x1), \ 1708c2ecf20Sopenharmony_ci "=&r" (x0) \ 1718c2ecf20Sopenharmony_ci : "rI" ((USItype)(i)), \ 1728c2ecf20Sopenharmony_ci "0" ((USItype)(x3)), \ 1738c2ecf20Sopenharmony_ci "1" ((USItype)(x2)), \ 1748c2ecf20Sopenharmony_ci "2" ((USItype)(x1)), \ 1758c2ecf20Sopenharmony_ci "3" ((USItype)(x0)) \ 1768c2ecf20Sopenharmony_ci : "cc") 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci#ifndef CONFIG_SMP 1798c2ecf20Sopenharmony_ciextern struct task_struct *last_task_used_math; 1808c2ecf20Sopenharmony_ci#endif 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci/* Obtain the current rounding mode. */ 1838c2ecf20Sopenharmony_ci#ifndef FP_ROUNDMODE 1848c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 1858c2ecf20Sopenharmony_ci#define FP_ROUNDMODE ((current->thread.fsr >> 30) & 0x3) 1868c2ecf20Sopenharmony_ci#else 1878c2ecf20Sopenharmony_ci#define FP_ROUNDMODE ((last_task_used_math->thread.fsr >> 30) & 0x3) 1888c2ecf20Sopenharmony_ci#endif 1898c2ecf20Sopenharmony_ci#endif 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci/* Exception flags. */ 1928c2ecf20Sopenharmony_ci#define FP_EX_INVALID (1 << 4) 1938c2ecf20Sopenharmony_ci#define FP_EX_OVERFLOW (1 << 3) 1948c2ecf20Sopenharmony_ci#define FP_EX_UNDERFLOW (1 << 2) 1958c2ecf20Sopenharmony_ci#define FP_EX_DIVZERO (1 << 1) 1968c2ecf20Sopenharmony_ci#define FP_EX_INEXACT (1 << 0) 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci#define FP_HANDLE_EXCEPTIONS return _fex 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 2018c2ecf20Sopenharmony_ci#define FP_INHIBIT_RESULTS ((current->thread.fsr >> 23) & _fex) 2028c2ecf20Sopenharmony_ci#else 2038c2ecf20Sopenharmony_ci#define FP_INHIBIT_RESULTS ((last_task_used_math->thread.fsr >> 23) & _fex) 2048c2ecf20Sopenharmony_ci#endif 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 2078c2ecf20Sopenharmony_ci#define FP_TRAPPING_EXCEPTIONS ((current->thread.fsr >> 23) & 0x1f) 2088c2ecf20Sopenharmony_ci#else 2098c2ecf20Sopenharmony_ci#define FP_TRAPPING_EXCEPTIONS ((last_task_used_math->thread.fsr >> 23) & 0x1f) 2108c2ecf20Sopenharmony_ci#endif 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci#endif 213