Annotation of sys/arch/m68k/fpsp/sgetem.sa, Revision 1.1
1.1 ! nbrk 1: * $OpenBSD: sgetem.sa,v 1.2 1996/05/29 21:05:37 niklas Exp $
! 2: * $NetBSD: sgetem.sa,v 1.2 1994/10/26 07:49:45 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: * sgetem.sa 3.1 12/10/90
! 36: *
! 37: * The entry point sGETEXP returns the exponent portion
! 38: * of the input argument. The exponent bias is removed
! 39: * and the exponent value is returned as an extended
! 40: * precision number in fp0. sGETEXPD handles denormalized
! 41: * numbers.
! 42: *
! 43: * The entry point sGETMAN extracts the mantissa of the
! 44: * input argument. The mantissa is converted to an
! 45: * extended precision number and returned in fp0. The
! 46: * range of the result is [1.0 - 2.0).
! 47: *
! 48: *
! 49: * Input: Double-extended number X in the ETEMP space in
! 50: * the floating-point save stack.
! 51: *
! 52: * Output: The functions return exp(X) or man(X) in fp0.
! 53: *
! 54: * Modified: fp0.
! 55: *
! 56:
! 57: SGETEM IDNT 2,1 Motorola 040 Floating Point Software Package
! 58:
! 59: section 8
! 60:
! 61: include fpsp.h
! 62:
! 63: xref nrm_set
! 64:
! 65: *
! 66: * This entry point is used by the unimplemented instruction exception
! 67: * handler. It points a0 to the input operand.
! 68: *
! 69: *
! 70: *
! 71: * SGETEXP
! 72: *
! 73:
! 74: xdef sgetexp
! 75: sgetexp:
! 76: move.w LOCAL_EX(a0),d0 ;get the exponent
! 77: bclr.l #15,d0 ;clear the sign bit
! 78: sub.w #$3fff,d0 ;subtract off the bias
! 79: fmove.w d0,fp0 ;move the exp to fp0
! 80: rts
! 81:
! 82: xdef sgetexpd
! 83: sgetexpd:
! 84: bclr.b #sign_bit,LOCAL_EX(a0)
! 85: bsr nrm_set ;normalize (exp will go negative)
! 86: move.w LOCAL_EX(a0),d0 ;load resulting exponent into d0
! 87: sub.w #$3fff,d0 ;subtract off the bias
! 88: fmove.w d0,fp0 ;move the exp to fp0
! 89: rts
! 90: *
! 91: *
! 92: * This entry point is used by the unimplemented instruction exception
! 93: * handler. It points a0 to the input operand.
! 94: *
! 95: *
! 96: *
! 97: * SGETMAN
! 98: *
! 99: *
! 100: * For normalized numbers, leave the mantissa alone, simply load
! 101: * with an exponent of +/- $3fff.
! 102: *
! 103: xdef sgetman
! 104: sgetman:
! 105: move.l USER_FPCR(a6),d0
! 106: andi.l #$ffffff00,d0 ;clear rounding precision and mode
! 107: fmove.l d0,fpcr ;this fpcr setting is used by the 882
! 108: move.w LOCAL_EX(a0),d0 ;get the exp (really just want sign bit)
! 109: or.w #$7fff,d0 ;clear old exp
! 110: bclr.l #14,d0 ;make it the new exp +-3fff
! 111: move.w d0,LOCAL_EX(a0) ;move the sign & exp back to fsave stack
! 112: fmove.x (a0),fp0 ;put new value back in fp0
! 113: rts
! 114:
! 115: *
! 116: * For denormalized numbers, shift the mantissa until the j-bit = 1,
! 117: * then load the exponent with +/1 $3fff.
! 118: *
! 119: xdef sgetmand
! 120: sgetmand:
! 121: move.l LOCAL_HI(a0),d0 ;load ms mant in d0
! 122: move.l LOCAL_LO(a0),d1 ;load ls mant in d1
! 123: bsr shft ;shift mantissa bits till msbit is set
! 124: move.l d0,LOCAL_HI(a0) ;put ms mant back on stack
! 125: move.l d1,LOCAL_LO(a0) ;put ls mant back on stack
! 126: bra.b sgetman
! 127:
! 128: *
! 129: * SHFT
! 130: *
! 131: * Shifts the mantissa bits until msbit is set.
! 132: * input:
! 133: * ms mantissa part in d0
! 134: * ls mantissa part in d1
! 135: * output:
! 136: * shifted bits in d0 and d1
! 137: shft:
! 138: tst.l d0 ;if any bits set in ms mant
! 139: bne.b upper ;then branch
! 140: * ;else no bits set in ms mant
! 141: tst.l d1 ;test if any bits set in ls mant
! 142: bne.b cont ;if set then continue
! 143: bra.b shft_end ;else return
! 144: cont:
! 145: move.l d3,-(a7) ;save d3
! 146: exg d0,d1 ;shift ls mant to ms mant
! 147: bfffo d0{0:32},d3 ;find first 1 in ls mant to d0
! 148: lsl.l d3,d0 ;shift first 1 to integer bit in ms mant
! 149: move.l (a7)+,d3 ;restore d3
! 150: bra.b shft_end
! 151: upper:
! 152:
! 153: movem.l d3/d5/d6,-(a7) ;save registers
! 154: bfffo d0{0:32},d3 ;find first 1 in ls mant to d0
! 155: lsl.l d3,d0 ;shift ms mant until j-bit is set
! 156: move.l d1,d6 ;save ls mant in d6
! 157: lsl.l d3,d1 ;shift ls mant by count
! 158: move.l #32,d5
! 159: sub.l d3,d5 ;sub 32 from shift for ls mant
! 160: lsr.l d5,d6 ;shift off all bits but those that will
! 161: * ;be shifted into ms mant
! 162: or.l d6,d0 ;shift the ls mant bits into the ms mant
! 163: movem.l (a7)+,d3/d5/d6 ;restore registers
! 164: shft_end:
! 165: rts
! 166:
! 167: end
CVSweb