xref: /titanic_52/usr/src/lib/libc/i386/fp/_xtoull.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	.text
38	.align	4
39two_to_63: .long	0x5f000000
40
41	ENTRY(__xtoull)	// 387-stack to unsigned long long
42	subl	$12,%esp
43	fstcw	cw_old(%esp)
44	movw	cw_old(%esp),%ax
45	movw	%ax,%cx
46	andw	$0x0c00,%cx		// save RC
47	orw	$0x0c00,%ax
48	movw	%ax,cw(%esp)
49	fldcw	cw(%esp)
50	_prologue_
51	fcoms	_sref_(two_to_63)	// compare st to 2**63
52	_epilogue_
53	fstsw	%ax			// store status in %ax
54					// use fstsw for correct trap handling
55	sahf				// load AH into flags
56	jb	.donotsub		// jump if st < 2**63 or is NaN
57	_prologue_
58	fsubs	_sref_(two_to_63)	// subtract 2**63
59	_epilogue_
60.donotsub:
61	fistpll	two_words(%esp)
62	fwait				// in case fistpll causes exception
63	movl	four_words(%esp),%edx
64	jb	.donotadd		// flags did not change
65	add	$0x80000000,%edx	// add back 2**63
66.donotadd:
67	fstcw	cw(%esp)		// fetch CW in case masks changed value
68	movw	cw(%esp),%ax
69	andw	$0xf3ff,%ax
70	orw	%cx,%ax			// restore RC
71	movw	%ax,cw(%esp)
72	fldcw	cw(%esp)
73	movl	two_words(%esp),%eax
74	addl	$12,%esp
75	ret
76	SET_SIZE(__xtoull)
77