sgetem.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. |
  2. | sgetem.sa 3.1 12/10/90
  3. |
  4. | The entry point sGETEXP returns the exponent portion
  5. | of the input argument. The exponent bias is removed
  6. | and the exponent value is returned as an extended
  7. | precision number in fp0. sGETEXPD handles denormalized
  8. | numbers.
  9. |
  10. | The entry point sGETMAN extracts the mantissa of the
  11. | input argument. The mantissa is converted to an
  12. | extended precision number and returned in fp0. The
  13. | range of the result is [1.0 - 2.0).
  14. |
  15. |
  16. | Input: Double-extended number X in the ETEMP space in
  17. | the floating-point save stack.
  18. |
  19. | Output: The functions return exp(X) or man(X) in fp0.
  20. |
  21. | Modified: fp0.
  22. |
  23. |
  24. | Copyright (C) Motorola, Inc. 1990
  25. | All Rights Reserved
  26. |
  27. | For details on the license for this file, please see the
  28. | file, README, in this same directory.
  29. |SGETEM idnt 2,1 | Motorola 040 Floating Point Software Package
  30. |section 8
  31. #include "fpsp.h"
  32. |xref nrm_set
  33. |
  34. | This entry point is used by the unimplemented instruction exception
  35. | handler. It points a0 to the input operand.
  36. |
  37. |
  38. |
  39. | SGETEXP
  40. |
  41. .global sgetexp
  42. sgetexp:
  43. movew LOCAL_EX(%a0),%d0 |get the exponent
  44. bclrl #15,%d0 |clear the sign bit
  45. subw #0x3fff,%d0 |subtract off the bias
  46. fmovew %d0,%fp0 |move the exp to fp0
  47. rts
  48. .global sgetexpd
  49. sgetexpd:
  50. bclrb #sign_bit,LOCAL_EX(%a0)
  51. bsr nrm_set |normalize (exp will go negative)
  52. movew LOCAL_EX(%a0),%d0 |load resulting exponent into d0
  53. subw #0x3fff,%d0 |subtract off the bias
  54. fmovew %d0,%fp0 |move the exp to fp0
  55. rts
  56. |
  57. |
  58. | This entry point is used by the unimplemented instruction exception
  59. | handler. It points a0 to the input operand.
  60. |
  61. |
  62. |
  63. | SGETMAN
  64. |
  65. |
  66. | For normalized numbers, leave the mantissa alone, simply load
  67. | with an exponent of +/- $3fff.
  68. |
  69. .global sgetman
  70. sgetman:
  71. movel USER_FPCR(%a6),%d0
  72. andil #0xffffff00,%d0 |clear rounding precision and mode
  73. fmovel %d0,%fpcr |this fpcr setting is used by the 882
  74. movew LOCAL_EX(%a0),%d0 |get the exp (really just want sign bit)
  75. orw #0x7fff,%d0 |clear old exp
  76. bclrl #14,%d0 |make it the new exp +-3fff
  77. movew %d0,LOCAL_EX(%a0) |move the sign & exp back to fsave stack
  78. fmovex (%a0),%fp0 |put new value back in fp0
  79. rts
  80. |
  81. | For denormalized numbers, shift the mantissa until the j-bit = 1,
  82. | then load the exponent with +/1 $3fff.
  83. |
  84. .global sgetmand
  85. sgetmand:
  86. movel LOCAL_HI(%a0),%d0 |load ms mant in d0
  87. movel LOCAL_LO(%a0),%d1 |load ls mant in d1
  88. bsr shft |shift mantissa bits till msbit is set
  89. movel %d0,LOCAL_HI(%a0) |put ms mant back on stack
  90. movel %d1,LOCAL_LO(%a0) |put ls mant back on stack
  91. bras sgetman
  92. |
  93. | SHFT
  94. |
  95. | Shifts the mantissa bits until msbit is set.
  96. | input:
  97. | ms mantissa part in d0
  98. | ls mantissa part in d1
  99. | output:
  100. | shifted bits in d0 and d1
  101. shft:
  102. tstl %d0 |if any bits set in ms mant
  103. bnes upper |then branch
  104. | ;else no bits set in ms mant
  105. tstl %d1 |test if any bits set in ls mant
  106. bnes cont |if set then continue
  107. bras shft_end |else return
  108. cont:
  109. movel %d3,-(%a7) |save d3
  110. exg %d0,%d1 |shift ls mant to ms mant
  111. bfffo %d0{#0:#32},%d3 |find first 1 in ls mant to d0
  112. lsll %d3,%d0 |shift first 1 to integer bit in ms mant
  113. movel (%a7)+,%d3 |restore d3
  114. bras shft_end
  115. upper:
  116. moveml %d3/%d5/%d6,-(%a7) |save registers
  117. bfffo %d0{#0:#32},%d3 |find first 1 in ls mant to d0
  118. lsll %d3,%d0 |shift ms mant until j-bit is set
  119. movel %d1,%d6 |save ls mant in d6
  120. lsll %d3,%d1 |shift ls mant by count
  121. movel #32,%d5
  122. subl %d3,%d5 |sub 32 from shift for ls mant
  123. lsrl %d5,%d6 |shift off all bits but those that will
  124. | ;be shifted into ms mant
  125. orl %d6,%d0 |shift the ls mant bits into the ms mant
  126. moveml (%a7)+,%d3/%d5/%d6 |restore registers
  127. shft_end:
  128. rts
  129. |end