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