1.file "libm_frexp_4.s" 2 3// Copyright (C) 2000, 2001, Intel Corporation 4// All rights reserved. 5// 6// 7// Redistribution and use in source and binary forms, with or without 8// modification, are permitted provided that the following conditions are 9// met: 10// 11// * Redistributions of source code must retain the above copyright 12// notice, this list of conditions and the following disclaimer. 13// 14// * Redistributions in binary form must reproduce the above copyright 15// notice, this list of conditions and the following disclaimer in the 16// documentation and/or other materials provided with the distribution. 17// 18// * The name of Intel Corporation may not be used to endorse or promote 19// products derived from this software without specific prior written 20// permission. 21// 22// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS 26// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 30// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING 31// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33// 34// Intel Corporation is the author of this code, and requests that all 35// problem reports or change requests be submitted to it directly at 36// http://developer.intel.com/opensource. 37// 38// History 39//============================================================== 40// 2/02/00: Initial version 41// 3/20/00: Improved speed 42// 6/01/00: Fixed bug when x a double-extended denormal 43// 12/08/00 Corrected label on .endp 44// 45// API 46//============================================================== 47// double frexp(double x, int* y) 48// double __libm_frexp_4(double x, int* y) 49// where int* y is a 32-bit integer 50// 51// Overview of operation 52//============================================================== 53// break a floating point x number into fraction and an exponent 54// The fraction is returned as a double 55// The exponent is returned as an integer pointed to by y 56// This is a true (not a biased exponent) but 0fffe is subtracted 57// as a bias instead of 0xffff. This is because the fraction returned 58// is between 0.5 and 1.0, not the expected IEEE range. 59// 60// The fraction is 0.5 <= fraction < 1.0 61// 62// Registers used 63//============================================================== 64// 65// general registers: 66// r14 exponent bias for x negative 67// r15 exponent bias for x positive 68// r16 signexp of x 69// r17 exponent mask 70// r18 exponent of x 71// r19 exponent result 72// r20 signexp of 2^64 73// r32 on input contains the 64-bit IEEE double that is in f8 74// r33 on input pointer to 32-bit integer for exponent 75// 76// predicate registers: 77// p6 set if x is Nan, zero, or infinity 78// p7 set if x negative 79// p8 set if x positive 80// p9 set if x double-extended denormal 81// 82// floating-point registers: 83// f8 input, output 84// f9 normalized x 85// f10 signexp for significand result for x positive 86// f11 signexp for significand result for x negative 87// f12 2^64 88 89#include "libm_support.h" 90 91.align 32 92.global __libm_frexp_4# 93 94.section .text 95.proc __libm_frexp_4# 96.align 32 97 98__libm_frexp_4: 99 100// Set signexp for significand result for x>0 101// If x is a NaN, zero, or infinity, return it. 102// Put 0 in the int pointer. 103// x NAN, ZERO, INFINITY? 104// Set signexp for significand result for x<0 105{ .mfi 106(p0) mov r15 = 0x0fffe 107(p0) fclass.m.unc p6,p0 = f8, 0xe7 108(p0) mov r14 = 0x2fffe 109} 110// Form signexp of 2^64 in case x double-extended denormal 111// Save the normalized value of input in f9 112// The normalization also sets fault flags and takes faults if necessary 113{ .mfi 114(p0) mov r20 = 0x1003f 115(p0) fnorm f9 = f8 116 nop.i 999 ;; 117} 118 119// Move signexp for significand result for x>0 to FP reg 120// Form 2^64 in case x double-extended denormal 121{ .mmi 122(p0) setf.exp f10 = r15 123(p0) setf.exp f12 = r20 124 nop.i 999 ;; 125} 126 127// Move signexp for significand result for x<0 to FP reg 128// If x NAN, ZERO, INFINITY, set *y=0 as a 32-bit integer, and exit 129{ .mmb 130(p0) setf.exp f11 = r14 131(p6) st4 [r33] = r0 132(p6) br.ret.spnt b0 ;; 133} 134 135// Form exponent mask 136// p7 if x<0, else p8 137{ .mfi 138(p0) mov r17 = 0x1ffff 139(p0) fcmp.lt.unc p7,p8 = f8,f0 140 nop.i 999 ;; 141} 142 143// Test for fnorm(x) denormal, means x double-extended denormal 144{ .mfi 145 nop.m 999 146(p0) fclass.m.unc p9,p0 = f9, 0x0b 147 nop.i 999 ;; 148} 149 150// If x double-extended denormal add 64 to exponent bias for scaling 151// If x double-extended denormal multiply x * 2^64 which is normal 152{ .mfi 153(p9) add r15 = 64, r15 154(p9) fmpy f9 = f9, f12 155 nop.i 999 ;; 156} 157 158// true exponent stored to int pointer 159// the bias is treated as 0xfffe instead of 160// normal 0xffff because we want the significand 161// to be in the range <=0.5 sig < 1.0 162// Store the value of the exponent at the pointer in r33 163 164// If x>0 form significand result 165{ .mfi 166 nop.m 999 167(p8) fmerge.se f8 = f10,f9 168 nop.i 999 ;; 169} 170 171// Get signexp of normalized x 172// If x<0 form significand result 173{ .mfi 174(p0) getf.exp r16 = f9 175(p7) fmerge.se f8 = f11,f9 176 nop.i 999 ;; 177} 178 179// Get exp of normalized x 180// Subtract off bias to get true exponent of x 181{ .mmi 182(p0) and r18 = r17,r16 ;; 183(p0) sub r19 = r18,r15 184 nop.i 999 ;; 185} 186 187// Store int y as a 32-bit integer 188// Make the value a double 189{ .mfb 190(p0) st4 [r33] = r19 191(p0) fnorm.d f8 = f8 192(p0) br.ret.sptk b0 ;; 193} 194 195.endp __libm_frexp_4 196ASM_SIZE_DIRECTIVE(__libm_frexp_4) 197strong_alias(__libm_frexp_4, _GI___libm_frexp_4) 198