1 * $NetBSD: slog2.sa,v 1.2 1994/10/26 07:49:52 cgd Exp $
3 * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
4 * M68000 Hi-Performance Microprocessor Division
5 * M68040 Software Package
7 * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
10 * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
11 * To the maximum extent permitted by applicable law,
12 * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
13 * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
14 * PARTICULAR PURPOSE and any warranty against infringement with
15 * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
16 * and any accompanying written materials.
18 * To the maximum extent permitted by applicable law,
19 * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
20 * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
21 * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
22 * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
23 * SOFTWARE. Motorola assumes no responsibility for the maintenance
24 * and support of the SOFTWARE.
26 * You are hereby granted a copyright license to use, modify, and
27 * distribute the SOFTWARE so long as this entire notice is retained
28 * without alteration in any modified and/or redistributed versions,
29 * and that such modified versions are clearly identified as such.
30 * No licenses are granted by implication, estoppel or otherwise
31 * under any patents or trademarks of Motorola, Inc.
34 * slog2.sa 3.1 12/10/90
36 * The entry point slog10 computes the base-10
37 * logarithm of an input argument X.
38 * slog10d does the same except the input value is a
39 * denormalized number.
40 * sLog2 and sLog2d are the base-2 analogues.
42 * INPUT: Double-extended value in memory location pointed to
43 * by address register a0.
45 * OUTPUT: log_10(X) or log_2(X) returned in floating-point
48 * ACCURACY and MONOTONICITY: The returned result is within 1.7
49 * ulps in 64 significant bit, i.e. within 0.5003 ulp
50 * to 53 bits if the result is subsequently rounded
51 * to double precision. The result is provably monotonic
52 * in double precision.
54 * SPEED: Two timings are measured, both in the copy-back mode.
55 * The first one is measured when the function is invoked
56 * the first time (so the instructions and data are not
57 * in cache), and the second one is measured when the
58 * function is reinvoked at the same input argument.
60 * ALGORITHM and IMPLEMENTATION NOTES:
64 * Step 0. If X < 0, create a NaN and raise the invalid operation
65 * flag. Otherwise, save FPCR in D1; set FpCR to default.
66 * Notes: Default means round-to-nearest mode, no floating-point
67 * traps, and precision control = double extended.
69 * Step 1. Call slognd to obtain Y = log(X), the natural log of X.
70 * Notes: Even if X is denormalized, log(X) is always normalized.
72 * Step 2. Compute log_10(X) = log(X) * (1/log(10)).
73 * 2.1 Restore the user FPCR
74 * 2.2 Return ans := Y * INV_L10.
79 * Step 0. If X < 0, create a NaN and raise the invalid operation
80 * flag. Otherwise, save FPCR in D1; set FpCR to default.
81 * Notes: Default means round-to-nearest mode, no floating-point
82 * traps, and precision control = double extended.
84 * Step 1. Call sLogN to obtain Y = log(X), the natural log of X.
86 * Step 2. Compute log_10(X) = log(X) * (1/log(10)).
87 * 2.1 Restore the user FPCR
88 * 2.2 Return ans := Y * INV_L10.
93 * Step 0. If X < 0, create a NaN and raise the invalid operation
94 * flag. Otherwise, save FPCR in D1; set FpCR to default.
95 * Notes: Default means round-to-nearest mode, no floating-point
96 * traps, and precision control = double extended.
98 * Step 1. Call slognd to obtain Y = log(X), the natural log of X.
99 * Notes: Even if X is denormalized, log(X) is always normalized.
101 * Step 2. Compute log_10(X) = log(X) * (1/log(2)).
102 * 2.1 Restore the user FPCR
103 * 2.2 Return ans := Y * INV_L2.
108 * Step 0. If X < 0, create a NaN and raise the invalid operation
109 * flag. Otherwise, save FPCR in D1; set FpCR to default.
110 * Notes: Default means round-to-nearest mode, no floating-point
111 * traps, and precision control = double extended.
113 * Step 1. If X is not an integer power of two, i.e., X != 2^k,
117 * 2.1 Get integer k, X = 2^k.
118 * 2.2 Restore the user FPCR.
119 * 2.3 Return ans := convert-to-double-extended(k).
121 * Step 3. Call sLogN to obtain Y = log(X), the natural log of X.
123 * Step 4. Compute log_2(X) = log(X) * (1/log(2)).
124 * 4.1 Restore the user FPCR
125 * 4.2 Return ans := Y * INV_L2.
128 SLOG2 IDNT 2,1 Motorola 040 Floating Point Software Package
137 INV_L10 DC.L $3FFD0000,$DE5BD8A9,$37287195,$00000000
139 INV_L2 DC.L $3FFF0000,$B8AA3B29,$5C17F0BC,$00000000
143 *--entry point for Log10(X), X is denormalized
148 bsr slognd ...log(X), X denorm.
155 *--entry point for Log10(X), X is normalized
161 bsr slogn ...log(X), X normal.
169 *--entry point for Log2(X), X is denormalized
175 bsr slognd ...log(X), X denorm.
182 *--entry point for Log2(X), X is normalized
187 bne.b continue ...X is not 2^k
205 bsr slogn ...log(X), X normal.