xref: /titanic_44/usr/src/lib/libm/i386/src/nextafterf.s (revision 4d0eb50e691de4c20b1dd9976ad6839fede8a42d)
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 "nextafterf.s"
30
31#include "libm.h"
32LIBM_ANSI_PRAGMA_WEAK(nextafterf,function)
33
34	.data
35	.align	4
36Fmaxf:	.long	0x7f7fffff
37Fminf:	.long	0x1
38ftmpf:	.long	0
39
40
41	ENTRY(nextafterf)
42	pushl	%ebp
43	movl	%esp,%ebp
44	movl	$0,%eax		/// upper half of %eax must be initialized
45	flds	12(%ebp)	/ y
46	subl	$4,%esp
47	flds	8(%ebp)		/ x, y
48	fucom			/ x : y
49	fstsw	%ax
50	sahf
51	jp	.NaN
52	je	.equal
53	fstp	%st(1)		/ x
54	ja	.bigger
55	/ x < y
56	ftst			/ x : 0
57	movl	$0x1,-4(%ebp)		/ -4(%ebp) contains Fminf
58	fnstsw	%ax
59	sahf
60	je	.final
61	ja	.addulp
62	jb	.subulp
63.bigger:
64	/ x > y
65	ftst			/ x : 0
66	movl	$0x80000001,-4(%ebp)	/ -4(%ebp) contains -Fminf
67	fnstsw	%ax
68	sahf
69	je	.final
70	jb	.addulp
71.subulp:
72	movl	8(%ebp),%eax	/ x
73	subl	$1,%eax		/ x - ulp
74	movl	%eax,-4(%ebp)
75	jmp	.final
76.addulp:
77	movl	8(%ebp),%eax	/ x
78	addl	$1,%eax		/ x + ulp
79	movl	%eax,-4(%ebp)
80
81.final:
82	fstp	%st(0)		/ empty
83	flds	-4(%ebp)	/ z
84	andl	$0x7f800000,%eax
85	jz	.underflow
86	cmpl	$0x7f800000,%eax
87	je	.overflow
88	jmp	.return
89.overflow:
90	PIC_SETUP(1)
91	flds	PIC_L(Fmaxf)	/ Fmaxf, z
92	fmul	%st(0),%st	/ overflow-to-Inf, z
93	fstps	PIC_L(ftmpf)	/ z & create overflow signal
94	PIC_WRAPUP
95	jmp	.return
96.underflow:
97	PIC_SETUP(2)
98	flds	PIC_L(Fminf)	/ Fminf, z
99	fmul	%st(0),%st	/ underflow-to-0, z
100	fstps	PIC_L(ftmpf)	/ z & create underflow signal
101	PIC_WRAPUP
102	jmp	.return
103.equal:
104	fstp	%st(0)		/ C99 says to return y when x == y
105	jmp	.return
106.NaN:
107	faddp	%st,%st(1)	/ x+y
108.return:
109	fwait
110	leave
111	ret
112	.align	4
113	SET_SIZE(nextafterf)
114