slog2.sa revision 1.1.1.1 1 * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
2 * M68000 Hi-Performance Microprocessor Division
3 * M68040 Software Package
4 *
5 * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
6 * All rights reserved.
7 *
8 * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
9 * To the maximum extent permitted by applicable law,
10 * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
11 * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
12 * PARTICULAR PURPOSE and any warranty against infringement with
13 * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
14 * and any accompanying written materials.
15 *
16 * To the maximum extent permitted by applicable law,
17 * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
18 * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
19 * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
20 * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
21 * SOFTWARE. Motorola assumes no responsibility for the maintenance
22 * and support of the SOFTWARE.
23 *
24 * You are hereby granted a copyright license to use, modify, and
25 * distribute the SOFTWARE so long as this entire notice is retained
26 * without alteration in any modified and/or redistributed versions,
27 * and that such modified versions are clearly identified as such.
28 * No licenses are granted by implication, estoppel or otherwise
29 * under any patents or trademarks of Motorola, Inc.
30
31 *
32 * slog2.sa 3.1 12/10/90
33 *
34 * The entry point slog10 computes the base-10
35 * logarithm of an input argument X.
36 * slog10d does the same except the input value is a
37 * denormalized number.
38 * sLog2 and sLog2d are the base-2 analogues.
39 *
40 * INPUT: Double-extended value in memory location pointed to
41 * by address register a0.
42 *
43 * OUTPUT: log_10(X) or log_2(X) returned in floating-point
44 * register fp0.
45 *
46 * ACCURACY and MONOTONICITY: The returned result is within 1.7
47 * ulps in 64 significant bit, i.e. within 0.5003 ulp
48 * to 53 bits if the result is subsequently rounded
49 * to double precision. The result is provably monotonic
50 * in double precision.
51 *
52 * SPEED: Two timings are measured, both in the copy-back mode.
53 * The first one is measured when the function is invoked
54 * the first time (so the instructions and data are not
55 * in cache), and the second one is measured when the
56 * function is reinvoked at the same input argument.
57 *
58 * ALGORITHM and IMPLEMENTATION NOTES:
59 *
60 * slog10d:
61 *
62 * Step 0. If X < 0, create a NaN and raise the invalid operation
63 * flag. Otherwise, save FPCR in D1; set FpCR to default.
64 * Notes: Default means round-to-nearest mode, no floating-point
65 * traps, and precision control = double extended.
66 *
67 * Step 1. Call slognd to obtain Y = log(X), the natural log of X.
68 * Notes: Even if X is denormalized, log(X) is always normalized.
69 *
70 * Step 2. Compute log_10(X) = log(X) * (1/log(10)).
71 * 2.1 Restore the user FPCR
72 * 2.2 Return ans := Y * INV_L10.
73 *
74 *
75 * slog10:
76 *
77 * Step 0. If X < 0, create a NaN and raise the invalid operation
78 * flag. Otherwise, save FPCR in D1; set FpCR to default.
79 * Notes: Default means round-to-nearest mode, no floating-point
80 * traps, and precision control = double extended.
81 *
82 * Step 1. Call sLogN to obtain Y = log(X), the natural log of X.
83 *
84 * Step 2. Compute log_10(X) = log(X) * (1/log(10)).
85 * 2.1 Restore the user FPCR
86 * 2.2 Return ans := Y * INV_L10.
87 *
88 *
89 * sLog2d:
90 *
91 * Step 0. If X < 0, create a NaN and raise the invalid operation
92 * flag. Otherwise, save FPCR in D1; set FpCR to default.
93 * Notes: Default means round-to-nearest mode, no floating-point
94 * traps, and precision control = double extended.
95 *
96 * Step 1. Call slognd to obtain Y = log(X), the natural log of X.
97 * Notes: Even if X is denormalized, log(X) is always normalized.
98 *
99 * Step 2. Compute log_10(X) = log(X) * (1/log(2)).
100 * 2.1 Restore the user FPCR
101 * 2.2 Return ans := Y * INV_L2.
102 *
103 *
104 * sLog2:
105 *
106 * Step 0. If X < 0, create a NaN and raise the invalid operation
107 * flag. Otherwise, save FPCR in D1; set FpCR to default.
108 * Notes: Default means round-to-nearest mode, no floating-point
109 * traps, and precision control = double extended.
110 *
111 * Step 1. If X is not an integer power of two, i.e., X != 2^k,
112 * go to Step 3.
113 *
114 * Step 2. Return k.
115 * 2.1 Get integer k, X = 2^k.
116 * 2.2 Restore the user FPCR.
117 * 2.3 Return ans := convert-to-double-extended(k).
118 *
119 * Step 3. Call sLogN to obtain Y = log(X), the natural log of X.
120 *
121 * Step 4. Compute log_2(X) = log(X) * (1/log(2)).
122 * 4.1 Restore the user FPCR
123 * 4.2 Return ans := Y * INV_L2.
124 *
125
126 SLOG2 IDNT 2,1 Motorola 040 Floating Point Software Package
127
128 section 8
129
130 xref t_frcinx
131 xref t_operr
132 xref slogn
133 xref slognd
134
135 INV_L10 DC.L $3FFD0000,$DE5BD8A9,$37287195,$00000000
136
137 INV_L2 DC.L $3FFF0000,$B8AA3B29,$5C17F0BC,$00000000
138
139 xdef slog10d
140 slog10d:
141 *--entry point for Log10(X), X is denormalized
142 move.l (a0),d0
143 blt.w invalid
144 move.l d1,-(sp)
145 clr.l d1
146 bsr slognd ...log(X), X denorm.
147 fmove.l (sp)+,fpcr
148 fmul.x INV_L10,fp0
149 bra t_frcinx
150
151 xdef slog10
152 slog10:
153 *--entry point for Log10(X), X is normalized
154
155 move.l (a0),d0
156 blt.w invalid
157 move.l d1,-(sp)
158 clr.l d1
159 bsr slogn ...log(X), X normal.
160 fmove.l (sp)+,fpcr
161 fmul.x INV_L10,fp0
162 bra t_frcinx
163
164
165 xdef slog2d
166 slog2d:
167 *--entry point for Log2(X), X is denormalized
168
169 move.l (a0),d0
170 blt.w invalid
171 move.l d1,-(sp)
172 clr.l d1
173 bsr slognd ...log(X), X denorm.
174 fmove.l (sp)+,fpcr
175 fmul.x INV_L2,fp0
176 bra t_frcinx
177
178 xdef slog2
179 slog2:
180 *--entry point for Log2(X), X is normalized
181 move.l (a0),d0
182 blt.w invalid
183
184 move.l 8(a0),d0
185 bne.b continue ...X is not 2^k
186
187 move.l 4(a0),d0
188 and.l #$7FFFFFFF,d0
189 tst.l d0
190 bne.b continue
191
192 *--X = 2^k.
193 move.w (a0),d0
194 and.l #$00007FFF,d0
195 sub.l #$3FFF,d0
196 fmove.l d1,fpcr
197 fmove.l d0,fp0
198 bra t_frcinx
199
200 continue:
201 move.l d1,-(sp)
202 clr.l d1
203 bsr slogn ...log(X), X normal.
204 fmove.l (sp)+,fpcr
205 fmul.x INV_L2,fp0
206 bra t_frcinx
207
208 invalid:
209 bra t_operr
210
211 end
212