1/* 2 * Written by J.T. Conklin <jtc@netbsd.org>. 3 * Public domain. 4 * Adapted for float type by Ulrich Drepper <drepper@cygnus.com>. 5 */ 6 7#include <machine/asm.h> 8 9RCSID("$NetBSD: $") 10 11/* e^x = 2^(x * log2(e)) */ 12ENTRY(__ieee754_expf) 13 flds 4(%esp) 14/* I added the following ugly construct because exp(+-Inf) resulted 15 in NaN. The ugliness results from the bright minds at Intel. 16 For the i686 the code can be written better. 17 -- drepper@cygnus.com. */ 18 fxam /* Is NaN or +-Inf? */ 19 fstsw %ax 20 movb $0x45, %dh 21 andb %ah, %dh 22 cmpb $0x05, %dh 23 je 1f /* Is +-Inf, jump. */ 24 fldl2e 25 fmulp /* x * log2(e) */ 26 fld %st 27 frndint /* int(x * log2(e)) */ 28 fsubr %st,%st(1) /* fract(x * log2(e)) */ 29 fxch 30 f2xm1 /* 2^(fract(x * log2(e))) - 1 */ 31 fld1 32 faddp /* 2^(fract(x * log2(e))) */ 33 fscale /* e^x */ 34 fstp %st(1) 35 ret 36 371: testl $0x200, %eax /* Test sign. */ 38 jz 2f /* If positive, jump. */ 39 fstp %st 40 fldz /* Set result to 0. */ 412: ret 42END (__ieee754_expf) 43