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 2011 Nexenta Systems, Inc. All rights reserved. 23 */ 24 /* 25 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 .file "rndintl.s" 30 31 #include "libm.h" 32 LIBM_ANSI_PRAGMA_WEAK(aintl,function) 33 LIBM_ANSI_PRAGMA_WEAK(irintl,function) 34 LIBM_ANSI_PRAGMA_WEAK(anintl,function) 35 LIBM_ANSI_PRAGMA_WEAK(nintl,function) 36 #include "libm_synonyms.h" 37 #undef fabs 38 39 ENTRY(aintl) 40 movl %esp,%eax 41 subl $8,%esp 42 fstcw -8(%eax) 43 fldt 4(%eax) 44 movw -8(%eax),%cx 45 orw $0x0c00,%cx 46 movw %cx,-4(%eax) 47 fldcw -4(%eax) / set RD = to_zero 48 frndint 49 fstcw -4(%eax) 50 movw -4(%eax),%dx 51 andw $0xf3ff,%dx 52 movw -8(%eax),%cx 53 andw $0x0c00,%cx 54 orw %dx,%cx 55 movw %cx,-8(%eax) 56 fldcw -8(%eax) / restore RD 57 addl $8,%esp 58 ret 59 .align 4 60 SET_SIZE(aintl) 61 62 ENTRY(irintl) 63 movl %esp,%ecx 64 subl $8,%esp 65 fldt 4(%ecx) / load x 66 fistpl -8(%ecx) / [x] 67 fwait 68 movl -8(%ecx),%eax 69 addl $8,%esp 70 ret 71 .align 4 72 SET_SIZE(irintl) 73 74 .data 75 .align 4 76 half: .float 0.5 77 78 ENTRY(anintl) 79 .Lanintl: 80 movl %esp,%ecx 81 subl $8,%esp 82 fstcw -8(%ecx) 83 fldt 4(%ecx) 84 movw -8(%ecx),%dx 85 andw $0xf3ff,%dx 86 movw %dx,-4(%ecx) 87 fldcw -4(%ecx) / set RD = to_nearest 88 fld %st(0) 89 frndint / [x],x 90 fstcw -4(%ecx) 91 movw -4(%ecx),%dx 92 andw $0xf3ff,%dx 93 movw -8(%ecx),%ax 94 andw $0x0c00,%ax 95 orw %dx,%ax 96 movw %ax,-8(%ecx) 97 fldcw -8(%ecx) / restore RD 98 fucom / check if x is already an integer 99 fstsw %ax 100 sahf 101 jp .L0 102 je .L0 103 fxch / x,[x] 104 fsub %st(1),%st / x-[x],[x] 105 fabs / |x-[x]|,[x] 106 PIC_SETUP(1) 107 fcoms PIC_L(half) 108 PIC_WRAPUP 109 fnstsw %ax 110 sahf 111 jae .halfway / if |x-[x]| = 0.5 goto halfway, 112 / most cases will not take branch. 113 .L0: 114 addl $8,%esp 115 fstp %st(0) 116 ret 117 .halfway: 118 / x = n+0.5, recompute anint(x) as x+sign(x)*0.5 119 fldt 4(%ecx) / x, 0.5, [x] 120 movw 12(%ecx),%ax / sign+exp part of x 121 andw $0x8000,%ax / look at sign bit 122 jnz .x_neg 123 faddp 124 addl $8,%esp 125 fstp %st(1) 126 ret 127 .x_neg: 128 / here, x is negative, so return x-0.5 129 fsubp %st,%st(1) / x-0.5,[x] 130 addl $8,%esp 131 fstp %st(1) 132 ret 133 .align 4 134 SET_SIZE(anintl) 135 136 ENTRY(nintl) 137 pushl %ebp 138 movl %esp,%ebp 139 subl $8,%esp 140 pushl 16(%ebp) 141 pushl 12(%ebp) 142 pushl 8(%ebp) 143 call .Lanintl /// LOCAL 144 fistpl -8(%ebp) 145 fwait 146 movl -8(%ebp),%eax 147 leave 148 ret 149 .align 4 150 SET_SIZE(nintl)