sgetem.sa revision 1.1       1 *	MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
      2 *	M68000 Hi-Performance Microprocessor Division
      3 *	M68040 Software Package 
      4 *
      5 *	M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
      6 *	All rights reserved.
      7 *
      8 *	THE SOFTWARE is provided on an "AS IS" basis and without warranty.
      9 *	To the maximum extent permitted by applicable law,
     10 *	MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
     11 *	INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
     12 *	PARTICULAR PURPOSE and any warranty against infringement with
     13 *	regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
     14 *	and any accompanying written materials. 
     15 *
     16 *	To the maximum extent permitted by applicable law,
     17 *	IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
     18 *	(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
     19 *	PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
     20 *	OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
     21 *	SOFTWARE.  Motorola assumes no responsibility for the maintenance
     22 *	and support of the SOFTWARE.  
     23 *
     24 *	You are hereby granted a copyright license to use, modify, and
     25 *	distribute the SOFTWARE so long as this entire notice is retained
     26 *	without alteration in any modified and/or redistributed versions,
     27 *	and that such modified versions are clearly identified as such.
     28 *	No licenses are granted by implication, estoppel or otherwise
     29 *	under any patents or trademarks of Motorola, Inc.
     30 
     31 *
     32 *	sgetem.sa 3.1 12/10/90
     33 *
     34 *	The entry point sGETEXP returns the exponent portion 
     35 *	of the input argument.  The exponent bias is removed
     36 *	and the exponent value is returned as an extended 
     37 *	precision number in fp0.  sGETEXPD handles denormalized
     38 *	numbers.
     39 *
     40 *	The entry point sGETMAN extracts the mantissa of the 
     41 *	input argument.  The mantissa is converted to an 
     42 *	extended precision number and returned in fp0.  The
     43 *	range of the result is [1.0 - 2.0).
     44 *
     45 *
     46 *	Input:  Double-extended number X in the ETEMP space in
     47 *		the floating-point save stack.
     48 *
     49 *	Output:	The functions return exp(X) or man(X) in fp0.
     50 *
     51 *	Modified: fp0.
     52 *
     53 
     54 SGETEM	IDNT	2,1 Motorola 040 Floating Point Software Package
     55 
     56 	section 8
     57 
     58 	include fpsp.h
     59 
     60 	xref	nrm_set
     61 
     62 *
     63 * This entry point is used by the unimplemented instruction exception
     64 * handler.  It points a0 to the input operand.
     65 *
     66 *
     67 *
     68 *	SGETEXP
     69 *
     70 
     71 	xdef	sgetexp
     72 sgetexp:
     73 	move.w	LOCAL_EX(a0),d0	;get the exponent
     74 	bclr.l	#15,d0		;clear the sign bit
     75 	sub.w	#$3fff,d0	;subtract off the bias
     76 	fmove.w  d0,fp0		;move the exp to fp0
     77 	rts
     78 
     79 	xdef	sgetexpd
     80 sgetexpd:
     81 	bclr.b	#sign_bit,LOCAL_EX(a0)
     82 	bsr	nrm_set		;normalize (exp will go negative)
     83 	move.w	LOCAL_EX(a0),d0	;load resulting exponent into d0
     84 	sub.w	#$3fff,d0	;subtract off the bias
     85 	fmove.w	d0,fp0		;move the exp to fp0
     86 	rts
     87 *
     88 *
     89 * This entry point is used by the unimplemented instruction exception
     90 * handler.  It points a0 to the input operand.
     91 *
     92 *
     93 *
     94 *	SGETMAN
     95 *
     96 *
     97 * For normalized numbers, leave the mantissa alone, simply load
     98 * with an exponent of +/- $3fff.
     99 *
    100 	xdef	sgetman
    101 sgetman:
    102 	move.l	USER_FPCR(a6),d0
    103 	andi.l	#$ffffff00,d0	;clear rounding precision and mode
    104 	fmove.l	d0,fpcr		;this fpcr setting is used by the 882
    105 	move.w	LOCAL_EX(a0),d0	;get the exp (really just want sign bit)
    106 	or.w	#$7fff,d0	;clear old exp
    107 	bclr.l	#14,d0	 	;make it the new exp +-3fff
    108 	move.w	d0,LOCAL_EX(a0)	;move the sign & exp back to fsave stack
    109 	fmove.x	(a0),fp0	;put new value back in fp0
    110 	rts
    111 
    112 *
    113 * For denormalized numbers, shift the mantissa until the j-bit = 1,
    114 * then load the exponent with +/1 $3fff.
    115 *
    116 	xdef	sgetmand
    117 sgetmand:
    118 	move.l	LOCAL_HI(a0),d0	;load ms mant in d0
    119 	move.l	LOCAL_LO(a0),d1	;load ls mant in d1
    120 	bsr	shft		;shift mantissa bits till msbit is set
    121 	move.l	d0,LOCAL_HI(a0)	;put ms mant back on stack
    122 	move.l	d1,LOCAL_LO(a0)	;put ls mant back on stack
    123 	bra.b	sgetman
    124 
    125 *
    126 *	SHFT
    127 *
    128 *	Shifts the mantissa bits until msbit is set.
    129 *	input:
    130 *		ms mantissa part in d0
    131 *		ls mantissa part in d1
    132 *	output:
    133 *		shifted bits in d0 and d1
    134 shft:
    135 	tst.l	d0		;if any bits set in ms mant
    136 	bne.b	upper		;then branch
    137 *				;else no bits set in ms mant
    138 	tst.l	d1		;test if any bits set in ls mant
    139 	bne.b	cont		;if set then continue
    140 	bra.b	shft_end	;else return
    141 cont:
    142 	move.l	d3,-(a7)	;save d3
    143 	exg	d0,d1		;shift ls mant to ms mant
    144 	bfffo	d0{0:32},d3	;find first 1 in ls mant to d0
    145 	lsl.l	d3,d0		;shift first 1 to integer bit in ms mant
    146 	move.l	(a7)+,d3	;restore d3
    147 	bra.b	shft_end
    148 upper:
    149 
    150 	movem.l	d3/d5/d6,-(a7)	;save registers
    151 	bfffo	d0{0:32},d3	;find first 1 in ls mant to d0
    152 	lsl.l	d3,d0		;shift ms mant until j-bit is set
    153 	move.l	d1,d6		;save ls mant in d6
    154 	lsl.l	d3,d1		;shift ls mant by count
    155 	move.l	#32,d5
    156 	sub.l	d3,d5		;sub 32 from shift for ls mant
    157 	lsr.l	d5,d6		;shift off all bits but those that will
    158 *				;be shifted into ms mant
    159 	or.l	d6,d0		;shift the ls mant bits into the ms mant
    160 	movem.l	(a7)+,d3/d5/d6	;restore registers
    161 shft_end:
    162 	rts
    163 
    164 	end
    165