xref: /titanic_44/usr/src/lib/libc/amd64/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	.text
36	.align	16
37two_to_63: .4byte	0x5f000000
38
39	ENTRY(__xtoull)	/* 387-stack to unsigned long long */
40	subq	$16,%rsp
41	fstcw	cw_old(%rsp)
42	movw	cw_old(%rsp),%ax
43	movw	%ax,%cx
44	andw	$0x0c00,%cx		/* save RC */
45	orw	$0x0c00,%ax
46	movw	%ax,cw(%rsp)
47	fldcw	cw(%rsp)
48	flds	two_to_63(%rip)
49	fcomip	%st(1),%st		/* compare 2**63 to x */
50	jp	.donotsub		/* jump if x is NaN */
51	ja	.donotsub		/* jump if 2**63 > x */
52	fsubs	two_to_63(%rip)		/* subtract 2**63 */
53.donotsub:
54	fistpll	8(%rsp)
55	fwait				/* in case fistpll causes exception */
56	movq	8(%rsp),%rax
57	jp	.donotadd
58	ja	.donotadd		/* flags did not change */
59	movq	$0x8000000000000000,%rcx
60	addq	%rcx,%rax		/* add back 2**63 */
61.donotadd:
62	fstcw	cw(%rsp)		/* fetch CW in case masks changed */
63	movw	cw(%rsp),%dx
64	andw	$0xf3ff,%dx
65	orw	%cx,%dx			/* restore RC */
66	movw	%dx,cw(%rsp)
67	fldcw	cw(%rsp)
68	addq	$16,%rsp
69	ret
70	SET_SIZE(__xtoull)
71