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