From b6161bb16a36adb82a94ec10c7fe47c27a4c55fd Mon Sep 17 00:00:00 2001 From: Stefan Farfeleder Date: Sat, 19 Jun 2004 09:30:00 +0000 Subject: [PATCH] Return the same result as the MI version for 0.0, INFINITY and NaN. Reviewed by: standards@ --- lib/msun/i387/s_ilogb.S | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/msun/i387/s_ilogb.S b/lib/msun/i387/s_ilogb.S index c9de0bd2e5f9..34497a8f4040 100644 --- a/lib/msun/i387/s_ilogb.S +++ b/lib/msun/i387/s_ilogb.S @@ -33,10 +33,15 @@ * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. */ +#include #include RCSID("$FreeBSD$") +#define FP_ILOGB0 (-__INT_MAX) +#define FP_ILOGBNAN __INT_MAX +#define FP_ILOGBINF __INT_MAX + ENTRY(ilogb) pushl %ebp movl %esp,%ebp @@ -44,10 +49,35 @@ ENTRY(ilogb) fldl 8(%ebp) fxtract - fstp %st + fstp %st(0) fistpl -4(%ebp) movl -4(%ebp),%eax + /* fistpl yields __INT_MIN for NaN, Inf and 0. */ + cmpl $__INT_MIN,%eax + je .L2 + +.L1: leave ret + +.L2: + fldl 8(%ebp) + fldz + fucompp + fnstsw %ax + sahf + jp .L3 + jz .L4 + + movl $FP_ILOGBINF,%eax + jmp .L1 + +.L3: + movl $FP_ILOGBNAN,%eax + jmp .L1 + +.L4: + movl $FP_ILOGB0,%eax + jmp .L1