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