Add more files to the architecture specific section.
[dragonfly.git] / lib / msun / i387 / s_log1pf.S
1 /*
2  * Written by J.T. Conklin <jtc@NetBSD.org>.
3  * Public domain.
4  */
5
6 /*
7  * Modified by Lex Wennmacher <wennmach@NetBSD.org>
8  * Still public domain.
9  */
10
11 #include <machine/asm.h>
12
13 #include "abi.h"
14
15 #if 0
16 RCSID("$NetBSD$")
17 #endif
18 RCSID("$DragonFly: src/lib/msun/i387/Attic/s_log1pf.S,v 1.1 2004/12/29 12:55:50 asmodai Exp $")
19
20 /*
21  * The log1pf() function is provided to compute an accurate value of
22  * log(1 + x), even for tiny values of x. The i387 FPU provides the
23  * fyl2xp1 instruction for this purpose. However, the range of this
24  * instruction is limited to:
25  *              -(1 - (sqrt(2) / 2)) <= x <= sqrt(2) - 1
26  *                         -0.292893 <= x <= 0.414214
27  * at least on older processor versions.
28  *
29  * log1pf() is implemented by testing the range of the argument.
30  * If it is appropriate for fyl2xp1, this instruction is used.
31  * Else, we compute log1pf(x) = ln(2)*ld(1 + x) the traditional way
32  * (using fyl2x).
33  *
34  * The range testing costs speed, but as the rationale for the very
35  * existence of this function is accuracy, we accept that.
36  *
37  * In order to reduce the cost for testing the range, we check if
38  * the argument is in the range
39  *                             -0.25 <= x <= 0.25
40  * which can be done with just one conditional branch. If x is
41  * inside this range, we use fyl2xp1. Outside of this range,
42  * the use of fyl2x is accurate enough.
43  * 
44  */
45
46 .text
47         .align  4
48 ENTRY(log1pf)
49         XMM_ONE_ARG_FLOAT_PROLOGUE
50         flds    ARG_FLOAT_ONE
51         fabs
52         fld1                            /* ... x 1 */
53         fadd    %st(0)                  /* ... x 2 */
54         fadd    %st(0)                  /* ... x 4 */
55         fld1                            /* ... 4 1 */
56         fdivp                           /* ... x 0.25 */
57         fcompp
58         fnstsw  %ax
59         andb    $69,%ah
60         jne     use_fyl2x
61         jmp     use_fyl2xp1
62
63         .align  4
64 use_fyl2x:
65         fldln2
66         flds    ARG_FLOAT_ONE
67         fld1
68         faddp
69         fyl2x
70         XMM_FLOAT_EPILOGUE
71         ret
72
73         .align  4
74 use_fyl2xp1:
75         fldln2
76         flds    ARG_FLOAT_ONE
77         fyl2xp1
78         XMM_FLOAT_EPILOGUE
79         ret