1*1da177e4SLinus Torvalds| 2*1da177e4SLinus Torvalds| sint.sa 3.1 12/10/90 3*1da177e4SLinus Torvalds| 4*1da177e4SLinus Torvalds| The entry point sINT computes the rounded integer 5*1da177e4SLinus Torvalds| equivalent of the input argument, sINTRZ computes 6*1da177e4SLinus Torvalds| the integer rounded to zero of the input argument. 7*1da177e4SLinus Torvalds| 8*1da177e4SLinus Torvalds| Entry points sint and sintrz are called from do_func 9*1da177e4SLinus Torvalds| to emulate the fint and fintrz unimplemented instructions, 10*1da177e4SLinus Torvalds| respectively. Entry point sintdo is used by bindec. 11*1da177e4SLinus Torvalds| 12*1da177e4SLinus Torvalds| Input: (Entry points sint and sintrz) Double-extended 13*1da177e4SLinus Torvalds| number X in the ETEMP space in the floating-point 14*1da177e4SLinus Torvalds| save stack. 15*1da177e4SLinus Torvalds| (Entry point sintdo) Double-extended number X in 16*1da177e4SLinus Torvalds| location pointed to by the address register a0. 17*1da177e4SLinus Torvalds| (Entry point sintd) Double-extended denormalized 18*1da177e4SLinus Torvalds| number X in the ETEMP space in the floating-point 19*1da177e4SLinus Torvalds| save stack. 20*1da177e4SLinus Torvalds| 21*1da177e4SLinus Torvalds| Output: The function returns int(X) or intrz(X) in fp0. 22*1da177e4SLinus Torvalds| 23*1da177e4SLinus Torvalds| Modifies: fp0. 24*1da177e4SLinus Torvalds| 25*1da177e4SLinus Torvalds| Algorithm: (sint and sintrz) 26*1da177e4SLinus Torvalds| 27*1da177e4SLinus Torvalds| 1. If exp(X) >= 63, return X. 28*1da177e4SLinus Torvalds| If exp(X) < 0, return +/- 0 or +/- 1, according to 29*1da177e4SLinus Torvalds| the rounding mode. 30*1da177e4SLinus Torvalds| 31*1da177e4SLinus Torvalds| 2. (X is in range) set rsc = 63 - exp(X). Unnormalize the 32*1da177e4SLinus Torvalds| result to the exponent $403e. 33*1da177e4SLinus Torvalds| 34*1da177e4SLinus Torvalds| 3. Round the result in the mode given in USER_FPCR. For 35*1da177e4SLinus Torvalds| sintrz, force round-to-zero mode. 36*1da177e4SLinus Torvalds| 37*1da177e4SLinus Torvalds| 4. Normalize the rounded result; store in fp0. 38*1da177e4SLinus Torvalds| 39*1da177e4SLinus Torvalds| For the denormalized cases, force the correct result 40*1da177e4SLinus Torvalds| for the given sign and rounding mode. 41*1da177e4SLinus Torvalds| 42*1da177e4SLinus Torvalds| Sign(X) 43*1da177e4SLinus Torvalds| RMODE + - 44*1da177e4SLinus Torvalds| ----- -------- 45*1da177e4SLinus Torvalds| RN +0 -0 46*1da177e4SLinus Torvalds| RZ +0 -0 47*1da177e4SLinus Torvalds| RM +0 -1 48*1da177e4SLinus Torvalds| RP +1 -0 49*1da177e4SLinus Torvalds| 50*1da177e4SLinus Torvalds| 51*1da177e4SLinus Torvalds| Copyright (C) Motorola, Inc. 1990 52*1da177e4SLinus Torvalds| All Rights Reserved 53*1da177e4SLinus Torvalds| 54*1da177e4SLinus Torvalds| THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA 55*1da177e4SLinus Torvalds| The copyright notice above does not evidence any 56*1da177e4SLinus Torvalds| actual or intended publication of such source code. 57*1da177e4SLinus Torvalds 58*1da177e4SLinus Torvalds|SINT idnt 2,1 | Motorola 040 Floating Point Software Package 59*1da177e4SLinus Torvalds 60*1da177e4SLinus Torvalds |section 8 61*1da177e4SLinus Torvalds 62*1da177e4SLinus Torvalds#include "fpsp.h" 63*1da177e4SLinus Torvalds 64*1da177e4SLinus Torvalds |xref dnrm_lp 65*1da177e4SLinus Torvalds |xref nrm_set 66*1da177e4SLinus Torvalds |xref round 67*1da177e4SLinus Torvalds |xref t_inx2 68*1da177e4SLinus Torvalds |xref ld_pone 69*1da177e4SLinus Torvalds |xref ld_mone 70*1da177e4SLinus Torvalds |xref ld_pzero 71*1da177e4SLinus Torvalds |xref ld_mzero 72*1da177e4SLinus Torvalds |xref snzrinx 73*1da177e4SLinus Torvalds 74*1da177e4SLinus Torvalds| 75*1da177e4SLinus Torvalds| FINT 76*1da177e4SLinus Torvalds| 77*1da177e4SLinus Torvalds .global sint 78*1da177e4SLinus Torvaldssint: 79*1da177e4SLinus Torvalds bfextu FPCR_MODE(%a6){#2:#2},%d1 |use user's mode for rounding 80*1da177e4SLinus Torvalds| ;implicitly has extend precision 81*1da177e4SLinus Torvalds| ;in upper word. 82*1da177e4SLinus Torvalds movel %d1,L_SCR1(%a6) |save mode bits 83*1da177e4SLinus Torvalds bras sintexc 84*1da177e4SLinus Torvalds 85*1da177e4SLinus Torvalds| 86*1da177e4SLinus Torvalds| FINT with extended denorm inputs. 87*1da177e4SLinus Torvalds| 88*1da177e4SLinus Torvalds .global sintd 89*1da177e4SLinus Torvaldssintd: 90*1da177e4SLinus Torvalds btstb #5,FPCR_MODE(%a6) 91*1da177e4SLinus Torvalds beq snzrinx |if round nearest or round zero, +/- 0 92*1da177e4SLinus Torvalds btstb #4,FPCR_MODE(%a6) 93*1da177e4SLinus Torvalds beqs rnd_mns 94*1da177e4SLinus Torvaldsrnd_pls: 95*1da177e4SLinus Torvalds btstb #sign_bit,LOCAL_EX(%a0) 96*1da177e4SLinus Torvalds bnes sintmz 97*1da177e4SLinus Torvalds bsr ld_pone |if round plus inf and pos, answer is +1 98*1da177e4SLinus Torvalds bra t_inx2 99*1da177e4SLinus Torvaldsrnd_mns: 100*1da177e4SLinus Torvalds btstb #sign_bit,LOCAL_EX(%a0) 101*1da177e4SLinus Torvalds beqs sintpz 102*1da177e4SLinus Torvalds bsr ld_mone |if round mns inf and neg, answer is -1 103*1da177e4SLinus Torvalds bra t_inx2 104*1da177e4SLinus Torvaldssintpz: 105*1da177e4SLinus Torvalds bsr ld_pzero 106*1da177e4SLinus Torvalds bra t_inx2 107*1da177e4SLinus Torvaldssintmz: 108*1da177e4SLinus Torvalds bsr ld_mzero 109*1da177e4SLinus Torvalds bra t_inx2 110*1da177e4SLinus Torvalds 111*1da177e4SLinus Torvalds| 112*1da177e4SLinus Torvalds| FINTRZ 113*1da177e4SLinus Torvalds| 114*1da177e4SLinus Torvalds .global sintrz 115*1da177e4SLinus Torvaldssintrz: 116*1da177e4SLinus Torvalds movel #1,L_SCR1(%a6) |use rz mode for rounding 117*1da177e4SLinus Torvalds| ;implicitly has extend precision 118*1da177e4SLinus Torvalds| ;in upper word. 119*1da177e4SLinus Torvalds bras sintexc 120*1da177e4SLinus Torvalds| 121*1da177e4SLinus Torvalds| SINTDO 122*1da177e4SLinus Torvalds| 123*1da177e4SLinus Torvalds| Input: a0 points to an IEEE extended format operand 124*1da177e4SLinus Torvalds| Output: fp0 has the result 125*1da177e4SLinus Torvalds| 126*1da177e4SLinus Torvalds| Exceptions: 127*1da177e4SLinus Torvalds| 128*1da177e4SLinus Torvalds| If the subroutine results in an inexact operation, the inx2 and 129*1da177e4SLinus Torvalds| ainx bits in the USER_FPSR are set. 130*1da177e4SLinus Torvalds| 131*1da177e4SLinus Torvalds| 132*1da177e4SLinus Torvalds .global sintdo 133*1da177e4SLinus Torvaldssintdo: 134*1da177e4SLinus Torvalds bfextu FPCR_MODE(%a6){#2:#2},%d1 |use user's mode for rounding 135*1da177e4SLinus Torvalds| ;implicitly has ext precision 136*1da177e4SLinus Torvalds| ;in upper word. 137*1da177e4SLinus Torvalds movel %d1,L_SCR1(%a6) |save mode bits 138*1da177e4SLinus Torvalds| 139*1da177e4SLinus Torvalds| Real work of sint is in sintexc 140*1da177e4SLinus Torvalds| 141*1da177e4SLinus Torvaldssintexc: 142*1da177e4SLinus Torvalds bclrb #sign_bit,LOCAL_EX(%a0) |convert to internal extended 143*1da177e4SLinus Torvalds| ;format 144*1da177e4SLinus Torvalds sne LOCAL_SGN(%a0) 145*1da177e4SLinus Torvalds cmpw #0x403e,LOCAL_EX(%a0) |check if (unbiased) exp > 63 146*1da177e4SLinus Torvalds bgts out_rnge |branch if exp < 63 147*1da177e4SLinus Torvalds cmpw #0x3ffd,LOCAL_EX(%a0) |check if (unbiased) exp < 0 148*1da177e4SLinus Torvalds bgt in_rnge |if 63 >= exp > 0, do calc 149*1da177e4SLinus Torvalds| 150*1da177e4SLinus Torvalds| Input is less than zero. Restore sign, and check for directed 151*1da177e4SLinus Torvalds| rounding modes. L_SCR1 contains the rmode in the lower byte. 152*1da177e4SLinus Torvalds| 153*1da177e4SLinus Torvaldsun_rnge: 154*1da177e4SLinus Torvalds btstb #1,L_SCR1+3(%a6) |check for rn and rz 155*1da177e4SLinus Torvalds beqs un_rnrz 156*1da177e4SLinus Torvalds tstb LOCAL_SGN(%a0) |check for sign 157*1da177e4SLinus Torvalds bnes un_rmrp_neg 158*1da177e4SLinus Torvalds| 159*1da177e4SLinus Torvalds| Sign is +. If rp, load +1.0, if rm, load +0.0 160*1da177e4SLinus Torvalds| 161*1da177e4SLinus Torvalds cmpib #3,L_SCR1+3(%a6) |check for rp 162*1da177e4SLinus Torvalds beqs un_ldpone |if rp, load +1.0 163*1da177e4SLinus Torvalds bsr ld_pzero |if rm, load +0.0 164*1da177e4SLinus Torvalds bra t_inx2 165*1da177e4SLinus Torvaldsun_ldpone: 166*1da177e4SLinus Torvalds bsr ld_pone 167*1da177e4SLinus Torvalds bra t_inx2 168*1da177e4SLinus Torvalds| 169*1da177e4SLinus Torvalds| Sign is -. If rm, load -1.0, if rp, load -0.0 170*1da177e4SLinus Torvalds| 171*1da177e4SLinus Torvaldsun_rmrp_neg: 172*1da177e4SLinus Torvalds cmpib #2,L_SCR1+3(%a6) |check for rm 173*1da177e4SLinus Torvalds beqs un_ldmone |if rm, load -1.0 174*1da177e4SLinus Torvalds bsr ld_mzero |if rp, load -0.0 175*1da177e4SLinus Torvalds bra t_inx2 176*1da177e4SLinus Torvaldsun_ldmone: 177*1da177e4SLinus Torvalds bsr ld_mone 178*1da177e4SLinus Torvalds bra t_inx2 179*1da177e4SLinus Torvalds| 180*1da177e4SLinus Torvalds| Rmode is rn or rz; return signed zero 181*1da177e4SLinus Torvalds| 182*1da177e4SLinus Torvaldsun_rnrz: 183*1da177e4SLinus Torvalds tstb LOCAL_SGN(%a0) |check for sign 184*1da177e4SLinus Torvalds bnes un_rnrz_neg 185*1da177e4SLinus Torvalds bsr ld_pzero 186*1da177e4SLinus Torvalds bra t_inx2 187*1da177e4SLinus Torvaldsun_rnrz_neg: 188*1da177e4SLinus Torvalds bsr ld_mzero 189*1da177e4SLinus Torvalds bra t_inx2 190*1da177e4SLinus Torvalds 191*1da177e4SLinus Torvalds| 192*1da177e4SLinus Torvalds| Input is greater than 2^63. All bits are significant. Return 193*1da177e4SLinus Torvalds| the input. 194*1da177e4SLinus Torvalds| 195*1da177e4SLinus Torvaldsout_rnge: 196*1da177e4SLinus Torvalds bfclr LOCAL_SGN(%a0){#0:#8} |change back to IEEE ext format 197*1da177e4SLinus Torvalds beqs intps 198*1da177e4SLinus Torvalds bsetb #sign_bit,LOCAL_EX(%a0) 199*1da177e4SLinus Torvaldsintps: 200*1da177e4SLinus Torvalds fmovel %fpcr,-(%sp) 201*1da177e4SLinus Torvalds fmovel #0,%fpcr 202*1da177e4SLinus Torvalds fmovex LOCAL_EX(%a0),%fp0 |if exp > 63 203*1da177e4SLinus Torvalds| ;then return X to the user 204*1da177e4SLinus Torvalds| ;there are no fraction bits 205*1da177e4SLinus Torvalds fmovel (%sp)+,%fpcr 206*1da177e4SLinus Torvalds rts 207*1da177e4SLinus Torvalds 208*1da177e4SLinus Torvaldsin_rnge: 209*1da177e4SLinus Torvalds| ;shift off fraction bits 210*1da177e4SLinus Torvalds clrl %d0 |clear d0 - initial g,r,s for 211*1da177e4SLinus Torvalds| ;dnrm_lp 212*1da177e4SLinus Torvalds movel #0x403e,%d1 |set threshold for dnrm_lp 213*1da177e4SLinus Torvalds| ;assumes a0 points to operand 214*1da177e4SLinus Torvalds bsr dnrm_lp 215*1da177e4SLinus Torvalds| ;returns unnormalized number 216*1da177e4SLinus Torvalds| ;pointed by a0 217*1da177e4SLinus Torvalds| ;output d0 supplies g,r,s 218*1da177e4SLinus Torvalds| ;used by round 219*1da177e4SLinus Torvalds movel L_SCR1(%a6),%d1 |use selected rounding mode 220*1da177e4SLinus Torvalds| 221*1da177e4SLinus Torvalds| 222*1da177e4SLinus Torvalds bsr round |round the unnorm based on users 223*1da177e4SLinus Torvalds| ;input a0 ptr to ext X 224*1da177e4SLinus Torvalds| ; d0 g,r,s bits 225*1da177e4SLinus Torvalds| ; d1 PREC/MODE info 226*1da177e4SLinus Torvalds| ;output a0 ptr to rounded result 227*1da177e4SLinus Torvalds| ;inexact flag set in USER_FPSR 228*1da177e4SLinus Torvalds| ;if initial grs set 229*1da177e4SLinus Torvalds| 230*1da177e4SLinus Torvalds| normalize the rounded result and store value in fp0 231*1da177e4SLinus Torvalds| 232*1da177e4SLinus Torvalds bsr nrm_set |normalize the unnorm 233*1da177e4SLinus Torvalds| ;Input: a0 points to operand to 234*1da177e4SLinus Torvalds| ;be normalized 235*1da177e4SLinus Torvalds| ;Output: a0 points to normalized 236*1da177e4SLinus Torvalds| ;result 237*1da177e4SLinus Torvalds bfclr LOCAL_SGN(%a0){#0:#8} 238*1da177e4SLinus Torvalds beqs nrmrndp 239*1da177e4SLinus Torvalds bsetb #sign_bit,LOCAL_EX(%a0) |return to IEEE extended format 240*1da177e4SLinus Torvaldsnrmrndp: 241*1da177e4SLinus Torvalds fmovel %fpcr,-(%sp) 242*1da177e4SLinus Torvalds fmovel #0,%fpcr 243*1da177e4SLinus Torvalds fmovex LOCAL_EX(%a0),%fp0 |move result to fp0 244*1da177e4SLinus Torvalds fmovel (%sp)+,%fpcr 245*1da177e4SLinus Torvalds rts 246*1da177e4SLinus Torvalds 247*1da177e4SLinus Torvalds |end 248