Blame sysdeps/ia64/fpu/s_modf.S

Packit 6c4009
.file "modf.s"
Packit 6c4009
Packit 6c4009
Packit 6c4009
// Copyright (c) 2000 - 2003, Intel Corporation
Packit 6c4009
// All rights reserved.
Packit 6c4009
//
Packit 6c4009
// Contributed 2000 by the Intel Numerics Group, Intel Corporation
Packit 6c4009
//
Packit 6c4009
// Redistribution and use in source and binary forms, with or without
Packit 6c4009
// modification, are permitted provided that the following conditions are
Packit 6c4009
// met:
Packit 6c4009
//
Packit 6c4009
// * Redistributions of source code must retain the above copyright
Packit 6c4009
// notice, this list of conditions and the following disclaimer.
Packit 6c4009
//
Packit 6c4009
// * Redistributions in binary form must reproduce the above copyright
Packit 6c4009
// notice, this list of conditions and the following disclaimer in the
Packit 6c4009
// documentation and/or other materials provided with the distribution.
Packit 6c4009
//
Packit 6c4009
// * The name of Intel Corporation may not be used to endorse or promote
Packit 6c4009
// products derived from this software without specific prior written
Packit 6c4009
// permission.
Packit 6c4009
Packit 6c4009
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 6c4009
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 6c4009
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 6c4009
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
Packit 6c4009
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Packit 6c4009
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Packit 6c4009
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit 6c4009
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
Packit 6c4009
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
Packit 6c4009
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Packit 6c4009
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 6c4009
//
Packit 6c4009
// Intel Corporation is the author of this code, and requests that all
Packit 6c4009
// problem reports or change requests be submitted to it directly at
Packit 6c4009
// http://www.intel.com/software/products/opensource/libraries/num.htm.
Packit 6c4009
//
Packit 6c4009
// History
Packit 6c4009
//==============================================================
Packit 6c4009
// 02/02/00 Initial version
Packit 6c4009
// 04/04/00 Improved speed, corrected result for NaN input
Packit 6c4009
// 12/22/00 Fixed so inexact flag is never set, and invalid is not set for
Packit 6c4009
//            qnans nor for inputs larger than 2^63.
Packit 6c4009
// 05/20/02 Cleaned up namespace and sf0 syntax
Packit 6c4009
// 02/10/03 Reordered header: .section, .global, .proc, .align
Packit 6c4009
//
Packit 6c4009
// API
Packit 6c4009
//==============================================================
Packit 6c4009
// double modf(double x, double *iptr)
Packit 6c4009
// break a floating point x number into fraction and an exponent
Packit 6c4009
//
Packit 6c4009
// input  floating point f8, address in r33
Packit 6c4009
// output floating point f8 (x fraction), and *iptr (x integral part)
Packit 6c4009
//
Packit 6c4009
// OVERVIEW
Packit 6c4009
//==============================================================
Packit 6c4009
//
Packit 6c4009
// NO FRACTIONAL PART: HUGE
Packit 6c4009
// If
Packit 6c4009
// for double-extended
Packit 6c4009
// If the true exponent is greater than or equal 63
Packit 6c4009
//      1003e ==> 1003e -ffff = 3f = 63(dec)
Packit 6c4009
// for double
Packit 6c4009
// If the true exponent is greater than or equal 52
Packit 6c4009
//                10033 -ffff = 34 = 52(dec)
Packit 6c4009
// for single
Packit 6c4009
// If the true exponent is greater than or equal 23
Packit 6c4009
//                10016 -ffff = 17 = 23(dec)
Packit 6c4009
// then
Packit 6c4009
// we are already an integer (p9 true)
Packit 6c4009
Packit 6c4009
// NO INTEGER PART:    SMALL
Packit 6c4009
//     Is f8 exponent less than register bias (that is, is it
Packit 6c4009
//     less than 1). If it is, get the right sign of
Packit 6c4009
//     zero and store this in iptr.
Packit 6c4009
Packit 6c4009
// CALCULATION: NOT HUGE, NOT SMALL
Packit 6c4009
// To get the integer part
Packit 6c4009
// Take the floating-point  input and truncate
Packit 6c4009
//   then convert  this integer to fp  Call it  MODF_INTEGER_PART
Packit 6c4009
Packit 6c4009
// Subtract  MODF_INTEGER_PART from MODF_NORM_F8 to get fraction part
Packit 6c4009
// Then put fraction part in f8
Packit 6c4009
//      put integer  part MODF_INTEGER_PART into *iptr
Packit 6c4009
Packit 6c4009
// Registers used
Packit 6c4009
//==============================================================
Packit 6c4009
Packit 6c4009
// predicate registers used:
Packit 6c4009
// p6 - p13
Packit 6c4009
Packit 6c4009
//                      0xFFFF           0x10033
Packit 6c4009
// -----------------------+-----------------+-------------
Packit 6c4009
//              SMALL     |      NORMAL     | HUGE
Packit 6c4009
//    p11 --------------->|<----- p12 ----->| <-------------- p9
Packit 6c4009
//    p10 --------------------------------->|
Packit 6c4009
//    p13 --------------------------------------------------->|
Packit 6c4009
//
Packit 6c4009
Packit 6c4009
// floating-point registers used:
Packit 6c4009
MODF_NORM_F8               = f9
Packit 6c4009
MODF_FRACTION_PART         = f10
Packit 6c4009
MODF_INTEGER_PART          = f11
Packit 6c4009
MODF_INT_INTEGER_PART      = f12
Packit 6c4009
Packit 6c4009
Packit 6c4009
// general registers used
Packit 6c4009
modf_signexp    = r14
Packit 6c4009
modf_GR_no_frac = r15
Packit 6c4009
modf_GR_FFFF    = r16
Packit 6c4009
modf_17_ones    = r17
Packit 6c4009
modf_exp        = r18
Packit 6c4009
// r33 = iptr
Packit 6c4009
Packit 6c4009
Packit 6c4009
.section .text
Packit 6c4009
GLOBAL_LIBM_ENTRY(modf)
Packit 6c4009
Packit 6c4009
// Main path is p9, p11, p8 FALSE and p12 TRUE
Packit 6c4009
Packit 6c4009
// Assume input is normalized and get signexp
Packit 6c4009
// Normalize input just in case
Packit 6c4009
// Form exponent bias
Packit 6c4009
{ .mfi
Packit 6c4009
      getf.exp  modf_signexp = f8
Packit 6c4009
      fnorm.s0          MODF_NORM_F8  = f8
Packit 6c4009
      addl           modf_GR_FFFF  = 0xffff, r0
Packit 6c4009
}
Packit 6c4009
// Get integer part of input
Packit 6c4009
// Form exponent mask
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m 999
Packit 6c4009
      fcvt.fx.trunc.s1  MODF_INT_INTEGER_PART   = f8
Packit 6c4009
      mov  modf_17_ones     = 0x1ffff ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// Is x nan or inf?
Packit 6c4009
// qnan snan inf norm     unorm 0 -+
Packit 6c4009
// 1    1    1   0        0     0 11 = 0xe3 NAN_INF
Packit 6c4009
// Form biased exponent where input only has an integer part
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m 999
Packit 6c4009
      fclass.m.unc p6,p13 = f8, 0xe3
Packit 6c4009
      addl modf_GR_no_frac = 0x10033, r0 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// Mask to get exponent
Packit 6c4009
// Is x unnorm?
Packit 6c4009
// qnan snan inf norm     unorm 0 -+
Packit 6c4009
// 0    0    0   0        1     0 11 = 0x0b UNORM
Packit 6c4009
// Set p13 to indicate calculation path, else p6 if nan or inf
Packit 6c4009
{ .mfi
Packit 6c4009
      and       modf_exp = modf_17_ones, modf_signexp
Packit 6c4009
      fclass.m.unc p8,p0 = f8, 0x0b
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// p11 <== SMALL, no integer part, fraction is everyting
Packit 6c4009
// p9  <== HUGE,  no fraction part, integer is everything
Packit 6c4009
// p12 <== NORMAL, fraction part and integer part
Packit 6c4009
{ .mii
Packit 6c4009
(p13) cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
Packit 6c4009
      nop.i 999
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// Is x inf? p6 if inf, p7 if nan
Packit 6c4009
{ .mfb
Packit 6c4009
(p10) cmp.ge.unc p9,p12  = modf_exp, modf_GR_no_frac
Packit 6c4009
(p6)  fclass.m.unc p6,p7 = f8, 0x23
Packit 6c4009
(p8)  br.cond.spnt MODF_DENORM ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
MODF_COMMON:
Packit 6c4009
// For HUGE set fraction to signed 0
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m 999
Packit 6c4009
(p9)  fmerge.s f8 = f8,f0
Packit 6c4009
      nop.i 999
Packit 6c4009
}
Packit 6c4009
// For HUGE set integer part to normalized input
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m 999
Packit 6c4009
(p9)  fnorm.d.s0 MODF_INTEGER_PART = MODF_NORM_F8
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// For SMALL set fraction to normalized input, integer part to signed 0
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m 999
Packit 6c4009
(p11) fmerge.s MODF_INTEGER_PART = f8,f0
Packit 6c4009
      nop.i 999
Packit 6c4009
}
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m 999
Packit 6c4009
(p11) fnorm.d.s0 f8 = MODF_NORM_F8
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// For NORMAL float the integer part
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m 999
Packit 6c4009
(p12) fcvt.xf    MODF_INTEGER_PART = MODF_INT_INTEGER_PART
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// If x inf set integer part to INF, fraction to signed 0
Packit 6c4009
{ .mfi
Packit 6c4009
(p6)  stfd [r33] = MODF_NORM_F8
Packit 6c4009
(p6)  fmerge.s  f8 = f8,f0
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// If x nan set integer and fraction parts to NaN (quietized)
Packit 6c4009
{ .mfi
Packit 6c4009
(p7)  stfd [r33] = MODF_NORM_F8
Packit 6c4009
(p7)  fmerge.s  f8 = MODF_NORM_F8, MODF_NORM_F8
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{ .mmi
Packit 6c4009
(p9)  stfd [r33] = MODF_INTEGER_PART
Packit 6c4009
      nop.m 999
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// For NORMAL compute fraction part
Packit 6c4009
{ .mfi
Packit 6c4009
(p11) stfd [r33] = MODF_INTEGER_PART
Packit 6c4009
(p12) fms.d.s0   f8 = MODF_NORM_F8,f1, MODF_INTEGER_PART
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// For NORMAL test if fraction part is zero; if so append correct sign
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m 999
Packit 6c4009
(p12) fcmp.eq.unc.s0 p7,p0 = MODF_NORM_F8, MODF_INTEGER_PART
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
(p12) stfd [r33] = MODF_INTEGER_PART
Packit 6c4009
      nop.f 999
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// For NORMAL if fraction part is zero append sign of input
Packit 6c4009
{ .mfb
Packit 6c4009
      nop.m 999
Packit 6c4009
(p7)  fmerge.s f8 = MODF_NORM_F8, f0
Packit 6c4009
      br.ret.sptk    b0 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
MODF_DENORM:
Packit 6c4009
// If x unorm get signexp from normalized input
Packit 6c4009
// If x unorm get integer part from normalized input
Packit 6c4009
{ .mfi
Packit 6c4009
      getf.exp  modf_signexp = MODF_NORM_F8
Packit 6c4009
      fcvt.fx.trunc.s1  MODF_INT_INTEGER_PART   = MODF_NORM_F8
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
// If x unorm mask to get exponent
Packit 6c4009
{ .mmi
Packit 6c4009
      and       modf_exp = modf_17_ones, modf_signexp ;;
Packit 6c4009
      cmp.lt.unc p11,p10 = modf_exp, modf_GR_FFFF
Packit 6c4009
      nop.i 999 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{ .mfb
Packit 6c4009
(p10) cmp.ge.unc p9,p12  = modf_exp, modf_GR_no_frac
Packit 6c4009
      nop.f 999
Packit 6c4009
      br.cond.spnt MODF_COMMON ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
GLOBAL_LIBM_END(modf)
Packit 6c4009
libm_alias_double_other (modf, modf)