1.file "modf.s" 2 3 4// Copyright (c) 2000 - 2003, Intel Corporation 5// All rights reserved. 6// 7// 8// Redistribution and use in source and binary forms, with or without 9// modification, are permitted provided that the following conditions are 10// met: 11// 12// * Redistributions of source code must retain the above copyright 13// notice, this list of conditions and the following disclaimer. 14// 15// * Redistributions in binary form must reproduce the above copyright 16// notice, this list of conditions and the following disclaimer in the 17// documentation and/or other materials provided with the distribution. 18// 19// * The name of Intel Corporation may not be used to endorse or promote 20// products derived from this software without specific prior written 21// permission. 22 23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS 27// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 31// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING 32// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34// 35// Intel Corporation is the author of this code, and requests that all 36// problem reports or change requests be submitted to it directly at 37// http://www.intel.com/software/products/opensource/libraries/num.htm. 38// 39// History 40//============================================================== 41// 02/02/00 Initial version 42// 04/04/00 Improved speed, corrected result for NaN input 43// 12/22/00 Fixed so inexact flag is never set, and invalid is not set for 44// qnans nor for inputs larger than 2^63. 45// 05/20/02 Cleaned up namespace and sf0 syntax 46// 02/10/03 Reordered header: .section, .global, .proc, .align 47// 48// API 49//============================================================== 50// double modf(double x, double *iptr) 51// break a floating point x number into fraction and an exponent 52// 53// input floating point f8, address in r33 54// output floating point f8 (x fraction), and *iptr (x integral part) 55// 56// OVERVIEW 57//============================================================== 58// 59// NO FRACTIONAL PART: HUGE 60// If 61// for double-extended 62// If the true exponent is greater than or equal 63 63// 1003e ==> 1003e -ffff = 3f = 63(dec) 64// for double 65// If the true exponent is greater than or equal 52 66// 10033 -ffff = 34 = 52(dec) 67// for single 68// If the true exponent is greater than or equal 23 69// 10016 -ffff = 17 = 23(dec) 70// then 71// we are already an integer (p9 true) 72 73// NO INTEGER PART: SMALL 74// Is f8 exponent less than register bias (that is, is it 75// less than 1). If it is, get the right sign of 76// zero and store this in iptr. 77 78// CALCULATION: NOT HUGE, NOT SMALL 79// To get the integer part 80// Take the floating-point input and truncate 81// then convert this integer to fp Call it MODF_INTEGER_PART 82 83// Subtract MODF_INTEGER_PART from MODF_NORM_F8 to get fraction part 84// Then put fraction part in f8 85// put integer part MODF_INTEGER_PART into *iptr 86 87// Registers used 88//============================================================== 89 90// predicate registers used: 91// p6 - p13 92 93// 0xFFFF 0x10033 94// -----------------------+-----------------+------------- 95// SMALL | NORMAL | HUGE 96// p11 --------------->|<----- p12 ----->| <-------------- p9 97// p10 --------------------------------->| 98// p13 --------------------------------------------------->| 99// 100 101// floating-point registers used: 102MODF_NORM_F8 = f9 103MODF_FRACTION_PART = f10 104MODF_INTEGER_PART = f11 105MODF_INT_INTEGER_PART = f12 106 107 108// general registers used 109modf_signexp = r14 110modf_GR_no_frac = r15 111modf_GR_FFFF = r16 112modf_17_ones = r17 113modf_exp = r18 114// r33 = iptr 115 116 117.section .text 118GLOBAL_LIBM_ENTRY(modf) 119 120// Main path is p9, p11, p8 FALSE and p12 TRUE 121 122// Assume input is normalized and get signexp 123// Normalize input just in case 124// Form exponent bias 125{ .mfi 126 getf.exp modf_signexp = f8 127 fnorm.s0 MODF_NORM_F8 = f8 128 addl modf_GR_FFFF = 0xffff, r0 129} 130// Get integer part of input 131// Form exponent mask 132{ .mfi 133 nop.m 999 134 fcvt.fx.trunc.s1 MODF_INT_INTEGER_PART = f8 135 mov modf_17_ones = 0x1ffff ;; 136} 137 138// Is x nan or inf? 139// qnan snan inf norm unorm 0 -+ 140// 1 1 1 0 0 0 11 = 0xe3 NAN_INF 141// Form biased exponent where input only has an integer part 142{ .mfi 143 nop.m 999 144 fclass.m.unc p6,p13 = f8, 0xe3 145 addl modf_GR_no_frac = 0x10033, r0 ;; 146} 147 148// Mask to get exponent 149// Is x unnorm? 150// qnan snan inf norm unorm 0 -+ 151// 0 0 0 0 1 0 11 = 0x0b UNORM 152// Set p13 to indicate calculation path, else p6 if nan or inf 153{ .mfi 154 and modf_exp = modf_17_ones, modf_signexp 155 fclass.m.unc p8,p0 = f8, 0x0b 156 nop.i 999 ;; 157} 158 159// p11 <== SMALL, no integer part, fraction is everyting 160// p9 <== HUGE, no fraction part, integer is everything 161// p12 <== NORMAL, fraction part and integer part 162{ .mii 163(p13) cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF 164 nop.i 999 165 nop.i 999 ;; 166} 167 168// Is x inf? p6 if inf, p7 if nan 169{ .mfb 170(p10) cmp.ge.unc p9,p12 = modf_exp, modf_GR_no_frac 171(p6) fclass.m.unc p6,p7 = f8, 0x23 172(p8) br.cond.spnt MODF_DENORM ;; 173} 174 175MODF_COMMON: 176// For HUGE set fraction to signed 0 177{ .mfi 178 nop.m 999 179(p9) fmerge.s f8 = f8,f0 180 nop.i 999 181} 182// For HUGE set integer part to normalized input 183{ .mfi 184 nop.m 999 185(p9) fnorm.d.s0 MODF_INTEGER_PART = MODF_NORM_F8 186 nop.i 999 ;; 187} 188 189// For SMALL set fraction to normalized input, integer part to signed 0 190{ .mfi 191 nop.m 999 192(p11) fmerge.s MODF_INTEGER_PART = f8,f0 193 nop.i 999 194} 195{ .mfi 196 nop.m 999 197(p11) fnorm.d.s0 f8 = MODF_NORM_F8 198 nop.i 999 ;; 199} 200 201// For NORMAL float the integer part 202{ .mfi 203 nop.m 999 204(p12) fcvt.xf MODF_INTEGER_PART = MODF_INT_INTEGER_PART 205 nop.i 999 ;; 206} 207 208// If x inf set integer part to INF, fraction to signed 0 209{ .mfi 210(p6) stfd [r33] = MODF_NORM_F8 211(p6) fmerge.s f8 = f8,f0 212 nop.i 999 ;; 213} 214 215// If x nan set integer and fraction parts to NaN (quietized) 216{ .mfi 217(p7) stfd [r33] = MODF_NORM_F8 218(p7) fmerge.s f8 = MODF_NORM_F8, MODF_NORM_F8 219 nop.i 999 ;; 220} 221 222{ .mmi 223(p9) stfd [r33] = MODF_INTEGER_PART 224 nop.m 999 225 nop.i 999 ;; 226} 227 228// For NORMAL compute fraction part 229{ .mfi 230(p11) stfd [r33] = MODF_INTEGER_PART 231(p12) fms.d.s0 f8 = MODF_NORM_F8,f1, MODF_INTEGER_PART 232 nop.i 999 ;; 233} 234 235// For NORMAL test if fraction part is zero; if so append correct sign 236{ .mfi 237 nop.m 999 238(p12) fcmp.eq.unc.s0 p7,p0 = MODF_NORM_F8, MODF_INTEGER_PART 239 nop.i 999 ;; 240} 241 242{ .mfi 243(p12) stfd [r33] = MODF_INTEGER_PART 244 nop.f 999 245 nop.i 999 ;; 246} 247 248// For NORMAL if fraction part is zero append sign of input 249{ .mfb 250 nop.m 999 251(p7) fmerge.s f8 = MODF_NORM_F8, f0 252 br.ret.sptk b0 ;; 253} 254 255MODF_DENORM: 256// If x unorm get signexp from normalized input 257// If x unorm get integer part from normalized input 258{ .mfi 259 getf.exp modf_signexp = MODF_NORM_F8 260 fcvt.fx.trunc.s1 MODF_INT_INTEGER_PART = MODF_NORM_F8 261 nop.i 999 ;; 262} 263 264// If x unorm mask to get exponent 265{ .mmi 266 and modf_exp = modf_17_ones, modf_signexp ;; 267 cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF 268 nop.i 999 ;; 269} 270 271{ .mfb 272(p10) cmp.ge.unc p9,p12 = modf_exp, modf_GR_no_frac 273 nop.f 999 274 br.cond.spnt MODF_COMMON ;; 275} 276 277GLOBAL_LIBM_END(modf) 278libm_alias_double_other (modf, modf) 279