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