xref: /titanic_41/usr/src/lib/libm/amd64/src/ilogbl.s (revision 5b2ba9d3d1e04dde804c89e9879f7dfc9bcebf61)
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 2005 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 "libm_synonyms.h"
34#include "xpg6.h"
35
36	.data
37	.align	16
38two63:	.4byte	0x0,0x43d00000		/ 2**63
39
40	ENTRY(ilogbl)
41	movq	16(%rsp),%rax		/ eax <-- sign and bexp of x
42	andq	$0x7fff,%rax		/ eax <-- bexp(x)
43	jz	.bexp_0			/ jump iff x is 0 or subnormal
44					/ here, biased exponent is non-zero
45	testl	$0x80000000,12(%rsp)	/ test msb of hi_32(sgnfcnd(x))
46	jz	.ilogbl_not_finite	/ jump if unsupported format
47	cmpq	$0x7fff,%rax
48	je	.ilogbl_not_finite
49	subq	$16383,%rax 		/ unbias exponent by 16383 = 0x3fff
50	ret
51
52.ilogbl_not_finite:
53	movq	$0x7fffffff,%rax	/ x is NaN/inf/unsup
54	jmp	0f
55
56.bexp_0:
57	movq	8(%rsp),%rax		/ rax <-- sgnfcnd(x)
58	orq	%rax,%rax
59	jnz	.ilogbl_subnorm		/ jump iff x is subnormal
60	movq	$-2147483647,%rax 	/ x is +/-0, so return 1-2^31
610:
62	PIC_SETUP(0)
63	PIC_G_LOAD(movzwq,__xpg6,rcx)
64	PIC_WRAPUP
65	andl	$_C99SUSv3_ilogb_0InfNaN_raises_invalid,%ecx
66	cmpl	$0,%ecx
67	je	1f
68	fldz
69	fdivp	%st,%st(0)		/ raise invalid as per SUSv3
701:
71	ret
72
73
74.ilogbl_subnorm:			/ subnormal or pseudo-denormal input
75	fldt	8(%rsp)			/ push x, setting D-flag
76	PIC_SETUP(1)
77	fmull	PIC_L(two63)		/ x*2**63
78	PIC_WRAPUP
79	subq	$16,%rsp
80	fstpt	(%rsp)
81	movq	$0x7fff,%rax
82	andq    8(%rsp),%rax            / eax <-- sign and bexp of x*2**63
83	subq    $16445,%rax             / unbias it by (16,383 + 63)
84	addq	$16,%rsp
85	ret
86	.align	16
87	SET_SIZE(ilogbl)
88