xref: /titanic_41/usr/src/lib/libm/sparc/src/nextafter.S (revision a9d3dcd5820128b4f34bf38f447e47aa95c004e8)
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	"nextafter.S"
30
31#include "libm.h"
32LIBM_ANSI_PRAGMA_WEAK(nextafter,function)
33	.weak _nextafter
34	.type _nextafter,#function
35_nextafter	= __nextafter
36#include "libm_protos.h"
37
38	RO_DATA
39	.align	8
40.Lconstant:
41two54 	= 0x00
42	.word	0x43500000,0x0		!  2**54
43twom54 	= 0x08
44	.word	0x3c900000,0x0		!  2**-54
45tiny	= 0x10
46	.word	0x00100000,0x0		!  tiny
47
48! variable using fp
49x 	= -0x8
50y 	= -0x10
51
52	ENTRY(nextafter)
53	save	%sp,-128,%sp
54	PIC_SETUP(l7)
55	std	%i0,[%fp+x]
56	or	%g0,%i0,%o0		! save original arguments
57	or	%g0,%i1,%o1
58	std	%i2,[%fp+y]
59	or	%g0,%i2,%o2
60	or	%g0,%i3,%o3
61	ldd	[%fp+x],%f2		! x
62	ldd	[%fp+y],%f0		! y
63	fcmpd	%f2,%f0			! x:y
64	PIC_SET(l7,.Lconstant,l0)
65	sethi	%hi(0x80000000),%l1
66	andn	%i0,%l1,%l4
67	fbe	9f			! next_return
68	nop
69	fbu,a	9f			! next_return
70	fmuld	%f2,%f0,%f0		! + -> * for Cheetah
71	orcc	%i1,%l4,%g0		! see if x is zero
72	bne	1f
73	tst	%i0
74    ! x is zero, return sign(y)*min
75	and	%i2,%l1,%i0
76	ba	4f			! next_final
77	mov	1,%i1
781:	bge	2f
79	nop
80    ! x is negative
81	fbl	1f			! next_subulp
82	nop
83	fbg	3f			! next_addulp
84	nop
852:
86	fbl	3f			! next_addulp
87	nop
881:					! next_subulp
89	subcc	%i1,1,%i1
90	ba	4f			! next_final
91	subx	%i0,0,%i0
923:					! next_addulp
93	addcc	%i1,1,%i1
94	addx	%i0,0,%i0
954:					! next_final
96	sethi	%hi(0x7ff00000),%l3
97	std	%i0,[%fp+x]
98	andcc	%i0,%l3,%i2
99	be,a	1f			! xflow
100	ldd	[%l0+tiny],%f2
101	cmp	%i2,%l3
102	bne,a	9f			! next_return
103	ldd	[%fp+x],%f0
104	call	NAME(_SVID_libm_err)	! overflow
105	or	%g0,46,%o4
106	ba	9f
107	nop
1081:					! xflow
109	fmuld	%f2,%f2,%f2
110	ldd	[%fp+x],%f0
1119:					! next_return
112	ret
113	restore
114
115	SET_SIZE(nextafter)
116