slog2.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. |
  2. | slog2.sa 3.1 12/10/90
  3. |
  4. | The entry point slog10 computes the base-10
  5. | logarithm of an input argument X.
  6. | slog10d does the same except the input value is a
  7. | denormalized number.
  8. | sLog2 and sLog2d are the base-2 analogues.
  9. |
  10. | INPUT: Double-extended value in memory location pointed to
  11. | by address register a0.
  12. |
  13. | OUTPUT: log_10(X) or log_2(X) returned in floating-point
  14. | register fp0.
  15. |
  16. | ACCURACY and MONOTONICITY: The returned result is within 1.7
  17. | ulps in 64 significant bit, i.e. within 0.5003 ulp
  18. | to 53 bits if the result is subsequently rounded
  19. | to double precision. The result is provably monotonic
  20. | in double precision.
  21. |
  22. | SPEED: Two timings are measured, both in the copy-back mode.
  23. | The first one is measured when the function is invoked
  24. | the first time (so the instructions and data are not
  25. | in cache), and the second one is measured when the
  26. | function is reinvoked at the same input argument.
  27. |
  28. | ALGORITHM and IMPLEMENTATION NOTES:
  29. |
  30. | slog10d:
  31. |
  32. | Step 0. If X < 0, create a NaN and raise the invalid operation
  33. | flag. Otherwise, save FPCR in D1; set FpCR to default.
  34. | Notes: Default means round-to-nearest mode, no floating-point
  35. | traps, and precision control = double extended.
  36. |
  37. | Step 1. Call slognd to obtain Y = log(X), the natural log of X.
  38. | Notes: Even if X is denormalized, log(X) is always normalized.
  39. |
  40. | Step 2. Compute log_10(X) = log(X) * (1/log(10)).
  41. | 2.1 Restore the user FPCR
  42. | 2.2 Return ans := Y * INV_L10.
  43. |
  44. |
  45. | slog10:
  46. |
  47. | Step 0. If X < 0, create a NaN and raise the invalid operation
  48. | flag. Otherwise, save FPCR in D1; set FpCR to default.
  49. | Notes: Default means round-to-nearest mode, no floating-point
  50. | traps, and precision control = double extended.
  51. |
  52. | Step 1. Call sLogN to obtain Y = log(X), the natural log of X.
  53. |
  54. | Step 2. Compute log_10(X) = log(X) * (1/log(10)).
  55. | 2.1 Restore the user FPCR
  56. | 2.2 Return ans := Y * INV_L10.
  57. |
  58. |
  59. | sLog2d:
  60. |
  61. | Step 0. If X < 0, create a NaN and raise the invalid operation
  62. | flag. Otherwise, save FPCR in D1; set FpCR to default.
  63. | Notes: Default means round-to-nearest mode, no floating-point
  64. | traps, and precision control = double extended.
  65. |
  66. | Step 1. Call slognd to obtain Y = log(X), the natural log of X.
  67. | Notes: Even if X is denormalized, log(X) is always normalized.
  68. |
  69. | Step 2. Compute log_10(X) = log(X) * (1/log(2)).
  70. | 2.1 Restore the user FPCR
  71. | 2.2 Return ans := Y * INV_L2.
  72. |
  73. |
  74. | sLog2:
  75. |
  76. | Step 0. If X < 0, create a NaN and raise the invalid operation
  77. | flag. Otherwise, save FPCR in D1; set FpCR to default.
  78. | Notes: Default means round-to-nearest mode, no floating-point
  79. | traps, and precision control = double extended.
  80. |
  81. | Step 1. If X is not an integer power of two, i.e., X != 2^k,
  82. | go to Step 3.
  83. |
  84. | Step 2. Return k.
  85. | 2.1 Get integer k, X = 2^k.
  86. | 2.2 Restore the user FPCR.
  87. | 2.3 Return ans := convert-to-double-extended(k).
  88. |
  89. | Step 3. Call sLogN to obtain Y = log(X), the natural log of X.
  90. |
  91. | Step 4. Compute log_2(X) = log(X) * (1/log(2)).
  92. | 4.1 Restore the user FPCR
  93. | 4.2 Return ans := Y * INV_L2.
  94. |
  95. | Copyright (C) Motorola, Inc. 1990
  96. | All Rights Reserved
  97. |
  98. | THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA
  99. | The copyright notice above does not evidence any
  100. | actual or intended publication of such source code.
  101. |SLOG2 idnt 2,1 | Motorola 040 Floating Point Software Package
  102. |section 8
  103. |xref t_frcinx
  104. |xref t_operr
  105. |xref slogn
  106. |xref slognd
  107. INV_L10: .long 0x3FFD0000,0xDE5BD8A9,0x37287195,0x00000000
  108. INV_L2: .long 0x3FFF0000,0xB8AA3B29,0x5C17F0BC,0x00000000
  109. .global slog10d
  110. slog10d:
  111. |--entry point for Log10(X), X is denormalized
  112. movel (%a0),%d0
  113. blt invalid
  114. movel %d1,-(%sp)
  115. clrl %d1
  116. bsr slognd | ...log(X), X denorm.
  117. fmovel (%sp)+,%fpcr
  118. fmulx INV_L10,%fp0
  119. bra t_frcinx
  120. .global slog10
  121. slog10:
  122. |--entry point for Log10(X), X is normalized
  123. movel (%a0),%d0
  124. blt invalid
  125. movel %d1,-(%sp)
  126. clrl %d1
  127. bsr slogn | ...log(X), X normal.
  128. fmovel (%sp)+,%fpcr
  129. fmulx INV_L10,%fp0
  130. bra t_frcinx
  131. .global slog2d
  132. slog2d:
  133. |--entry point for Log2(X), X is denormalized
  134. movel (%a0),%d0
  135. blt invalid
  136. movel %d1,-(%sp)
  137. clrl %d1
  138. bsr slognd | ...log(X), X denorm.
  139. fmovel (%sp)+,%fpcr
  140. fmulx INV_L2,%fp0
  141. bra t_frcinx
  142. .global slog2
  143. slog2:
  144. |--entry point for Log2(X), X is normalized
  145. movel (%a0),%d0
  146. blt invalid
  147. movel 8(%a0),%d0
  148. bnes continue | ...X is not 2^k
  149. movel 4(%a0),%d0
  150. andl #0x7FFFFFFF,%d0
  151. tstl %d0
  152. bnes continue
  153. |--X = 2^k.
  154. movew (%a0),%d0
  155. andl #0x00007FFF,%d0
  156. subl #0x3FFF,%d0
  157. fmovel %d1,%fpcr
  158. fmovel %d0,%fp0
  159. bra t_frcinx
  160. continue:
  161. movel %d1,-(%sp)
  162. clrl %d1
  163. bsr slogn | ...log(X), X normal.
  164. fmovel (%sp)+,%fpcr
  165. fmulx INV_L2,%fp0
  166. bra t_frcinx
  167. invalid:
  168. bra t_operr
  169. |end