Blame sysdeps/ia64/fpu/e_sqrt.S

Packit 6c4009
.file "sqrt.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
// History
Packit 6c4009
//********************************************************************
Packit 6c4009
// 02/02/00 Initial version
Packit 6c4009
// 04/04/00 Unwind support added
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
// 02/10/03 Reordered header: .section, .global, .proc, .align
Packit 6c4009
//
Packit 6c4009
//********************************************************************
Packit 6c4009
//
Packit 6c4009
// Function:   Combined sqrt(x), where
Packit 6c4009
//                        _
Packit 6c4009
//             sqrt(x) = |x, for double precision x values
Packit 6c4009
//
Packit 6c4009
//********************************************************************
Packit 6c4009
//
Packit 6c4009
// Accuracy:       Correctly Rounded
Packit 6c4009
//
Packit 6c4009
//********************************************************************
Packit 6c4009
//
Packit 6c4009
// Resources Used:
Packit 6c4009
//
Packit 6c4009
//    Floating-Point Registers: f8  (Input and Return Value)
Packit 6c4009
//                              f7 -f14
Packit 6c4009
//
Packit 6c4009
//    General Purpose Registers:
Packit 6c4009
//      r32-r36 (Locals)
Packit 6c4009
//      r37-r40 (Used to pass arguments to error handling routine)
Packit 6c4009
//
Packit 6c4009
//    Predicate Registers:      p6, p7, p8
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
//    sqrt(QNaN) = QNaN
Packit 6c4009
//    sqrt(SNaN) = QNaN
Packit 6c4009
//    sqrt(+/-0) = +/-0
Packit 6c4009
//    sqrt(negative) = QNaN and error handling is called
Packit 6c4009
//
Packit 6c4009
//*********************************************************************
Packit 6c4009
//
Packit 6c4009
// Implementation:
Packit 6c4009
//
Packit 6c4009
//  Modified Newton-Raphson Algorithm
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
Packit 6c4009
GR_Parameter_X       = r37
Packit 6c4009
GR_Parameter_Y       = r38
Packit 6c4009
GR_Parameter_RESULT  = r39
Packit 6c4009
Packit 6c4009
Packit 6c4009
.section .text
Packit 6c4009
GLOBAL_IEEE754_ENTRY(sqrt)
Packit 6c4009
{ .mfi
Packit 6c4009
  alloc r32= ar.pfs,0,5,4,0
Packit 6c4009
  frsqrta.s0 f7,p6=f8
Packit 6c4009
  nop.i 0
Packit 6c4009
} { .mlx
Packit 6c4009
  // BEGIN DOUBLE PRECISION MINIMUM LATENCY SQUARE ROOT ALGORITHM
Packit 6c4009
  nop.m 0
Packit 6c4009
  // exponent of +1/2 in r2
Packit 6c4009
  movl r2 = 0x0fffe;;
Packit 6c4009
} { .mmi
Packit 6c4009
  // +1/2 in f9
Packit 6c4009
  setf.exp f9 = r2
Packit 6c4009
  nop.m 0
Packit 6c4009
  nop.i 0
Packit 6c4009
} { .mlx
Packit 6c4009
  nop.m 0
Packit 6c4009
  // 3/2 in r3
Packit 6c4009
  movl r3=0x3fc00000;;
Packit 6c4009
} { .mfi
Packit 6c4009
  setf.s f10=r3
Packit 6c4009
  // Step (1)
Packit 6c4009
  // y0 = 1/sqrt(a) in f7
Packit 6c4009
  fclass.m.unc p7,p8 = f8,0x3A
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mlx
Packit 6c4009
  nop.m 0
Packit 6c4009
  // 5/2 in r2
Packit 6c4009
  movl r2 = 0x40200000
Packit 6c4009
} { .mlx
Packit 6c4009
  nop.m 0
Packit 6c4009
  // 63/8 in r3
Packit 6c4009
  movl r3 = 0x40fc0000;;
Packit 6c4009
} { .mfi
Packit 6c4009
  setf.s f11=r2
Packit 6c4009
  // Step (2)
Packit 6c4009
  // h = +1/2 * y0 in f6
Packit 6c4009
  (p6) fma.s1 f6=f9,f7,f0
Packit 6c4009
  nop.i 0
Packit 6c4009
} { .mfi
Packit 6c4009
  setf.s f12=r3
Packit 6c4009
  // Step (3)
Packit 6c4009
  // g = a * y0 in f7
Packit 6c4009
  (p6) fma.s1 f7=f8,f7,f0
Packit 6c4009
  nop.i 0
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  mov   f15 = f8
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mlx
Packit 6c4009
  nop.m 0
Packit 6c4009
  // 231/16 in r2
Packit 6c4009
  movl r2 = 0x41670000;;
Packit 6c4009
} { .mfi
Packit 6c4009
  setf.s f13=r2
Packit 6c4009
  // Step (4)
Packit 6c4009
  // e = 1/2 - g * h in f9
Packit 6c4009
  (p6) fnma.s1 f9=f7,f6,f9
Packit 6c4009
  nop.i 0
Packit 6c4009
} { .mlx
Packit 6c4009
  nop.m 0
Packit 6c4009
  // 35/8 in r3
Packit 6c4009
  movl r3 = 0x408c0000;;
Packit 6c4009
} { .mfi
Packit 6c4009
  setf.s f14=r3
Packit 6c4009
  // Step (5)
Packit 6c4009
  // S = 3/2 + 5/2 * e in f10
Packit 6c4009
  (p6) fma.s1 f10=f11,f9,f10
Packit 6c4009
  nop.i 0
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (6)
Packit 6c4009
  // e2 = e * e in f11
Packit 6c4009
  (p6) fma.s1 f11=f9,f9,f0
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (7)
Packit 6c4009
  // t = 63/8 + 231/16 * e in f12
Packit 6c4009
  (p6) fma.s1 f12=f13,f9,f12
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (8)
Packit 6c4009
  // S1 = e + e2 * S in f10
Packit 6c4009
  (p6) fma.s1 f10=f11,f10,f9
Packit 6c4009
  nop.i 0
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (9)
Packit 6c4009
  // e4 = e2 * e2 in f11
Packit 6c4009
  (p6) fma.s1 f11=f11,f11,f0
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (10)
Packit 6c4009
  // t1 = 35/8 + e * t in f9
Packit 6c4009
  (p6) fma.s1 f9=f9,f12,f14
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (11)
Packit 6c4009
  // G = g + S1 * g in f12
Packit 6c4009
  (p6) fma.s1 f12=f10,f7,f7
Packit 6c4009
  nop.i 0
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (12)
Packit 6c4009
  // E = g * e4 in f7
Packit 6c4009
  (p6) fma.s1 f7=f7,f11,f0
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (13)
Packit 6c4009
  // u = S1 + e4 * t1 in f10
Packit 6c4009
  (p6) fma.s1 f10=f11,f9,f10
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (14)
Packit 6c4009
  // g1 = G + t1 * E in f7
Packit 6c4009
  (p6) fma.d.s1 f7=f9,f7,f12
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (15)
Packit 6c4009
  // h1 = h + u * h in f6
Packit 6c4009
  (p6) fma.s1 f6=f10,f6,f6
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mfi
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (16)
Packit 6c4009
  // d = a - g1 * g1 in f9
Packit 6c4009
  (p6) fnma.s1 f9=f7,f7,f8
Packit 6c4009
  nop.i 0;;
Packit 6c4009
} { .mfb
Packit 6c4009
  nop.m 0
Packit 6c4009
  // Step (17)
Packit 6c4009
  // g2 = g1 + d * h1 in f7
Packit 6c4009
  (p6) fma.d.s0 f8=f9,f6,f7
Packit 6c4009
  (p6) br.ret.sptk b0 ;;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
{ .mfb
Packit 6c4009
  nop.m 0
Packit 6c4009
       mov   f8 = f7
Packit 6c4009
  (p8) br.ret.sptk b0 ;;
Packit 6c4009
}
Packit 6c4009
{ .mfb
Packit 6c4009
  (p7) mov   r40 = 49
Packit 6c4009
  nop.f 0
Packit 6c4009
  (p7) br.cond.sptk __libm_error_region ;;
Packit 6c4009
}
Packit 6c4009
// END DOUBLE PRECISION MINIMUM LATENCY SQUARE ROOT ALGORITHM
Packit 6c4009
GLOBAL_IEEE754_END(sqrt)
Packit 6c4009
libm_alias_double_other (__sqrt, sqrt)
Packit 6c4009
Packit 6c4009
// Stack operations when calling error support.
Packit 6c4009
//       (1)               (2)                          (3) (call)              (4)
Packit 6c4009
//   sp   -> +          psp -> +                     psp -> +                   sp -> +
Packit 6c4009
//           |                 |                            |                         |
Packit 6c4009
//           |                 | <- GR_Y               R3 ->| <- GR_RESULT            | -> f8
Packit 6c4009
//           |                 |                            |                         |
Packit 6c4009
//           | <-GR_Y      Y2->|                       Y2 ->| <- GR_Y                 |
Packit 6c4009
//           |                 |                            |                         |
Packit 6c4009
//           |                 | <- GR_X               X1 ->|                         |
Packit 6c4009
//           |                 |                            |                         |
Packit 6c4009
//  sp-64 -> +          sp ->  +                     sp ->  +                         +
Packit 6c4009
//    save ar.pfs          save b0                                               restore gp
Packit 6c4009
//    save gp                                                                    restore ar.pfs
Packit 6c4009
Packit 6c4009
Packit 6c4009
LOCAL_LIBM_ENTRY(__libm_error_region)
Packit 6c4009
Packit 6c4009
//
Packit 6c4009
// This branch includes all those special values that are not negative,
Packit 6c4009
// with the result equal to frcpa(x)
Packit 6c4009
//
Packit 6c4009
Packit 6c4009
.prologue
Packit 6c4009
// We are distinguishing between over(under)flow and letting
Packit 6c4009
// __libm_error_support set ERANGE or do anything else needed.
Packit 6c4009
Packit 6c4009
// (1)
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
Packit 6c4009
// (2)
Packit 6c4009
{ .mmi
Packit 6c4009
        stfd [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
// (3)
Packit 6c4009
{ .mib
Packit 6c4009
        stfd [GR_Parameter_X] = f15                    // 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] = f8                     // 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
Packit 6c4009
// (4)
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
{ .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
Packit 6c4009
Packit 6c4009
.type   __libm_error_support#,@function
Packit 6c4009
.global __libm_error_support#