2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A .file "_xtoull.s"
2N/A
2N/A#include <SYS.h>
2N/A
2N/A .set cw,0
2N/A .set cw_old,2
2N/A .text
2N/A .align 16
2N/Atwo_to_63: .4byte 0x5f000000
2N/A
2N/A ENTRY(__xtoull) /* 387-stack to unsigned long long */
2N/A subq $16,%rsp
2N/A fstcw cw_old(%rsp)
2N/A movw cw_old(%rsp),%ax
2N/A movw %ax,%cx
2N/A andw $0x0c00,%cx /* save RC */
2N/A orw $0x0c00,%ax
2N/A movw %ax,cw(%rsp)
2N/A fldcw cw(%rsp)
2N/A flds two_to_63(%rip)
2N/A fcomip %st(1),%st /* compare 2**63 to x */
2N/A jp .donotsub /* jump if x is NaN */
2N/A ja .donotsub /* jump if 2**63 > x */
2N/A fsubs two_to_63(%rip) /* subtract 2**63 */
2N/A.donotsub:
2N/A fistpll 8(%rsp)
2N/A fwait /* in case fistpll causes exception */
2N/A movq 8(%rsp),%rax
2N/A jp .donotadd
2N/A ja .donotadd /* flags did not change */
2N/A movq $0x8000000000000000,%rcx
2N/A addq %rcx,%rax /* add back 2**63 */
2N/A.donotadd:
2N/A fstcw cw(%rsp) /* fetch CW in case masks changed */
2N/A movw cw(%rsp),%dx
2N/A andw $0xf3ff,%dx
2N/A orw %cx,%dx /* restore RC */
2N/A movw %dx,cw(%rsp)
2N/A fldcw cw(%rsp)
2N/A addq $16,%rsp
2N/A ret
2N/A SET_SIZE(__xtoull)