Blame sysdeps/ia64/fpu/e_ilogbl.S

Packit 6c4009
.file "ilogbl.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/03/00 Initial version
Packit 6c4009
// 05/26/00 Fix bug when x a double-extended denormal;
Packit 6c4009
//          if x=0 call error routine, per C9X
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
// 01/20/01 Fixed result for x=0
Packit 6c4009
// 05/20/02 Cleaned up namespace and sf0 syntax
Packit 6c4009
// 01/20/03 Improved performance
Packit 6c4009
//
Packit 6c4009
// API
Packit 6c4009
//==============================================================
Packit 6c4009
// int ilogbl( long double x );
Packit 6c4009
//
Packit 6c4009
// Overview of operation
Packit 6c4009
//==============================================================
Packit 6c4009
// The ilogbl function extracts the exponent of x as an integer
Packit 6c4009
// and returns it in r8
Packit 6c4009
//
Packit 6c4009
// ilogbl is similar to logbl but differs in the following ways:
Packit 6c4009
//         +-inf
Packit 6c4009
//            ilogbl: returns INT_MAX
Packit 6c4009
//             logbl: returns +inf
Packit 6c4009
//         Nan  returns FP_LOGBNAN (which is either INT_MAX or INT_MIN)
Packit 6c4009
//            ilogbl: returns INT_MAX (7fffffff)
Packit 6c4009
//             logbl: returns QNAN (quietized SNAN)
Packit 6c4009
//         0    returns FP_ILOGB0 (which is either INT_MIN or -INT_MAX)
Packit 6c4009
//            ilogbl: returns -INT_MAX (80000001)
Packit 6c4009
//             logbl: returns -inf, raises the divide-by-zero exception,
Packit 6c4009
//                   and calls libm_error_support to set domain error
Packit 6c4009
//
Packit 6c4009
// Registers used
Packit 6c4009
//==============================================================
Packit 6c4009
// general registers used:
Packit 6c4009
// r26 -> r39
Packit 6c4009
// r36 -> r39 used as parameters to error path
Packit 6c4009
//
Packit 6c4009
// predicate registers used:
Packit 6c4009
// p6 -> p10
Packit 6c4009
// floating-point registers used:
Packit 6c4009
// f9, f10, f11
Packit 6c4009
// f8, input
Packit 6c4009
Packit 6c4009
rExpBias            = r26
Packit 6c4009
rExpMask            = r27
Packit 6c4009
rSignexp_x          = r28
Packit 6c4009
rExp_x              = r29
Packit 6c4009
rIntMax             = r30
Packit 6c4009
rExp_2to64          = r31
Packit 6c4009
Packit 6c4009
GR_SAVE_PFS         = r32
Packit 6c4009
rTrialResult        = r33
Packit 6c4009
GR_SAVE_B0          = r34
Packit 6c4009
GR_SAVE_GP          = 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
fTmp                = f9
Packit 6c4009
fNorm_x             = f10
Packit 6c4009
f2to64              = f11
Packit 6c4009
Packit 6c4009
.section .text
Packit 6c4009
GLOBAL_LIBM_ENTRY(__ieee754_ilogbl)
Packit 6c4009
Packit 6c4009
// X NORMAL
Packit 6c4009
// TrueExp_x = exp(f8) - 0xffff
Packit 6c4009
// r8 = TrueExp_x
Packit 6c4009
{ .mfi
Packit 6c4009
      getf.exp        rSignexp_x = f8
Packit 6c4009
      fclass.m        p8,p0 = f8, 0x0b   // Test for x unorm
Packit 6c4009
      mov             rExpBias = 0xffff  // Exponent bias
Packit 6c4009
}
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m           0
Packit 6c4009
      fnorm.s1        fNorm_x = f8
Packit 6c4009
      mov             rExpMask = 0x1ffff // Exponent mask
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
// Form signexp of 2^64 in case need to scale denormal
Packit 6c4009
{ .mfb
Packit 6c4009
      mov             rExp_2to64 = 0x1003f
Packit 6c4009
      fclass.m        p6,p9 = f8, 0x1e3  // Test x natval, nan, inf
Packit 6c4009
(p8)  br.cond.spnt    ILOGB_DENORM       // Branch if x unorm
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
ILOGB_COMMON:
Packit 6c4009
// Return here from ILOGB_DENORM
Packit 6c4009
{ .mfi
Packit 6c4009
      and             rExp_x = rSignexp_x, rExpMask // Get biased exponent
Packit 6c4009
      fclass.m        p7,p10 = f8, 0x07   // Test x zero
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
{ .mlx
Packit 6c4009
      nop.m           0
Packit 6c4009
      movl            rIntMax = 0x000000007fffffff // Form INT_MAX
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
.pred.rel "mutex",p6,p9
Packit 6c4009
{ .mfi
Packit 6c4009
(p9)  sub             r8 = rExp_x, rExpBias // Get true exponent for normal path
Packit 6c4009
(p6)  fma.s0          fTmp = f8, f8, f0     // Dummy to set Invalid flag
Packit 6c4009
(p6)  mov             r8 = rIntMax          // If nan, inf, return INT_MAX
Packit 6c4009
}
Packit 6c4009
{ .mbb
Packit 6c4009
      nop.m           0
Packit 6c4009
(p7)  br.cond.spnt    ILOGB_ZERO            // Branch if x zero
Packit 6c4009
(p10) br.ret.sptk     b0                    // Exit if x not zero
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
Packit 6c4009
ILOGB_DENORM:
Packit 6c4009
// Form 2^64 in case need to scale denormal
Packit 6c4009
// Check to see if double-extended denormal
Packit 6c4009
{ .mfi
Packit 6c4009
      setf.exp        f2to64 = rExp_2to64
Packit 6c4009
      fclass.m        p8,p0 = fNorm_x, 0x0b
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
{ .mfi
Packit 6c4009
      nop.m           0
Packit 6c4009
      fcmp.eq.s0      p7,p0 = f8, f0           // Dummy op to set denormal flag
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
// If double-extended denormal add 64 to exponent bias for scaling
Packit 6c4009
// If double-extended denormal form x * 2^64 which is normal
Packit 6c4009
{ .mfi
Packit 6c4009
(p8)  add             rExpBias = 64, rExpBias
Packit 6c4009
(p8)  fmpy.s1         fNorm_x = fNorm_x, f2to64
Packit 6c4009
      nop.i           0
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
// Logic is the same as normal path but use normalized input
Packit 6c4009
{ .mib
Packit 6c4009
      getf.exp        rSignexp_x = fNorm_x
Packit 6c4009
      nop.i           0
Packit 6c4009
      br.cond.sptk    ILOGB_COMMON             // Return to main path
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
ILOGB_ZERO:
Packit 6c4009
// Here if x zero
Packit 6c4009
// Return INT_MIN, call error support
Packit 6c4009
Packit 6c4009
{ .mlx
Packit 6c4009
      alloc           r32=ar.pfs,1,3,4,0
Packit 6c4009
      movl            rTrialResult = 0x0000000080000000
Packit 6c4009
}
Packit 6c4009
{ .mib
Packit 6c4009
      mov             GR_Parameter_TAG = 156  // Error code
Packit 6c4009
      nop.i           0
Packit 6c4009
      br.cond.sptk    __libm_error_region     // Call error support
Packit 6c4009
}
Packit 6c4009
;;
Packit 6c4009
Packit 6c4009
GLOBAL_LIBM_END(__ieee754_ilogbl)
Packit 6c4009
Packit 6c4009
Packit 6c4009
LOCAL_LIBM_ENTRY(__libm_error_region)
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
        stfe [GR_Parameter_Y] = f0,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
        stfe [GR_Parameter_X] = f8            // 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
        stfe [GR_Parameter_Y] = f9            // 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
        mov   r8 = rTrialResult
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
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#