Annotation of sys/arch/m68k/fpsp/sint.sa, Revision 1.1
1.1 ! nbrk 1: * $OpenBSD: sint.sa,v 1.2 1996/05/29 21:05:38 niklas Exp $
! 2: * $NetBSD: sint.sa,v 1.2 1994/10/26 07:49:48 cgd Exp $
! 3:
! 4: * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
! 5: * M68000 Hi-Performance Microprocessor Division
! 6: * M68040 Software Package
! 7: *
! 8: * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
! 9: * All rights reserved.
! 10: *
! 11: * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
! 12: * To the maximum extent permitted by applicable law,
! 13: * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
! 14: * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
! 15: * PARTICULAR PURPOSE and any warranty against infringement with
! 16: * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
! 17: * and any accompanying written materials.
! 18: *
! 19: * To the maximum extent permitted by applicable law,
! 20: * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
! 21: * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
! 22: * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
! 23: * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
! 24: * SOFTWARE. Motorola assumes no responsibility for the maintenance
! 25: * and support of the SOFTWARE.
! 26: *
! 27: * You are hereby granted a copyright license to use, modify, and
! 28: * distribute the SOFTWARE so long as this entire notice is retained
! 29: * without alteration in any modified and/or redistributed versions,
! 30: * and that such modified versions are clearly identified as such.
! 31: * No licenses are granted by implication, estoppel or otherwise
! 32: * under any patents or trademarks of Motorola, Inc.
! 33:
! 34: *
! 35: * sint.sa 3.1 12/10/90
! 36: *
! 37: * The entry point sINT computes the rounded integer
! 38: * equivalent of the input argument, sINTRZ computes
! 39: * the integer rounded to zero of the input argument.
! 40: *
! 41: * Entry points sint and sintrz are called from do_func
! 42: * to emulate the fint and fintrz unimplemented instructions,
! 43: * respectively. Entry point sintdo is used by bindec.
! 44: *
! 45: * Input: (Entry points sint and sintrz) Double-extended
! 46: * number X in the ETEMP space in the floating-point
! 47: * save stack.
! 48: * (Entry point sintdo) Double-extended number X in
! 49: * location pointed to by the address register a0.
! 50: * (Entry point sintd) Double-extended denormalized
! 51: * number X in the ETEMP space in the floating-point
! 52: * save stack.
! 53: *
! 54: * Output: The function returns int(X) or intrz(X) in fp0.
! 55: *
! 56: * Modifies: fp0.
! 57: *
! 58: * Algorithm: (sint and sintrz)
! 59: *
! 60: * 1. If exp(X) >= 63, return X.
! 61: * If exp(X) < 0, return +/- 0 or +/- 1, according to
! 62: * the rounding mode.
! 63: *
! 64: * 2. (X is in range) set rsc = 63 - exp(X). Unnormalize the
! 65: * result to the exponent $403e.
! 66: *
! 67: * 3. Round the result in the mode given in USER_FPCR. For
! 68: * sintrz, force round-to-zero mode.
! 69: *
! 70: * 4. Normalize the rounded result; store in fp0.
! 71: *
! 72: * For the denormalized cases, force the correct result
! 73: * for the given sign and rounding mode.
! 74: *
! 75: * Sign(X)
! 76: * RMODE + -
! 77: * ----- --------
! 78: * RN +0 -0
! 79: * RZ +0 -0
! 80: * RM +0 -1
! 81: * RP +1 -0
! 82: *
! 83:
! 84: SINT IDNT 2,1 Motorola 040 Floating Point Software Package
! 85:
! 86: section 8
! 87:
! 88: include fpsp.h
! 89:
! 90: xref dnrm_lp
! 91: xref nrm_set
! 92: xref round
! 93: xref t_inx2
! 94: xref ld_pone
! 95: xref ld_mone
! 96: xref ld_pzero
! 97: xref ld_mzero
! 98: xref snzrinx
! 99:
! 100: *
! 101: * FINT
! 102: *
! 103: xdef sint
! 104: sint:
! 105: bfextu FPCR_MODE(a6){2:2},d1 ;use user's mode for rounding
! 106: * ;implicity has extend precision
! 107: * ;in upper word.
! 108: move.l d1,L_SCR1(a6) ;save mode bits
! 109: bra.b sintexc
! 110:
! 111: *
! 112: * FINT with extended denorm inputs.
! 113: *
! 114: xdef sintd
! 115: sintd:
! 116: btst.b #5,FPCR_MODE(a6)
! 117: beq snzrinx ;if round nearest or round zero, +/- 0
! 118: btst.b #4,FPCR_MODE(a6)
! 119: beq.b rnd_mns
! 120: rnd_pls:
! 121: btst.b #sign_bit,LOCAL_EX(a0)
! 122: bne.b sintmz
! 123: bsr ld_pone ;if round plus inf and pos, answer is +1
! 124: bra t_inx2
! 125: rnd_mns:
! 126: btst.b #sign_bit,LOCAL_EX(a0)
! 127: beq.b sintpz
! 128: bsr ld_mone ;if round mns inf and neg, answer is -1
! 129: bra t_inx2
! 130: sintpz:
! 131: bsr ld_pzero
! 132: bra t_inx2
! 133: sintmz:
! 134: bsr ld_mzero
! 135: bra t_inx2
! 136:
! 137: *
! 138: * FINTRZ
! 139: *
! 140: xdef sintrz
! 141: sintrz:
! 142: move.l #1,L_SCR1(a6) ;use rz mode for rounding
! 143: * ;implicity has extend precision
! 144: * ;in upper word.
! 145: bra.b sintexc
! 146: *
! 147: * SINTDO
! 148: *
! 149: * Input: a0 points to an IEEE extended format operand
! 150: * Output: fp0 has the result
! 151: *
! 152: * Exeptions:
! 153: *
! 154: * If the subroutine results in an inexact operation, the inx2 and
! 155: * ainx bits in the USER_FPSR are set.
! 156: *
! 157: *
! 158: xdef sintdo
! 159: sintdo:
! 160: bfextu FPCR_MODE(a6){2:2},d1 ;use user's mode for rounding
! 161: * ;implicitly has ext precision
! 162: * ;in upper word.
! 163: move.l d1,L_SCR1(a6) ;save mode bits
! 164: *
! 165: * Real work of sint is in sintexc
! 166: *
! 167: sintexc:
! 168: bclr.b #sign_bit,LOCAL_EX(a0) ;convert to internal extended
! 169: * ;format
! 170: sne LOCAL_SGN(a0)
! 171: cmp.w #$403e,LOCAL_EX(a0) ;check if (unbiased) exp > 63
! 172: bgt.b out_rnge ;branch if exp < 63
! 173: cmp.w #$3ffd,LOCAL_EX(a0) ;check if (unbiased) exp < 0
! 174: bgt.w in_rnge ;if 63 >= exp > 0, do calc
! 175: *
! 176: * Input is less than zero. Restore sign, and check for directed
! 177: * rounding modes. L_SCR1 contains the rmode in the lower byte.
! 178: *
! 179: un_rnge:
! 180: btst.b #1,L_SCR1+3(a6) ;check for rn and rz
! 181: beq.b un_rnrz
! 182: tst.b LOCAL_SGN(a0) ;check for sign
! 183: bne.b un_rmrp_neg
! 184: *
! 185: * Sign is +. If rp, load +1.0, if rm, load +0.0
! 186: *
! 187: cmpi.b #3,L_SCR1+3(a6) ;check for rp
! 188: beq.b un_ldpone ;if rp, load +1.0
! 189: bsr ld_pzero ;if rm, load +0.0
! 190: bra t_inx2
! 191: un_ldpone:
! 192: bsr ld_pone
! 193: bra t_inx2
! 194: *
! 195: * Sign is -. If rm, load -1.0, if rp, load -0.0
! 196: *
! 197: un_rmrp_neg:
! 198: cmpi.b #2,L_SCR1+3(a6) ;check for rm
! 199: beq.b un_ldmone ;if rm, load -1.0
! 200: bsr ld_mzero ;if rp, load -0.0
! 201: bra t_inx2
! 202: un_ldmone:
! 203: bsr ld_mone
! 204: bra t_inx2
! 205: *
! 206: * Rmode is rn or rz; return signed zero
! 207: *
! 208: un_rnrz:
! 209: tst.b LOCAL_SGN(a0) ;check for sign
! 210: bne.b un_rnrz_neg
! 211: bsr ld_pzero
! 212: bra t_inx2
! 213: un_rnrz_neg:
! 214: bsr ld_mzero
! 215: bra t_inx2
! 216:
! 217: *
! 218: * Input is greater than 2^63. All bits are significant. Return
! 219: * the input.
! 220: *
! 221: out_rnge:
! 222: bfclr LOCAL_SGN(a0){0:8} ;change back to IEEE ext format
! 223: beq.b intps
! 224: bset.b #sign_bit,LOCAL_EX(a0)
! 225: intps:
! 226: fmove.l fpcr,-(sp)
! 227: fmove.l #0,fpcr
! 228: fmove.x LOCAL_EX(a0),fp0 ;if exp > 63
! 229: * ;then return X to the user
! 230: * ;there are no fraction bits
! 231: fmove.l (sp)+,fpcr
! 232: rts
! 233:
! 234: in_rnge:
! 235: * ;shift off fraction bits
! 236: clr.l d0 ;clear d0 - initial g,r,s for
! 237: * ;dnrm_lp
! 238: move.l #$403e,d1 ;set threshold for dnrm_lp
! 239: * ;assumes a0 points to operand
! 240: bsr dnrm_lp
! 241: * ;returns unnormalized number
! 242: * ;pointed by a0
! 243: * ;output d0 supplies g,r,s
! 244: * ;used by round
! 245: move.l L_SCR1(a6),d1 ;use selected rounding mode
! 246: *
! 247: *
! 248: bsr round ;round the unnorm based on users
! 249: * ;input a0 ptr to ext X
! 250: * ; d0 g,r,s bits
! 251: * ; d1 PREC/MODE info
! 252: * ;output a0 ptr to rounded result
! 253: * ;inexact flag set in USER_FPSR
! 254: * ;if initial grs set
! 255: *
! 256: * normalize the rounded result and store value in fp0
! 257: *
! 258: bsr nrm_set ;normalize the unnorm
! 259: * ;Input: a0 points to operand to
! 260: * ;be normalized
! 261: * ;Output: a0 points to normalized
! 262: * ;result
! 263: bfclr LOCAL_SGN(a0){0:8}
! 264: beq.b nrmrndp
! 265: bset.b #sign_bit,LOCAL_EX(a0) ;return to IEEE extended format
! 266: nrmrndp:
! 267: fmove.l fpcr,-(sp)
! 268: fmove.l #0,fpcr
! 269: fmove.x LOCAL_EX(a0),fp0 ;move result to fp0
! 270: fmove.l (sp)+,fpcr
! 271: rts
! 272:
! 273: end
CVSweb