]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ia64/fpu/s_log1pl.S
ia64: move from main tree
[thirdparty/glibc.git] / sysdeps / ia64 / fpu / s_log1pl.S
1 .file "log1pl.s"
2
3
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 // Contributed 2000 by the Intel Numerics Group, Intel Corporation
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 //
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // * Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // * The name of Intel Corporation may not be used to endorse or promote
21 // products derived from this software without specific prior written
22 // permission.
23
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
32 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // Intel Corporation is the author of this code, and requests that all
37 // problem reports or change requests be submitted to it directly at
38 // http://www.intel.com/software/products/opensource/libraries/num.htm.
39 //
40 //*********************************************************************
41 //
42 // History:
43 // 02/02/00 Initial version
44 // 04/04/00 Unwind support added
45 // 08/15/00 Bundle added after call to __libm_error_support to properly
46 // set [the previously overwritten] GR_Parameter_RESULT.
47 // 05/21/01 Removed logl and log10l, putting them in a separate file
48 // 06/29/01 Improved speed of all paths
49 // 05/20/02 Cleaned up namespace and sf0 syntax
50 // 02/10/03 Reordered header: .section, .global, .proc, .align;
51 // used data8 for long double table values
52 //
53 //*********************************************************************
54 //
55 //*********************************************************************
56 //
57 // Function: log1pl(x) = ln(x+1), for double-extended precision x values
58 //
59 //*********************************************************************
60 //
61 // Resources Used:
62 //
63 // Floating-Point Registers: f8 (Input and Return Value)
64 // f34-f82
65 //
66 // General Purpose Registers:
67 // r32-r56
68 // r53-r56 (Used to pass arguments to error handling routine)
69 //
70 // Predicate Registers: p6-p13
71 //
72 //*********************************************************************
73 //
74 // IEEE Special Conditions:
75 //
76 // Denormal fault raised on denormal inputs
77 // Overflow exceptions cannot occur
78 // Underflow exceptions raised when appropriate for log1p
79 // Inexact raised when appropriate by algorithm
80 //
81 // log1pl(inf) = inf
82 // log1pl(-inf) = QNaN
83 // log1pl(+/-0) = +/-0
84 // log1pl(-1) = -inf
85 // log1pl(SNaN) = QNaN
86 // log1pl(QNaN) = QNaN
87 // log1pl(EM_special Values) = QNaN
88 //
89 //*********************************************************************
90 //
91 // Overview
92 //
93 // The method consists of three cases.
94 //
95 // If |X| < 2^(-80) use case log1p_small;
96 // else |X| < 2^(-7) use case log_near1;
97 // else use case log_regular;
98 //
99 // Case log1p_small:
100 //
101 // log1pl( X ) = logl( X+1 ) can be approximated by X
102 //
103 // Case log_near1:
104 //
105 // log1pl( X ) = log( X+1 ) can be approximated by a simple polynomial
106 // in W = X. This polynomial resembles the truncated Taylor
107 // series W - W^/2 + W^3/3 - ...
108 //
109 // Case log_regular:
110 //
111 // Here we use a table lookup method. The basic idea is that in
112 // order to compute logl(Arg) = log1pl (Arg-1) for an argument Arg in [1,2),
113 // we construct a value G such that G*Arg is close to 1 and that
114 // logl(1/G) is obtainable easily from a table of values calculated
115 // beforehand. Thus
116 //
117 // logl(Arg) = logl(1/G) + logl(G*Arg)
118 // = logl(1/G) + logl(1 + (G*Arg - 1))
119 //
120 // Because |G*Arg - 1| is small, the second term on the right hand
121 // side can be approximated by a short polynomial. We elaborate
122 // this method in four steps.
123 //
124 // Step 0: Initialization
125 //
126 // We need to calculate logl( X+1 ). Obtain N, S_hi such that
127 //
128 // X+1 = 2^N * ( S_hi + S_lo ) exactly
129 //
130 // where S_hi in [1,2) and S_lo is a correction to S_hi in the sense
131 // that |S_lo| <= ulp(S_hi).
132 //
133 // Step 1: Argument Reduction
134 //
135 // Based on S_hi, obtain G_1, G_2, G_3 from a table and calculate
136 //
137 // G := G_1 * G_2 * G_3
138 // r := (G * S_hi - 1) + G * S_lo
139 //
140 // These G_j's have the property that the product is exactly
141 // representable and that |r| < 2^(-12) as a result.
142 //
143 // Step 2: Approximation
144 //
145 //
146 // logl(1 + r) is approximated by a short polynomial poly(r).
147 //
148 // Step 3: Reconstruction
149 //
150 //
151 // Finally, log1pl( X ) = logl( X+1 ) is given by
152 //
153 // logl( X+1 ) = logl( 2^N * (S_hi + S_lo) )
154 // ~=~ N*logl(2) + logl(1/G) + logl(1 + r)
155 // ~=~ N*logl(2) + logl(1/G) + poly(r).
156 //
157 // **** Algorithm ****
158 //
159 // Case log1p_small:
160 //
161 // Although log1pl(X) is basically X, we would like to preserve the inexactness
162 // nature as well as consistent behavior under different rounding modes.
163 // We can do this by computing the result as
164 //
165 // log1pl(X) = X - X*X
166 //
167 //
168 // Case log_near1:
169 //
170 // Here we compute a simple polynomial. To exploit parallelism, we split
171 // the polynomial into two portions.
172 //
173 // W := X
174 // Wsq := W * W
175 // W4 := Wsq*Wsq
176 // W6 := W4*Wsq
177 // Y_hi := W + Wsq*(P_1 + W*(P_2 + W*(P_3 + W*P_4))
178 // Y_lo := W6*(P_5 + W*(P_6 + W*(P_7 + W*P_8)))
179 //
180 // Case log_regular:
181 //
182 // We present the algorithm in four steps.
183 //
184 // Step 0. Initialization
185 // ----------------------
186 //
187 // Z := X + 1
188 // N := unbaised exponent of Z
189 // S_hi := 2^(-N) * Z
190 // S_lo := 2^(-N) * { (max(X,1)-Z) + min(X,1) }
191 //
192 // Step 1. Argument Reduction
193 // --------------------------
194 //
195 // Let
196 //
197 // Z = 2^N * S_hi = 2^N * 1.d_1 d_2 d_3 ... d_63
198 //
199 // We obtain G_1, G_2, G_3 by the following steps.
200 //
201 //
202 // Define X_0 := 1.d_1 d_2 ... d_14. This is extracted
203 // from S_hi.
204 //
205 // Define A_1 := 1.d_1 d_2 d_3 d_4. This is X_0 truncated
206 // to lsb = 2^(-4).
207 //
208 // Define index_1 := [ d_1 d_2 d_3 d_4 ].
209 //
210 // Fetch Z_1 := (1/A_1) rounded UP in fixed point with
211 // fixed point lsb = 2^(-15).
212 // Z_1 looks like z_0.z_1 z_2 ... z_15
213 // Note that the fetching is done using index_1.
214 // A_1 is actually not needed in the implementation
215 // and is used here only to explain how is the value
216 // Z_1 defined.
217 //
218 // Fetch G_1 := (1/A_1) truncated to 21 sig. bits.
219 // floating pt. Again, fetching is done using index_1. A_1
220 // explains how G_1 is defined.
221 //
222 // Calculate X_1 := X_0 * Z_1 truncated to lsb = 2^(-14)
223 // = 1.0 0 0 0 d_5 ... d_14
224 // This is accomplised by integer multiplication.
225 // It is proved that X_1 indeed always begin
226 // with 1.0000 in fixed point.
227 //
228 //
229 // Define A_2 := 1.0 0 0 0 d_5 d_6 d_7 d_8. This is X_1
230 // truncated to lsb = 2^(-8). Similar to A_1,
231 // A_2 is not needed in actual implementation. It
232 // helps explain how some of the values are defined.
233 //
234 // Define index_2 := [ d_5 d_6 d_7 d_8 ].
235 //
236 // Fetch Z_2 := (1/A_2) rounded UP in fixed point with
237 // fixed point lsb = 2^(-15). Fetch done using index_2.
238 // Z_2 looks like z_0.z_1 z_2 ... z_15
239 //
240 // Fetch G_2 := (1/A_2) truncated to 21 sig. bits.
241 // floating pt.
242 //
243 // Calculate X_2 := X_1 * Z_2 truncated to lsb = 2^(-14)
244 // = 1.0 0 0 0 0 0 0 0 d_9 d_10 ... d_14
245 // This is accomplised by integer multiplication.
246 // It is proved that X_2 indeed always begin
247 // with 1.00000000 in fixed point.
248 //
249 //
250 // Define A_3 := 1.0 0 0 0 0 0 0 0 d_9 d_10 d_11 d_12 d_13 1.
251 // This is 2^(-14) + X_2 truncated to lsb = 2^(-13).
252 //
253 // Define index_3 := [ d_9 d_10 d_11 d_12 d_13 ].
254 //
255 // Fetch G_3 := (1/A_3) truncated to 21 sig. bits.
256 // floating pt. Fetch is done using index_3.
257 //
258 // Compute G := G_1 * G_2 * G_3.
259 //
260 // This is done exactly since each of G_j only has 21 sig. bits.
261 //
262 // Compute
263 //
264 // r := (G*S_hi - 1) + G*S_lo using 2 FMA operations.
265 //
266 // Thus r approximates G*(S_hi + S_lo) - 1 to within a couple of
267 // rounding errors.
268 //
269 //
270 // Step 2. Approximation
271 // ---------------------
272 //
273 // This step computes an approximation to logl( 1 + r ) where r is the
274 // reduced argument just obtained. It is proved that |r| <= 1.9*2^(-13);
275 // thus logl(1+r) can be approximated by a short polynomial:
276 //
277 // logl(1+r) ~=~ poly = r + Q1 r^2 + ... + Q4 r^5
278 //
279 //
280 // Step 3. Reconstruction
281 // ----------------------
282 //
283 // This step computes the desired result of logl(X+1):
284 //
285 // logl(X+1) = logl( 2^N * (S_hi + S_lo) )
286 // = N*logl(2) + logl( S_hi + S_lo) )
287 // = N*logl(2) + logl(1/G) +
288 // logl(1 + G * ( S_hi + S_lo ) - 1 )
289 //
290 // logl(2), logl(1/G_j) are stored as pairs of (single,double) numbers:
291 // log2_hi, log2_lo, log1byGj_hi, log1byGj_lo. The high parts are
292 // single-precision numbers and the low parts are double precision
293 // numbers. These have the property that
294 //
295 // N*log2_hi + SUM ( log1byGj_hi )
296 //
297 // is computable exactly in double-extended precision (64 sig. bits).
298 // Finally
299 //
300 // Y_hi := N*log2_hi + SUM ( log1byGj_hi )
301 // Y_lo := poly_hi + [ poly_lo +
302 // ( SUM ( log1byGj_lo ) + N*log2_lo ) ]
303 //
304
305 RODATA
306 .align 64
307
308 // ************* DO NOT CHANGE THE ORDER OF THESE TABLES *************
309
310 // P_8, P_7, P_6, P_5, P_4, P_3, P_2, and P_1
311
312 LOCAL_OBJECT_START(Constants_P)
313 //data4 0xEFD62B15,0xE3936754,0x00003FFB,0x00000000
314 //data4 0xA5E56381,0x8003B271,0x0000BFFC,0x00000000
315 //data4 0x73282DB0,0x9249248C,0x00003FFC,0x00000000
316 //data4 0x47305052,0xAAAAAA9F,0x0000BFFC,0x00000000
317 //data4 0xCCD17FC9,0xCCCCCCCC,0x00003FFC,0x00000000
318 //data4 0x00067ED5,0x80000000,0x0000BFFD,0x00000000
319 //data4 0xAAAAAAAA,0xAAAAAAAA,0x00003FFD,0x00000000
320 //data4 0xFFFFFFFE,0xFFFFFFFF,0x0000BFFD,0x00000000
321 data8 0xE3936754EFD62B15,0x00003FFB
322 data8 0x8003B271A5E56381,0x0000BFFC
323 data8 0x9249248C73282DB0,0x00003FFC
324 data8 0xAAAAAA9F47305052,0x0000BFFC
325 data8 0xCCCCCCCCCCD17FC9,0x00003FFC
326 data8 0x8000000000067ED5,0x0000BFFD
327 data8 0xAAAAAAAAAAAAAAAA,0x00003FFD
328 data8 0xFFFFFFFFFFFFFFFE,0x0000BFFD
329 LOCAL_OBJECT_END(Constants_P)
330
331 // log2_hi, log2_lo, Q_4, Q_3, Q_2, and Q_1
332
333 LOCAL_OBJECT_START(Constants_Q)
334 //data4 0x00000000,0xB1721800,0x00003FFE,0x00000000
335 //data4 0x4361C4C6,0x82E30865,0x0000BFE2,0x00000000
336 //data4 0x328833CB,0xCCCCCAF2,0x00003FFC,0x00000000
337 //data4 0xA9D4BAFB,0x80000077,0x0000BFFD,0x00000000
338 //data4 0xAAABE3D2,0xAAAAAAAA,0x00003FFD,0x00000000
339 //data4 0xFFFFDAB7,0xFFFFFFFF,0x0000BFFD,0x00000000
340 data8 0xB172180000000000,0x00003FFE
341 data8 0x82E308654361C4C6,0x0000BFE2
342 data8 0xCCCCCAF2328833CB,0x00003FFC
343 data8 0x80000077A9D4BAFB,0x0000BFFD
344 data8 0xAAAAAAAAAAABE3D2,0x00003FFD
345 data8 0xFFFFFFFFFFFFDAB7,0x0000BFFD
346 LOCAL_OBJECT_END(Constants_Q)
347
348 // 1/ln10_hi, 1/ln10_lo
349
350 LOCAL_OBJECT_START(Constants_1_by_LN10)
351 //data4 0x37287195,0xDE5BD8A9,0x00003FFD,0x00000000
352 //data4 0xACCF70C8,0xD56EAABE,0x00003FBB,0x00000000
353 data8 0xDE5BD8A937287195,0x00003FFD
354 data8 0xD56EAABEACCF70C8,0x00003FBB
355 LOCAL_OBJECT_END(Constants_1_by_LN10)
356
357
358 // Z1 - 16 bit fixed
359
360 LOCAL_OBJECT_START(Constants_Z_1)
361 data4 0x00008000
362 data4 0x00007879
363 data4 0x000071C8
364 data4 0x00006BCB
365 data4 0x00006667
366 data4 0x00006187
367 data4 0x00005D18
368 data4 0x0000590C
369 data4 0x00005556
370 data4 0x000051EC
371 data4 0x00004EC5
372 data4 0x00004BDB
373 data4 0x00004925
374 data4 0x0000469F
375 data4 0x00004445
376 data4 0x00004211
377 LOCAL_OBJECT_END(Constants_Z_1)
378
379 // G1 and H1 - IEEE single and h1 - IEEE double
380
381 LOCAL_OBJECT_START(Constants_G_H_h1)
382 data4 0x3F800000,0x00000000
383 data8 0x0000000000000000
384 data4 0x3F70F0F0,0x3D785196
385 data8 0x3DA163A6617D741C
386 data4 0x3F638E38,0x3DF13843
387 data8 0x3E2C55E6CBD3D5BB
388 data4 0x3F579430,0x3E2FF9A0
389 data8 0xBE3EB0BFD86EA5E7
390 data4 0x3F4CCCC8,0x3E647FD6
391 data8 0x3E2E6A8C86B12760
392 data4 0x3F430C30,0x3E8B3AE7
393 data8 0x3E47574C5C0739BA
394 data4 0x3F3A2E88,0x3EA30C68
395 data8 0x3E20E30F13E8AF2F
396 data4 0x3F321640,0x3EB9CEC8
397 data8 0xBE42885BF2C630BD
398 data4 0x3F2AAAA8,0x3ECF9927
399 data8 0x3E497F3497E577C6
400 data4 0x3F23D708,0x3EE47FC5
401 data8 0x3E3E6A6EA6B0A5AB
402 data4 0x3F1D89D8,0x3EF8947D
403 data8 0xBDF43E3CD328D9BE
404 data4 0x3F17B420,0x3F05F3A1
405 data8 0x3E4094C30ADB090A
406 data4 0x3F124920,0x3F0F4303
407 data8 0xBE28FBB2FC1FE510
408 data4 0x3F0D3DC8,0x3F183EBF
409 data8 0x3E3A789510FDE3FA
410 data4 0x3F088888,0x3F20EC80
411 data8 0x3E508CE57CC8C98F
412 data4 0x3F042108,0x3F29516A
413 data8 0xBE534874A223106C
414 LOCAL_OBJECT_END(Constants_G_H_h1)
415
416 // Z2 - 16 bit fixed
417
418 LOCAL_OBJECT_START(Constants_Z_2)
419 data4 0x00008000
420 data4 0x00007F81
421 data4 0x00007F02
422 data4 0x00007E85
423 data4 0x00007E08
424 data4 0x00007D8D
425 data4 0x00007D12
426 data4 0x00007C98
427 data4 0x00007C20
428 data4 0x00007BA8
429 data4 0x00007B31
430 data4 0x00007ABB
431 data4 0x00007A45
432 data4 0x000079D1
433 data4 0x0000795D
434 data4 0x000078EB
435 LOCAL_OBJECT_END(Constants_Z_2)
436
437 // G2 and H2 - IEEE single and h2 - IEEE double
438
439 LOCAL_OBJECT_START(Constants_G_H_h2)
440 data4 0x3F800000,0x00000000
441 data8 0x0000000000000000
442 data4 0x3F7F00F8,0x3B7F875D
443 data8 0x3DB5A11622C42273
444 data4 0x3F7E03F8,0x3BFF015B
445 data8 0x3DE620CF21F86ED3
446 data4 0x3F7D08E0,0x3C3EE393
447 data8 0xBDAFA07E484F34ED
448 data4 0x3F7C0FC0,0x3C7E0586
449 data8 0xBDFE07F03860BCF6
450 data4 0x3F7B1880,0x3C9E75D2
451 data8 0x3DEA370FA78093D6
452 data4 0x3F7A2328,0x3CBDC97A
453 data8 0x3DFF579172A753D0
454 data4 0x3F792FB0,0x3CDCFE47
455 data8 0x3DFEBE6CA7EF896B
456 data4 0x3F783E08,0x3CFC15D0
457 data8 0x3E0CF156409ECB43
458 data4 0x3F774E38,0x3D0D874D
459 data8 0xBE0B6F97FFEF71DF
460 data4 0x3F766038,0x3D1CF49B
461 data8 0xBE0804835D59EEE8
462 data4 0x3F757400,0x3D2C531D
463 data8 0x3E1F91E9A9192A74
464 data4 0x3F748988,0x3D3BA322
465 data8 0xBE139A06BF72A8CD
466 data4 0x3F73A0D0,0x3D4AE46F
467 data8 0x3E1D9202F8FBA6CF
468 data4 0x3F72B9D0,0x3D5A1756
469 data8 0xBE1DCCC4BA796223
470 data4 0x3F71D488,0x3D693B9D
471 data8 0xBE049391B6B7C239
472 LOCAL_OBJECT_END(Constants_G_H_h2)
473
474 // G3 and H3 - IEEE single and h3 - IEEE double
475
476 LOCAL_OBJECT_START(Constants_G_H_h3)
477 data4 0x3F7FFC00,0x38800100
478 data8 0x3D355595562224CD
479 data4 0x3F7FF400,0x39400480
480 data8 0x3D8200A206136FF6
481 data4 0x3F7FEC00,0x39A00640
482 data8 0x3DA4D68DE8DE9AF0
483 data4 0x3F7FE400,0x39E00C41
484 data8 0xBD8B4291B10238DC
485 data4 0x3F7FDC00,0x3A100A21
486 data8 0xBD89CCB83B1952CA
487 data4 0x3F7FD400,0x3A300F22
488 data8 0xBDB107071DC46826
489 data4 0x3F7FCC08,0x3A4FF51C
490 data8 0x3DB6FCB9F43307DB
491 data4 0x3F7FC408,0x3A6FFC1D
492 data8 0xBD9B7C4762DC7872
493 data4 0x3F7FBC10,0x3A87F20B
494 data8 0xBDC3725E3F89154A
495 data4 0x3F7FB410,0x3A97F68B
496 data8 0xBD93519D62B9D392
497 data4 0x3F7FAC18,0x3AA7EB86
498 data8 0x3DC184410F21BD9D
499 data4 0x3F7FA420,0x3AB7E101
500 data8 0xBDA64B952245E0A6
501 data4 0x3F7F9C20,0x3AC7E701
502 data8 0x3DB4B0ECAABB34B8
503 data4 0x3F7F9428,0x3AD7DD7B
504 data8 0x3D9923376DC40A7E
505 data4 0x3F7F8C30,0x3AE7D474
506 data8 0x3DC6E17B4F2083D3
507 data4 0x3F7F8438,0x3AF7CBED
508 data8 0x3DAE314B811D4394
509 data4 0x3F7F7C40,0x3B03E1F3
510 data8 0xBDD46F21B08F2DB1
511 data4 0x3F7F7448,0x3B0BDE2F
512 data8 0xBDDC30A46D34522B
513 data4 0x3F7F6C50,0x3B13DAAA
514 data8 0x3DCB0070B1F473DB
515 data4 0x3F7F6458,0x3B1BD766
516 data8 0xBDD65DDC6AD282FD
517 data4 0x3F7F5C68,0x3B23CC5C
518 data8 0xBDCDAB83F153761A
519 data4 0x3F7F5470,0x3B2BC997
520 data8 0xBDDADA40341D0F8F
521 data4 0x3F7F4C78,0x3B33C711
522 data8 0x3DCD1BD7EBC394E8
523 data4 0x3F7F4488,0x3B3BBCC6
524 data8 0xBDC3532B52E3E695
525 data4 0x3F7F3C90,0x3B43BAC0
526 data8 0xBDA3961EE846B3DE
527 data4 0x3F7F34A0,0x3B4BB0F4
528 data8 0xBDDADF06785778D4
529 data4 0x3F7F2CA8,0x3B53AF6D
530 data8 0x3DCC3ED1E55CE212
531 data4 0x3F7F24B8,0x3B5BA620
532 data8 0xBDBA31039E382C15
533 data4 0x3F7F1CC8,0x3B639D12
534 data8 0x3D635A0B5C5AF197
535 data4 0x3F7F14D8,0x3B6B9444
536 data8 0xBDDCCB1971D34EFC
537 data4 0x3F7F0CE0,0x3B7393BC
538 data8 0x3DC7450252CD7ADA
539 data4 0x3F7F04F0,0x3B7B8B6D
540 data8 0xBDB68F177D7F2A42
541 LOCAL_OBJECT_END(Constants_G_H_h3)
542
543
544 // Floating Point Registers
545
546 FR_Input_X = f8
547
548 FR_Y_hi = f34
549 FR_Y_lo = f35
550
551 FR_Scale = f36
552 FR_X_Prime = f37
553 FR_S_hi = f38
554 FR_W = f39
555 FR_G = f40
556
557 FR_H = f41
558 FR_wsq = f42
559 FR_w4 = f43
560 FR_h = f44
561 FR_w6 = f45
562
563 FR_G2 = f46
564 FR_H2 = f47
565 FR_poly_lo = f48
566 FR_P8 = f49
567 FR_poly_hi = f50
568
569 FR_P7 = f51
570 FR_h2 = f52
571 FR_rsq = f53
572 FR_P6 = f54
573 FR_r = f55
574
575 FR_log2_hi = f56
576 FR_log2_lo = f57
577 FR_p87 = f58
578 FR_p876 = f58
579 FR_p8765 = f58
580 FR_float_N = f59
581 FR_Q4 = f60
582
583 FR_p43 = f61
584 FR_p432 = f61
585 FR_p4321 = f61
586 FR_P4 = f62
587 FR_G3 = f63
588 FR_H3 = f64
589 FR_h3 = f65
590
591 FR_Q3 = f66
592 FR_P3 = f67
593 FR_Q2 = f68
594 FR_P2 = f69
595 FR_1LN10_hi = f70
596
597 FR_Q1 = f71
598 FR_P1 = f72
599 FR_1LN10_lo = f73
600 FR_P5 = f74
601 FR_rcub = f75
602
603 FR_Output_X_tmp = f76
604 FR_Neg_One = f77
605 FR_Z = f78
606 FR_AA = f79
607 FR_BB = f80
608 FR_S_lo = f81
609 FR_2_to_minus_N = f82
610
611 FR_X = f8
612 FR_Y = f0
613 FR_RESULT = f76
614
615
616 // General Purpose Registers
617
618 GR_ad_p = r33
619 GR_Index1 = r34
620 GR_Index2 = r35
621 GR_signif = r36
622 GR_X_0 = r37
623 GR_X_1 = r38
624 GR_X_2 = r39
625 GR_minus_N = r39
626 GR_Z_1 = r40
627 GR_Z_2 = r41
628 GR_N = r42
629 GR_Bias = r43
630 GR_M = r44
631 GR_Index3 = r45
632 GR_exp_2tom80 = r45
633 GR_ad_p2 = r46
634 GR_exp_mask = r47
635 GR_exp_2tom7 = r48
636 GR_ad_ln10 = r49
637 GR_ad_tbl_1 = r50
638 GR_ad_tbl_2 = r51
639 GR_ad_tbl_3 = r52
640 GR_ad_q = r53
641 GR_ad_z_1 = r54
642 GR_ad_z_2 = r55
643 GR_ad_z_3 = r56
644 GR_minus_N = r39
645
646 //
647 // Added for unwind support
648 //
649
650 GR_SAVE_PFS = r50
651 GR_SAVE_B0 = r51
652 GR_SAVE_GP = r52
653 GR_Parameter_X = r53
654 GR_Parameter_Y = r54
655 GR_Parameter_RESULT = r55
656 GR_Parameter_TAG = r56
657
658 .section .text
659 GLOBAL_IEEE754_ENTRY(log1pl)
660 { .mfi
661 alloc r32 = ar.pfs,0,21,4,0
662 fclass.m p6, p0 = FR_Input_X, 0x1E3 // Test for natval, nan, inf
663 nop.i 999
664 }
665 { .mfi
666 addl GR_ad_z_1 = @ltoff(Constants_Z_1#),gp
667 fma.s1 FR_Z = FR_Input_X, f1, f1 // x+1
668 nop.i 999
669 }
670 ;;
671
672 { .mfi
673 nop.m 999
674 fmerge.ns FR_Neg_One = f1, f1 // Form -1.0
675 nop.i 999
676 }
677 { .mfi
678 nop.m 999
679 fnorm.s1 FR_X_Prime = FR_Input_X // Normalize x
680 nop.i 999
681 }
682 ;;
683
684 { .mfi
685 ld8 GR_ad_z_1 = [GR_ad_z_1] // Get pointer to Constants_Z_1
686 nop.f 999
687 mov GR_exp_2tom7 = 0x0fff8 // Exponent of 2^-7
688 }
689 ;;
690
691 { .mfb
692 getf.sig GR_signif = FR_Z // Get significand of x+1
693 fcmp.eq.s1 p9, p0 = FR_Input_X, f0 // Test for x=0
694 (p6) br.cond.spnt LOG1P_special // Branch for nan, inf, natval
695 }
696 ;;
697
698 { .mfi
699 add GR_ad_tbl_1 = 0x040, GR_ad_z_1 // Point to Constants_G_H_h1
700 fcmp.lt.s1 p13, p0 = FR_X_Prime, FR_Neg_One // Test for x<-1
701 add GR_ad_p = -0x100, GR_ad_z_1 // Point to Constants_P
702 }
703 { .mfi
704 add GR_ad_z_2 = 0x140, GR_ad_z_1 // Point to Constants_Z_2
705 nop.f 999
706 add GR_ad_tbl_2 = 0x180, GR_ad_z_1 // Point to Constants_G_H_h2
707 }
708 ;;
709
710 { .mfi
711 add GR_ad_q = 0x080, GR_ad_p // Point to Constants_Q
712 fcmp.eq.s1 p8, p0 = FR_X_Prime, FR_Neg_One // Test for x=-1
713 extr.u GR_Index1 = GR_signif, 59, 4 // Get high 4 bits of signif
714 }
715 { .mfb
716 add GR_ad_tbl_3 = 0x280, GR_ad_z_1 // Point to Constants_G_H_h3
717 nop.f 999
718 (p9) br.ret.spnt b0 // Exit if x=0, return input
719 }
720 ;;
721
722 { .mfi
723 shladd GR_ad_z_1 = GR_Index1, 2, GR_ad_z_1 // Point to Z_1
724 fclass.nm p10, p0 = FR_Input_X, 0x1FF // Test for unsupported
725 extr.u GR_X_0 = GR_signif, 49, 15 // Get high 15 bits of significand
726 }
727 { .mfi
728 ldfe FR_P8 = [GR_ad_p],16 // Load P_8 for near1 path
729 fsub.s1 FR_W = FR_X_Prime, f0 // W = x
730 add GR_ad_ln10 = 0x060, GR_ad_q // Point to Constants_1_by_LN10
731 }
732 ;;
733
734 { .mfi
735 ld4 GR_Z_1 = [GR_ad_z_1] // Load Z_1
736 fmax.s1 FR_AA = FR_X_Prime, f1 // For S_lo, form AA = max(X,1.0)
737 mov GR_exp_mask = 0x1FFFF // Create exponent mask
738 }
739 { .mib
740 shladd GR_ad_tbl_1 = GR_Index1, 4, GR_ad_tbl_1 // Point to G_1
741 mov GR_Bias = 0x0FFFF // Create exponent bias
742 (p13) br.cond.spnt LOG1P_LT_Minus_1 // Branch if x<-1
743 }
744 ;;
745
746 { .mfb
747 ldfps FR_G, FR_H = [GR_ad_tbl_1],8 // Load G_1, H_1
748 fmerge.se FR_S_hi = f1,FR_Z // Form |x+1|
749 (p8) br.cond.spnt LOG1P_EQ_Minus_1 // Branch if x=-1
750 }
751 ;;
752
753 { .mmb
754 getf.exp GR_N = FR_Z // Get N = exponent of x+1
755 ldfd FR_h = [GR_ad_tbl_1] // Load h_1
756 (p10) br.cond.spnt LOG1P_unsupported // Branch for unsupported type
757 }
758 ;;
759
760 { .mfi
761 ldfe FR_log2_hi = [GR_ad_q],16 // Load log2_hi
762 fcmp.eq.s0 p8, p0 = FR_Input_X, f0 // Dummy op to flag denormals
763 pmpyshr2.u GR_X_1 = GR_X_0,GR_Z_1,15 // Get bits 30-15 of X_0 * Z_1
764 }
765 ;;
766
767 //
768 // For performance, don't use result of pmpyshr2.u for 4 cycles.
769 //
770 { .mmi
771 ldfe FR_log2_lo = [GR_ad_q],16 // Load log2_lo
772 sub GR_N = GR_N, GR_Bias
773 mov GR_exp_2tom80 = 0x0ffaf // Exponent of 2^-80
774 }
775 ;;
776
777 { .mfi
778 ldfe FR_Q4 = [GR_ad_q],16 // Load Q4
779 fms.s1 FR_S_lo = FR_AA, f1, FR_Z // Form S_lo = AA - Z
780 sub GR_minus_N = GR_Bias, GR_N // Form exponent of 2^(-N)
781 }
782 ;;
783
784 { .mmf
785 ldfe FR_Q3 = [GR_ad_q],16 // Load Q3
786 setf.sig FR_float_N = GR_N // Put integer N into rightmost significand
787 fmin.s1 FR_BB = FR_X_Prime, f1 // For S_lo, form BB = min(X,1.0)
788 }
789 ;;
790
791 { .mmi
792 getf.exp GR_M = FR_W // Get signexp of w = x
793 ldfe FR_Q2 = [GR_ad_q],16 // Load Q2
794 extr.u GR_Index2 = GR_X_1, 6, 4 // Extract bits 6-9 of X_1
795 }
796 ;;
797
798 { .mmi
799 ldfe FR_Q1 = [GR_ad_q] // Load Q1
800 shladd GR_ad_z_2 = GR_Index2, 2, GR_ad_z_2 // Point to Z_2
801 add GR_ad_p2 = 0x30,GR_ad_p // Point to P_4
802 }
803 ;;
804
805 { .mmi
806 ld4 GR_Z_2 = [GR_ad_z_2] // Load Z_2
807 shladd GR_ad_tbl_2 = GR_Index2, 4, GR_ad_tbl_2 // Point to G_2
808 and GR_M = GR_exp_mask, GR_M // Get exponent of w = x
809 }
810 ;;
811
812 { .mmi
813 ldfps FR_G2, FR_H2 = [GR_ad_tbl_2],8 // Load G_2, H_2
814 cmp.lt p8, p9 = GR_M, GR_exp_2tom7 // Test |x| < 2^-7
815 cmp.lt p7, p0 = GR_M, GR_exp_2tom80 // Test |x| < 2^-80
816 }
817 ;;
818
819 // Small path is separate code
820 // p7 is for the small path: |x| < 2^-80
821 // near1 and regular paths are merged.
822 // p8 is for the near1 path: |x| < 2^-7
823 // p9 is for regular path: |x| >= 2^-7
824
825 { .mfi
826 ldfd FR_h2 = [GR_ad_tbl_2] // Load h_2
827 nop.f 999
828 nop.i 999
829 }
830 { .mfb
831 (p9) setf.exp FR_2_to_minus_N = GR_minus_N // Form 2^(-N)
832 (p7) fnma.s0 f8 = FR_X_Prime, FR_X_Prime, FR_X_Prime // Result x - x*x
833 (p7) br.ret.spnt b0 // Branch if |x| < 2^-80
834 }
835 ;;
836
837 { .mmi
838 (p8) ldfe FR_P7 = [GR_ad_p],16 // Load P_7 for near1 path
839 (p8) ldfe FR_P4 = [GR_ad_p2],16 // Load P_4 for near1 path
840 (p9) pmpyshr2.u GR_X_2 = GR_X_1,GR_Z_2,15 // Get bits 30-15 of X_1 * Z_2
841 }
842 ;;
843
844 //
845 // For performance, don't use result of pmpyshr2.u for 4 cycles.
846 //
847 { .mmf
848 (p8) ldfe FR_P6 = [GR_ad_p],16 // Load P_6 for near1 path
849 (p8) ldfe FR_P3 = [GR_ad_p2],16 // Load P_3 for near1 path
850 (p9) fma.s1 FR_S_lo = FR_S_lo, f1, FR_BB // S_lo = S_lo + BB
851 }
852 ;;
853
854 { .mmf
855 (p8) ldfe FR_P5 = [GR_ad_p],16 // Load P_5 for near1 path
856 (p8) ldfe FR_P2 = [GR_ad_p2],16 // Load P_2 for near1 path
857 (p8) fmpy.s1 FR_wsq = FR_W, FR_W // wsq = w * w for near1 path
858 }
859 ;;
860
861 { .mmi
862 (p8) ldfe FR_P1 = [GR_ad_p2],16 ;; // Load P_1 for near1 path
863 nop.m 999
864 (p9) extr.u GR_Index3 = GR_X_2, 1, 5 // Extract bits 1-5 of X_2
865 }
866 ;;
867
868 { .mfi
869 (p9) shladd GR_ad_tbl_3 = GR_Index3, 4, GR_ad_tbl_3 // Point to G_3
870 (p9) fcvt.xf FR_float_N = FR_float_N
871 nop.i 999
872 }
873 ;;
874
875 { .mfi
876 (p9) ldfps FR_G3, FR_H3 = [GR_ad_tbl_3],8 // Load G_3, H_3
877 nop.f 999
878 nop.i 999
879 }
880 ;;
881
882 { .mfi
883 (p9) ldfd FR_h3 = [GR_ad_tbl_3] // Load h_3
884 (p9) fmpy.s1 FR_G = FR_G, FR_G2 // G = G_1 * G_2
885 nop.i 999
886 }
887 { .mfi
888 nop.m 999
889 (p9) fadd.s1 FR_H = FR_H, FR_H2 // H = H_1 + H_2
890 nop.i 999
891 }
892 ;;
893
894 { .mmf
895 nop.m 999
896 nop.m 999
897 (p9) fadd.s1 FR_h = FR_h, FR_h2 // h = h_1 + h_2
898 }
899 ;;
900
901 { .mfi
902 nop.m 999
903 (p8) fmpy.s1 FR_w4 = FR_wsq, FR_wsq // w4 = w^4 for near1 path
904 nop.i 999
905 }
906 { .mfi
907 nop.m 999
908 (p8) fma.s1 FR_p87 = FR_W, FR_P8, FR_P7 // p87 = w * P8 + P7
909 nop.i 999
910 }
911 ;;
912
913 { .mfi
914 nop.m 999
915 (p9) fma.s1 FR_S_lo = FR_S_lo, FR_2_to_minus_N, f0 // S_lo = S_lo * 2^(-N)
916 nop.i 999
917 }
918 { .mfi
919 nop.m 999
920 (p8) fma.s1 FR_p43 = FR_W, FR_P4, FR_P3 // p43 = w * P4 + P3
921 nop.i 999
922 }
923 ;;
924
925 { .mfi
926 nop.m 999
927 (p9) fmpy.s1 FR_G = FR_G, FR_G3 // G = (G_1 * G_2) * G_3
928 nop.i 999
929 }
930 { .mfi
931 nop.m 999
932 (p9) fadd.s1 FR_H = FR_H, FR_H3 // H = (H_1 + H_2) + H_3
933 nop.i 999
934 }
935 ;;
936
937 { .mfi
938 nop.m 999
939 (p9) fadd.s1 FR_h = FR_h, FR_h3 // h = (h_1 + h_2) + h_3
940 nop.i 999
941 }
942 { .mfi
943 nop.m 999
944 (p8) fmpy.s1 FR_w6 = FR_w4, FR_wsq // w6 = w^6 for near1 path
945 nop.i 999
946 }
947 ;;
948
949 { .mfi
950 nop.m 999
951 (p8) fma.s1 FR_p432 = FR_W, FR_p43, FR_P2 // p432 = w * p43 + P2
952 nop.i 999
953 }
954 { .mfi
955 nop.m 999
956 (p8) fma.s1 FR_p876 = FR_W, FR_p87, FR_P6 // p876 = w * p87 + P6
957 nop.i 999
958 }
959 ;;
960
961 { .mfi
962 nop.m 999
963 (p9) fms.s1 FR_r = FR_G, FR_S_hi, f1 // r = G * S_hi - 1
964 nop.i 999
965 }
966 { .mfi
967 nop.m 999
968 (p9) fma.s1 FR_Y_hi = FR_float_N, FR_log2_hi, FR_H // Y_hi = N * log2_hi + H
969 nop.i 999
970 }
971 ;;
972
973 { .mfi
974 nop.m 999
975 (p9) fma.s1 FR_h = FR_float_N, FR_log2_lo, FR_h // h = N * log2_lo + h
976 nop.i 999
977 }
978 ;;
979
980 { .mfi
981 nop.m 999
982 (p9) fma.s1 FR_r = FR_G, FR_S_lo, FR_r // r = G * S_lo + (G * S_hi - 1)
983 nop.i 999
984 }
985 ;;
986
987 { .mfi
988 nop.m 999
989 (p8) fma.s1 FR_p4321 = FR_W, FR_p432, FR_P1 // p4321 = w * p432 + P1
990 nop.i 999
991 }
992 { .mfi
993 nop.m 999
994 (p8) fma.s1 FR_p8765 = FR_W, FR_p876, FR_P5 // p8765 = w * p876 + P5
995 nop.i 999
996 }
997 ;;
998
999 { .mfi
1000 nop.m 999
1001 (p9) fma.s1 FR_poly_lo = FR_r, FR_Q4, FR_Q3 // poly_lo = r * Q4 + Q3
1002 nop.i 999
1003 }
1004 { .mfi
1005 nop.m 999
1006 (p9) fmpy.s1 FR_rsq = FR_r, FR_r // rsq = r * r
1007 nop.i 999
1008 }
1009 ;;
1010
1011 { .mfi
1012 nop.m 999
1013 (p8) fma.s1 FR_Y_lo = FR_wsq, FR_p4321, f0 // Y_lo = wsq * p4321
1014 nop.i 999
1015 }
1016 { .mfi
1017 nop.m 999
1018 (p8) fma.s1 FR_Y_hi = FR_W, f1, f0 // Y_hi = w for near1 path
1019 nop.i 999
1020 }
1021 ;;
1022
1023 { .mfi
1024 nop.m 999
1025 (p9) fma.s1 FR_poly_lo = FR_poly_lo, FR_r, FR_Q2 // poly_lo = poly_lo * r + Q2
1026 nop.i 999
1027 }
1028 { .mfi
1029 nop.m 999
1030 (p9) fma.s1 FR_rcub = FR_rsq, FR_r, f0 // rcub = r^3
1031 nop.i 999
1032 }
1033 ;;
1034
1035 { .mfi
1036 nop.m 999
1037 (p8) fma.s1 FR_Y_lo = FR_w6, FR_p8765,FR_Y_lo // Y_lo = w6 * p8765 + w2 * p4321
1038 nop.i 999
1039 }
1040 ;;
1041
1042 { .mfi
1043 nop.m 999
1044 (p9) fma.s1 FR_poly_hi = FR_Q1, FR_rsq, FR_r // poly_hi = Q1 * rsq + r
1045 nop.i 999
1046 }
1047 ;;
1048
1049 { .mfi
1050 nop.m 999
1051 (p9) fma.s1 FR_poly_lo = FR_poly_lo, FR_rcub, FR_h // poly_lo = poly_lo*r^3 + h
1052 nop.i 999
1053 }
1054 ;;
1055
1056 { .mfi
1057 nop.m 999
1058 (p9) fadd.s1 FR_Y_lo = FR_poly_hi, FR_poly_lo // Y_lo = poly_hi + poly_lo
1059 nop.i 999
1060 }
1061 ;;
1062
1063 // Remainder of code is common for near1 and regular paths
1064 { .mfb
1065 nop.m 999
1066 fadd.s0 f8 = FR_Y_lo,FR_Y_hi // Result=Y_lo+Y_hi
1067 br.ret.sptk b0 // Common exit for 2^-80 < x < inf
1068 }
1069 ;;
1070
1071
1072 // Here if x=-1
1073 LOG1P_EQ_Minus_1:
1074 //
1075 // If x=-1 raise divide by zero and return -inf
1076 //
1077 { .mfi
1078 mov GR_Parameter_TAG = 138
1079 fsub.s1 FR_Output_X_tmp = f0, f1
1080 nop.i 999
1081 }
1082 ;;
1083
1084 { .mfb
1085 nop.m 999
1086 frcpa.s0 FR_Output_X_tmp, p8 = FR_Output_X_tmp, f0
1087 br.cond.sptk __libm_error_region
1088 }
1089 ;;
1090
1091 LOG1P_special:
1092 { .mfi
1093 nop.m 999
1094 fclass.m.unc p8, p0 = FR_Input_X, 0x1E1 // Test for natval, nan, +inf
1095 nop.i 999
1096 }
1097 ;;
1098
1099 //
1100 // For SNaN raise invalid and return QNaN.
1101 // For QNaN raise invalid and return QNaN.
1102 // For +Inf return +Inf.
1103 //
1104 { .mfb
1105 nop.m 999
1106 (p8) fmpy.s0 f8 = FR_Input_X, f1
1107 (p8) br.ret.sptk b0 // Return for natval, nan, +inf
1108 }
1109 ;;
1110
1111 //
1112 // For -Inf raise invalid and return QNaN.
1113 //
1114 { .mfb
1115 mov GR_Parameter_TAG = 139
1116 fmpy.s0 FR_Output_X_tmp = FR_Input_X, f0
1117 br.cond.sptk __libm_error_region
1118 }
1119 ;;
1120
1121
1122 LOG1P_unsupported:
1123 //
1124 // Return generated NaN or other value.
1125 //
1126 { .mfb
1127 nop.m 999
1128 fmpy.s0 f8 = FR_Input_X, f0
1129 br.ret.sptk b0
1130 }
1131 ;;
1132
1133 // Here if -inf < x < -1
1134 LOG1P_LT_Minus_1:
1135 //
1136 // Deal with x < -1 in a special way - raise
1137 // invalid and produce QNaN indefinite.
1138 //
1139 { .mfb
1140 mov GR_Parameter_TAG = 139
1141 frcpa.s0 FR_Output_X_tmp, p8 = f0, f0
1142 br.cond.sptk __libm_error_region
1143 }
1144 ;;
1145
1146
1147 GLOBAL_IEEE754_END(log1pl)
1148
1149 LOCAL_LIBM_ENTRY(__libm_error_region)
1150 .prologue
1151 { .mfi
1152 add GR_Parameter_Y=-32,sp // Parameter 2 value
1153 nop.f 0
1154 .save ar.pfs,GR_SAVE_PFS
1155 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
1156 }
1157 { .mfi
1158 .fframe 64
1159 add sp=-64,sp // Create new stack
1160 nop.f 0
1161 mov GR_SAVE_GP=gp // Save gp
1162 };;
1163 { .mmi
1164 stfe [GR_Parameter_Y] = FR_Y,16 // Save Parameter 2 on stack
1165 add GR_Parameter_X = 16,sp // Parameter 1 address
1166 .save b0, GR_SAVE_B0
1167 mov GR_SAVE_B0=b0 // Save b0
1168 };;
1169 .body
1170 { .mib
1171 stfe [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
1172 add GR_Parameter_RESULT = 0,GR_Parameter_Y
1173 nop.b 0 // Parameter 3 address
1174 }
1175 { .mib
1176 stfe [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
1177 add GR_Parameter_Y = -16,GR_Parameter_Y
1178 br.call.sptk b0=__libm_error_support# // Call error handling function
1179 };;
1180 { .mmi
1181 nop.m 999
1182 nop.m 999
1183 add GR_Parameter_RESULT = 48,sp
1184 };;
1185 { .mmi
1186 ldfe f8 = [GR_Parameter_RESULT] // Get return result off stack
1187 .restore sp
1188 add sp = 64,sp // Restore stack pointer
1189 mov b0 = GR_SAVE_B0 // Restore return address
1190 };;
1191 { .mib
1192 mov gp = GR_SAVE_GP // Restore gp
1193 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
1194 br.ret.sptk b0 // Return
1195 };;
1196
1197 LOCAL_LIBM_END(__libm_error_region#)
1198
1199 .type __libm_error_support#,@function
1200 .global __libm_error_support#