sint.sa revision 1.1
11.1Smycroft* MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP 21.1Smycroft* M68000 Hi-Performance Microprocessor Division 31.1Smycroft* M68040 Software Package 41.1Smycroft* 51.1Smycroft* M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc. 61.1Smycroft* All rights reserved. 71.1Smycroft* 81.1Smycroft* THE SOFTWARE is provided on an "AS IS" basis and without warranty. 91.1Smycroft* To the maximum extent permitted by applicable law, 101.1Smycroft* MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED, 111.1Smycroft* INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A 121.1Smycroft* PARTICULAR PURPOSE and any warranty against infringement with 131.1Smycroft* regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF) 141.1Smycroft* and any accompanying written materials. 151.1Smycroft* 161.1Smycroft* To the maximum extent permitted by applicable law, 171.1Smycroft* IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER 181.1Smycroft* (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS 191.1Smycroft* PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR 201.1Smycroft* OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE 211.1Smycroft* SOFTWARE. Motorola assumes no responsibility for the maintenance 221.1Smycroft* and support of the SOFTWARE. 231.1Smycroft* 241.1Smycroft* You are hereby granted a copyright license to use, modify, and 251.1Smycroft* distribute the SOFTWARE so long as this entire notice is retained 261.1Smycroft* without alteration in any modified and/or redistributed versions, 271.1Smycroft* and that such modified versions are clearly identified as such. 281.1Smycroft* No licenses are granted by implication, estoppel or otherwise 291.1Smycroft* under any patents or trademarks of Motorola, Inc. 301.1Smycroft 311.1Smycroft* 321.1Smycroft* sint.sa 3.1 12/10/90 331.1Smycroft* 341.1Smycroft* The entry point sINT computes the rounded integer 351.1Smycroft* equivalent of the input argument, sINTRZ computes 361.1Smycroft* the integer rounded to zero of the input argument. 371.1Smycroft* 381.1Smycroft* Entry points sint and sintrz are called from do_func 391.1Smycroft* to emulate the fint and fintrz unimplemented instructions, 401.1Smycroft* respectively. Entry point sintdo is used by bindec. 411.1Smycroft* 421.1Smycroft* Input: (Entry points sint and sintrz) Double-extended 431.1Smycroft* number X in the ETEMP space in the floating-point 441.1Smycroft* save stack. 451.1Smycroft* (Entry point sintdo) Double-extended number X in 461.1Smycroft* location pointed to by the address register a0. 471.1Smycroft* (Entry point sintd) Double-extended denormalized 481.1Smycroft* number X in the ETEMP space in the floating-point 491.1Smycroft* save stack. 501.1Smycroft* 511.1Smycroft* Output: The function returns int(X) or intrz(X) in fp0. 521.1Smycroft* 531.1Smycroft* Modifies: fp0. 541.1Smycroft* 551.1Smycroft* Algorithm: (sint and sintrz) 561.1Smycroft* 571.1Smycroft* 1. If exp(X) >= 63, return X. 581.1Smycroft* If exp(X) < 0, return +/- 0 or +/- 1, according to 591.1Smycroft* the rounding mode. 601.1Smycroft* 611.1Smycroft* 2. (X is in range) set rsc = 63 - exp(X). Unnormalize the 621.1Smycroft* result to the exponent $403e. 631.1Smycroft* 641.1Smycroft* 3. Round the result in the mode given in USER_FPCR. For 651.1Smycroft* sintrz, force round-to-zero mode. 661.1Smycroft* 671.1Smycroft* 4. Normalize the rounded result; store in fp0. 681.1Smycroft* 691.1Smycroft* For the denormalized cases, force the correct result 701.1Smycroft* for the given sign and rounding mode. 711.1Smycroft* 721.1Smycroft* Sign(X) 731.1Smycroft* RMODE + - 741.1Smycroft* ----- -------- 751.1Smycroft* RN +0 -0 761.1Smycroft* RZ +0 -0 771.1Smycroft* RM +0 -1 781.1Smycroft* RP +1 -0 791.1Smycroft* 801.1Smycroft 811.1SmycroftSINT IDNT 2,1 Motorola 040 Floating Point Software Package 821.1Smycroft 831.1Smycroft section 8 841.1Smycroft 851.1Smycroft include fpsp.h 861.1Smycroft 871.1Smycroft xref dnrm_lp 881.1Smycroft xref nrm_set 891.1Smycroft xref round 901.1Smycroft xref t_inx2 911.1Smycroft xref ld_pone 921.1Smycroft xref ld_mone 931.1Smycroft xref ld_pzero 941.1Smycroft xref ld_mzero 951.1Smycroft xref snzrinx 961.1Smycroft 971.1Smycroft* 981.1Smycroft* FINT 991.1Smycroft* 1001.1Smycroft xdef sint 1011.1Smycroftsint: 1021.1Smycroft bfextu FPCR_MODE(a6){2:2},d1 ;use user's mode for rounding 1031.1Smycroft* ;implicity has extend precision 1041.1Smycroft* ;in upper word. 1051.1Smycroft move.l d1,L_SCR1(a6) ;save mode bits 1061.1Smycroft bra.b sintexc 1071.1Smycroft 1081.1Smycroft* 1091.1Smycroft* FINT with extended denorm inputs. 1101.1Smycroft* 1111.1Smycroft xdef sintd 1121.1Smycroftsintd: 1131.1Smycroft btst.b #5,FPCR_MODE(a6) 1141.1Smycroft beq snzrinx ;if round nearest or round zero, +/- 0 1151.1Smycroft btst.b #4,FPCR_MODE(a6) 1161.1Smycroft beq.b rnd_mns 1171.1Smycroftrnd_pls: 1181.1Smycroft btst.b #sign_bit,LOCAL_EX(a0) 1191.1Smycroft bne.b sintmz 1201.1Smycroft bsr ld_pone ;if round plus inf and pos, answer is +1 1211.1Smycroft bra t_inx2 1221.1Smycroftrnd_mns: 1231.1Smycroft btst.b #sign_bit,LOCAL_EX(a0) 1241.1Smycroft beq.b sintpz 1251.1Smycroft bsr ld_mone ;if round mns inf and neg, answer is -1 1261.1Smycroft bra t_inx2 1271.1Smycroftsintpz: 1281.1Smycroft bsr ld_pzero 1291.1Smycroft bra t_inx2 1301.1Smycroftsintmz: 1311.1Smycroft bsr ld_mzero 1321.1Smycroft bra t_inx2 1331.1Smycroft 1341.1Smycroft* 1351.1Smycroft* FINTRZ 1361.1Smycroft* 1371.1Smycroft xdef sintrz 1381.1Smycroftsintrz: 1391.1Smycroft move.l #1,L_SCR1(a6) ;use rz mode for rounding 1401.1Smycroft* ;implicity has extend precision 1411.1Smycroft* ;in upper word. 1421.1Smycroft bra.b sintexc 1431.1Smycroft* 1441.1Smycroft* SINTDO 1451.1Smycroft* 1461.1Smycroft* Input: a0 points to an IEEE extended format operand 1471.1Smycroft* Output: fp0 has the result 1481.1Smycroft* 1491.1Smycroft* Exeptions: 1501.1Smycroft* 1511.1Smycroft* If the subroutine results in an inexact operation, the inx2 and 1521.1Smycroft* ainx bits in the USER_FPSR are set. 1531.1Smycroft* 1541.1Smycroft* 1551.1Smycroft xdef sintdo 1561.1Smycroftsintdo: 1571.1Smycroft bfextu FPCR_MODE(a6){2:2},d1 ;use user's mode for rounding 1581.1Smycroft* ;implicitly has ext precision 1591.1Smycroft* ;in upper word. 1601.1Smycroft move.l d1,L_SCR1(a6) ;save mode bits 1611.1Smycroft* 1621.1Smycroft* Real work of sint is in sintexc 1631.1Smycroft* 1641.1Smycroftsintexc: 1651.1Smycroft bclr.b #sign_bit,LOCAL_EX(a0) ;convert to internal extended 1661.1Smycroft* ;format 1671.1Smycroft sne LOCAL_SGN(a0) 1681.1Smycroft cmp.w #$403e,LOCAL_EX(a0) ;check if (unbiased) exp > 63 1691.1Smycroft bgt.b out_rnge ;branch if exp < 63 1701.1Smycroft cmp.w #$3ffd,LOCAL_EX(a0) ;check if (unbiased) exp < 0 1711.1Smycroft bgt.w in_rnge ;if 63 >= exp > 0, do calc 1721.1Smycroft* 1731.1Smycroft* Input is less than zero. Restore sign, and check for directed 1741.1Smycroft* rounding modes. L_SCR1 contains the rmode in the lower byte. 1751.1Smycroft* 1761.1Smycroftun_rnge: 1771.1Smycroft btst.b #1,L_SCR1+3(a6) ;check for rn and rz 1781.1Smycroft beq.b un_rnrz 1791.1Smycroft tst.b LOCAL_SGN(a0) ;check for sign 1801.1Smycroft bne.b un_rmrp_neg 1811.1Smycroft* 1821.1Smycroft* Sign is +. If rp, load +1.0, if rm, load +0.0 1831.1Smycroft* 1841.1Smycroft cmpi.b #3,L_SCR1+3(a6) ;check for rp 1851.1Smycroft beq.b un_ldpone ;if rp, load +1.0 1861.1Smycroft bsr ld_pzero ;if rm, load +0.0 1871.1Smycroft bra t_inx2 1881.1Smycroftun_ldpone: 1891.1Smycroft bsr ld_pone 1901.1Smycroft bra t_inx2 1911.1Smycroft* 1921.1Smycroft* Sign is -. If rm, load -1.0, if rp, load -0.0 1931.1Smycroft* 1941.1Smycroftun_rmrp_neg: 1951.1Smycroft cmpi.b #2,L_SCR1+3(a6) ;check for rm 1961.1Smycroft beq.b un_ldmone ;if rm, load -1.0 1971.1Smycroft bsr ld_mzero ;if rp, load -0.0 1981.1Smycroft bra t_inx2 1991.1Smycroftun_ldmone: 2001.1Smycroft bsr ld_mone 2011.1Smycroft bra t_inx2 2021.1Smycroft* 2031.1Smycroft* Rmode is rn or rz; return signed zero 2041.1Smycroft* 2051.1Smycroftun_rnrz: 2061.1Smycroft tst.b LOCAL_SGN(a0) ;check for sign 2071.1Smycroft bne.b un_rnrz_neg 2081.1Smycroft bsr ld_pzero 2091.1Smycroft bra t_inx2 2101.1Smycroftun_rnrz_neg: 2111.1Smycroft bsr ld_mzero 2121.1Smycroft bra t_inx2 2131.1Smycroft 2141.1Smycroft* 2151.1Smycroft* Input is greater than 2^63. All bits are significant. Return 2161.1Smycroft* the input. 2171.1Smycroft* 2181.1Smycroftout_rnge: 2191.1Smycroft bfclr LOCAL_SGN(a0){0:8} ;change back to IEEE ext format 2201.1Smycroft beq.b intps 2211.1Smycroft bset.b #sign_bit,LOCAL_EX(a0) 2221.1Smycroftintps: 2231.1Smycroft fmove.l fpcr,-(sp) 2241.1Smycroft fmove.l #0,fpcr 2251.1Smycroft fmove.x LOCAL_EX(a0),fp0 ;if exp > 63 2261.1Smycroft* ;then return X to the user 2271.1Smycroft* ;there are no fraction bits 2281.1Smycroft fmove.l (sp)+,fpcr 2291.1Smycroft rts 2301.1Smycroft 2311.1Smycroftin_rnge: 2321.1Smycroft* ;shift off fraction bits 2331.1Smycroft clr.l d0 ;clear d0 - initial g,r,s for 2341.1Smycroft* ;dnrm_lp 2351.1Smycroft move.l #$403e,d1 ;set threshold for dnrm_lp 2361.1Smycroft* ;assumes a0 points to operand 2371.1Smycroft bsr dnrm_lp 2381.1Smycroft* ;returns unnormalized number 2391.1Smycroft* ;pointed by a0 2401.1Smycroft* ;output d0 supplies g,r,s 2411.1Smycroft* ;used by round 2421.1Smycroft move.l L_SCR1(a6),d1 ;use selected rounding mode 2431.1Smycroft* 2441.1Smycroft* 2451.1Smycroft bsr round ;round the unnorm based on users 2461.1Smycroft* ;input a0 ptr to ext X 2471.1Smycroft* ; d0 g,r,s bits 2481.1Smycroft* ; d1 PREC/MODE info 2491.1Smycroft* ;output a0 ptr to rounded result 2501.1Smycroft* ;inexact flag set in USER_FPSR 2511.1Smycroft* ;if initial grs set 2521.1Smycroft* 2531.1Smycroft* normalize the rounded result and store value in fp0 2541.1Smycroft* 2551.1Smycroft bsr nrm_set ;normalize the unnorm 2561.1Smycroft* ;Input: a0 points to operand to 2571.1Smycroft* ;be normalized 2581.1Smycroft* ;Output: a0 points to normalized 2591.1Smycroft* ;result 2601.1Smycroft bfclr LOCAL_SGN(a0){0:8} 2611.1Smycroft beq.b nrmrndp 2621.1Smycroft bset.b #sign_bit,LOCAL_EX(a0) ;return to IEEE extended format 2631.1Smycroftnrmrndp: 2641.1Smycroft fmove.l fpcr,-(sp) 2651.1Smycroft fmove.l #0,fpcr 2661.1Smycroft fmove.x LOCAL_EX(a0),fp0 ;move result to fp0 2671.1Smycroft fmove.l (sp)+,fpcr 2681.1Smycroft rts 2691.1Smycroft 2701.1Smycroft end 271