|
Packit |
6c4009 |
.file "libm_frexpl.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 |
// 03/20/00 Improved speed
|
|
Packit |
6c4009 |
// 06/01/00 Fixed bug when x a double-extended denormal
|
|
Packit |
6c4009 |
// 12/08/00 Corrected label on .endp
|
|
Packit |
6c4009 |
// 01/23/02 Added handling for int 32 or 64 bits
|
|
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 |
// long double __libm_frexpl(long double x, int* y, int int_type)
|
|
Packit |
6c4009 |
// input floating point f8, pointer to y (r34), int int_type (r35)
|
|
Packit |
6c4009 |
// output floating point f8, returns the fraction of x, 0.5 <= fraction < 1.0
|
|
Packit |
6c4009 |
// output int* y, returns the true exponent of x
|
|
Packit |
6c4009 |
//
|
|
Packit |
6c4009 |
// int_type = 0 if int is 32 bits
|
|
Packit |
6c4009 |
// int_type = 1 if int is 64 bits
|
|
Packit |
6c4009 |
//
|
|
Packit |
6c4009 |
// int* y is returned as a 32 bit integer if int_type = 0
|
|
Packit |
6c4009 |
// int* y is returned as a 64 bit integer if int_type = 1
|
|
Packit |
6c4009 |
//
|
|
Packit |
6c4009 |
// Overview of operation
|
|
Packit |
6c4009 |
//==============================================================
|
|
Packit |
6c4009 |
// break a floating point x number into fraction and an exponent
|
|
Packit |
6c4009 |
// The fraction is returned as a long double
|
|
Packit |
6c4009 |
// The exponent is returned as an integer pointed to by y
|
|
Packit |
6c4009 |
// This is a true (not a biased exponent) but 0fffe is subtracted
|
|
Packit |
6c4009 |
// as a bias instead of 0xffff. This is because the fraction returned
|
|
Packit |
6c4009 |
// is between 0.5 and 1.0, not the expected IEEE range.
|
|
Packit |
6c4009 |
//
|
|
Packit |
6c4009 |
// The fraction is 0.5 <= fraction < 1.0
|
|
Packit |
6c4009 |
//
|
|
Packit |
6c4009 |
// Registers used
|
|
Packit |
6c4009 |
//==============================================================
|
|
Packit |
6c4009 |
//
|
|
Packit |
6c4009 |
// general registers:
|
|
Packit |
6c4009 |
// r14 exponent bias for x negative
|
|
Packit |
6c4009 |
// r15 exponent bias for x positive
|
|
Packit |
6c4009 |
// r16 signexp of x
|
|
Packit |
6c4009 |
// r17 exponent mask
|
|
Packit |
6c4009 |
// r18 exponent of x
|
|
Packit |
6c4009 |
// r19 exponent result
|
|
Packit |
6c4009 |
// r20 signexp of 2^64
|
|
Packit |
6c4009 |
// r32-33 on input contains the 80-bit IEEE long double that is in f8
|
|
Packit |
6c4009 |
// r34 on input pointer to 32-bit or 64-bit integer for exponent
|
|
Packit |
6c4009 |
// r35 on input contains 0 if output int is 32 bits, else output int is 64 bits
|
|
Packit |
6c4009 |
//
|
|
Packit |
6c4009 |
// predicate registers:
|
|
Packit |
6c4009 |
// p6 set if x is Nan, zero, or infinity
|
|
Packit |
6c4009 |
// p7 set if x negative
|
|
Packit |
6c4009 |
// p8 set if x positive
|
|
Packit |
6c4009 |
// p9 set if x double-extended denormal
|
|
Packit |
6c4009 |
// p10 set if int_type = 0, 32-bit integer
|
|
Packit |
6c4009 |
// p11 set if int_type = 1, 64-bit integer
|
|
Packit |
6c4009 |
//
|
|
Packit |
6c4009 |
// floating-point registers:
|
|
Packit |
6c4009 |
// f8 input, output
|
|
Packit |
6c4009 |
// f9 normalized x
|
|
Packit |
6c4009 |
// f10 signexp for significand result for x positive
|
|
Packit |
6c4009 |
// f11 signexp for significand result for x negative
|
|
Packit |
6c4009 |
// f12 2^64
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.section .text
|
|
Packit |
6c4009 |
GLOBAL_LIBM_ENTRY(__libm_frexpl)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// Set signexp for significand result for x>0
|
|
Packit |
6c4009 |
// If x is a NaN, zero, or infinity, return it.
|
|
Packit |
6c4009 |
// Put 0 in the int pointer.
|
|
Packit |
6c4009 |
// x NAN, ZERO, INFINITY?
|
|
Packit |
6c4009 |
// Set signexp for significand result for x<0
|
|
Packit |
6c4009 |
{ .mfi
|
|
Packit |
6c4009 |
mov r15 = 0x0fffe
|
|
Packit |
6c4009 |
fclass.m p6,p7 = f8, 0xe7
|
|
Packit |
6c4009 |
mov r14 = 0x2fffe
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
// Form signexp of 2^64 in case x double-extended denormal
|
|
Packit |
6c4009 |
// Save the normalized value of input in f9
|
|
Packit |
6c4009 |
// The normalization also sets fault flags and takes faults if necessary
|
|
Packit |
6c4009 |
{ .mfi
|
|
Packit |
6c4009 |
mov r20 = 0x1003f
|
|
Packit |
6c4009 |
fnorm.s0 f9 = f8
|
|
Packit |
6c4009 |
nop.i 999 ;;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// Move signexp for significand result for x>0 to FP reg
|
|
Packit |
6c4009 |
// Form 2^64 in case x double-extended denormal
|
|
Packit |
6c4009 |
{ .mmi
|
|
Packit |
6c4009 |
setf.exp f10 = r15
|
|
Packit |
6c4009 |
setf.exp f12 = r20
|
|
Packit |
6c4009 |
nop.i 999 ;;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// Move signexp for significand result for x<0 to FP reg
|
|
Packit |
6c4009 |
// p7 if x<0, else p8
|
|
Packit |
6c4009 |
// If x=0,nan,inf, set p10 if output int to be 32 bits, or set p11 if 64 bits
|
|
Packit |
6c4009 |
{ .mfi
|
|
Packit |
6c4009 |
setf.exp f11 = r14
|
|
Packit |
6c4009 |
(p7) fcmp.lt.s0 p7,p8 = f8,f0
|
|
Packit |
6c4009 |
(p6) cmp.eq.unc p10,p11 = r35, r0 ;;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// If x NAN, ZERO, INFINITY, set *y=0 and exit
|
|
Packit |
6c4009 |
{ .mmb
|
|
Packit |
6c4009 |
(p10) st4 [r34] = r0 // Store *y=0 as 32-bit integer
|
|
Packit |
6c4009 |
(p11) st8 [r34] = r0 // Store *y=0 as 64-bit integer
|
|
Packit |
6c4009 |
(p6) br.ret.spnt b0 ;;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// Form exponent mask
|
|
Packit |
6c4009 |
// Test for fnorm(x) denormal, means x double-extended denormal
|
|
Packit |
6c4009 |
{ .mfi
|
|
Packit |
6c4009 |
mov r17 = 0x1ffff
|
|
Packit |
6c4009 |
fclass.m p9,p0 = f9, 0x0b
|
|
Packit |
6c4009 |
nop.i 999 ;;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// If x double-extended denormal add 64 to exponent bias for scaling
|
|
Packit |
6c4009 |
// If x double-extended denormal multiply x * 2^64 which is normal
|
|
Packit |
6c4009 |
// Set p10 if output int to be 32 bits, or set p11 if 64 bits
|
|
Packit |
6c4009 |
{ .mfi
|
|
Packit |
6c4009 |
(p9) add r15 = 64, r15
|
|
Packit |
6c4009 |
(p9) fmpy.s0 f9 = f9, f12
|
|
Packit |
6c4009 |
cmp.eq p10,p11 = r35, r0 ;;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// true exponent stored to int pointer
|
|
Packit |
6c4009 |
// the bias is treated as 0xfffe instead of
|
|
Packit |
6c4009 |
// normal 0xffff because we want the significand
|
|
Packit |
6c4009 |
// to be in the range <=0.5 sig < 1.0
|
|
Packit |
6c4009 |
// Store the value of the exponent at the pointer in r34
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// If x>0 form significand result
|
|
Packit |
6c4009 |
{ .mfi
|
|
Packit |
6c4009 |
nop.m 999
|
|
Packit |
6c4009 |
(p8) fmerge.se f8 = f10,f9
|
|
Packit |
6c4009 |
nop.i 999 ;;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// Get signexp of normalized x
|
|
Packit |
6c4009 |
// If x<0 form significand result
|
|
Packit |
6c4009 |
{ .mfi
|
|
Packit |
6c4009 |
getf.exp r16 = f9
|
|
Packit |
6c4009 |
(p7) fmerge.se f8 = f11,f9
|
|
Packit |
6c4009 |
nop.i 999 ;;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// Get exp of normalized x
|
|
Packit |
6c4009 |
// Subtract off bias to get true exponent of x
|
|
Packit |
6c4009 |
{ .mmi
|
|
Packit |
6c4009 |
and r18 = r17,r16 ;;
|
|
Packit |
6c4009 |
sub r19 = r18,r15
|
|
Packit |
6c4009 |
nop.i 999 ;;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
// Store int *y as a 32-bit integer
|
|
Packit |
6c4009 |
// Make the value a long double
|
|
Packit |
6c4009 |
{ .mfi
|
|
Packit |
6c4009 |
(p10) st4 [r34] = r19 // Store *y as 32-bit integer
|
|
Packit |
6c4009 |
fnorm.s0 f8 = f8
|
|
Packit |
6c4009 |
nop.i 999
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
{ .mfb
|
|
Packit |
6c4009 |
(p11) st8 [r34] = r19 // Store *y as 64-bit integer
|
|
Packit |
6c4009 |
nop.f 999
|
|
Packit |
6c4009 |
br.ret.sptk b0 ;;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
GLOBAL_LIBM_END(__libm_frexpl)
|