Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:49

0001 #include "fpsp-namespace.h"
0002 //
0003 //
0004 //  sgetem.sa 3.1 12/10/90
0005 //
0006 //  The entry point sGETEXP returns the exponent portion
0007 //  of the input argument.  The exponent bias is removed
0008 //  and the exponent value is returned as an extended
0009 //  precision number in fp0.  sGETEXPD handles denormalized
0010 //  numbers.
0011 //
0012 //  The entry point sGETMAN extracts the mantissa of the
0013 //  input argument.  The mantissa is converted to an
0014 //  extended precision number and returned in fp0.  The
0015 //  range of the result is [1.0 - 2.0).
0016 //
0017 //
0018 //  Input:  Double-extended number X in the ETEMP space in
0019 //      the floating-point save stack.
0020 //
0021 //  Output: The functions return exp(X) or man(X) in fp0.
0022 //
0023 //  Modified: fp0.
0024 //
0025 //
0026 //      Copyright (C) Motorola, Inc. 1990
0027 //          All Rights Reserved
0028 //
0029 //  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA
0030 //  The copyright notice above does not evidence any
0031 //  actual or intended publication of such source code.
0032 
0033 //SGETEM    idnt    2,1 | Motorola 040 Floating Point Software Package
0034 
0035     |section 8
0036 
0037 #include "fpsp.defs"
0038 
0039     |xref   nrm_set
0040 
0041 //
0042 // This entry point is used by the unimplemented instruction exception
0043 // handler.  It points a0 to the input operand.
0044 //
0045 //
0046 //
0047 //  SGETEXP
0048 //
0049 
0050     .global sgetexp
0051 sgetexp:
0052     movew   LOCAL_EX(%a0),%d0   //get the exponent
0053     bclrl   #15,%d0     //clear the sign bit
0054     subw    #0x3fff,%d0 //subtract off the bias
0055     fmovew  %d0,%fp0        //move the exp to fp0
0056     rts
0057 
0058     .global sgetexpd
0059 sgetexpd:
0060     bclrb   #sign_bit,LOCAL_EX(%a0)
0061     bsr nrm_set     //normalize (exp will go negative)
0062     movew   LOCAL_EX(%a0),%d0   //load resulting exponent into d0
0063     subw    #0x3fff,%d0 //subtract off the bias
0064     fmovew  %d0,%fp0        //move the exp to fp0
0065     rts
0066 //
0067 //
0068 // This entry point is used by the unimplemented instruction exception
0069 // handler.  It points a0 to the input operand.
0070 //
0071 //
0072 //
0073 //  SGETMAN
0074 //
0075 //
0076 // For normalized numbers, leave the mantissa alone, simply load
0077 // with an exponent of +/- $3fff.
0078 //
0079     .global sgetman
0080 sgetman:
0081     movel   USER_FPCR(%a6),%d0
0082     andil   #0xffffff00,%d0 //clear rounding precision and mode
0083     fmovel  %d0,%fpcr       //this fpcr setting is used by the 882
0084     movew   LOCAL_EX(%a0),%d0   //get the exp (really just want sign bit)
0085     orw #0x7fff,%d0 //clear old exp
0086     bclrl   #14,%d0     //make it the new exp +-3fff
0087     movew   %d0,LOCAL_EX(%a0)   //move the sign & exp back to fsave stack
0088     fmovex  (%a0),%fp0  //put new value back in fp0
0089     rts
0090 
0091 //
0092 // For denormalized numbers, shift the mantissa until the j-bit = 1,
0093 // then load the exponent with +/1 $3fff.
0094 //
0095     .global sgetmand
0096 sgetmand:
0097     movel   LOCAL_HI(%a0),%d0   //load ms mant in d0
0098     movel   LOCAL_LO(%a0),%d1   //load ls mant in d1
0099     bsr shft        //shift mantissa bits till msbit is set
0100     movel   %d0,LOCAL_HI(%a0)   //put ms mant back on stack
0101     movel   %d1,LOCAL_LO(%a0)   //put ls mant back on stack
0102     bras    sgetman
0103 
0104 //
0105 //  SHFT
0106 //
0107 //  Shifts the mantissa bits until msbit is set.
0108 //  input:
0109 //      ms mantissa part in d0
0110 //      ls mantissa part in d1
0111 //  output:
0112 //      shifted bits in d0 and d1
0113 shft:
0114     tstl    %d0     //if any bits set in ms mant
0115     bnes    upper       //then branch
0116 //              ;else no bits set in ms mant
0117     tstl    %d1     //test if any bits set in ls mant
0118     bnes    cont        //if set then continue
0119     bras    shft_end    //else return
0120 cont:
0121     movel   %d3,-(%a7)  //save d3
0122     exg %d0,%d1     //shift ls mant to ms mant
0123     bfffo   %d0{#0:#32},%d3 //find first 1 in ls mant to d0
0124     lsll    %d3,%d0     //shift first 1 to integer bit in ms mant
0125     movel   (%a7)+,%d3  //restore d3
0126     bras    shft_end
0127 upper:
0128 
0129     moveml  %d3/%d5/%d6,-(%a7)  //save registers
0130     bfffo   %d0{#0:#32},%d3 //find first 1 in ls mant to d0
0131     lsll    %d3,%d0     //shift ms mant until j-bit is set
0132     movel   %d1,%d6     //save ls mant in d6
0133     lsll    %d3,%d1     //shift ls mant by count
0134     movel   #32,%d5
0135     subl    %d3,%d5     //sub 32 from shift for ls mant
0136     lsrl    %d5,%d6     //shift off all bits but those that will
0137 //              ;be shifted into ms mant
0138     orl %d6,%d0     //shift the ls mant bits into the ms mant
0139     moveml  (%a7)+,%d3/%d5/%d6  //restore registers
0140 shft_end:
0141     rts
0142 
0143     |end