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