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