1/*
2 * Public domain.
3 */
4
5#include <machine/asm.h>
6
7RCSID("$NetBSD: s_ilogb.S,v 1.5 1995/10/12 15:53:09 jtc Exp $")
8
9ENTRY(__ieee754_ilogb)
10	fldl	4(%esp)
11/* I added the following ugly construct because ilogb(+-Inf) is
12   required to return INT_MAX in ISO C99.
13   -- jakub@redhat.com.  */
14	fxam			/* Is NaN or +-Inf?  */
15	fstsw   %ax
16	movb    $0x45, %dh
17	andb    %ah, %dh
18	cmpb    $0x05, %dh
19	je      1f		/* Is +-Inf, jump.  */
20	cmpb    $0x40, %dh
21	je      2f		/* Is +-0, jump.  */
22
23	fxtract
24	pushl	%eax
25	cfi_adjust_cfa_offset (4)
26	fstp	%st
27
28	fistpl	(%esp)
29	fwait
30	popl	%eax
31	cfi_adjust_cfa_offset (-4)
32
33	ret
34
351:	fstp	%st
36	movl	$0x7fffffff, %eax
37	ret
382:	fstp	%st
39	movl	$0x80000000, %eax	/* FP_ILOGB0  */
40	ret
41END (__ieee754_ilogb)
42