xref: /illumos-gate/usr/src/lib/libm/i386/src/ilogb.s (revision ddc0e0b5)
1*25c28e83SPiotr Jasiukajtis/*
2*25c28e83SPiotr Jasiukajtis * CDDL HEADER START
3*25c28e83SPiotr Jasiukajtis *
4*25c28e83SPiotr Jasiukajtis * The contents of this file are subject to the terms of the
5*25c28e83SPiotr Jasiukajtis * Common Development and Distribution License (the "License").
6*25c28e83SPiotr Jasiukajtis * You may not use this file except in compliance with the License.
7*25c28e83SPiotr Jasiukajtis *
8*25c28e83SPiotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*25c28e83SPiotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
10*25c28e83SPiotr Jasiukajtis * See the License for the specific language governing permissions
11*25c28e83SPiotr Jasiukajtis * and limitations under the License.
12*25c28e83SPiotr Jasiukajtis *
13*25c28e83SPiotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
14*25c28e83SPiotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*25c28e83SPiotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
16*25c28e83SPiotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
17*25c28e83SPiotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
18*25c28e83SPiotr Jasiukajtis *
19*25c28e83SPiotr Jasiukajtis * CDDL HEADER END
20*25c28e83SPiotr Jasiukajtis */
21*25c28e83SPiotr Jasiukajtis/*
22*25c28e83SPiotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
23*25c28e83SPiotr Jasiukajtis */
24*25c28e83SPiotr Jasiukajtis/*
25*25c28e83SPiotr Jasiukajtis * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
26*25c28e83SPiotr Jasiukajtis * Use is subject to license terms.
27*25c28e83SPiotr Jasiukajtis */
28*25c28e83SPiotr Jasiukajtis
29*25c28e83SPiotr Jasiukajtis        .file "ilogb.s"
30*25c28e83SPiotr Jasiukajtis
31*25c28e83SPiotr Jasiukajtis#include "libm.h"
32*25c28e83SPiotr JasiukajtisLIBM_ANSI_PRAGMA_WEAK(ilogb,function)
33*25c28e83SPiotr Jasiukajtis#include "xpg6.h"
34*25c28e83SPiotr Jasiukajtis
35*25c28e83SPiotr Jasiukajtis	.data
36*25c28e83SPiotr Jasiukajtis	.align	8
37*25c28e83SPiotr Jasiukajtistwo52:	.long	0x0,0x43300000	/ 2**52
38*25c28e83SPiotr Jasiukajtis
39*25c28e83SPiotr Jasiukajtis	ENTRY(ilogb)
40*25c28e83SPiotr Jasiukajtis	movl	8(%esp),%eax		/ eax <-- hi_32(x)
41*25c28e83SPiotr Jasiukajtis	andl	$0x7fffffff,%eax	/ eax <-- hi_32(abs(x))
42*25c28e83SPiotr Jasiukajtis	testl	$0x7ff00000,%eax	/ is bexp(x) 0?
43*25c28e83SPiotr Jasiukajtis	jz	.bexp_0 		/ jump if x is 0 or subnormal
44*25c28e83SPiotr Jasiukajtis					/ biased exponent is non-zero
45*25c28e83SPiotr Jasiukajtis	cmpl	$0x7ff00000,%eax	/ is bexp(x) 0x7ff?
46*25c28e83SPiotr Jasiukajtis	jae	.bexp_all_1		/ jump if x is NaN or Inf
47*25c28e83SPiotr Jasiukajtis	shrl	$20,%eax		/ eax <-- bexp(x)
48*25c28e83SPiotr Jasiukajtis	subl	$1023,%eax		/ unbias exponent by 1023
49*25c28e83SPiotr Jasiukajtis	ret
50*25c28e83SPiotr Jasiukajtis
51*25c28e83SPiotr Jasiukajtis.bexp_all_1:
52*25c28e83SPiotr Jasiukajtis	movl	$0x7fffffff,%eax	/ x is NaN or inf, so return 0x7fffffff
53*25c28e83SPiotr Jasiukajtis	jmp	0f
54*25c28e83SPiotr Jasiukajtis
55*25c28e83SPiotr Jasiukajtis.bexp_0:
56*25c28e83SPiotr Jasiukajtis	orl	4(%esp),%eax		/ test whether x is 0
57*25c28e83SPiotr Jasiukajtis	jnz	.ilogb_subnorm
58*25c28e83SPiotr Jasiukajtis	movl	$0x80000001,%eax	/ x is +/-0, so return 0x80000001
59*25c28e83SPiotr Jasiukajtis0:
60*25c28e83SPiotr Jasiukajtis	PIC_SETUP(0)
61*25c28e83SPiotr Jasiukajtis	PIC_G_LOAD(movzwl,__xpg6,ecx)
62*25c28e83SPiotr Jasiukajtis	PIC_WRAPUP
63*25c28e83SPiotr Jasiukajtis	andl	$_C99SUSv3_ilogb_0InfNaN_raises_invalid,%ecx
64*25c28e83SPiotr Jasiukajtis	cmpl	$0,%ecx
65*25c28e83SPiotr Jasiukajtis	je	1f
66*25c28e83SPiotr Jasiukajtis	fldz
67*25c28e83SPiotr Jasiukajtis	fdivp	%st,%st(0)		/ raise invalid as per SUSv3
68*25c28e83SPiotr Jasiukajtis1:
69*25c28e83SPiotr Jasiukajtis	ret
70*25c28e83SPiotr Jasiukajtis
71*25c28e83SPiotr Jasiukajtis.ilogb_subnorm:				/ subnormal input
72*25c28e83SPiotr Jasiukajtis	fldl	4(%esp)			/ push x
73*25c28e83SPiotr Jasiukajtis	PIC_SETUP(1)
74*25c28e83SPiotr Jasiukajtis	fmull	PIC_L(two52)		/ x*2**52
75*25c28e83SPiotr Jasiukajtis	PIC_WRAPUP
76*25c28e83SPiotr Jasiukajtis	subl	$8,%esp			/ set up storage area
77*25c28e83SPiotr Jasiukajtis	fstpl	(%esp)			/ store x*2**52 in storage are
78*25c28e83SPiotr Jasiukajtis	movl	$0x7ff00000,%eax
79*25c28e83SPiotr Jasiukajtis	andl	4(%esp),%eax
80*25c28e83SPiotr Jasiukajtis	shrl	$20,%eax		/ extract exponent of x*2**52
81*25c28e83SPiotr Jasiukajtis	subl	$1075,%eax		/ unbias it by 1075 (= 1023 + 52)
82*25c28e83SPiotr Jasiukajtis	addl	$8,%esp
83*25c28e83SPiotr Jasiukajtis	ret
84*25c28e83SPiotr Jasiukajtis	.align	4
85*25c28e83SPiotr Jasiukajtis	SET_SIZE(ilogb)
86