162306a36Sopenharmony_ci/* Machine-dependent software floating-point definitions. 262306a36Sopenharmony_ci Sparc userland (_Q_*) version. 362306a36Sopenharmony_ci Copyright (C) 1997,1998,1999 Free Software Foundation, Inc. 462306a36Sopenharmony_ci This file is part of the GNU C Library. 562306a36Sopenharmony_ci Contributed by Richard Henderson (rth@cygnus.com), 662306a36Sopenharmony_ci Jakub Jelinek (jj@ultra.linux.cz), 762306a36Sopenharmony_ci David S. Miller (davem@redhat.com) and 862306a36Sopenharmony_ci Peter Maydell (pmaydell@chiark.greenend.org.uk). 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci The GNU C Library is free software; you can redistribute it and/or 1162306a36Sopenharmony_ci modify it under the terms of the GNU Library General Public License as 1262306a36Sopenharmony_ci published by the Free Software Foundation; either version 2 of the 1362306a36Sopenharmony_ci License, or (at your option) any later version. 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci The GNU C Library is distributed in the hope that it will be useful, 1662306a36Sopenharmony_ci but WITHOUT ANY WARRANTY; without even the implied warranty of 1762306a36Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1862306a36Sopenharmony_ci Library General Public License for more details. 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci You should have received a copy of the GNU Library General Public 2162306a36Sopenharmony_ci License along with the GNU C Library; see the file COPYING.LIB. If 2262306a36Sopenharmony_ci not, write to the Free Software Foundation, Inc., 2362306a36Sopenharmony_ci 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#ifndef _SFP_MACHINE_H 2662306a36Sopenharmony_ci#define _SFP_MACHINE_H 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#define _FP_W_TYPE_SIZE 32 3062306a36Sopenharmony_ci#define _FP_W_TYPE unsigned long 3162306a36Sopenharmony_ci#define _FP_WS_TYPE signed long 3262306a36Sopenharmony_ci#define _FP_I_TYPE long 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define _FP_MUL_MEAT_S(R,X,Y) \ 3562306a36Sopenharmony_ci _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm) 3662306a36Sopenharmony_ci#define _FP_MUL_MEAT_D(R,X,Y) \ 3762306a36Sopenharmony_ci _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm) 3862306a36Sopenharmony_ci#define _FP_MUL_MEAT_Q(R,X,Y) \ 3962306a36Sopenharmony_ci _FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm) 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci#define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv(S,R,X,Y) 4262306a36Sopenharmony_ci#define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y) 4362306a36Sopenharmony_ci#define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_4_udiv(Q,R,X,Y) 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1) 4662306a36Sopenharmony_ci#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1 4762306a36Sopenharmony_ci#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1 4862306a36Sopenharmony_ci#define _FP_NANSIGN_S 0 4962306a36Sopenharmony_ci#define _FP_NANSIGN_D 0 5062306a36Sopenharmony_ci#define _FP_NANSIGN_Q 0 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define _FP_KEEPNANFRACP 1 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci/* If one NaN is signaling and the other is not, 5562306a36Sopenharmony_ci * we choose that one, otherwise we choose X. 5662306a36Sopenharmony_ci */ 5762306a36Sopenharmony_ci/* For _Qp_* and _Q_*, this should prefer X, for 5862306a36Sopenharmony_ci * CPU instruction emulation this should prefer Y. 5962306a36Sopenharmony_ci * (see SPAMv9 B.2.2 section). 6062306a36Sopenharmony_ci */ 6162306a36Sopenharmony_ci#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \ 6262306a36Sopenharmony_ci do { \ 6362306a36Sopenharmony_ci if ((_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs) \ 6462306a36Sopenharmony_ci && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \ 6562306a36Sopenharmony_ci { \ 6662306a36Sopenharmony_ci R##_s = X##_s; \ 6762306a36Sopenharmony_ci _FP_FRAC_COPY_##wc(R,X); \ 6862306a36Sopenharmony_ci } \ 6962306a36Sopenharmony_ci else \ 7062306a36Sopenharmony_ci { \ 7162306a36Sopenharmony_ci R##_s = Y##_s; \ 7262306a36Sopenharmony_ci _FP_FRAC_COPY_##wc(R,Y); \ 7362306a36Sopenharmony_ci } \ 7462306a36Sopenharmony_ci R##_c = FP_CLS_NAN; \ 7562306a36Sopenharmony_ci } while (0) 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* Some assembly to speed things up. */ 7862306a36Sopenharmony_ci#define __FP_FRAC_ADD_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \ 7962306a36Sopenharmony_ci __asm__ ("addcc %r7,%8,%2\n\t" \ 8062306a36Sopenharmony_ci "addxcc %r5,%6,%1\n\t" \ 8162306a36Sopenharmony_ci "addx %r3,%4,%0\n" \ 8262306a36Sopenharmony_ci : "=r" (r2), \ 8362306a36Sopenharmony_ci "=&r" (r1), \ 8462306a36Sopenharmony_ci "=&r" (r0) \ 8562306a36Sopenharmony_ci : "%rJ" ((USItype)(x2)), \ 8662306a36Sopenharmony_ci "rI" ((USItype)(y2)), \ 8762306a36Sopenharmony_ci "%rJ" ((USItype)(x1)), \ 8862306a36Sopenharmony_ci "rI" ((USItype)(y1)), \ 8962306a36Sopenharmony_ci "%rJ" ((USItype)(x0)), \ 9062306a36Sopenharmony_ci "rI" ((USItype)(y0)) \ 9162306a36Sopenharmony_ci : "cc") 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci#define __FP_FRAC_SUB_3(r2,r1,r0,x2,x1,x0,y2,y1,y0) \ 9462306a36Sopenharmony_ci __asm__ ("subcc %r7,%8,%2\n\t" \ 9562306a36Sopenharmony_ci "subxcc %r5,%6,%1\n\t" \ 9662306a36Sopenharmony_ci "subx %r3,%4,%0\n" \ 9762306a36Sopenharmony_ci : "=r" (r2), \ 9862306a36Sopenharmony_ci "=&r" (r1), \ 9962306a36Sopenharmony_ci "=&r" (r0) \ 10062306a36Sopenharmony_ci : "%rJ" ((USItype)(x2)), \ 10162306a36Sopenharmony_ci "rI" ((USItype)(y2)), \ 10262306a36Sopenharmony_ci "%rJ" ((USItype)(x1)), \ 10362306a36Sopenharmony_ci "rI" ((USItype)(y1)), \ 10462306a36Sopenharmony_ci "%rJ" ((USItype)(x0)), \ 10562306a36Sopenharmony_ci "rI" ((USItype)(y0)) \ 10662306a36Sopenharmony_ci : "cc") 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci#define __FP_FRAC_ADD_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \ 10962306a36Sopenharmony_ci do { \ 11062306a36Sopenharmony_ci /* We need to fool gcc, as we need to pass more than 10 \ 11162306a36Sopenharmony_ci input/outputs. */ \ 11262306a36Sopenharmony_ci register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \ 11362306a36Sopenharmony_ci __asm__ __volatile__ ( \ 11462306a36Sopenharmony_ci "addcc %r8,%9,%1\n\t" \ 11562306a36Sopenharmony_ci "addxcc %r6,%7,%0\n\t" \ 11662306a36Sopenharmony_ci "addxcc %r4,%5,%%g2\n\t" \ 11762306a36Sopenharmony_ci "addx %r2,%3,%%g1\n\t" \ 11862306a36Sopenharmony_ci : "=&r" (r1), \ 11962306a36Sopenharmony_ci "=&r" (r0) \ 12062306a36Sopenharmony_ci : "%rJ" ((USItype)(x3)), \ 12162306a36Sopenharmony_ci "rI" ((USItype)(y3)), \ 12262306a36Sopenharmony_ci "%rJ" ((USItype)(x2)), \ 12362306a36Sopenharmony_ci "rI" ((USItype)(y2)), \ 12462306a36Sopenharmony_ci "%rJ" ((USItype)(x1)), \ 12562306a36Sopenharmony_ci "rI" ((USItype)(y1)), \ 12662306a36Sopenharmony_ci "%rJ" ((USItype)(x0)), \ 12762306a36Sopenharmony_ci "rI" ((USItype)(y0)) \ 12862306a36Sopenharmony_ci : "cc", "g1", "g2"); \ 12962306a36Sopenharmony_ci __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \ 13062306a36Sopenharmony_ci r3 = _t1; r2 = _t2; \ 13162306a36Sopenharmony_ci } while (0) 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci#define __FP_FRAC_SUB_4(r3,r2,r1,r0,x3,x2,x1,x0,y3,y2,y1,y0) \ 13462306a36Sopenharmony_ci do { \ 13562306a36Sopenharmony_ci /* We need to fool gcc, as we need to pass more than 10 \ 13662306a36Sopenharmony_ci input/outputs. */ \ 13762306a36Sopenharmony_ci register USItype _t1 __asm__ ("g1"), _t2 __asm__ ("g2"); \ 13862306a36Sopenharmony_ci __asm__ __volatile__ ( \ 13962306a36Sopenharmony_ci "subcc %r8,%9,%1\n\t" \ 14062306a36Sopenharmony_ci "subxcc %r6,%7,%0\n\t" \ 14162306a36Sopenharmony_ci "subxcc %r4,%5,%%g2\n\t" \ 14262306a36Sopenharmony_ci "subx %r2,%3,%%g1\n\t" \ 14362306a36Sopenharmony_ci : "=&r" (r1), \ 14462306a36Sopenharmony_ci "=&r" (r0) \ 14562306a36Sopenharmony_ci : "%rJ" ((USItype)(x3)), \ 14662306a36Sopenharmony_ci "rI" ((USItype)(y3)), \ 14762306a36Sopenharmony_ci "%rJ" ((USItype)(x2)), \ 14862306a36Sopenharmony_ci "rI" ((USItype)(y2)), \ 14962306a36Sopenharmony_ci "%rJ" ((USItype)(x1)), \ 15062306a36Sopenharmony_ci "rI" ((USItype)(y1)), \ 15162306a36Sopenharmony_ci "%rJ" ((USItype)(x0)), \ 15262306a36Sopenharmony_ci "rI" ((USItype)(y0)) \ 15362306a36Sopenharmony_ci : "cc", "g1", "g2"); \ 15462306a36Sopenharmony_ci __asm__ __volatile__ ("" : "=r" (_t1), "=r" (_t2)); \ 15562306a36Sopenharmony_ci r3 = _t1; r2 = _t2; \ 15662306a36Sopenharmony_ci } while (0) 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_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) 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_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) 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#define __FP_FRAC_ADDI_4(x3,x2,x1,x0,i) \ 16362306a36Sopenharmony_ci __asm__ ("addcc %3,%4,%3\n\t" \ 16462306a36Sopenharmony_ci "addxcc %2,%%g0,%2\n\t" \ 16562306a36Sopenharmony_ci "addxcc %1,%%g0,%1\n\t" \ 16662306a36Sopenharmony_ci "addx %0,%%g0,%0\n\t" \ 16762306a36Sopenharmony_ci : "=&r" (x3), \ 16862306a36Sopenharmony_ci "=&r" (x2), \ 16962306a36Sopenharmony_ci "=&r" (x1), \ 17062306a36Sopenharmony_ci "=&r" (x0) \ 17162306a36Sopenharmony_ci : "rI" ((USItype)(i)), \ 17262306a36Sopenharmony_ci "0" ((USItype)(x3)), \ 17362306a36Sopenharmony_ci "1" ((USItype)(x2)), \ 17462306a36Sopenharmony_ci "2" ((USItype)(x1)), \ 17562306a36Sopenharmony_ci "3" ((USItype)(x0)) \ 17662306a36Sopenharmony_ci : "cc") 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci#ifndef CONFIG_SMP 17962306a36Sopenharmony_ciextern struct task_struct *last_task_used_math; 18062306a36Sopenharmony_ci#endif 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci/* Obtain the current rounding mode. */ 18362306a36Sopenharmony_ci#ifndef FP_ROUNDMODE 18462306a36Sopenharmony_ci#ifdef CONFIG_SMP 18562306a36Sopenharmony_ci#define FP_ROUNDMODE ((current->thread.fsr >> 30) & 0x3) 18662306a36Sopenharmony_ci#else 18762306a36Sopenharmony_ci#define FP_ROUNDMODE ((last_task_used_math->thread.fsr >> 30) & 0x3) 18862306a36Sopenharmony_ci#endif 18962306a36Sopenharmony_ci#endif 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci/* Exception flags. */ 19262306a36Sopenharmony_ci#define FP_EX_INVALID (1 << 4) 19362306a36Sopenharmony_ci#define FP_EX_OVERFLOW (1 << 3) 19462306a36Sopenharmony_ci#define FP_EX_UNDERFLOW (1 << 2) 19562306a36Sopenharmony_ci#define FP_EX_DIVZERO (1 << 1) 19662306a36Sopenharmony_ci#define FP_EX_INEXACT (1 << 0) 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci#define FP_HANDLE_EXCEPTIONS return _fex 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci#ifdef CONFIG_SMP 20162306a36Sopenharmony_ci#define FP_INHIBIT_RESULTS ((current->thread.fsr >> 23) & _fex) 20262306a36Sopenharmony_ci#else 20362306a36Sopenharmony_ci#define FP_INHIBIT_RESULTS ((last_task_used_math->thread.fsr >> 23) & _fex) 20462306a36Sopenharmony_ci#endif 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci#ifdef CONFIG_SMP 20762306a36Sopenharmony_ci#define FP_TRAPPING_EXCEPTIONS ((current->thread.fsr >> 23) & 0x1f) 20862306a36Sopenharmony_ci#else 20962306a36Sopenharmony_ci#define FP_TRAPPING_EXCEPTIONS ((last_task_used_math->thread.fsr >> 23) & 0x1f) 21062306a36Sopenharmony_ci#endif 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ci#endif 213