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 2004 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 .file "_xtoull.s" 27 28#include <SYS.h> 29 30 .set cw,0 31 .set cw_old,2 32 .set two_words,4 33 .set four_words,8 34 .text 35 .align 4 36two_to_63: .long 0x5f000000 37 38 ENTRY(__xtoull) // 387-stack to unsigned long long 39 subl $12,%esp 40 fstcw cw_old(%esp) 41 movw cw_old(%esp),%ax 42 movw %ax,%cx 43 andw $0x0c00,%cx // save RC 44 orw $0x0c00,%ax 45 movw %ax,cw(%esp) 46 fldcw cw(%esp) 47 _prologue_ 48 fcoms _sref_(two_to_63) // compare st to 2**63 49 _epilogue_ 50 fstsw %ax // store status in %ax 51 // use fstsw for correct trap handling 52 sahf // load AH into flags 53 jb .donotsub // jump if st < 2**63 or is NaN 54 _prologue_ 55 fsubs _sref_(two_to_63) // subtract 2**63 56 _epilogue_ 57.donotsub: 58 fistpll two_words(%esp) 59 fwait // in case fistpll causes exception 60 movl four_words(%esp),%edx 61 jb .donotadd // flags did not change 62 add $0x80000000,%edx // add back 2**63 63.donotadd: 64 fstcw cw(%esp) // fetch CW in case masks changed value 65 movw cw(%esp),%ax 66 andw $0xf3ff,%ax 67 orw %cx,%ax // restore RC 68 movw %ax,cw(%esp) 69 fldcw cw(%esp) 70 movl two_words(%esp),%eax 71 addl $12,%esp 72 ret 73 SET_SIZE(__xtoull) 74