Blame sysdeps/ia64/fpu/e_hypotf.S

Packit 6c4009
.file "hypotf.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
//*********************************************************************
Packit 6c4009
//
Packit 6c4009
// History:
Packit 6c4009
// 02/02/00 hand-optimized
Packit 6c4009
// 04/04/00 Unwind support added
Packit 6c4009
// 06/26/00 new version
Packit 6c4009
// 08/15/00 Bundle added after call to __libm_error_support to properly
Packit 6c4009
//          set [the previously overwritten] GR_Parameter_RESULT.
Packit 6c4009
// 05/20/02 Cleaned up namespace and sf0 syntax
Packit 6c4009
// 02/10/03 Reordered header: .section, .global, .proc, .align
Packit 6c4009
// 04/17/03 Added missing mutex directive
Packit 6c4009
//
Packit 6c4009
//*********************************************************************
Packit 6c4009
//                           ___________
Packit 6c4009
// Function:   hypotf(x,y) = |(x^2 + y^2) = for single precision values
Packit 6c4009
//             x and y
Packit 6c4009
//             Also provides cabsf functionality.
Packit 6c4009
//
Packit 6c4009
//*********************************************************************
Packit 6c4009
//
Packit 6c4009
// Resources Used:
Packit 6c4009
//
Packit 6c4009
//    Floating-Point Registers: f8  (Input and Return Value)
Packit 6c4009
//                              f9  (Input)
Packit 6c4009
//                              f6 -f15
Packit 6c4009
//
Packit 6c4009
//    General Purpose Registers:
Packit 6c4009
//      r2-r3   (Scratch)
Packit 6c4009
//      r32-r36 (Locals)
Packit 6c4009
//      r37-r40 (Used to pass arguments to error handling routine)
Packit 6c4009
//
Packit 6c4009
//    Predicate Registers:      p6 - p10
Packit 6c4009
//
Packit 6c4009
//*********************************************************************
Packit 6c4009
//
Packit 6c4009
// IEEE Special Conditions:
Packit 6c4009
//
Packit 6c4009
//    All faults and exceptions should be raised correctly.
Packit 6c4009
//    Overflow can occur.
Packit 6c4009
//    hypotf(Infinity and anything) = +Infinity
Packit 6c4009
//    hypotf(QNaN and anything) = QNaN
Packit 6c4009
//    hypotf(SNaN and anything ) = QNaN
Packit 6c4009
//
Packit 6c4009
//*********************************************************************
Packit 6c4009
//
Packit 6c4009
// Implementation:
Packit 6c4009
//  x2 = x * x   in double-extended
Packit 6c4009
//  y2 = y * y   in double-extended
Packit 6c4009
//  temp = x2 + y2   in double-extended
Packit 6c4009
//  sqrt(temp) rounded to single precision
Packit 6c4009
//
Packit 6c4009
//*********************************************************************
Packit 6c4009
Packit 6c4009
GR_SAVE_PFS         = r33
Packit 6c4009
GR_SAVE_B0          = r34
Packit 6c4009
GR_SAVE_GP          = r35
Packit 6c4009
GR_Parameter_X      = r36
Packit 6c4009
GR_Parameter_Y      = r37
Packit 6c4009
GR_Parameter_RESULT = r38
Packit 6c4009
GR_Parameter_TAG    = r39
Packit 6c4009
Packit 6c4009
FR_X                = f14
Packit 6c4009
FR_Y                = f15
Packit 6c4009
FR_RESULT           = f8
Packit 6c4009
Packit 6c4009
.section .text
Packit 6c4009
Packit 6c4009
LOCAL_LIBM_ENTRY(cabsf)
Packit 6c4009
LOCAL_LIBM_END(cabsf)
Packit 6c4009
Packit 6c4009
GLOBAL_IEEE754_ENTRY(hypotf)
Packit 6c4009
{.mfi
Packit 6c4009
  alloc r32= ar.pfs,0,4,4,0
Packit 6c4009
  // Compute x*x
Packit 6c4009
  fma.s1 f10=f8,f8,f0
Packit 6c4009
  // r2=bias-1
Packit 6c4009
  mov r2=0xfffe
Packit 6c4009
}
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // y*y
Packit 6c4009
  fma.s1 f11=f9,f9,f0
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
     nop.m 0
Packit 6c4009
//   Check if x is an Inf - if so return Inf even
Packit 6c4009
//   if y is a NaN (C9X)
Packit 6c4009
     fclass.m.unc p7, p6 = f8, 0x023
Packit 6c4009
     nop.i 0
Packit 6c4009
}
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // if possible overflow, copy f8 to f14
Packit 6c4009
  // set Denormal, if necessary
Packit 6c4009
  // (p8)
Packit 6c4009
  fma.s.s0 f14=f8,f1,f0
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
     nop.m 0
Packit 6c4009
//   Check if y is an Inf - if so return Inf even
Packit 6c4009
//   if x is a NaN (C9X)
Packit 6c4009
     fclass.m.unc p8, p9 = f9, 0x023
Packit 6c4009
	 nop.i 0
Packit 6c4009
}
Packit 6c4009
{ .mfi
Packit 6c4009
     nop.m 0
Packit 6c4009
//   For x=inf, multiply y by 1 to raise invalid on y an SNaN
Packit 6c4009
//   (p7) fma.s0 f9=f9,f1,f0
Packit 6c4009
     // copy f9 to f15; set Denormal, if necessary
Packit 6c4009
	 fma.s.s0 f15=f9,f1,f0
Packit 6c4009
     nop.i 0;;
Packit 6c4009
}
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // is y Zero ?
Packit 6c4009
  (p6) fclass.m p6,p0=f9,0x7
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // is x Zero ?
Packit 6c4009
  (p9) fclass.m p9,p0=f8,0x7
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{.mfi
Packit 6c4009
  // f7=0.5
Packit 6c4009
  setf.exp f7=r2
Packit 6c4009
  // a=x2+y2
Packit 6c4009
  fma.s1 f12=f10,f1,f11
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // x not NaN ?
Packit 6c4009
  (p6) fclass.m p7,p0=f8,0x3f
Packit 6c4009
  nop.i 0
Packit 6c4009
}
Packit 6c4009
{.mfi
Packit 6c4009
  // 2*emax-2
Packit 6c4009
  mov r2=0x100fb
Packit 6c4009
  // f6=2
Packit 6c4009
  fma.s1 f6=f1,f1,f1
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // y not NaN ?
Packit 6c4009
  (p9) fclass.m p8,p0=f9,0x3f
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
.pred.rel "mutex",p7,p8
Packit 6c4009
{.mfb
Packit 6c4009
  nop.m 0
Packit 6c4009
  // if f8=Infinity or f9=Zero, return |f8|
Packit 6c4009
  (p7) fmerge.s f8=f0,f14
Packit 6c4009
  (p7) br.ret.spnt b0
Packit 6c4009
}
Packit 6c4009
{.mfb
Packit 6c4009
  nop.m 0
Packit 6c4009
  // if f9=Infinity or f8=Zero, return |f9|
Packit 6c4009
  (p8) fmerge.s f8=f0,f15
Packit 6c4009
  (p8) br.ret.spnt b0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
	 nop.m 0
Packit 6c4009
//   Identify Natvals, Infs, NaNs, and Zeros
Packit 6c4009
//   and return result
Packit 6c4009
     fclass.m.unc p7, p0 = f12, 0x1E7
Packit 6c4009
     nop.i 0
Packit 6c4009
}
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // z0=frsqrta(a)
Packit 6c4009
  frsqrta.s1 f8,p6=f12
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{.mfb
Packit 6c4009
  // get exponent of x^2+y^2
Packit 6c4009
  getf.exp r3=f12
Packit 6c4009
  // if special case, set f8
Packit 6c4009
  (p7) mov f8=f12
Packit 6c4009
  (p7) br.ret.spnt b0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // S0=a*z0
Packit 6c4009
  (p6) fma.s1 f12=f12,f8,f0
Packit 6c4009
  nop.i 0
Packit 6c4009
}
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // H0=0.5*z0
Packit 6c4009
  (p6) fma.s1 f10=f8,f7,f0
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // f6=5/2
Packit 6c4009
  fma.s1 f6=f7,f1,f6
Packit 6c4009
  nop.i 0
Packit 6c4009
}
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // f11=3/2
Packit 6c4009
  fma.s1 f11=f7,f1,f1
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // d=0.5-S0*H0
Packit 6c4009
  (p6) fnma.s1 f7=f12,f10,f7
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // P01=d+1
Packit 6c4009
  (p6) fma.s1 f10=f1,f7,f1
Packit 6c4009
  nop.i 0
Packit 6c4009
}
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // P23=5/2*d+3/2
Packit 6c4009
  (p6) fma.s1 f11=f6,f7,f11
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
{.mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // d2=d*d
Packit 6c4009
  (p6) fma.s1 f7=f7,f7,f0
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
{.mfi
Packit 6c4009
  // Is x^2 + y^2 well less than the overflow
Packit 6c4009
  // threshold?
Packit 6c4009
  (p6) cmp.lt.unc p7, p8 =  r3,r2
Packit 6c4009
  // P=P01+d2*P23
Packit 6c4009
  (p6) fma.s1 f10=f7,f11,f10
Packit 6c4009
  nop.i 0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{.mfb
Packit 6c4009
  nop.m 0
Packit 6c4009
  // S=P*S0
Packit 6c4009
  fma.s.s0 f8=f10,f12,f0
Packit 6c4009
  // No overflow in this case
Packit 6c4009
  (p7) br.ret.sptk b0;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
     nop.m 0
Packit 6c4009
(p8) fsetc.s2 0x7F,0x42
Packit 6c4009
     // Possible overflow path, must detect by
Packit 6c4009
     // Setting widest range exponent with prevailing
Packit 6c4009
     // rounding mode.
Packit 6c4009
     nop.i 0 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
   // bias+0x400 (bias+EMAX+1)
Packit 6c4009
   (p8) mov r2=0x1007f
Packit 6c4009
   // S=P*S0
Packit 6c4009
   (p8) fma.s.s2 f12=f10,f12,f0
Packit 6c4009
   nop.i 0 ;;
Packit 6c4009
}
Packit 6c4009
{ .mfi
Packit 6c4009
(p8) setf.exp f11 = r2
Packit 6c4009
(p8) fsetc.s2 0x7F,0x40
Packit 6c4009
//   Restore Original Mode in S2
Packit 6c4009
     nop.i 0 ;;
Packit 6c4009
}
Packit 6c4009
{ .mfi
Packit 6c4009
     nop.m 0
Packit 6c4009
(p8) fcmp.lt.unc.s1 p9, p10 =  f12, f11
Packit 6c4009
     nop.i 0 ;;
Packit 6c4009
}
Packit 6c4009
{ .mib
Packit 6c4009
     nop.m 0
Packit 6c4009
     mov GR_Parameter_TAG = 47
Packit 6c4009
	 // No overflow
Packit 6c4009
(p9) br.ret.sptk b0;;
Packit 6c4009
}
Packit 6c4009
GLOBAL_IEEE754_END(hypotf)
Packit 6c4009
libm_alias_float_other (__hypot, hypot)
Packit 6c4009
Packit 6c4009
LOCAL_LIBM_ENTRY(__libm_error_region)
Packit 6c4009
.prologue
Packit 6c4009
{ .mii
Packit 6c4009
        add   GR_Parameter_Y=-32,sp             // Parameter 2 value
Packit 6c4009
        mov   GR_Parameter_TAG = 47
Packit 6c4009
.save   ar.pfs,GR_SAVE_PFS
Packit 6c4009
        mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
Packit 6c4009
}
Packit 6c4009
{ .mfi
Packit 6c4009
.fframe 64
Packit 6c4009
        add sp=-64,sp                           // Create new stack
Packit 6c4009
        nop.f 0
Packit 6c4009
        mov GR_SAVE_GP=gp                       // Save gp
Packit 6c4009
};;
Packit 6c4009
{ .mmi
Packit 6c4009
        stfs [GR_Parameter_Y] = FR_Y,16         // Store Parameter 2 on stack
Packit 6c4009
        add GR_Parameter_X = 16,sp              // Parameter 1 address
Packit 6c4009
.save   b0, GR_SAVE_B0
Packit 6c4009
        mov GR_SAVE_B0=b0                       // Save b0
Packit 6c4009
};;
Packit 6c4009
.body
Packit 6c4009
{ .mib
Packit 6c4009
        stfs [GR_Parameter_X] = FR_X            // Store Parameter 1 on stack
Packit 6c4009
        add   GR_Parameter_RESULT = 0,GR_Parameter_Y
Packit 6c4009
        nop.b 0                                 // Parameter 3 address
Packit 6c4009
}
Packit 6c4009
{ .mib
Packit 6c4009
        stfs [GR_Parameter_Y] = FR_RESULT       // Store Parameter 3 on stack
Packit 6c4009
        add   GR_Parameter_Y = -16,GR_Parameter_Y
Packit 6c4009
        br.call.sptk b0=__libm_error_support#   // Call error handling function
Packit 6c4009
};;
Packit 6c4009
{ .mmi
Packit 6c4009
        nop.m 0
Packit 6c4009
        nop.m 0
Packit 6c4009
        add   GR_Parameter_RESULT = 48,sp
Packit 6c4009
};;
Packit 6c4009
{ .mmi
Packit 6c4009
        ldfs  f8 = [GR_Parameter_RESULT]       // Get return result off stack
Packit 6c4009
.restore sp
Packit 6c4009
        add   sp = 64,sp                       // Restore stack pointer
Packit 6c4009
        mov   b0 = GR_SAVE_B0                  // Restore return address
Packit 6c4009
};;
Packit 6c4009
{ .mib
Packit 6c4009
        mov   gp = GR_SAVE_GP                  // Restore gp
Packit 6c4009
        mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
Packit 6c4009
        br.ret.sptk     b0                     // Return
Packit 6c4009
};;
Packit 6c4009
Packit 6c4009
LOCAL_LIBM_END(__libm_error_region)
Packit 6c4009
Packit 6c4009
Packit 6c4009
.type   __libm_error_support#,@function
Packit 6c4009
.global __libm_error_support#