Blame sysdeps/i386/fpu/e_log2.S
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* Written by J.T. Conklin <jtc@netbsd.org>.
|
|
Packit |
6c4009 |
* Adapted for use as log2 by Ulrich Drepper <drepper@cygnus.com>.
|
|
Packit |
6c4009 |
* Public domain.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Changed to use fyl2xp1 for values near 1, <drepper@cygnus.com>.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <machine/asm.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.section .rodata.cst8,"aM",@progbits,8
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.p2align 3
|
|
Packit |
6c4009 |
.type one,@object
|
|
Packit |
6c4009 |
one: .double 1.0
|
|
Packit |
6c4009 |
ASM_SIZE_DIRECTIVE(one)
|
|
Packit |
6c4009 |
/* It is not important that this constant is precise. It is only
|
|
Packit |
6c4009 |
a value which is known to be on the safe side for using the
|
|
Packit |
6c4009 |
fyl2xp1 instruction. */
|
|
Packit |
6c4009 |
.type limit,@object
|
|
Packit |
6c4009 |
limit: .double 0.29
|
|
Packit |
6c4009 |
ASM_SIZE_DIRECTIVE(limit)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef PIC
|
|
Packit |
6c4009 |
# define MO(op) op##@GOTOFF(%edx)
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
# define MO(op) op
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.text
|
|
Packit |
6c4009 |
ENTRY(__ieee754_log2)
|
|
Packit |
6c4009 |
#ifdef PIC
|
|
Packit |
6c4009 |
LOAD_PIC_REG (dx)
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
fldl MO(one)
|
|
Packit |
6c4009 |
fldl 4(%esp) // x : 1
|
|
Packit |
6c4009 |
fxam
|
|
Packit |
6c4009 |
fnstsw
|
|
Packit |
6c4009 |
fld %st // x : x : 1
|
|
Packit |
6c4009 |
sahf
|
|
Packit |
6c4009 |
jc 3f // in case x is NaN or ±Inf
|
|
Packit |
6c4009 |
4: fsub %st(2), %st // x-1 : x : 1
|
|
Packit |
6c4009 |
fld %st // x-1 : x-1 : x : 1
|
|
Packit |
6c4009 |
fabs // |x-1| : x-1 : x : 1
|
|
Packit |
6c4009 |
fcompl MO(limit) // x-1 : x : 1
|
|
Packit |
6c4009 |
fnstsw // x-1 : x : 1
|
|
Packit |
6c4009 |
andb $0x45, %ah
|
|
Packit |
6c4009 |
jz 2f
|
|
Packit |
6c4009 |
fxam
|
|
Packit |
6c4009 |
fnstsw
|
|
Packit |
6c4009 |
andb $0x45, %ah
|
|
Packit |
6c4009 |
cmpb $0x40, %ah
|
|
Packit |
6c4009 |
jne 5f
|
|
Packit |
6c4009 |
fabs // log2(1) is +0 in all rounding modes.
|
|
Packit |
6c4009 |
5: fstp %st(1) // x-1 : 1
|
|
Packit |
6c4009 |
fyl2xp1 // log(x)
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
2: fstp %st(0) // x : 1
|
|
Packit |
6c4009 |
fyl2x // log(x)
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
3: jp 4b // in case x is ±Inf
|
|
Packit |
6c4009 |
fstp %st(1)
|
|
Packit |
6c4009 |
fstp %st(1)
|
|
Packit |
6c4009 |
ret
|
|
Packit |
6c4009 |
END (__ieee754_log2)
|
|
Packit |
6c4009 |
strong_alias (__ieee754_log2, __log2_finite)
|