xref: /titanic_52/usr/src/lib/libc/i386/fp/_xtoll.s (revision c7158ae983f5a04c4a998f468ecefba6d23ba721)
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, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27	.ident	"%Z%%M%	%I%	%E% SMI"
28
29	.file	"%M%"
30
31#include <SYS.h>
32
33	.set	cw,0
34	.set	cw_old,2
35	.set	two_words,4
36	.set	four_words,8
37
38/ This function truncates the top of the 387 stack into a signed long.
39
40	ENTRY(__xtol)	// 387-stack to signed long
41	subl	$8,%esp
42	fstcw	cw_old(%esp)
43	movw	cw_old(%esp),%ax
44	movw	%ax,%cx
45	andw	$0x0c00,%cx		// save RC
46	orw	$0x0c00,%ax
47	movw	%ax,cw(%esp)
48	fldcw	cw(%esp)
49	fistpl	two_words(%esp)
50					// fwait implied here
51	fstcw	cw(%esp)		// fetch CW in case masks changed value
52	movw	cw(%esp),%ax
53	andw	$0xf3ff,%ax
54	orw	%cx,%ax			// restore RC
55	movw	%ax,cw(%esp)
56	fldcw	cw(%esp)
57	movl	two_words(%esp),%eax
58	addl	$8,%esp
59	ret
60	SET_SIZE(__xtol)
61
62/ This function truncates the top of the 387 stack into a signed long long.
63
64	ENTRY(__xtoll)	// 387-stack to signed long long
65	subl	$12,%esp
66	fstcw	cw_old(%esp)
67	movw	cw_old(%esp),%ax
68	movw	%ax,%cx
69	andw	$0x0c00,%cx		// save RC
70	orw	$0x0c00,%ax
71	movw	%ax,cw(%esp)
72	fldcw	cw(%esp)
73	fistpll	two_words(%esp)
74					// fwait implied here
75	fstcw	cw(%esp)		// fetch CW in case masks changed value
76	movw	cw(%esp),%ax
77	andw	$0xf3ff,%ax
78	orw	%cx,%ax			// restore RC
79	movw	%ax,cw(%esp)
80	fldcw	cw(%esp)
81	movl	two_words(%esp),%eax
82	movl	four_words(%esp),%edx
83	addl	$12,%esp
84	ret
85	SET_SIZE(__xtoll)
86
87/ This function truncates the top of the 387 stack into a unsigned long.
88
89	.align	4
90two_to_31: .long	0x4f000000
91
92	ENTRY(__xtoul)	// 387-stack to unsigned long
93	subl	$8,%esp
94	fstcw	cw_old(%esp)
95	movw	cw_old(%esp),%ax
96	movw	%ax,%cx
97	andw	$0x0c00,%cx		// save RC
98	orw	$0x0c00,%ax
99	movw	%ax,cw(%esp)
100	fldcw	cw(%esp)
101	_prologue_
102	fcoms	_sref_(two_to_31)	// compare st to 2**31
103	_epilogue_
104	fstsw	%ax			// store status in %ax
105					// use fstsw for correct trap handling
106	sahf				// load AH into flags
107	jb	.donotsub		// jump if st < 2**31 or is NaN
108	_prologue_
109	fsubs	_sref_(two_to_31)	// subtract 2**31
110	_epilogue_
111.donotsub:
112	fistpl	two_words(%esp)
113	fwait				// in case fistpl causes exception
114	movl	two_words(%esp),%eax
115	jb	.donotadd		// flags did not change
116	add	$0x80000000,%eax	// add back 2**31
117.donotadd:
118	fstcw	cw(%esp)		// fetch CW in case masks changed value
119	movw	cw(%esp),%dx
120	andw	$0xf3ff,%dx
121	orw	%cx,%dx			// restore RC
122	movw	%dx,cw(%esp)
123	fldcw	cw(%esp)
124	addl	$8,%esp
125	ret
126	SET_SIZE(__xtoul)
127