Blame sysdeps/ia64/fpu/s_fdim.S

Packit 6c4009
.file "fdim.s"
Packit 6c4009
Packit 6c4009
Packit 6c4009
// Copyright (c) 2001 - 2003, Intel Corporation
Packit 6c4009
// All rights reserved.
Packit 6c4009
//
Packit 6c4009
// Contributed 2001 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
// 06/08/01 Initial version
Packit 6c4009
// 08/23/01 Corrected error tag number
Packit 6c4009
// 05/20/02 Cleaned up namespace and sf0 syntax
Packit 6c4009
// 01/28/03 Improved performance
Packit 6c4009
//
Packit 6c4009
// API
Packit 6c4009
//==============================================================
Packit 6c4009
// double fdim( double x, double y );
Packit 6c4009
// input  floating point f8, f9
Packit 6c4009
// output floating point f8
Packit 6c4009
//
Packit 6c4009
//
Packit 6c4009
// Overview of operation
Packit 6c4009
//==============================================================
Packit 6c4009
// fdim determines the positive difference between the arguments
Packit 6c4009
//   Result = x - y   if x > y
Packit 6c4009
//          = +0      if x <= y
Packit 6c4009
//
Packit 6c4009
// Error support is called if x-y overflows for x > y
Packit 6c4009
//
Packit 6c4009
Packit 6c4009
// Registers used
Packit 6c4009
//==============================================================
Packit 6c4009
// General purpose registers: r14, r32 - r39
Packit 6c4009
Packit 6c4009
rExpBig               = r14
Packit 6c4009
Packit 6c4009
// r36-39 parameters for libm_error_support
Packit 6c4009
GR_SAVE_B0            = r33
Packit 6c4009
GR_SAVE_GP            = r34
Packit 6c4009
GR_SAVE_PFS           = r35
Packit 6c4009
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
// Floating-point registers: f8 - f12
Packit 6c4009
Packit 6c4009
f_tmp_result          = f10
Packit 6c4009
fBig                  = f11
Packit 6c4009
fNormX                = f12
Packit 6c4009
Packit 6c4009
// Predicate registers: p6 - p10
Packit 6c4009
Packit 6c4009
Packit 6c4009
.section .text
Packit 6c4009
GLOBAL_LIBM_ENTRY(fdim)
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
      mov             rExpBig = 0x103ff  // Exponent to indicate overflow
Packit 6c4009
      fcmp.le.s1      p6,p7 = f8, f9     // Is x <= y?
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m           0
Packit 6c4009
      fnorm.s1        fNormX = f8        // Save x
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
      setf.exp        fBig = rExpBig     // Constant to test for overflow
Packit 6c4009
      fcmp.eq.s0      p8,p0 = f8, f9     // Dummy op to set Denormal or Invalid
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m           0
Packit 6c4009
      fclass.m        p9,p10 = f8, 0x1e3 // Test for x natval, nan, inf
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m           0
Packit 6c4009
(p6)  fmerge.s        f8 = f0, f0        // Result is +0 if x <= y
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m           0
Packit 6c4009
(p7)  fms.d.s0        f8 = f8, f1, f9    // Result is x - y if x > y
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m           0
Packit 6c4009
(p10) fclass.m        p9,p10 = f9, 0x1e3 // Test for y natval, nan, inf
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m           0
Packit 6c4009
(p10) fcmp.ge.s1      p8,p0 = f8, fBig   // Test result for overflow
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
{ .mbb
Packit 6c4009
(p9)  cmp.ne          p8,p0 = r0,r0      // Clear p8 if x or y natval,nan,inf
Packit 6c4009
(p8)  br.cond.spnt    FDIM_OVERFLOW      // Branch if result overflows
Packit 6c4009
      br.ret.sptk     b0                 // Normal return
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
Packit 6c4009
// Here if result will overflow
Packit 6c4009
FDIM_OVERFLOW:
Packit 6c4009
{ .mfi
Packit 6c4009
      alloc           r32=ar.pfs,2,2,4,0
Packit 6c4009
      fms.d.s0        f_tmp_result = f8,f1,f9 // Normalize result force overflow
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
{ .mfb
Packit 6c4009
      mov             GR_Parameter_TAG = 196  // Error code
Packit 6c4009
      nop.f           0
Packit 6c4009
      br.cond.sptk    __libm_error_region     // Branch to error code
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
GLOBAL_LIBM_END(fdim)
Packit 6c4009
libm_alias_double_other (fdim, fdim)
Packit 6c4009
Packit 6c4009
Packit 6c4009
LOCAL_LIBM_ENTRY(__libm_error_region)
Packit 6c4009
// Call error support to report possible range error
Packit 6c4009
.prologue
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
        add   GR_Parameter_Y=-32,sp            // Parameter 2 value
Packit 6c4009
        nop.f 0
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
Packit 6c4009
{ .mmi
Packit 6c4009
        stfd [GR_Parameter_Y] = f9,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
Packit 6c4009
.body
Packit 6c4009
{ .mib
Packit 6c4009
        stfd [GR_Parameter_X] = fNormX         // STORE Parameter 1 on stack
Packit 6c4009
        add   GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address
Packit 6c4009
        nop.b 0
Packit 6c4009
}
Packit 6c4009
{ .mib
Packit 6c4009
        stfd [GR_Parameter_Y] = f_tmp_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
Packit 6c4009
{ .mmi
Packit 6c4009
        add   GR_Parameter_RESULT = 48,sp
Packit 6c4009
        nop.m 0
Packit 6c4009
        nop.i 0
Packit 6c4009
};;
Packit 6c4009
Packit 6c4009
{ .mmi
Packit 6c4009
        ldfd  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
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#