4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
7 // Contributed 2000 by the Intel Numerics Group, Intel Corporation
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
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.
20 // * The name of Intel Corporation may not be used to endorse or promote
21 // products derived from this software without specific prior written
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.
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.
41 //==============================================================
42 // 02/02/00 Initial Version
43 // 04/04/00 Unwind support added
44 // 08/15/00 Bundle added after call to __libm_error_support to properly
45 // set [the previously overwritten] GR_Parameter_RESULT.
46 // 07/07/01 Improved speed of all paths
47 // 05/20/02 Cleaned up namespace and sf0 syntax
48 // 02/10/03 Reordered header: .section, .global, .proc, .align;
49 // used data8 for long double table values
50 // 03/11/03 Improved accuracy and performance, corrected missing inexact flags
51 // 04/17/03 Eliminated misplaced and unused data label
53 //*********************************************************************
55 // Function: Combined expl(x) and expm1l(x), where
57 // expl(x) = e , for double-extended precision x values
59 // expm1l(x) = e - 1 for double-extended precision x values
61 //*********************************************************************
65 // Floating-Point Registers: f8 (Input and Return Value)
68 // General Purpose Registers:
70 // r35-r38 (Used to pass arguments to error handling routine)
72 // Predicate Registers: p6-p15
74 //*********************************************************************
76 // IEEE Special Conditions:
78 // Denormal fault raised on denormal inputs
79 // Overflow exceptions raised when appropriate for exp and expm1
80 // Underflow exceptions raised when appropriate for exp and expm1
81 // (Error Handling Routine called for overflow and Underflow)
82 // Inexact raised when appropriate by algorithm
89 // exp(EM_special Values) = QNaN
95 // expm1(EM_special Values) = QNaN
97 //*********************************************************************
99 // Implementation and Algorithm Notes:
101 // ker_exp_64( in_FR : X,
107 // On input, X is in register format
113 // scale*(Y_hi + Y_lo) approximates exp(X) if exp
114 // scale*(Y_hi + Y_lo) approximates exp(X)-1 if expm1
116 // The accuracy is sufficient for a highly accurate 64 sig.
117 // bit implementation. Safe is set if there is no danger of
118 // overflow/underflow when the result is composed from scale,
119 // Y_hi and Y_lo. Thus, we can have a fast return if Safe is set.
120 // Otherwise, one must prepare to handle the possible exception
121 // appropriately. Note that SAFE not set (false) does not mean
122 // that overflow/underflow will occur; only the setting of SAFE
123 // guarantees the opposite.
125 // **** High Level Overview ****
127 // The method consists of three cases.
129 // If |X| < Tiny use case exp_tiny;
130 // else if |X| < 2^(-m) use case exp_small; m=12 for exp, m=7 for expm1
131 // else use case exp_regular;
135 // 1 + X can be used to approximate exp(X)
136 // X + X^2/2 can be used to approximate exp(X) - 1
140 // Here, exp(X) and exp(X) - 1 can all be
141 // appproximated by a relatively simple polynomial.
143 // This polynomial resembles the truncated Taylor series
145 // exp(w) = 1 + w + w^2/2! + w^3/3! + ... + w^n/n!
149 // Here we use a table lookup method. The basic idea is that in
150 // order to compute exp(X), we accurately decompose X into
152 // X = N * log(2)/(2^12) + r, |r| <= log(2)/2^13.
156 // exp(X) = 2^( N / 2^12 ) * exp(r).
158 // The value 2^( N / 2^12 ) is obtained by simple combinations
159 // of values calculated beforehand and stored in table; exp(r)
160 // is approximated by a short polynomial because |r| is small.
162 // We elaborate this method in 4 steps.
166 // The value 2^12/log(2) is stored as a double-extended number
169 // N := round_to_nearest_integer( X * L_Inv )
171 // The value log(2)/2^12 is stored as two numbers L_hi and L_lo so
172 // that r can be computed accurately via
174 // r := (X - N*L_hi) - N*L_lo
176 // We pick L_hi such that N*L_hi is representable in 64 sig. bits
177 // and thus the FMA X - N*L_hi is error free. So r is the
178 // 1 rounding error from an exact reduction with respect to
182 // In particular, L_hi has 30 significant bit and can be stored
183 // as a double-precision number; L_lo has 64 significant bits and
184 // stored as a double-extended number.
186 // Step 2: Approximation
188 // exp(r) - 1 is approximated by a short polynomial of the form
190 // r + A_1 r^2 + A_2 r^3 + A_3 r^4 .
192 // Step 3: Composition from Table Values
194 // The value 2^( N / 2^12 ) can be composed from a couple of tables
195 // of precalculated values. First, express N as three integers
196 // K, M_1, and M_2 as
198 // N = K * 2^12 + M_1 * 2^6 + M_2
200 // Where 0 <= M_1, M_2 < 2^6; and K can be positive or negative.
201 // When N is represented in 2's complement, M_2 is simply the 6
202 // lsb's, M_1 is the next 6, and K is simply N shifted right
203 // arithmetically (sign extended) by 12 bits.
205 // Now, 2^( N / 2^12 ) is simply
207 // 2^K * 2^( M_1 / 2^6 ) * 2^( M_2 / 2^12 )
209 // Clearly, 2^K needs no tabulation. The other two values are less
210 // trivial because if we store each accurately to more than working
211 // precision, than its product is too expensive to calculate. We
212 // use the following method.
214 // Define two mathematical values, delta_1 and delta_2, implicitly
217 // T_1 = exp( [M_1 log(2)/2^6] - delta_1 )
218 // T_2 = exp( [M_2 log(2)/2^12] - delta_2 )
220 // are representable as 24 significant bits. To illustrate the idea,
221 // we show how we define delta_1:
223 // T_1 := round_to_24_bits( exp( M_1 log(2)/2^6 ) )
224 // delta_1 = (M_1 log(2)/2^6) - log( T_1 )
226 // The last equality means mathematical equality. We then tabulate
228 // W_1 := exp(delta_1) - 1
229 // W_2 := exp(delta_2) - 1
231 // Both in double precision.
233 // From the tabulated values T_1, T_2, W_1, W_2, we compose the values
236 // T := T_1 * T_2 ...exactly
237 // W := W_1 + (1 + W_1)*W_2
239 // W approximates exp( delta ) - 1 where delta = delta_1 + delta_2.
240 // The mathematical product of T and (W+1) is an accurate representation
241 // of 2^(M_1/2^6) * 2^(M_2/2^12).
243 // Step 4. Reconstruction
245 // Finally, we can reconstruct exp(X), exp(X) - 1.
248 // X = K * log(2) + (M_1*log(2)/2^6 - delta_1)
249 // + (M_2*log(2)/2^12 - delta_2)
250 // + delta_1 + delta_2 + r ...accurately
253 // exp(X) ~=~ 2^K * ( T + T*[exp(delta_1+delta_2+r) - 1] )
254 // ~=~ 2^K * ( T + T*[exp(delta + r) - 1] )
255 // ~=~ 2^K * ( T + T*[(exp(delta)-1)
256 // + exp(delta)*(exp(r)-1)] )
257 // ~=~ 2^K * ( T + T*( W + (1+W)*poly(r) ) )
258 // ~=~ 2^K * ( Y_hi + Y_lo )
260 // where Y_hi = T and Y_lo = T*(W + (1+W)*poly(r))
262 // For exp(X)-1, we have
264 // exp(X)-1 ~=~ 2^K * ( Y_hi + Y_lo ) - 1
265 // ~=~ 2^K * ( Y_hi + Y_lo - 2^(-K) )
267 // and we combine Y_hi + Y_lo - 2^(-N) into the form of two
268 // numbers Y_hi + Y_lo carefully.
270 // **** Algorithm Details ****
272 // A careful algorithm must be used to realize the mathematical ideas
273 // accurately. We describe each of the three cases. We assume SAFE
274 // is preset to be TRUE.
278 // The important points are to ensure an accurate result under
279 // different rounding directions and a correct setting of the SAFE
282 // If expm1 is 1, then
283 // SAFE := False ...possibility of underflow
286 // Y_lo := 2^(-17000)
290 // Y_lo := X ...for different rounding modes
295 // Here we compute a simple polynomial. To exploit parallelism, we split
296 // the polynomial into several portions.
300 // If exp ...i.e. exp( argument )
304 // poly_lo := P_3 + r*(P_4 + r*(P_5 + r*P_6))
305 // poly_hi := r + rsq*(P_1 + r*P_2)
306 // Y_lo := poly_hi + r4 * poly_lo
310 // Else ...i.e. exp( argument ) - 1
314 // poly_lo := Q_7 + r*(Q_8 + r*Q_9))
315 // poly_med:= Q_3 + r*Q_4 + rsq*(Q_5 + r*Q_6)
316 // poly_med:= poly_med + r4*poly_lo
317 // poly_hi := Q_1 + r*Q_2
318 // Y_lo := rsq*(poly_hi + rsq*poly_lo)
326 // The previous description contain enough information except the
327 // computation of poly and the final Y_hi and Y_lo in the case for
330 // The computation of poly for Step 2:
333 // poly := r + rsq*(A_1 + r*(A_2 + r*A_3))
335 // For the case exp(X) - 1, we need to incorporate 2^(-K) into
336 // Y_hi and Y_lo at the end of Step 4.
339 // Y_lo := Y_lo - 2^(-K)
342 // Y_lo := Y_hi + Y_lo
345 // Y_hi := Y_hi - 2^(-K)
349 //=======================================================
350 // General Purpose Registers
366 GR_exp_underflow = r21
380 GR_big_expo_neg = r28
381 GR_very_small_exp = r29
391 GR_Parameter_RESULT = r37
392 GR_Parameter_TAG = r38
394 // Floating Point Registers
398 FR_INV_LN2_2TO63 = f11
461 FR_zero_uflow_x = f71
478 // ************* DO NOT CHANGE ORDER OF THESE TABLES ********************
480 // double-extended 1/ln(2)
481 // 3fff b8aa 3b29 5c17 f0bb be87fed0691d3e88
482 // 3fff b8aa 3b29 5c17 f0bc
483 // For speed the significand will be loaded directly with a movl and setf.sig
484 // and the exponent will be bias+63 instead of bias+0. Thus subsequent
485 // computations need to scale appropriately.
486 // The constant 2^12/ln(2) is needed for the computation of N. This is also
487 // obtained by scaling the computations.
489 // Two shifting constants are loaded directly with movl and setf.d.
490 // 1. RSHF_2TO51 = 1.1000..00 * 2^(63-12)
491 // This constant is added to x*1/ln2 to shift the integer part of
492 // x*2^12/ln2 into the rightmost bits of the significand.
493 // The result of this fma is N_signif.
494 // 2. RSHF = 1.1000..00 * 2^(63)
495 // This constant is subtracted from N_signif * 2^(-51) to give
496 // the integer part of N, N_fix, as a floating-point number.
497 // The result of this fms is float_N.
501 LOCAL_OBJECT_START(Constants_exp_64_Arg)
502 //data8 0xB8AA3B295C17F0BC,0x0000400B // Inv_L = 2^12/log(2)
503 data8 0xB17217F400000000,0x00003FF2 // L_hi = hi part log(2)/2^12
504 data8 0xF473DE6AF278ECE6,0x00003FD4 // L_lo = lo part log(2)/2^12
505 LOCAL_OBJECT_END(Constants_exp_64_Arg)
507 LOCAL_OBJECT_START(Constants_exp_64_Limits)
508 data8 0xb17217f7d1cf79ac,0x0000400c // Smallest long dbl oflow x
509 data8 0xb220000000000000,0x0000c00c // Small long dbl uflow zero x
510 LOCAL_OBJECT_END(Constants_exp_64_Limits)
512 LOCAL_OBJECT_START(Constants_exp_64_A)
513 data8 0xAAAAAAABB1B736A0,0x00003FFA // A3
514 data8 0xAAAAAAAB90CD6327,0x00003FFC // A2
515 data8 0xFFFFFFFFFFFFFFFF,0x00003FFD // A1
516 LOCAL_OBJECT_END(Constants_exp_64_A)
518 LOCAL_OBJECT_START(Constants_exp_64_P)
519 data8 0xD00D6C8143914A8A,0x00003FF2 // P6
520 data8 0xB60BC4AC30304B30,0x00003FF5 // P5
521 data8 0x888888887474C518,0x00003FF8 // P4
522 data8 0xAAAAAAAA8DAE729D,0x00003FFA // P3
523 data8 0xAAAAAAAAAAAAAF61,0x00003FFC // P2
524 data8 0x80000000000004C7,0x00003FFE // P1
525 LOCAL_OBJECT_END(Constants_exp_64_P)
527 LOCAL_OBJECT_START(Constants_exp_64_Q)
528 data8 0x93F2AC5F7471F32E, 0x00003FE9 // Q9
529 data8 0xB8DA0F3550B3E764, 0x00003FEC // Q8
530 data8 0xD00D00D0028E89C4, 0x00003FEF // Q7
531 data8 0xD00D00DAEB8C4E91, 0x00003FF2 // Q6
532 data8 0xB60B60B60B60B6F5, 0x00003FF5 // Q5
533 data8 0x888888888886CC23, 0x00003FF8 // Q4
534 data8 0xAAAAAAAAAAAAAAAB, 0x00003FFA // Q3
535 data8 0xAAAAAAAAAAAAAAAB, 0x00003FFC // Q2
536 data8 0x8000000000000000, 0x00003FFE // Q1
537 LOCAL_OBJECT_END(Constants_exp_64_Q)
539 LOCAL_OBJECT_START(Constants_exp_64_T1)
540 data4 0x3F800000,0x3F8164D2,0x3F82CD87,0x3F843A29
541 data4 0x3F85AAC3,0x3F871F62,0x3F88980F,0x3F8A14D5
542 data4 0x3F8B95C2,0x3F8D1ADF,0x3F8EA43A,0x3F9031DC
543 data4 0x3F91C3D3,0x3F935A2B,0x3F94F4F0,0x3F96942D
544 data4 0x3F9837F0,0x3F99E046,0x3F9B8D3A,0x3F9D3EDA
545 data4 0x3F9EF532,0x3FA0B051,0x3FA27043,0x3FA43516
546 data4 0x3FA5FED7,0x3FA7CD94,0x3FA9A15B,0x3FAB7A3A
547 data4 0x3FAD583F,0x3FAF3B79,0x3FB123F6,0x3FB311C4
548 data4 0x3FB504F3,0x3FB6FD92,0x3FB8FBAF,0x3FBAFF5B
549 data4 0x3FBD08A4,0x3FBF179A,0x3FC12C4D,0x3FC346CD
550 data4 0x3FC5672A,0x3FC78D75,0x3FC9B9BE,0x3FCBEC15
551 data4 0x3FCE248C,0x3FD06334,0x3FD2A81E,0x3FD4F35B
552 data4 0x3FD744FD,0x3FD99D16,0x3FDBFBB8,0x3FDE60F5
553 data4 0x3FE0CCDF,0x3FE33F89,0x3FE5B907,0x3FE8396A
554 data4 0x3FEAC0C7,0x3FED4F30,0x3FEFE4BA,0x3FF28177
555 data4 0x3FF5257D,0x3FF7D0DF,0x3FFA83B3,0x3FFD3E0C
556 LOCAL_OBJECT_END(Constants_exp_64_T1)
558 LOCAL_OBJECT_START(Constants_exp_64_T2)
559 data4 0x3F800000,0x3F80058C,0x3F800B18,0x3F8010A4
560 data4 0x3F801630,0x3F801BBD,0x3F80214A,0x3F8026D7
561 data4 0x3F802C64,0x3F8031F2,0x3F803780,0x3F803D0E
562 data4 0x3F80429C,0x3F80482B,0x3F804DB9,0x3F805349
563 data4 0x3F8058D8,0x3F805E67,0x3F8063F7,0x3F806987
564 data4 0x3F806F17,0x3F8074A8,0x3F807A39,0x3F807FCA
565 data4 0x3F80855B,0x3F808AEC,0x3F80907E,0x3F809610
566 data4 0x3F809BA2,0x3F80A135,0x3F80A6C7,0x3F80AC5A
567 data4 0x3F80B1ED,0x3F80B781,0x3F80BD14,0x3F80C2A8
568 data4 0x3F80C83C,0x3F80CDD1,0x3F80D365,0x3F80D8FA
569 data4 0x3F80DE8F,0x3F80E425,0x3F80E9BA,0x3F80EF50
570 data4 0x3F80F4E6,0x3F80FA7C,0x3F810013,0x3F8105AA
571 data4 0x3F810B41,0x3F8110D8,0x3F81166F,0x3F811C07
572 data4 0x3F81219F,0x3F812737,0x3F812CD0,0x3F813269
573 data4 0x3F813802,0x3F813D9B,0x3F814334,0x3F8148CE
574 data4 0x3F814E68,0x3F815402,0x3F81599C,0x3F815F37
575 LOCAL_OBJECT_END(Constants_exp_64_T2)
577 LOCAL_OBJECT_START(Constants_exp_64_W1)
578 data8 0x0000000000000000, 0xBE384454171EC4B4
579 data8 0xBE6947414AA72766, 0xBE5D32B6D42518F8
580 data8 0x3E68D96D3A319149, 0xBE68F4DA62415F36
581 data8 0xBE6DDA2FC9C86A3B, 0x3E6B2E50F49228FE
582 data8 0xBE49C0C21188B886, 0x3E64BFC21A4C2F1F
583 data8 0xBE6A2FBB2CB98B54, 0x3E5DC5DE9A55D329
584 data8 0x3E69649039A7AACE, 0x3E54728B5C66DBA5
585 data8 0xBE62B0DBBA1C7D7D, 0x3E576E0409F1AF5F
586 data8 0x3E6125001A0DD6A1, 0xBE66A419795FBDEF
587 data8 0xBE5CDE8CE1BD41FC, 0xBE621376EA54964F
588 data8 0x3E6370BE476E76EE, 0x3E390D1A3427EB92
589 data8 0x3E1336DE2BF82BF8, 0xBE5FF1CBD0F7BD9E
590 data8 0xBE60A3550CEB09DD, 0xBE5CA37E0980F30D
591 data8 0xBE5C541B4C082D25, 0xBE5BBECA3B467D29
592 data8 0xBE400D8AB9D946C5, 0xBE5E2A0807ED374A
593 data8 0xBE66CB28365C8B0A, 0x3E3AAD5BD3403BCA
594 data8 0x3E526055C7EA21E0, 0xBE442C75E72880D6
595 data8 0x3E58B2BB85222A43, 0xBE5AAB79522C42BF
596 data8 0xBE605CB4469DC2BC, 0xBE589FA7A48C40DC
597 data8 0xBE51C2141AA42614, 0xBE48D087C37293F4
598 data8 0x3E367A1CA2D673E0, 0xBE51BEBB114F7A38
599 data8 0xBE6348E5661A4B48, 0xBDF526431D3B9962
600 data8 0x3E3A3B5E35A78A53, 0xBE46C46C1CECD788
601 data8 0xBE60B7EC7857D689, 0xBE594D3DD14F1AD7
602 data8 0xBE4F9C304C9A8F60, 0xBE52187302DFF9D2
603 data8 0xBE5E4C8855E6D68F, 0xBE62140F667F3DC4
604 data8 0xBE36961B3BF88747, 0x3E602861C96EC6AA
605 data8 0xBE3B5151D57FD718, 0x3E561CD0FC4A627B
606 data8 0xBE3A5217CA913FEA, 0x3E40A3CC9A5D193A
607 data8 0xBE5AB71310A9C312, 0x3E4FDADBC5F57719
608 data8 0x3E361428DBDF59D5, 0x3E5DB5DB61B4180D
609 data8 0xBE42AD5F7408D856, 0x3E2A314831B2B707
610 LOCAL_OBJECT_END(Constants_exp_64_W1)
612 LOCAL_OBJECT_START(Constants_exp_64_W2)
613 data8 0x0000000000000000, 0xBE641F2537A3D7A2
614 data8 0xBE68DD57AD028C40, 0xBE5C77D8F212B1B6
615 data8 0x3E57878F1BA5B070, 0xBE55A36A2ECAE6FE
616 data8 0xBE620608569DFA3B, 0xBE53B50EA6D300A3
617 data8 0x3E5B5EF2223F8F2C, 0xBE56A0D9D6DE0DF4
618 data8 0xBE64EEF3EAE28F51, 0xBE5E5AE2367EA80B
619 data8 0x3E47CB1A5FCBC02D, 0xBE656BA09BDAFEB7
620 data8 0x3E6E70C6805AFEE7, 0xBE6E0509A3415EBA
621 data8 0xBE56856B49BFF529, 0x3E66DD3300508651
622 data8 0x3E51165FC114BC13, 0x3E53333DC453290F
623 data8 0x3E6A072B05539FDA, 0xBE47CD877C0A7696
624 data8 0xBE668BF4EB05C6D9, 0xBE67C3E36AE86C93
625 data8 0xBE533904D0B3E84B, 0x3E63E8D9556B53CE
626 data8 0x3E212C8963A98DC8, 0xBE33138F032A7A22
627 data8 0x3E530FA9BC584008, 0xBE6ADF82CCB93C97
628 data8 0x3E5F91138370EA39, 0x3E5443A4FB6A05D8
629 data8 0x3E63DACD181FEE7A, 0xBE62B29DF0F67DEC
630 data8 0x3E65C4833DDE6307, 0x3E5BF030D40A24C1
631 data8 0x3E658B8F14E437BE, 0xBE631C29ED98B6C7
632 data8 0x3E6335D204CF7C71, 0x3E529EEDE954A79D
633 data8 0x3E5D9257F64A2FB8, 0xBE6BED1B854ED06C
634 data8 0x3E5096F6D71405CB, 0xBE3D4893ACB9FDF5
635 data8 0xBDFEB15801B68349, 0x3E628D35C6A463B9
636 data8 0xBE559725ADE45917, 0xBE68C29C042FC476
637 data8 0xBE67593B01E511FA, 0xBE4A4313398801ED
638 data8 0x3E699571DA7C3300, 0x3E5349BE08062A9E
639 data8 0x3E5229C4755BB28E, 0x3E67E42677A1F80D
640 data8 0xBE52B33F6B69C352, 0xBE6B3550084DA57F
641 data8 0xBE6DB03FD1D09A20, 0xBE60CBC42161B2C1
642 data8 0x3E56ED9C78A2B771, 0xBE508E319D0FA795
643 data8 0xBE59482AFD1A54E9, 0xBE2A17CEB07FD23E
644 data8 0x3E68BF5C17365712, 0x3E3956F9B3785569
645 LOCAL_OBJECT_END(Constants_exp_64_W2)
650 GLOBAL_IEEE754_ENTRY(expm1l)
653 // Set p7 true for expm1, p6 false
657 getf.exp GR_signexp_x = f8 // Get sign and exponent of x, redo if unorm
658 movl GR_sig_inv_ln2 = 0xb8aa3b295c17f0bc // significand of 1/ln2
661 addl GR_ad_Arg = @ltoff(Constants_exp_64_Arg#),gp
662 movl GR_rshf_2to51 = 0x4718000000000000 // 1.10000 2^(63+51)
667 ld8 GR_ad_Arg = [GR_ad_Arg] // Point to Arg table
668 fclass.m p8, p0 = f8, 0x1E7 // Test x for natval, nan, inf, zero
669 cmp.eq p7, p6 = r0, r0
672 mov GR_exp_half = 0x0FFFE // Exponent of 0.5, for very small path
673 fnorm.s1 FR_norm_x = f8 // Normalize x
674 br.cond.sptk exp_continue
678 GLOBAL_IEEE754_END(expm1l)
680 GLOBAL_IEEE754_ENTRY(expl)
682 // Set p7 false for exp, p6 true
685 getf.exp GR_signexp_x = f8 // Get sign and exponent of x, redo if unorm
686 movl GR_sig_inv_ln2 = 0xb8aa3b295c17f0bc // significand of 1/ln2
689 addl GR_ad_Arg = @ltoff(Constants_exp_64_Arg#),gp
690 movl GR_rshf_2to51 = 0x4718000000000000 // 1.10000 2^(63+51)
695 ld8 GR_ad_Arg = [GR_ad_Arg] // Point to Arg table
696 fclass.m p8, p0 = f8, 0x1E7 // Test x for natval, nan, inf, zero
697 cmp.eq p6, p7 = r0, r0
700 mov GR_exp_half = 0x0FFFE // Exponent of 0.5, for very small path
701 fnorm.s1 FR_norm_x = f8 // Normalize x
707 // Form two constants we need
708 // 1/ln2 * 2^63 to compute w = x * 1/ln2 * 128
709 // 1.1000..000 * 2^(63+63-12) to right shift int(N) into the significand
712 setf.sig FR_INV_LN2_2TO63 = GR_sig_inv_ln2 // form 1/ln2 * 2^63
713 fclass.nm.unc p9, p0 = f8, 0x1FF // Test x for unsupported
714 mov GR_exp_2tom51 = 0xffff-51
717 setf.d FR_RSHF_2TO51 = GR_rshf_2to51 // Form const 1.1000 * 2^(63+51)
718 movl GR_rshf = 0x43e8000000000000 // 1.10000 2^63 for right shift
723 setf.exp FR_half = GR_exp_half // Form 0.5 for very small path
724 fma.s1 FR_scale = f1,f1,f0 // Scale = 1.0
725 mov GR_exp_bias = 0x0FFFF // Set exponent bias
728 add GR_ad_Limits = 0x20, GR_ad_Arg // Point to Limits table
729 mov GR_exp_mask = 0x1FFFF // Form exponent mask
730 (p8) br.cond.spnt EXP_64_SPECIAL // Branch if natval, nan, inf, zero
735 setf.exp FR_2TOM51 = GR_exp_2tom51 // Form 2^-51 for scaling float_N
737 add GR_ad_A = 0x40, GR_ad_Arg // Point to A table
740 setf.d FR_RSHF = GR_rshf // Form right shift const 1.1000 * 2^63
741 add GR_ad_T1 = 0x160, GR_ad_Arg // Point to T1 table
742 (p9) br.cond.spnt EXP_64_UNSUPPORTED // Branch if unsupported
746 .pred.rel "mutex",p6,p7
748 ldfe FR_L_hi = [GR_ad_Arg],16 // Get L_hi
749 fcmp.eq.s0 p9,p0 = f8, f0 // Dummy op to flag denormals
750 (p6) add GR_ad_PQ = 0x30, GR_ad_A // Point to P table for exp
753 ldfe FR_min_oflow_x = [GR_ad_Limits],16 // Get min x to cause overflow
754 fmpy.s1 FR_rsq = f8, f8 // rsq = x * x for small path
755 (p7) add GR_ad_PQ = 0x90, GR_ad_A // Point to Q table for expm1
759 ldfe FR_L_lo = [GR_ad_Arg],16 // Get L_lo
760 ldfe FR_zero_uflow_x = [GR_ad_Limits],16 // Get x for zero uflow result
761 add GR_ad_W1 = 0x200, GR_ad_T1 // Point to W1 table
766 ldfe FR_P6Q9 = [GR_ad_PQ],16 // P6(exp) or Q9(expm1) for small path
767 mov FR_r = FR_norm_x // r = X for small path
768 mov GR_very_small_exp = -60 // Exponent of x for very small path
771 add GR_ad_W2 = 0x400, GR_ad_T1 // Point to W2 table
773 (p7) mov GR_small_exp = -7 // Exponent of x for small path expm1
778 ldfe FR_P5Q8 = [GR_ad_PQ],16 // P5(exp) or Q8(expm1) for small path
779 and GR_exp_x = GR_signexp_x, GR_exp_mask
780 (p6) mov GR_small_exp = -12 // Exponent of x for small path exp
784 // N_signif = X * Inv_log2_by_2^12
785 // By adding 1.10...0*2^63 we shift and get round_int(N_signif) in significand.
786 // We actually add 1.10...0*2^51 to X * Inv_log2 to do the same thing.
788 ldfe FR_P4Q7 = [GR_ad_PQ],16 // P4(exp) or Q7(expm1) for small path
789 fma.s1 FR_N_signif = FR_norm_x, FR_INV_LN2_2TO63, FR_RSHF_2TO51
793 sub GR_exp_x = GR_exp_x, GR_exp_bias // Get exponent
794 fmpy.s1 FR_r4 = FR_rsq, FR_rsq // Form r4 for small path
795 cmp.eq.unc p15, p0 = r0, r0 // Set Safe as default
800 ldfe FR_P3Q6 = [GR_ad_PQ],16 // P3(exp) or Q6(expm1) for small path
801 cmp.lt p14, p0 = GR_exp_x, GR_very_small_exp // Is |x| < 2^-60?
807 ldfe FR_P2Q5 = [GR_ad_PQ],16 // P2(exp) or Q5(expm1) for small path
808 fmpy.s1 FR_half_x = FR_half, FR_norm_x // 0.5 * x for very small path
809 cmp.lt p13, p0 = GR_exp_x, GR_small_exp // Is |x| < 2^-m?
814 (p14) br.cond.spnt EXP_VERY_SMALL // Branch if |x| < 2^-60
819 ldfe FR_A3 = [GR_ad_A],16 // Get A3 for normal path
820 fcmp.ge.s1 p10,p0 = FR_norm_x, FR_min_oflow_x // Will result overflow?
821 mov GR_big_expo_neg = -16381 // -0x3ffd
824 ldfe FR_P1Q4 = [GR_ad_PQ],16 // P1(exp) or Q4(expm1) for small path
826 (p13) br.cond.spnt EXP_SMALL // Branch if |x| < 2^-m
827 // m=12 for exp, m=7 for expm1
831 // Now we are on the main path for |x| >= 2^-m, m=12 for exp, m=7 for expm1
833 // float_N = round_int(N_signif)
834 // The signficand of N_signif contains the rounded integer part of X * 2^12/ln2,
835 // as a twos complement number in the lower bits (that is, it may be negative).
836 // That twos complement number (called N) is put into GR_N.
838 // Since N_signif is scaled by 2^51, it must be multiplied by 2^-51
839 // before the shift constant 1.10000 * 2^63 is subtracted to yield float_N.
840 // Thus, float_N contains the floating point version of N
844 ldfe FR_A2 = [GR_ad_A],16 // Get A2 for main path
845 fcmp.lt.s1 p11,p0 = FR_norm_x, FR_zero_uflow_x // Certain zero, uflow?
846 add GR_ad_T2 = 0x100, GR_ad_T1 // Point to T2 table
850 fms.s1 FR_float_N = FR_N_signif, FR_2TOM51, FR_RSHF // Form float_N
856 getf.sig GR_N_fix = FR_N_signif // Get N from significand
857 (p10) br.cond.spnt EXP_OVERFLOW // Branch if result will overflow
858 (p11) br.cond.spnt EXP_CERTAIN_UNDERFLOW_ZERO // Branch if certain zero, uflow
863 ldfe FR_A1 = [GR_ad_A],16 // Get A1 for main path
864 fnma.s1 FR_r = FR_L_hi, FR_float_N, FR_norm_x // r = -L_hi * float_N + x
865 extr.u GR_M1 = GR_N_fix, 6, 6 // Extract index M_1
868 and GR_M2 = 0x3f, GR_N_fix // Extract index M_2
874 // N_fix is only correct up to 50 bits because of our right shift technique.
875 // Actually in the normal path we will have restricted K to about 14 bits.
876 // Somewhat arbitrarily we extract 32 bits.
878 shladd GR_ad_W1 = GR_M1,3,GR_ad_W1 // Point to W1
880 extr GR_K = GR_N_fix, 12, 32 // Extract limited range K
883 shladd GR_ad_T1 = GR_M1,2,GR_ad_T1 // Point to T1
885 shladd GR_ad_T2 = GR_M2,2,GR_ad_T2 // Point to T2
890 ldfs FR_T1 = [GR_ad_T1],0 // Get T1
891 ldfd FR_W1 = [GR_ad_W1],0 // Get W1
892 add GR_exp_2_k = GR_exp_bias, GR_K // Form exponent of 2^k
897 ldfs FR_T2 = [GR_ad_T2],0 // Get T2
898 shladd GR_ad_W2 = GR_M2,3,GR_ad_W2 // Point to W2
899 sub GR_exp_2_mk = GR_exp_bias, GR_K // Form exponent of 2^-k
904 ldfd FR_W2 = [GR_ad_W2],0 // Get W2
905 setf.exp FR_scale = GR_exp_2_k // Set scale = 2^k
906 fnma.s1 FR_r = FR_L_lo, FR_float_N, FR_r // r = -L_lo * float_N + r
911 setf.exp FR_2_mk = GR_exp_2_mk // Form 2^-k
912 fma.s1 FR_poly = FR_r, FR_A3, FR_A2 // poly = r * A3 + A2
913 cmp.lt p8,p15 = GR_K,GR_big_expo_neg // Set Safe if K > big_expo_neg
917 fmpy.s1 FR_rsq = FR_r, FR_r // rsq = r * r
924 fmpy.s1 FR_T = FR_T1, FR_T2 // T = T1 * T2
929 fadd.s1 FR_W1_p1 = FR_W1, f1 // W1_p1 = W1 + 1.0
935 (p7) cmp.lt.unc p8, p9 = 10, GR_K // If expm1, set p8 if K > 10
936 fma.s1 FR_poly = FR_r, FR_poly, FR_A1 // poly = r * poly + A1
942 (p7) cmp.eq p15, p0 = r0, r0 // If expm1, set Safe flag
943 fma.s1 FR_T_scale = FR_T, FR_scale, f0 // T_scale = T * scale
944 (p9) cmp.gt.unc p9, p10 = -10, GR_K // If expm1, set p9 if K < -10
945 // If expm1, set p10 if -10<=K<=10
949 fma.s1 FR_W = FR_W2, FR_W1_p1, FR_W1 // W = W2 * (W1+1.0) + W1
956 mov FR_Y_hi = FR_T // Assume Y_hi = T
963 fma.s1 FR_poly = FR_rsq, FR_poly, FR_r // poly = rsq * poly + r
970 fma.s1 FR_Wp1_T_scale = FR_W, FR_T_scale, FR_T_scale // (W+1)*T*scale
975 fma.s1 FR_W_T_scale = FR_W, FR_T_scale, f0 // W*T*scale
982 (p9) fsub.s1 FR_Y_hi = f0, FR_2_mk // If expm1, if K < -10 set Y_hi
987 (p10) fsub.s1 FR_Y_hi = FR_T, FR_2_mk // If expm1, if |K|<=10 set Y_hi
994 fma.s1 FR_result_lo = FR_Wp1_T_scale, FR_poly, FR_W_T_scale
999 .pred.rel "mutex",p8,p9
1000 // If K > 10 adjust result_lo = result_lo - scale * 2^-k
1001 // If |K| <= 10 adjust result_lo = result_lo + scale * T
1004 (p8) fnma.s1 FR_result_lo = FR_scale, FR_2_mk, FR_result_lo // If K > 10
1009 (p9) fma.s1 FR_result_lo = FR_T_scale, f1, FR_result_lo // If |K| <= 10
1016 fmpy.s0 FR_tmp = FR_A1, FR_A1 // Dummy op to set inexact
1021 (p15) fma.s0 f8 = FR_Y_hi, FR_scale, FR_result_lo // Safe result
1022 (p15) br.ret.sptk b0 // Safe exit for normal path
1026 // Here if unsafe, will only be here for exp with K < big_expo_neg
1029 fma.s0 FR_RESULT = FR_Y_hi, FR_scale, FR_result_lo // Prelim result
1030 br.cond.sptk EXP_POSSIBLE_UNDERFLOW // Branch to unsafe code
1036 // Here if 2^-60 < |x| < 2^-m, m=12 for exp, m=7 for expm1
1038 (p7) ldfe FR_Q3 = [GR_ad_Q],16 // Get Q3 for small path, if expm1
1039 (p6) fma.s1 FR_p65 = FR_P6, FR_r, FR_P5 // If exp, p65 = P6 * r + P5
1043 mov GR_minus_one = -1
1044 (p7) fma.s1 FR_q98 = FR_Q9, FR_r, FR_Q8 // If expm1, q98 = Q9 * r + Q8
1050 (p7) ldfe FR_Q2 = [GR_ad_Q],16 // Get Q2 for small path, if expm1
1051 (p7) fma.s1 FR_q65 = FR_Q6, FR_r, FR_Q5 // If expm1, q65 = Q6 * r + Q5
1057 setf.sig FR_tmp = GR_minus_one // Create value to force inexact
1058 (p6) fma.s1 FR_p21 = FR_P2, FR_r, FR_P1 // If exp, p21 = P2 * r + P1
1062 (p7) ldfe FR_Q1 = [GR_ad_Q],16 // Get Q1 for small path, if expm1
1063 (p7) fma.s1 FR_q43 = FR_Q4, FR_r, FR_Q3 // If expm1, q43 = Q4 * r + Q3
1070 (p6) fma.s1 FR_p654 = FR_p65, FR_r, FR_P4 // If exp, p654 = p65 * r + P4
1075 (p7) fma.s1 FR_q987 = FR_q98, FR_r, FR_Q7 // If expm1, q987 = q98 * r + Q7
1082 (p7) fma.s1 FR_q21 = FR_Q2, FR_r, FR_Q1 // If expm1, q21 = Q2 * r + Q1
1089 (p6) fma.s1 FR_p210 = FR_p21, FR_rsq, FR_r // If exp, p210 = p21 * r + P0
1094 (p7) fma.s1 FR_q6543 = FR_q65, FR_rsq, FR_q43 // If expm1, q6543 = q65*r2+q43
1101 (p6) fma.s1 FR_p6543 = FR_p654, FR_r, FR_P3 // If exp, p6543 = p654 * r + P3
1106 (p7) fma.s1 FR_q9876543 = FR_q987, FR_r4, FR_q6543 // If expm1, q9876543 = ...
1113 (p6) fma.s1 FR_Y_lo = FR_p6543, FR_r4, FR_p210 // If exp, form Y_lo
1120 (p7) fma.s1 FR_Y_lo = FR_q9876543, FR_rsq, FR_q21 // If expm1, form Y_lo
1127 fmpy.s0 FR_tmp = FR_tmp, FR_tmp // Dummy op to set inexact
1132 .pred.rel "mutex",p6,p7
1135 (p6) fma.s0 f8 = FR_Y_lo, f1, f1 // If exp, result = 1 + Y_lo
1140 (p7) fma.s0 f8 = FR_Y_lo, FR_rsq, FR_norm_x // If expm1, result = Y_lo*r2+x
1141 br.ret.sptk b0 // Exit for 2^-60 <= |x| < 2^-m
1142 // m=12 for exp, m=7 for expm1
1149 // Here if 0 < |x| < 2^-60
1150 // If exp, result = 1.0 + x
1151 // If expm1, result = x +x*x/2, but have to check for possible underflow
1155 (p7) mov GR_exp_underflow = -16381 // Exponent for possible underflow
1156 (p6) fadd.s0 f8 = f1, FR_norm_x // If exp, result = 1+x
1161 (p7) fmpy.s1 FR_result_lo = FR_half_x, FR_norm_x // If expm1 result_lo = x*x/2
1167 (p7) cmp.lt.unc p0, p8 = GR_exp_x, GR_exp_underflow // Unsafe if expm1 x small
1168 (p7) mov FR_Y_hi = FR_norm_x // If expm1, Y_hi = x
1169 (p7) cmp.lt p0, p15 = GR_exp_x, GR_exp_underflow // Unsafe if expm1 x small
1175 (p8) fma.s0 f8 = FR_norm_x, f1, FR_result_lo // If expm1, result=x+x*x/2
1176 (p15) br.ret.sptk b0 // If Safe, exit
1180 // Here if expm1 and 0 < |x| < 2^-16381; may be possible underflow
1183 fma.s0 FR_RESULT = FR_Y_hi, FR_scale, FR_result_lo // Prelim result
1184 br.cond.sptk EXP_POSSIBLE_UNDERFLOW // Branch to unsafe code
1188 EXP_CERTAIN_UNDERFLOW_ZERO:
1189 // Here if x < zero_uflow_x
1190 // For exp, set result to tiny+0.0 and set I, U, and branch to error handling
1191 // For expm1, set result to tiny-1.0 and set I, and exit
1193 alloc GR_SAVE_PFS = ar.pfs,0,3,4,0
1200 setf.exp FR_small = GR_one // Form small value
1202 (p6) mov GR_Parameter_TAG = 13 // Error tag for exp underflow
1208 fmerge.s FR_X = f8,f8 // Save x for error call
1213 .pred.rel "mutex",p6,p7
1216 (p6) fma.s0 FR_RESULT = FR_small, FR_small, f0 // If exp, set I,U, tiny result
1217 (p6) br.cond.sptk __libm_error_region // If exp, go to error handling
1221 (p7) fms.s0 f8 = FR_small, FR_small, f1 // If expm1, set I, result -1.0
1222 (p7) br.ret.sptk b0 // If expm1, exit
1228 // Here if x >= min_oflow_x
1230 alloc GR_SAVE_PFS = ar.pfs,0,3,4,0
1231 mov GR_huge_exp = 0x1fffe
1235 mov GR_huge_signif = -0x1
1237 (p6) mov GR_Parameter_TAG = 12 // Error tag for exp overflow
1242 setf.exp FR_huge_exp = GR_huge_exp // Create huge value
1243 setf.sig FR_huge_signif = GR_huge_signif // Create huge value
1244 fmerge.s FR_X = f8,f8 // Save x for error call
1250 fmerge.se FR_huge = FR_huge_exp, FR_huge_signif
1251 (p7) mov GR_Parameter_TAG = 39 // Error tag for expm1 overflow
1257 fma.s0 FR_RESULT = FR_huge, FR_huge, FR_huge // Force I, O, and Inf
1258 br.cond.sptk __libm_error_region // Branch to error handling
1264 EXP_POSSIBLE_UNDERFLOW:
1265 // Here if exp and zero_uflow_x < x < about -11356 [where k < -16381]
1266 // Here if expm1 and |x| < 2^-16381
1268 alloc GR_SAVE_PFS = ar.pfs,0,3,4,0
1269 fsetc.s2 0x7F,0x41 // Set FTZ and disable traps
1276 fma.s2 FR_ftz = FR_Y_hi, FR_scale, FR_result_lo // Result with FTZ
1283 fsetc.s2 0x7F,0x40 // Disable traps (set s2 default)
1290 (p7) fclass.m.unc p12, p0 = FR_ftz, 0x00F // If expm1, FTZ result denorm, zero?
1297 (p6) fclass.m.unc p11, p0 = FR_ftz, 0x00F // If exp, FTZ result denorm or zero?
1303 (p12) mov GR_Parameter_TAG = 40 // expm1 underflow
1304 fmerge.s FR_X = f8,f8 // Save x for error call
1305 (p12) br.cond.spnt __libm_error_region // Branch on expm1 underflow
1310 (p11) mov GR_Parameter_TAG = 13 // exp underflow
1312 (p11) br.cond.spnt __libm_error_region // Branch on exp underflow
1318 mov f8 = FR_RESULT // Was safe after all
1325 // Here if x natval, nan, inf, zero
1326 // If x natval, +inf, or if expm1 and x zero, just return x.
1327 // The other cases must be tested for, and results set.
1328 // These cases do not generate exceptions.
1331 fclass.m p8, p0 = f8, 0x0c3 // Is x nan?
1338 (p6) fclass.m.unc p13, p0 = f8, 0x007 // If exp, is x zero?
1345 (p6) fclass.m.unc p11, p0 = f8, 0x022 // If exp, is x -inf?
1350 (p8) fadd.s0 f8 = f8, f1 // If x nan, result quietized x
1357 (p7) fclass.m.unc p10, p0 = f8, 0x022 // If expm1, is x -inf?
1362 (p13) fadd.s0 f8 = f0, f1 // If exp and x zero, result 1.0
1369 (p11) mov f8 = f0 // If exp and x -inf, result 0
1376 (p10) fsub.s1 f8 = f0, f1 // If expm1, x -inf, result -1.0
1377 br.ret.sptk b0 // Exit special cases
1383 // Here if x unsupported type
1386 fmpy.s0 f8 = f8, f0 // Return nan
1391 GLOBAL_IEEE754_END(expl)
1392 LOCAL_LIBM_ENTRY(__libm_error_region)
1395 add GR_Parameter_Y=-32,sp // Parameter 2 value
1397 .save ar.pfs,GR_SAVE_PFS
1398 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
1402 add sp=-64,sp // Create new stack
1404 mov GR_SAVE_GP=gp // Save gp
1407 stfe [GR_Parameter_Y] = FR_Y,16 // Save Parameter 2 on stack
1408 add GR_Parameter_X = 16,sp // Parameter 1 address
1409 .save b0, GR_SAVE_B0
1410 mov GR_SAVE_B0=b0 // Save b0
1414 stfe [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
1415 add GR_Parameter_RESULT = 0,GR_Parameter_Y
1416 nop.b 0 // Parameter 3 address
1419 stfe [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
1420 add GR_Parameter_Y = -16,GR_Parameter_Y
1421 br.call.sptk b0=__libm_error_support# // Call error handling function
1424 add GR_Parameter_RESULT = 48,sp
1429 ldfe f8 = [GR_Parameter_RESULT] // Get return result off stack
1431 add sp = 64,sp // Restore stack pointer
1432 mov b0 = GR_SAVE_B0 // Restore return address
1435 mov gp = GR_SAVE_GP // Restore gp
1436 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
1437 br.ret.sptk b0 // Return
1439 LOCAL_LIBM_END(__libm_error_region#)
1441 .type __libm_error_support#,@function
1442 .global __libm_error_support#