xref: /titanic_44/usr/src/lib/libm/i386/src/nextafter.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 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 "nextafter.s"
30*25c28e83SPiotr Jasiukajtis
31*25c28e83SPiotr Jasiukajtis#include "libm.h"
32*25c28e83SPiotr JasiukajtisLIBM_ANSI_PRAGMA_WEAK(nextafter,function)
33*25c28e83SPiotr Jasiukajtis	.weak _nextafter
34*25c28e83SPiotr Jasiukajtis	.type _nextafter,@function
35*25c28e83SPiotr Jasiukajtis_nextafter	= __nextafter
36*25c28e83SPiotr Jasiukajtis#include "libm_protos.h"
37*25c28e83SPiotr Jasiukajtis
38*25c28e83SPiotr Jasiukajtis	.data
39*25c28e83SPiotr Jasiukajtis	.align	8
40*25c28e83SPiotr JasiukajtisFmin:	.long	0x1,0x0
41*25c28e83SPiotr Jasiukajtisftmp:	.long	0,0		/// WILL WRITE INTO
42*25c28e83SPiotr Jasiukajtis
43*25c28e83SPiotr Jasiukajtis
44*25c28e83SPiotr Jasiukajtis	ENTRY(nextafter)
45*25c28e83SPiotr Jasiukajtis	pushl	%ebp
46*25c28e83SPiotr Jasiukajtis	movl	%esp,%ebp
47*25c28e83SPiotr Jasiukajtis	fldl	16(%ebp)	/ y
48*25c28e83SPiotr Jasiukajtis	subl	$8,%esp
49*25c28e83SPiotr Jasiukajtis	fldl	8(%ebp)		/ load x
50*25c28e83SPiotr Jasiukajtis	fucom			/ x : y
51*25c28e83SPiotr Jasiukajtis	fstsw	%ax
52*25c28e83SPiotr Jasiukajtis	sahf
53*25c28e83SPiotr Jasiukajtis	jp	.NaN
54*25c28e83SPiotr Jasiukajtis	je	.equal
55*25c28e83SPiotr Jasiukajtis	fstp	%st(1)		/ x
56*25c28e83SPiotr Jasiukajtis	ja	.bigger
57*25c28e83SPiotr Jasiukajtis	/ x < y
58*25c28e83SPiotr Jasiukajtis	ftst
59*25c28e83SPiotr Jasiukajtis	movl	$1,%ecx		/// Fmin
60*25c28e83SPiotr Jasiukajtis	movl	%ecx,-8(%ebp)
61*25c28e83SPiotr Jasiukajtis	movl	$0,%ecx		/// Fmin+4
62*25c28e83SPiotr Jasiukajtis	movl	%ecx,-4(%ebp)
63*25c28e83SPiotr Jasiukajtis	fnstsw	%ax
64*25c28e83SPiotr Jasiukajtis	sahf
65*25c28e83SPiotr Jasiukajtis	je	.final
66*25c28e83SPiotr Jasiukajtis	ja	.addulp
67*25c28e83SPiotr Jasiukajtis	jb	.subulp
68*25c28e83SPiotr Jasiukajtis.bigger:
69*25c28e83SPiotr Jasiukajtis	/ x > y
70*25c28e83SPiotr Jasiukajtis	ftst
71*25c28e83SPiotr Jasiukajtis	movl	$1,%ecx		/// Fmin
72*25c28e83SPiotr Jasiukajtis	movl	%ecx,-8(%ebp)
73*25c28e83SPiotr Jasiukajtis	movl	$0,%ecx		/// Fmin+4
74*25c28e83SPiotr Jasiukajtis	xorl	$0x80000000,%ecx
75*25c28e83SPiotr Jasiukajtis	movl	%ecx,-4(%ebp)
76*25c28e83SPiotr Jasiukajtis	fnstsw	%ax
77*25c28e83SPiotr Jasiukajtis	sahf
78*25c28e83SPiotr Jasiukajtis	je	.final
79*25c28e83SPiotr Jasiukajtis	jb	.addulp
80*25c28e83SPiotr Jasiukajtis.subulp:
81*25c28e83SPiotr Jasiukajtis	movl	8(%ebp),%eax	/ low x
82*25c28e83SPiotr Jasiukajtis	movl	12(%ebp),%ecx	/ high x
83*25c28e83SPiotr Jasiukajtis	subl	$1,%eax		/ low x - ulp
84*25c28e83SPiotr Jasiukajtis	movl	%eax,-8(%ebp)
85*25c28e83SPiotr Jasiukajtis	sbbl	$0x0,%ecx
86*25c28e83SPiotr Jasiukajtis	movl	%ecx,-4(%ebp)
87*25c28e83SPiotr Jasiukajtis	jmp	.final
88*25c28e83SPiotr Jasiukajtis.addulp:
89*25c28e83SPiotr Jasiukajtis	movl	8(%ebp),%eax	/ low x
90*25c28e83SPiotr Jasiukajtis	movl	12(%ebp),%ecx	/ high x
91*25c28e83SPiotr Jasiukajtis	addl	$1,%eax		/ low x + ulp
92*25c28e83SPiotr Jasiukajtis	movl	%eax,-8(%ebp)
93*25c28e83SPiotr Jasiukajtis	adcl	$0x0,%ecx
94*25c28e83SPiotr Jasiukajtis	movl	%ecx,-4(%ebp)
95*25c28e83SPiotr Jasiukajtis
96*25c28e83SPiotr Jasiukajtis.final:
97*25c28e83SPiotr Jasiukajtis	fstp	%st(0)
98*25c28e83SPiotr Jasiukajtis	fldl	-8(%ebp)
99*25c28e83SPiotr Jasiukajtis	andl	$0x7ff00000,%ecx
100*25c28e83SPiotr Jasiukajtis	jz	.underflow
101*25c28e83SPiotr Jasiukajtis	cmpl	$0x7ff00000,%ecx
102*25c28e83SPiotr Jasiukajtis	je	.overflow
103*25c28e83SPiotr Jasiukajtis	jmp	.return
104*25c28e83SPiotr Jasiukajtis.overflow:
105*25c28e83SPiotr Jasiukajtis	PIC_SETUP(1)
106*25c28e83SPiotr Jasiukajtis	pushl	$46
107*25c28e83SPiotr Jasiukajtis	fstp	%st(0)		/ stack empty
108*25c28e83SPiotr Jasiukajtis	pushl	-4(%ebp)
109*25c28e83SPiotr Jasiukajtis	pushl	-8(%ebp)
110*25c28e83SPiotr Jasiukajtis	pushl	-4(%ebp)
111*25c28e83SPiotr Jasiukajtis	pushl	-8(%ebp)
112*25c28e83SPiotr Jasiukajtis	call	PIC_F(_SVID_libm_err)
113*25c28e83SPiotr Jasiukajtis	addl	$20,%esp
114*25c28e83SPiotr Jasiukajtis	PIC_WRAPUP
115*25c28e83SPiotr Jasiukajtis	jmp	.return
116*25c28e83SPiotr Jasiukajtis.underflow:
117*25c28e83SPiotr Jasiukajtis	PIC_SETUP(2)
118*25c28e83SPiotr Jasiukajtis	fldl	PIC_L(Fmin)
119*25c28e83SPiotr Jasiukajtis	fmul	%st(0),%st
120*25c28e83SPiotr Jasiukajtis	fstpl	PIC_L(ftmp)	/ create underflow signal
121*25c28e83SPiotr Jasiukajtis	PIC_WRAPUP
122*25c28e83SPiotr Jasiukajtis	jmp	.return
123*25c28e83SPiotr Jasiukajtis.equal:
124*25c28e83SPiotr Jasiukajtis	fstp	%st(0)		/ C99 says to return y when x == y
125*25c28e83SPiotr Jasiukajtis	jmp	.return
126*25c28e83SPiotr Jasiukajtis.NaN:
127*25c28e83SPiotr Jasiukajtis	faddp	%st,%st(1)	/ x+y,x
128*25c28e83SPiotr Jasiukajtis.return:
129*25c28e83SPiotr Jasiukajtis	fwait
130*25c28e83SPiotr Jasiukajtis	leave
131*25c28e83SPiotr Jasiukajtis	ret
132*25c28e83SPiotr Jasiukajtis	.align	4
133*25c28e83SPiotr Jasiukajtis	SET_SIZE(nextafter)
134