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