mirror of
https://github.com/NVIDIA/open-gpu-kernel-modules.git
synced 2026-01-30 13:09:47 +00:00
515.43.04
This commit is contained in:
37
src/common/softfloat/COPYING.txt
Normal file
37
src/common/softfloat/COPYING.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
License for Berkeley SoftFloat Release 3d
|
||||
|
||||
John R. Hauser
|
||||
2017 August 10
|
||||
|
||||
The following applies to the whole of SoftFloat Release 3d as well as to
|
||||
each source file individually.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions, and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
163
src/common/softfloat/nvidia/nv-softfloat.h
Normal file
163
src/common/softfloat/nvidia/nv-softfloat.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2017 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __NV_SOFTFLOAT_H__
|
||||
#define __NV_SOFTFLOAT_H__
|
||||
|
||||
/*
|
||||
* This header file provides utility code built on top of the softfloat floating
|
||||
* point emulation library.
|
||||
*/
|
||||
|
||||
#include "softfloat.h"
|
||||
#include "nvtypes.h"
|
||||
#include "platform.h"
|
||||
|
||||
/*
|
||||
* float32_t stores the bit pattern for a 32-bit single-precision IEEE floating
|
||||
* point value in a structure containing an uint32_t:
|
||||
*
|
||||
* typedef struct { uint32_t v; } float32_t;
|
||||
*
|
||||
* In some cases, clients pass in a 32-bit single-precision IEEE floating
|
||||
* point value in an NvU32.
|
||||
*
|
||||
* Define functions to change the "view" between an NvU32 and a float32_t.
|
||||
*/
|
||||
INLINE float32_t NvU32viewAsF32(NvU32 u)
|
||||
{
|
||||
float32_t f = { .v = u };
|
||||
return f;
|
||||
}
|
||||
|
||||
INLINE NvU32 F32viewAsNvU32(float32_t f)
|
||||
{
|
||||
return f.v;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert the value of a float32_t to an NvU16.
|
||||
*
|
||||
* The conversion requires several steps:
|
||||
*
|
||||
* - Clamp the float32_t value to the [0,NV_U16_MAX] range of NvU16.
|
||||
*
|
||||
* - Use softfloat to convert the float32_t to ui32, with appropriate rounding.
|
||||
*
|
||||
* - Due to the clamping and rounding above, the value in the ui32 should be in
|
||||
* the range of NvU16 and can be safely returned as NvU16.
|
||||
*/
|
||||
INLINE NvU16 F32toNvU16(float32_t f)
|
||||
{
|
||||
const float32_t minF32 = NvU32viewAsF32(0);
|
||||
const float32_t maxF32 = ui32_to_f32(NV_U16_MAX);
|
||||
NvU32 u;
|
||||
|
||||
/* clamp to zero: f = (f < minF32) ? minF32 : f */
|
||||
f = f32_lt(f, minF32) ? minF32 : f;
|
||||
|
||||
/* clamp to NV_U16_MAX: f = (maxF32 < f) ? maxF32 : f */
|
||||
f = f32_lt(maxF32, f) ? maxF32 : f;
|
||||
|
||||
/*
|
||||
* The "_r_minMag" in "f32_to_ui32_r_minMag" means round "to minimum
|
||||
* magnitude" (i.e., round towards zero).
|
||||
*
|
||||
* The "exact = FALSE" argument means do not raise the inexact exception
|
||||
* flag, even if the conversion is inexact.
|
||||
*
|
||||
* For more on f32_to_ui32_r_minMag() semantics, see
|
||||
* drivers/common/softfloat/doc/SoftFloat.html
|
||||
*/
|
||||
u = f32_to_ui32_r_minMag(f, NV_FALSE /* exact */);
|
||||
nvAssert(u <= NV_U16_MAX);
|
||||
|
||||
return (NvU16) u;
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform the following with float32_t: (a * b) + (c * d) + e
|
||||
*/
|
||||
INLINE float32_t F32_AxB_plus_CxD_plus_E(
|
||||
float32_t a,
|
||||
float32_t b,
|
||||
float32_t c,
|
||||
float32_t d,
|
||||
float32_t e)
|
||||
{
|
||||
const float32_t tmpA = f32_mul(a, b);
|
||||
const float32_t tmpB = f32_mul(c, d);
|
||||
const float32_t tmpC = f32_add(tmpA, tmpB);
|
||||
|
||||
return f32_add(tmpC, e);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform the following with float32_t: (a * b) - (c * d)
|
||||
*/
|
||||
INLINE float32_t F32_AxB_minus_CxD(
|
||||
float32_t a,
|
||||
float32_t b,
|
||||
float32_t c,
|
||||
float32_t d)
|
||||
{
|
||||
const float32_t tmpA = f32_mul(a, b);
|
||||
const float32_t tmpB = f32_mul(c, d);
|
||||
|
||||
return f32_sub(tmpA, tmpB);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform the following with float64_t: a * -1
|
||||
*/
|
||||
INLINE float64_t F64_negate(float64_t a)
|
||||
{
|
||||
const float64_t negOneF64 = i32_to_f64(-1);
|
||||
return f64_mul(negOneF64, a);
|
||||
}
|
||||
|
||||
INLINE float16_t nvUnormToFp16(NvU16 unorm, float32_t maxf)
|
||||
{
|
||||
const float32_t unormf = ui32_to_f32(unorm);
|
||||
const float32_t normf = f32_div(unormf, maxf);
|
||||
|
||||
return f32_to_f16(normf);
|
||||
}
|
||||
|
||||
INLINE float16_t nvUnorm10ToFp16(NvU16 unorm10)
|
||||
{
|
||||
const float32_t maxf = NvU32viewAsF32(0x44800000U); // 1024.0f
|
||||
return nvUnormToFp16(unorm10, maxf);
|
||||
}
|
||||
|
||||
INLINE float32_t f32_min(float32_t a, float32_t b)
|
||||
{
|
||||
return (f32_lt(a, b)) ? a : b;
|
||||
}
|
||||
|
||||
INLINE float32_t f32_max(float32_t a, float32_t b)
|
||||
{
|
||||
return (f32_lt(a, b)) ? b : a;
|
||||
}
|
||||
|
||||
#endif /* __NV_SOFTFLOAT_H__ */
|
||||
56
src/common/softfloat/nvidia/platform.h
Normal file
56
src/common/softfloat/nvidia/platform.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Copyright (c) 2017 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef nvidia_softfloat_platform_h
|
||||
#define nvidia_softfloat_platform_h 1
|
||||
|
||||
#include "nvtypes.h"
|
||||
|
||||
/*
|
||||
* Build softfloat for little endian CPUs: all NVIDIA target platforms are
|
||||
* little endian.
|
||||
*/
|
||||
#define LITTLEENDIAN 1
|
||||
|
||||
/*
|
||||
* "INLINE" is used by softfloat like this:
|
||||
*
|
||||
* INLINE uint32_t softfloat_foo(...)
|
||||
* {
|
||||
* ...
|
||||
* }
|
||||
*/
|
||||
#define INLINE static NV_INLINE
|
||||
|
||||
#if !defined(nvAssert)
|
||||
#define nvAssert(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* softfloat will use THREAD_LOCAL to tag variables that should be per-thread;
|
||||
* it could be set to, e.g., gcc's "__thread" keyword. If THREAD_LOCAL is left
|
||||
* undefined, these variables will default to being ordinary global variables.
|
||||
*/
|
||||
#undef THREAD_LOCAL
|
||||
|
||||
#endif /* nvidia_softfloat_platform_h */
|
||||
51
src/common/softfloat/source/8086-SSE/s_commonNaNToF16UI.c
Normal file
51
src/common/softfloat/source/8086-SSE/s_commonNaNToF16UI.c
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "specialize.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Converts the common NaN pointed to by `aPtr' into a 16-bit floating-point
|
||||
| NaN, and returns the bit pattern of this value as an unsigned integer.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast16_t softfloat_commonNaNToF16UI( const struct commonNaN *aPtr )
|
||||
{
|
||||
|
||||
return (uint_fast16_t) aPtr->sign<<15 | 0x7E00 | aPtr->v64>>54;
|
||||
|
||||
}
|
||||
|
||||
51
src/common/softfloat/source/8086-SSE/s_commonNaNToF32UI.c
Normal file
51
src/common/softfloat/source/8086-SSE/s_commonNaNToF32UI.c
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "specialize.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Converts the common NaN pointed to by `aPtr' into a 32-bit floating-point
|
||||
| NaN, and returns the bit pattern of this value as an unsigned integer.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast32_t softfloat_commonNaNToF32UI( const struct commonNaN *aPtr )
|
||||
{
|
||||
|
||||
return (uint_fast32_t) aPtr->sign<<31 | 0x7FC00000 | aPtr->v64>>41;
|
||||
|
||||
}
|
||||
|
||||
53
src/common/softfloat/source/8086-SSE/s_commonNaNToF64UI.c
Normal file
53
src/common/softfloat/source/8086-SSE/s_commonNaNToF64UI.c
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "specialize.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Converts the common NaN pointed to by `aPtr' into a 64-bit floating-point
|
||||
| NaN, and returns the bit pattern of this value as an unsigned integer.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast64_t softfloat_commonNaNToF64UI( const struct commonNaN *aPtr )
|
||||
{
|
||||
|
||||
return
|
||||
(uint_fast64_t) aPtr->sign<<63 | UINT64_C( 0x7FF8000000000000 )
|
||||
| aPtr->v64>>12;
|
||||
|
||||
}
|
||||
|
||||
59
src/common/softfloat/source/8086-SSE/s_f32UIToCommonNaN.c
Normal file
59
src/common/softfloat/source/8086-SSE/s_f32UIToCommonNaN.c
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Assuming `uiA' has the bit pattern of a 32-bit floating-point NaN, converts
|
||||
| this NaN to the common NaN form, and stores the resulting common NaN at the
|
||||
| location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
|
||||
| exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void softfloat_f32UIToCommonNaN( uint_fast32_t uiA, struct commonNaN *zPtr )
|
||||
{
|
||||
|
||||
if ( softfloat_isSigNaNF32UI( uiA ) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
}
|
||||
zPtr->sign = uiA>>31;
|
||||
zPtr->v64 = (uint_fast64_t) uiA<<41;
|
||||
zPtr->v0 = 0;
|
||||
|
||||
}
|
||||
|
||||
59
src/common/softfloat/source/8086-SSE/s_f64UIToCommonNaN.c
Normal file
59
src/common/softfloat/source/8086-SSE/s_f64UIToCommonNaN.c
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Assuming `uiA' has the bit pattern of a 64-bit floating-point NaN, converts
|
||||
| this NaN to the common NaN form, and stores the resulting common NaN at the
|
||||
| location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
|
||||
| exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr )
|
||||
{
|
||||
|
||||
if ( softfloat_isSigNaNF64UI( uiA ) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
}
|
||||
zPtr->sign = uiA>>63;
|
||||
zPtr->v64 = uiA<<12;
|
||||
zPtr->v0 = 0;
|
||||
|
||||
}
|
||||
|
||||
63
src/common/softfloat/source/8086-SSE/s_propagateNaNF32UI.c
Normal file
63
src/common/softfloat/source/8086-SSE/s_propagateNaNF32UI.c
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Interpreting `uiA' and `uiB' as the bit patterns of two 32-bit floating-
|
||||
| point values, at least one of which is a NaN, returns the bit pattern of
|
||||
| the combined NaN result. If either `uiA' or `uiB' has the pattern of a
|
||||
| signaling NaN, the invalid exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast32_t
|
||||
softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB )
|
||||
{
|
||||
bool isSigNaNA;
|
||||
|
||||
isSigNaNA = softfloat_isSigNaNF32UI( uiA );
|
||||
if ( isSigNaNA || softfloat_isSigNaNF32UI( uiB ) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
if ( isSigNaNA ) return uiA | 0x00400000;
|
||||
}
|
||||
return (isNaNF32UI( uiA ) ? uiA : uiB) | 0x00400000;
|
||||
|
||||
}
|
||||
|
||||
63
src/common/softfloat/source/8086-SSE/s_propagateNaNF64UI.c
Normal file
63
src/common/softfloat/source/8086-SSE/s_propagateNaNF64UI.c
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Interpreting `uiA' and `uiB' as the bit patterns of two 64-bit floating-
|
||||
| point values, at least one of which is a NaN, returns the bit pattern of
|
||||
| the combined NaN result. If either `uiA' or `uiB' has the pattern of a
|
||||
| signaling NaN, the invalid exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast64_t
|
||||
softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB )
|
||||
{
|
||||
bool isSigNaNA;
|
||||
|
||||
isSigNaNA = softfloat_isSigNaNF64UI( uiA );
|
||||
if ( isSigNaNA || softfloat_isSigNaNF64UI( uiB ) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
if ( isSigNaNA ) return uiA | UINT64_C( 0x0008000000000000 );
|
||||
}
|
||||
return (isNaNF64UI( uiA ) ? uiA : uiB) | UINT64_C( 0x0008000000000000 );
|
||||
|
||||
}
|
||||
|
||||
52
src/common/softfloat/source/8086-SSE/softfloat_raiseFlags.c
Normal file
52
src/common/softfloat/source/8086-SSE/softfloat_raiseFlags.c
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include "platform.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Raises the exceptions specified by `flags'. Floating-point traps can be
|
||||
| defined here if desired. It is currently not possible for such a trap
|
||||
| to substitute a result value. If traps are not implemented, this routine
|
||||
| should be simply `softfloat_exceptionFlags |= flags;'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void softfloat_raiseFlags( uint_fast8_t flags )
|
||||
{
|
||||
|
||||
softfloat_exceptionFlags |= flags;
|
||||
|
||||
}
|
||||
|
||||
208
src/common/softfloat/source/8086-SSE/specialize.h
Normal file
208
src/common/softfloat/source/8086-SSE/specialize.h
Normal file
@@ -0,0 +1,208 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef specialize_h
|
||||
#define specialize_h 1
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "softfloat_types.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Default value for `softfloat_detectTininess'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define init_detectTininess softfloat_tininess_afterRounding
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The values to return on conversions to 32-bit integer formats that raise an
|
||||
| invalid exception.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define ui32_fromPosOverflow 0xFFFFFFFF
|
||||
#define ui32_fromNegOverflow 0
|
||||
#define ui32_fromNaN 0xFFFFFFFF
|
||||
#define i32_fromPosOverflow 0x7FFFFFFF
|
||||
#define i32_fromNegOverflow (-0x7FFFFFFF - 1)
|
||||
#define i32_fromNaN 0x7FFFFFFF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The values to return on conversions to 64-bit integer formats that raise an
|
||||
| invalid exception.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define ui64_fromPosOverflow UINT64_C( 0xFFFFFFFFFFFFFFFF )
|
||||
#define ui64_fromNegOverflow 0
|
||||
#define ui64_fromNaN UINT64_C( 0xFFFFFFFFFFFFFFFF )
|
||||
#define i64_fromPosOverflow UINT64_C( 0x7FFFFFFFFFFFFFFF )
|
||||
#define i64_fromNegOverflow (-UINT64_C( 0x7FFFFFFFFFFFFFFF ) - 1)
|
||||
#define i64_fromNaN UINT64_C( 0x7FFFFFFFFFFFFFFF )
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| "Common NaN" structure, used to transfer NaN representations from one format
|
||||
| to another.
|
||||
*----------------------------------------------------------------------------*/
|
||||
struct commonNaN {
|
||||
bool sign;
|
||||
#ifdef LITTLEENDIAN
|
||||
uint64_t v0, v64;
|
||||
#else
|
||||
uint64_t v64, v0;
|
||||
#endif
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The bit pattern for a default generated 16-bit floating-point NaN.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define defaultNaNF16UI 0xFE00
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns true when 16-bit unsigned integer `uiA' has the bit pattern of a
|
||||
| 16-bit floating-point signaling NaN.
|
||||
| Note: This macro evaluates its argument more than once.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define softfloat_isSigNaNF16UI( uiA ) ((((uiA) & 0x7E00) == 0x7C00) && ((uiA) & 0x01FF))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Converts the common NaN pointed to by `aPtr' into a 16-bit floating-point
|
||||
| NaN, and returns the bit pattern of this value as an unsigned integer.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast16_t softfloat_commonNaNToF16UI( const struct commonNaN *aPtr );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The bit pattern for a default generated 32-bit floating-point NaN.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define defaultNaNF32UI 0xFFC00000
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns true when 32-bit unsigned integer `uiA' has the bit pattern of a
|
||||
| 32-bit floating-point signaling NaN.
|
||||
| Note: This macro evaluates its argument more than once.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define softfloat_isSigNaNF32UI( uiA ) ((((uiA) & 0x7FC00000) == 0x7F800000) && ((uiA) & 0x003FFFFF))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Assuming `uiA' has the bit pattern of a 32-bit floating-point NaN, converts
|
||||
| this NaN to the common NaN form, and stores the resulting common NaN at the
|
||||
| location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
|
||||
| exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void softfloat_f32UIToCommonNaN( uint_fast32_t uiA, struct commonNaN *zPtr );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Converts the common NaN pointed to by `aPtr' into a 32-bit floating-point
|
||||
| NaN, and returns the bit pattern of this value as an unsigned integer.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast32_t softfloat_commonNaNToF32UI( const struct commonNaN *aPtr );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Interpreting `uiA' and `uiB' as the bit patterns of two 32-bit floating-
|
||||
| point values, at least one of which is a NaN, returns the bit pattern of
|
||||
| the combined NaN result. If either `uiA' or `uiB' has the pattern of a
|
||||
| signaling NaN, the invalid exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast32_t
|
||||
softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The bit pattern for a default generated 64-bit floating-point NaN.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define defaultNaNF64UI UINT64_C( 0xFFF8000000000000 )
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns true when 64-bit unsigned integer `uiA' has the bit pattern of a
|
||||
| 64-bit floating-point signaling NaN.
|
||||
| Note: This macro evaluates its argument more than once.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define softfloat_isSigNaNF64UI( uiA ) ((((uiA) & UINT64_C( 0x7FF8000000000000 )) == UINT64_C( 0x7FF0000000000000 )) && ((uiA) & UINT64_C( 0x0007FFFFFFFFFFFF )))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Assuming `uiA' has the bit pattern of a 64-bit floating-point NaN, converts
|
||||
| this NaN to the common NaN form, and stores the resulting common NaN at the
|
||||
| location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid
|
||||
| exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Converts the common NaN pointed to by `aPtr' into a 64-bit floating-point
|
||||
| NaN, and returns the bit pattern of this value as an unsigned integer.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast64_t softfloat_commonNaNToF64UI( const struct commonNaN *aPtr );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Interpreting `uiA' and `uiB' as the bit patterns of two 64-bit floating-
|
||||
| point values, at least one of which is a NaN, returns the bit pattern of
|
||||
| the combined NaN result. If either `uiA' or `uiB' has the pattern of a
|
||||
| signaling NaN, the invalid exception is raised.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast64_t
|
||||
softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The bit pattern for a default generated 80-bit extended floating-point NaN.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define defaultNaNExtF80UI64 0xFFFF
|
||||
#define defaultNaNExtF80UI0 UINT64_C( 0xC000000000000000 )
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns true when the 80-bit unsigned integer formed from concatenating
|
||||
| 16-bit `uiA64' and 64-bit `uiA0' has the bit pattern of an 80-bit extended
|
||||
| floating-point signaling NaN.
|
||||
| Note: This macro evaluates its arguments more than once.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define softfloat_isSigNaNExtF80UI( uiA64, uiA0 ) ((((uiA64) & 0x7FFF) == 0x7FFF) && ! ((uiA0) & UINT64_C( 0x4000000000000000 )) && ((uiA0) & UINT64_C( 0x3FFFFFFFFFFFFFFF )))
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The following functions are needed only when `SOFTFLOAT_FAST_INT64' is
|
||||
| defined.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The bit pattern for a default generated 128-bit floating-point NaN.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define defaultNaNF128UI64 UINT64_C( 0xFFFF800000000000 )
|
||||
#define defaultNaNF128UI0 UINT64_C( 0 )
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns true when the 128-bit unsigned integer formed from concatenating
|
||||
| 64-bit `uiA64' and 64-bit `uiA0' has the bit pattern of a 128-bit floating-
|
||||
| point signaling NaN.
|
||||
| Note: This macro evaluates its arguments more than once.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define softfloat_isSigNaNF128UI( uiA64, uiA0 ) ((((uiA64) & UINT64_C( 0x7FFF800000000000 )) == UINT64_C( 0x7FFF000000000000 )) && ((uiA0) || ((uiA64) & UINT64_C( 0x00007FFFFFFFFFFF ))))
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
61
src/common/softfloat/source/f32_add.c
Normal file
61
src/common/softfloat/source/f32_add.c
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t f32_add( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( signF32UI( uiA ^ uiB ) ) {
|
||||
return softfloat_subMagsF32( uiA, uiB );
|
||||
} else {
|
||||
return softfloat_addMagsF32( uiA, uiB );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
176
src/common/softfloat/source/f32_div.c
Normal file
176
src/common/softfloat/source/f32_div.c
Normal file
@@ -0,0 +1,176 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t f32_div( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
bool signA;
|
||||
int_fast16_t expA;
|
||||
uint_fast32_t sigA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
bool signB;
|
||||
int_fast16_t expB;
|
||||
uint_fast32_t sigB;
|
||||
bool signZ;
|
||||
struct exp16_sig32 normExpSig;
|
||||
int_fast16_t expZ;
|
||||
#ifdef SOFTFLOAT_FAST_DIV64TO32
|
||||
uint_fast64_t sig64A;
|
||||
uint_fast32_t sigZ;
|
||||
#else
|
||||
uint_fast32_t sigZ;
|
||||
uint_fast64_t rem;
|
||||
#endif
|
||||
uint_fast32_t uiZ;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
signA = signF32UI( uiA );
|
||||
expA = expF32UI( uiA );
|
||||
sigA = fracF32UI( uiA );
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
signB = signF32UI( uiB );
|
||||
expB = expF32UI( uiB );
|
||||
sigB = fracF32UI( uiB );
|
||||
signZ = signA ^ signB;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA == 0xFF ) {
|
||||
if ( sigA ) goto propagateNaN;
|
||||
if ( expB == 0xFF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
goto invalid;
|
||||
}
|
||||
goto infinity;
|
||||
}
|
||||
if ( expB == 0xFF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
goto zero;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! expB ) {
|
||||
if ( ! sigB ) {
|
||||
if ( ! (expA | sigA) ) goto invalid;
|
||||
softfloat_raiseFlags( softfloat_flag_infinite );
|
||||
goto infinity;
|
||||
}
|
||||
normExpSig = softfloat_normSubnormalF32Sig( sigB );
|
||||
expB = normExpSig.exp;
|
||||
sigB = normExpSig.sig;
|
||||
}
|
||||
if ( ! expA ) {
|
||||
if ( ! sigA ) goto zero;
|
||||
normExpSig = softfloat_normSubnormalF32Sig( sigA );
|
||||
expA = normExpSig.exp;
|
||||
sigA = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expZ = expA - expB + 0x7E;
|
||||
sigA |= 0x00800000;
|
||||
sigB |= 0x00800000;
|
||||
#ifdef SOFTFLOAT_FAST_DIV64TO32
|
||||
if ( sigA < sigB ) {
|
||||
--expZ;
|
||||
sig64A = (uint_fast64_t) sigA<<31;
|
||||
} else {
|
||||
sig64A = (uint_fast64_t) sigA<<30;
|
||||
}
|
||||
sigZ = sig64A / sigB;
|
||||
if ( ! (sigZ & 0x3F) ) sigZ |= ((uint_fast64_t) sigB * sigZ != sig64A);
|
||||
#else
|
||||
if ( sigA < sigB ) {
|
||||
--expZ;
|
||||
sigA <<= 8;
|
||||
} else {
|
||||
sigA <<= 7;
|
||||
}
|
||||
sigB <<= 8;
|
||||
sigZ = ((uint_fast64_t) sigA * softfloat_approxRecip32_1( sigB ))>>32;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sigZ += 2;
|
||||
if ( (sigZ & 0x3F) < 2 ) {
|
||||
sigZ &= ~3;
|
||||
rem = ((uint_fast64_t) sigA<<31) - (uint_fast64_t) sigZ * sigB;
|
||||
if ( rem & UINT64_C( 0x8000000000000000 ) ) {
|
||||
sigZ -= 4;
|
||||
} else {
|
||||
if ( rem ) sigZ |= 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return softfloat_roundPackToF32( signZ, expZ, sigZ );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN:
|
||||
uiZ = softfloat_propagateNaNF32UI( uiA, uiB );
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF32UI;
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
infinity:
|
||||
uiZ = packToF32UI( signZ, 0xFF, 0 );
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
zero:
|
||||
uiZ = packToF32UI( signZ, 0, 0 );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
66
src/common/softfloat/source/f32_eq.c
Normal file
66
src/common/softfloat/source/f32_eq.c
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f32_eq( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF32UI( uiA ) || isNaNF32UI( uiB ) ) {
|
||||
if (
|
||||
softfloat_isSigNaNF32UI( uiA ) || softfloat_isSigNaNF32UI( uiB )
|
||||
) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return (uiA == uiB) || ! (uint32_t) ((uiA | uiB)<<1);
|
||||
|
||||
}
|
||||
|
||||
61
src/common/softfloat/source/f32_eq_signaling.c
Normal file
61
src/common/softfloat/source/f32_eq_signaling.c
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f32_eq_signaling( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF32UI( uiA ) || isNaNF32UI( uiB ) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return false;
|
||||
}
|
||||
return (uiA == uiB) || ! (uint32_t) ((uiA | uiB)<<1);
|
||||
|
||||
}
|
||||
|
||||
51
src/common/softfloat/source/f32_isSignalingNaN.c
Normal file
51
src/common/softfloat/source/f32_isSignalingNaN.c
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f32_isSignalingNaN( float32_t a )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
|
||||
uA.f = a;
|
||||
return softfloat_isSigNaNF32UI( uA.ui );
|
||||
|
||||
}
|
||||
|
||||
66
src/common/softfloat/source/f32_le.c
Normal file
66
src/common/softfloat/source/f32_le.c
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f32_le( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
bool signA, signB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF32UI( uiA ) || isNaNF32UI( uiB ) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return false;
|
||||
}
|
||||
signA = signF32UI( uiA );
|
||||
signB = signF32UI( uiB );
|
||||
return
|
||||
(signA != signB) ? signA || ! (uint32_t) ((uiA | uiB)<<1)
|
||||
: (uiA == uiB) || (signA ^ (uiA < uiB));
|
||||
|
||||
}
|
||||
|
||||
71
src/common/softfloat/source/f32_le_quiet.c
Normal file
71
src/common/softfloat/source/f32_le_quiet.c
Normal file
@@ -0,0 +1,71 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f32_le_quiet( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
bool signA, signB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF32UI( uiA ) || isNaNF32UI( uiB ) ) {
|
||||
if (
|
||||
softfloat_isSigNaNF32UI( uiA ) || softfloat_isSigNaNF32UI( uiB )
|
||||
) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
signA = signF32UI( uiA );
|
||||
signB = signF32UI( uiB );
|
||||
return
|
||||
(signA != signB) ? signA || ! (uint32_t) ((uiA | uiB)<<1)
|
||||
: (uiA == uiB) || (signA ^ (uiA < uiB));
|
||||
|
||||
}
|
||||
|
||||
66
src/common/softfloat/source/f32_lt.c
Normal file
66
src/common/softfloat/source/f32_lt.c
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f32_lt( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
bool signA, signB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF32UI( uiA ) || isNaNF32UI( uiB ) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return false;
|
||||
}
|
||||
signA = signF32UI( uiA );
|
||||
signB = signF32UI( uiB );
|
||||
return
|
||||
(signA != signB) ? signA && ((uint32_t) ((uiA | uiB)<<1) != 0)
|
||||
: (uiA != uiB) && (signA ^ (uiA < uiB));
|
||||
|
||||
}
|
||||
|
||||
71
src/common/softfloat/source/f32_lt_quiet.c
Normal file
71
src/common/softfloat/source/f32_lt_quiet.c
Normal file
@@ -0,0 +1,71 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f32_lt_quiet( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
bool signA, signB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF32UI( uiA ) || isNaNF32UI( uiB ) ) {
|
||||
if (
|
||||
softfloat_isSigNaNF32UI( uiA ) || softfloat_isSigNaNF32UI( uiB )
|
||||
) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
signA = signF32UI( uiA );
|
||||
signB = signF32UI( uiB );
|
||||
return
|
||||
(signA != signB) ? signA && ((uint32_t) ((uiA | uiB)<<1) != 0)
|
||||
: (uiA != uiB) && (signA ^ (uiA < uiB));
|
||||
|
||||
}
|
||||
|
||||
137
src/common/softfloat/source/f32_mul.c
Normal file
137
src/common/softfloat/source/f32_mul.c
Normal file
@@ -0,0 +1,137 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t f32_mul( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
bool signA;
|
||||
int_fast16_t expA;
|
||||
uint_fast32_t sigA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
bool signB;
|
||||
int_fast16_t expB;
|
||||
uint_fast32_t sigB;
|
||||
bool signZ;
|
||||
uint_fast32_t magBits;
|
||||
struct exp16_sig32 normExpSig;
|
||||
int_fast16_t expZ;
|
||||
uint_fast32_t sigZ, uiZ;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
signA = signF32UI( uiA );
|
||||
expA = expF32UI( uiA );
|
||||
sigA = fracF32UI( uiA );
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
signB = signF32UI( uiB );
|
||||
expB = expF32UI( uiB );
|
||||
sigB = fracF32UI( uiB );
|
||||
signZ = signA ^ signB;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA == 0xFF ) {
|
||||
if ( sigA || ((expB == 0xFF) && sigB) ) goto propagateNaN;
|
||||
magBits = expB | sigB;
|
||||
goto infArg;
|
||||
}
|
||||
if ( expB == 0xFF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
magBits = expA | sigA;
|
||||
goto infArg;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! expA ) {
|
||||
if ( ! sigA ) goto zero;
|
||||
normExpSig = softfloat_normSubnormalF32Sig( sigA );
|
||||
expA = normExpSig.exp;
|
||||
sigA = normExpSig.sig;
|
||||
}
|
||||
if ( ! expB ) {
|
||||
if ( ! sigB ) goto zero;
|
||||
normExpSig = softfloat_normSubnormalF32Sig( sigB );
|
||||
expB = normExpSig.exp;
|
||||
sigB = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expZ = expA + expB - 0x7F;
|
||||
sigA = (sigA | 0x00800000)<<7;
|
||||
sigB = (sigB | 0x00800000)<<8;
|
||||
sigZ = softfloat_shortShiftRightJam64( (uint_fast64_t) sigA * sigB, 32 );
|
||||
if ( sigZ < 0x40000000 ) {
|
||||
--expZ;
|
||||
sigZ <<= 1;
|
||||
}
|
||||
return softfloat_roundPackToF32( signZ, expZ, sigZ );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN:
|
||||
uiZ = softfloat_propagateNaNF32UI( uiA, uiB );
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
infArg:
|
||||
if ( ! magBits ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF32UI;
|
||||
} else {
|
||||
uiZ = packToF32UI( signZ, 0xFF, 0 );
|
||||
}
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
zero:
|
||||
uiZ = packToF32UI( signZ, 0, 0 );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
60
src/common/softfloat/source/f32_mulAdd.c
Normal file
60
src/common/softfloat/source/f32_mulAdd.c
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t f32_mulAdd( float32_t a, float32_t b, float32_t c )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
union ui32_f32 uC;
|
||||
uint_fast32_t uiC;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
uC.f = c;
|
||||
uiC = uC.ui;
|
||||
return softfloat_mulAddF32( uiA, uiB, uiC, 0 );
|
||||
|
||||
}
|
||||
|
||||
168
src/common/softfloat/source/f32_rem.c
Normal file
168
src/common/softfloat/source/f32_rem.c
Normal file
@@ -0,0 +1,168 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t f32_rem( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
bool signA;
|
||||
int_fast16_t expA;
|
||||
uint_fast32_t sigA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
int_fast16_t expB;
|
||||
uint_fast32_t sigB;
|
||||
struct exp16_sig32 normExpSig;
|
||||
uint32_t rem;
|
||||
int_fast16_t expDiff;
|
||||
uint32_t q, recip32, altRem, meanRem;
|
||||
bool signRem;
|
||||
uint_fast32_t uiZ;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
signA = signF32UI( uiA );
|
||||
expA = expF32UI( uiA );
|
||||
sigA = fracF32UI( uiA );
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
expB = expF32UI( uiB );
|
||||
sigB = fracF32UI( uiB );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA == 0xFF ) {
|
||||
if ( sigA || ((expB == 0xFF) && sigB) ) goto propagateNaN;
|
||||
goto invalid;
|
||||
}
|
||||
if ( expB == 0xFF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
return a;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! expB ) {
|
||||
if ( ! sigB ) goto invalid;
|
||||
normExpSig = softfloat_normSubnormalF32Sig( sigB );
|
||||
expB = normExpSig.exp;
|
||||
sigB = normExpSig.sig;
|
||||
}
|
||||
if ( ! expA ) {
|
||||
if ( ! sigA ) return a;
|
||||
normExpSig = softfloat_normSubnormalF32Sig( sigA );
|
||||
expA = normExpSig.exp;
|
||||
sigA = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
rem = sigA | 0x00800000;
|
||||
sigB |= 0x00800000;
|
||||
expDiff = expA - expB;
|
||||
if ( expDiff < 1 ) {
|
||||
if ( expDiff < -1 ) return a;
|
||||
sigB <<= 6;
|
||||
if ( expDiff ) {
|
||||
rem <<= 5;
|
||||
q = 0;
|
||||
} else {
|
||||
rem <<= 6;
|
||||
q = (sigB <= rem);
|
||||
if ( q ) rem -= sigB;
|
||||
}
|
||||
} else {
|
||||
recip32 = softfloat_approxRecip32_1( sigB<<8 );
|
||||
/*--------------------------------------------------------------------
|
||||
| Changing the shift of `rem' here requires also changing the initial
|
||||
| subtraction from `expDiff'.
|
||||
*--------------------------------------------------------------------*/
|
||||
rem <<= 7;
|
||||
expDiff -= 31;
|
||||
/*--------------------------------------------------------------------
|
||||
| The scale of `sigB' affects how many bits are obtained during each
|
||||
| cycle of the loop. Currently this is 29 bits per loop iteration,
|
||||
| which is believed to be the maximum possible.
|
||||
*--------------------------------------------------------------------*/
|
||||
sigB <<= 6;
|
||||
for (;;) {
|
||||
q = (rem * (uint_fast64_t) recip32)>>32;
|
||||
if ( expDiff < 0 ) break;
|
||||
rem = -(q * (uint32_t) sigB);
|
||||
expDiff -= 29;
|
||||
}
|
||||
/*--------------------------------------------------------------------
|
||||
| (`expDiff' cannot be less than -30 here.)
|
||||
*--------------------------------------------------------------------*/
|
||||
q >>= ~expDiff & 31;
|
||||
rem = (rem<<(expDiff + 30)) - q * (uint32_t) sigB;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
do {
|
||||
altRem = rem;
|
||||
++q;
|
||||
rem -= sigB;
|
||||
} while ( ! (rem & 0x80000000) );
|
||||
meanRem = rem + altRem;
|
||||
if ( (meanRem & 0x80000000) || (! meanRem && (q & 1)) ) rem = altRem;
|
||||
signRem = signA;
|
||||
if ( 0x80000000 <= rem ) {
|
||||
signRem = ! signRem;
|
||||
rem = -rem;
|
||||
}
|
||||
return softfloat_normRoundPackToF32( signRem, expB, rem );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN:
|
||||
uiZ = softfloat_propagateNaNF32UI( uiA, uiB );
|
||||
goto uiZ;
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF32UI;
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
113
src/common/softfloat/source/f32_roundToInt.c
Normal file
113
src/common/softfloat/source/f32_roundToInt.c
Normal file
@@ -0,0 +1,113 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2017 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t f32_roundToInt( float32_t a, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t uiZ, lastBitMask, roundBitsMask;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
exp = expF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp <= 0x7E ) {
|
||||
if ( ! (uint32_t) (uiA<<1) ) return a;
|
||||
if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
uiZ = uiA & packToF32UI( 1, 0, 0 );
|
||||
switch ( roundingMode ) {
|
||||
case softfloat_round_near_even:
|
||||
if ( ! fracF32UI( uiA ) ) break;
|
||||
/* fall through */
|
||||
case softfloat_round_near_maxMag:
|
||||
if ( exp == 0x7E ) uiZ |= packToF32UI( 0, 0x7F, 0 );
|
||||
break;
|
||||
case softfloat_round_min:
|
||||
if ( uiZ ) uiZ = packToF32UI( 1, 0x7F, 0 );
|
||||
break;
|
||||
case softfloat_round_max:
|
||||
if ( ! uiZ ) uiZ = packToF32UI( 0, 0x7F, 0 );
|
||||
break;
|
||||
}
|
||||
goto uiZ;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( 0x96 <= exp ) {
|
||||
if ( (exp == 0xFF) && fracF32UI( uiA ) ) {
|
||||
uiZ = softfloat_propagateNaNF32UI( uiA, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uiZ = uiA;
|
||||
lastBitMask = (uint_fast32_t) 1<<(0x96 - exp);
|
||||
roundBitsMask = lastBitMask - 1;
|
||||
if ( roundingMode == softfloat_round_near_maxMag ) {
|
||||
uiZ += lastBitMask>>1;
|
||||
} else if ( roundingMode == softfloat_round_near_even ) {
|
||||
uiZ += lastBitMask>>1;
|
||||
if ( ! (uiZ & roundBitsMask) ) uiZ &= ~lastBitMask;
|
||||
} else if (
|
||||
roundingMode
|
||||
== (signF32UI( uiZ ) ? softfloat_round_min : softfloat_round_max)
|
||||
) {
|
||||
uiZ += roundBitsMask;
|
||||
}
|
||||
uiZ &= ~roundBitsMask;
|
||||
if ( exact && (uiZ != uiA) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
121
src/common/softfloat/source/f32_sqrt.c
Normal file
121
src/common/softfloat/source/f32_sqrt.c
Normal file
@@ -0,0 +1,121 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t f32_sqrt( float32_t a )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
bool signA;
|
||||
int_fast16_t expA;
|
||||
uint_fast32_t sigA, uiZ;
|
||||
struct exp16_sig32 normExpSig;
|
||||
int_fast16_t expZ;
|
||||
uint_fast32_t sigZ, shiftedSigZ;
|
||||
uint32_t negRem;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
signA = signF32UI( uiA );
|
||||
expA = expF32UI( uiA );
|
||||
sigA = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA == 0xFF ) {
|
||||
if ( sigA ) {
|
||||
uiZ = softfloat_propagateNaNF32UI( uiA, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
if ( ! signA ) return a;
|
||||
goto invalid;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( signA ) {
|
||||
if ( ! (expA | sigA) ) return a;
|
||||
goto invalid;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! expA ) {
|
||||
if ( ! sigA ) return a;
|
||||
normExpSig = softfloat_normSubnormalF32Sig( sigA );
|
||||
expA = normExpSig.exp;
|
||||
sigA = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expZ = ((expA - 0x7F)>>1) + 0x7E;
|
||||
expA &= 1;
|
||||
sigA = (sigA | 0x00800000)<<8;
|
||||
sigZ =
|
||||
((uint_fast64_t) sigA * softfloat_approxRecipSqrt32_1( expA, sigA ))
|
||||
>>32;
|
||||
if ( expA ) sigZ >>= 1;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sigZ += 2;
|
||||
if ( (sigZ & 0x3F) < 2 ) {
|
||||
shiftedSigZ = sigZ>>2;
|
||||
negRem = shiftedSigZ * shiftedSigZ;
|
||||
sigZ &= ~3;
|
||||
if ( negRem & 0x80000000 ) {
|
||||
sigZ |= 1;
|
||||
} else {
|
||||
if ( negRem ) --sigZ;
|
||||
}
|
||||
}
|
||||
return softfloat_roundPackToF32( 0, expZ, sigZ );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF32UI;
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
61
src/common/softfloat/source/f32_sub.c
Normal file
61
src/common/softfloat/source/f32_sub.c
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t f32_sub( float32_t a, float32_t b )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
union ui32_f32 uB;
|
||||
uint_fast32_t uiB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( signF32UI( uiA ^ uiB ) ) {
|
||||
return softfloat_addMagsF32( uiA, uiB );
|
||||
} else {
|
||||
return softfloat_subMagsF32( uiA, uiB );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
88
src/common/softfloat/source/f32_to_f16.c
Normal file
88
src/common/softfloat/source/f32_to_f16.c
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float16_t f32_to_f16( float32_t a )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t frac;
|
||||
struct commonNaN commonNaN;
|
||||
uint_fast16_t uiZ, frac16;
|
||||
union ui16_f16 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF32UI( uiA );
|
||||
exp = expF32UI( uiA );
|
||||
frac = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp == 0xFF ) {
|
||||
if ( frac ) {
|
||||
softfloat_f32UIToCommonNaN( uiA, &commonNaN );
|
||||
uiZ = softfloat_commonNaNToF16UI( &commonNaN );
|
||||
} else {
|
||||
uiZ = packToF16UI( sign, 0x1F, 0 );
|
||||
}
|
||||
goto uiZ;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
frac16 = frac>>9 | ((frac & 0x1FF) != 0);
|
||||
if ( ! (exp | frac16) ) {
|
||||
uiZ = packToF16UI( sign, 0, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
return softfloat_roundPackToF16( sign, exp - 0x71, frac16 | 0x4000 );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
93
src/common/softfloat/source/f32_to_f64.c
Normal file
93
src/common/softfloat/source/f32_to_f64.c
Normal file
@@ -0,0 +1,93 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t f32_to_f64( float32_t a )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t frac;
|
||||
struct commonNaN commonNaN;
|
||||
uint_fast64_t uiZ;
|
||||
struct exp16_sig32 normExpSig;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF32UI( uiA );
|
||||
exp = expF32UI( uiA );
|
||||
frac = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp == 0xFF ) {
|
||||
if ( frac ) {
|
||||
softfloat_f32UIToCommonNaN( uiA, &commonNaN );
|
||||
uiZ = softfloat_commonNaNToF64UI( &commonNaN );
|
||||
} else {
|
||||
uiZ = packToF64UI( sign, 0x7FF, 0 );
|
||||
}
|
||||
goto uiZ;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! exp ) {
|
||||
if ( ! frac ) {
|
||||
uiZ = packToF64UI( sign, 0, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
normExpSig = softfloat_normSubnormalF32Sig( frac );
|
||||
exp = normExpSig.exp - 1;
|
||||
frac = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uiZ = packToF64UI( sign, exp + 0x380, (uint_fast64_t) frac<<29 );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
84
src/common/softfloat/source/f32_to_i32.c
Normal file
84
src/common/softfloat/source/f32_to_i32.c
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
int_fast32_t f32_to_i32( float32_t a, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t sig;
|
||||
uint_fast64_t sig64;
|
||||
int_fast16_t shiftDist;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF32UI( uiA );
|
||||
exp = expF32UI( uiA );
|
||||
sig = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
#if (i32_fromNaN != i32_fromPosOverflow) || (i32_fromNaN != i32_fromNegOverflow)
|
||||
if ( (exp == 0xFF) && sig ) {
|
||||
#if (i32_fromNaN == i32_fromPosOverflow)
|
||||
sign = 0;
|
||||
#elif (i32_fromNaN == i32_fromNegOverflow)
|
||||
sign = 1;
|
||||
#else
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return i32_fromNaN;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp ) sig |= 0x00800000;
|
||||
sig64 = (uint_fast64_t) sig<<32;
|
||||
shiftDist = 0xAA - exp;
|
||||
if ( 0 < shiftDist ) sig64 = softfloat_shiftRightJam64( sig64, shiftDist );
|
||||
return softfloat_roundToI32( sign, sig64, roundingMode, exact );
|
||||
|
||||
}
|
||||
|
||||
89
src/common/softfloat/source/f32_to_i32_r_minMag.c
Normal file
89
src/common/softfloat/source/f32_to_i32_r_minMag.c
Normal file
@@ -0,0 +1,89 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
int_fast32_t f32_to_i32_r_minMag( float32_t a, bool exact )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
bool sign;
|
||||
int_fast32_t absZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
exp = expF32UI( uiA );
|
||||
sig = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
shiftDist = 0x9E - exp;
|
||||
if ( 32 <= shiftDist ) {
|
||||
if ( exact && (exp | sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sign = signF32UI( uiA );
|
||||
if ( shiftDist <= 0 ) {
|
||||
if ( uiA == packToF32UI( 1, 0x9E, 0 ) ) return -0x7FFFFFFF - 1;
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0xFF) && sig ? i32_fromNaN
|
||||
: sign ? i32_fromNegOverflow : i32_fromPosOverflow;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sig = (sig | 0x00800000)<<8;
|
||||
absZ = sig>>shiftDist;
|
||||
if ( exact && ((uint_fast32_t) absZ<<shiftDist != sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return sign ? -absZ : absZ;
|
||||
|
||||
}
|
||||
|
||||
84
src/common/softfloat/source/f32_to_i64.c
Normal file
84
src/common/softfloat/source/f32_to_i64.c
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
int_fast64_t f32_to_i64( float32_t a, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
uint_fast64_t sig64, extra;
|
||||
struct uint64_extra sig64Extra;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF32UI( uiA );
|
||||
exp = expF32UI( uiA );
|
||||
sig = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
shiftDist = 0xBE - exp;
|
||||
if ( shiftDist < 0 ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0xFF) && sig ? i64_fromNaN
|
||||
: sign ? i64_fromNegOverflow : i64_fromPosOverflow;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp ) sig |= 0x00800000;
|
||||
sig64 = (uint_fast64_t) sig<<40;
|
||||
extra = 0;
|
||||
if ( shiftDist ) {
|
||||
sig64Extra = softfloat_shiftRightJam64Extra( sig64, 0, shiftDist );
|
||||
sig64 = sig64Extra.v;
|
||||
extra = sig64Extra.extra;
|
||||
}
|
||||
return softfloat_roundToI64( sign, sig64, extra, roundingMode, exact );
|
||||
|
||||
}
|
||||
|
||||
94
src/common/softfloat/source/f32_to_i64_r_minMag.c
Normal file
94
src/common/softfloat/source/f32_to_i64_r_minMag.c
Normal file
@@ -0,0 +1,94 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
int_fast64_t f32_to_i64_r_minMag( float32_t a, bool exact )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
bool sign;
|
||||
uint_fast64_t sig64;
|
||||
int_fast64_t absZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
exp = expF32UI( uiA );
|
||||
sig = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
shiftDist = 0xBE - exp;
|
||||
if ( 64 <= shiftDist ) {
|
||||
if ( exact && (exp | sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sign = signF32UI( uiA );
|
||||
if ( shiftDist <= 0 ) {
|
||||
if ( uiA == packToF32UI( 1, 0xBE, 0 ) ) {
|
||||
return -INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1;
|
||||
}
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0xFF) && sig ? i64_fromNaN
|
||||
: sign ? i64_fromNegOverflow : i64_fromPosOverflow;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sig |= 0x00800000;
|
||||
sig64 = (uint_fast64_t) sig<<40;
|
||||
absZ = sig64>>shiftDist;
|
||||
shiftDist = 40 - shiftDist;
|
||||
if ( exact && (shiftDist < 0) && (uint32_t) (sig<<(shiftDist & 31)) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return sign ? -absZ : absZ;
|
||||
|
||||
}
|
||||
|
||||
84
src/common/softfloat/source/f32_to_ui32.c
Normal file
84
src/common/softfloat/source/f32_to_ui32.c
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
uint_fast32_t f32_to_ui32( float32_t a, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t sig;
|
||||
uint_fast64_t sig64;
|
||||
int_fast16_t shiftDist;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF32UI( uiA );
|
||||
exp = expF32UI( uiA );
|
||||
sig = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
#if (ui32_fromNaN != ui32_fromPosOverflow) || (ui32_fromNaN != ui32_fromNegOverflow)
|
||||
if ( (exp == 0xFF) && sig ) {
|
||||
#if (ui32_fromNaN == ui32_fromPosOverflow)
|
||||
sign = 0;
|
||||
#elif (ui32_fromNaN == ui32_fromNegOverflow)
|
||||
sign = 1;
|
||||
#else
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return ui32_fromNaN;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp ) sig |= 0x00800000;
|
||||
sig64 = (uint_fast64_t) sig<<32;
|
||||
shiftDist = 0xAA - exp;
|
||||
if ( 0 < shiftDist ) sig64 = softfloat_shiftRightJam64( sig64, shiftDist );
|
||||
return softfloat_roundToUI32( sign, sig64, roundingMode, exact );
|
||||
|
||||
}
|
||||
|
||||
88
src/common/softfloat/source/f32_to_ui32_r_minMag.c
Normal file
88
src/common/softfloat/source/f32_to_ui32_r_minMag.c
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
uint_fast32_t f32_to_ui32_r_minMag( float32_t a, bool exact )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
bool sign;
|
||||
uint_fast32_t z;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
exp = expF32UI( uiA );
|
||||
sig = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
shiftDist = 0x9E - exp;
|
||||
if ( 32 <= shiftDist ) {
|
||||
if ( exact && (exp | sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sign = signF32UI( uiA );
|
||||
if ( sign || (shiftDist < 0) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0xFF) && sig ? ui32_fromNaN
|
||||
: sign ? ui32_fromNegOverflow : ui32_fromPosOverflow;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sig = (sig | 0x00800000)<<8;
|
||||
z = sig>>shiftDist;
|
||||
if ( exact && (z<<shiftDist != sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
84
src/common/softfloat/source/f32_to_ui64.c
Normal file
84
src/common/softfloat/source/f32_to_ui64.c
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
uint_fast64_t f32_to_ui64( float32_t a, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
uint_fast64_t sig64, extra;
|
||||
struct uint64_extra sig64Extra;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF32UI( uiA );
|
||||
exp = expF32UI( uiA );
|
||||
sig = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
shiftDist = 0xBE - exp;
|
||||
if ( shiftDist < 0 ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0xFF) && sig ? ui64_fromNaN
|
||||
: sign ? ui64_fromNegOverflow : ui64_fromPosOverflow;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp ) sig |= 0x00800000;
|
||||
sig64 = (uint_fast64_t) sig<<40;
|
||||
extra = 0;
|
||||
if ( shiftDist ) {
|
||||
sig64Extra = softfloat_shiftRightJam64Extra( sig64, 0, shiftDist );
|
||||
sig64 = sig64Extra.v;
|
||||
extra = sig64Extra.extra;
|
||||
}
|
||||
return softfloat_roundToUI64( sign, sig64, extra, roundingMode, exact );
|
||||
|
||||
}
|
||||
|
||||
90
src/common/softfloat/source/f32_to_ui64_r_minMag.c
Normal file
90
src/common/softfloat/source/f32_to_ui64_r_minMag.c
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
uint_fast64_t f32_to_ui64_r_minMag( float32_t a, bool exact )
|
||||
{
|
||||
union ui32_f32 uA;
|
||||
uint_fast32_t uiA;
|
||||
int_fast16_t exp;
|
||||
uint_fast32_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
bool sign;
|
||||
uint_fast64_t sig64, z;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
exp = expF32UI( uiA );
|
||||
sig = fracF32UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
shiftDist = 0xBE - exp;
|
||||
if ( 64 <= shiftDist ) {
|
||||
if ( exact && (exp | sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sign = signF32UI( uiA );
|
||||
if ( sign || (shiftDist < 0) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0xFF) && sig ? ui64_fromNaN
|
||||
: sign ? ui64_fromNegOverflow : ui64_fromPosOverflow;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sig |= 0x00800000;
|
||||
sig64 = (uint_fast64_t) sig<<40;
|
||||
z = sig64>>shiftDist;
|
||||
shiftDist = 40 - shiftDist;
|
||||
if ( exact && (shiftDist < 0) && (uint32_t) (sig<<(shiftDist & 31)) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
65
src/common/softfloat/source/f64_add.c
Normal file
65
src/common/softfloat/source/f64_add.c
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t f64_add( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool signA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
bool signB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
signA = signF64UI( uiA );
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
signB = signF64UI( uiB );
|
||||
if ( signA == signB ) {
|
||||
return softfloat_addMagsF64( uiA, uiB, signA );
|
||||
} else {
|
||||
return softfloat_subMagsF64( uiA, uiB, signA );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
172
src/common/softfloat/source/f64_div.c
Normal file
172
src/common/softfloat/source/f64_div.c
Normal file
@@ -0,0 +1,172 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t f64_div( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool signA;
|
||||
int_fast16_t expA;
|
||||
uint_fast64_t sigA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
bool signB;
|
||||
int_fast16_t expB;
|
||||
uint_fast64_t sigB;
|
||||
bool signZ;
|
||||
struct exp16_sig64 normExpSig;
|
||||
int_fast16_t expZ;
|
||||
uint32_t recip32, sig32Z, doubleTerm;
|
||||
uint_fast64_t rem;
|
||||
uint32_t q;
|
||||
uint_fast64_t sigZ;
|
||||
uint_fast64_t uiZ;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
signA = signF64UI( uiA );
|
||||
expA = expF64UI( uiA );
|
||||
sigA = fracF64UI( uiA );
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
signB = signF64UI( uiB );
|
||||
expB = expF64UI( uiB );
|
||||
sigB = fracF64UI( uiB );
|
||||
signZ = signA ^ signB;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA == 0x7FF ) {
|
||||
if ( sigA ) goto propagateNaN;
|
||||
if ( expB == 0x7FF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
goto invalid;
|
||||
}
|
||||
goto infinity;
|
||||
}
|
||||
if ( expB == 0x7FF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
goto zero;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! expB ) {
|
||||
if ( ! sigB ) {
|
||||
if ( ! (expA | sigA) ) goto invalid;
|
||||
softfloat_raiseFlags( softfloat_flag_infinite );
|
||||
goto infinity;
|
||||
}
|
||||
normExpSig = softfloat_normSubnormalF64Sig( sigB );
|
||||
expB = normExpSig.exp;
|
||||
sigB = normExpSig.sig;
|
||||
}
|
||||
if ( ! expA ) {
|
||||
if ( ! sigA ) goto zero;
|
||||
normExpSig = softfloat_normSubnormalF64Sig( sigA );
|
||||
expA = normExpSig.exp;
|
||||
sigA = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expZ = expA - expB + 0x3FE;
|
||||
sigA |= UINT64_C( 0x0010000000000000 );
|
||||
sigB |= UINT64_C( 0x0010000000000000 );
|
||||
if ( sigA < sigB ) {
|
||||
--expZ;
|
||||
sigA <<= 11;
|
||||
} else {
|
||||
sigA <<= 10;
|
||||
}
|
||||
sigB <<= 11;
|
||||
recip32 = softfloat_approxRecip32_1( sigB>>32 ) - 2;
|
||||
sig32Z = ((uint32_t) (sigA>>32) * (uint_fast64_t) recip32)>>32;
|
||||
doubleTerm = sig32Z<<1;
|
||||
rem =
|
||||
((sigA - (uint_fast64_t) doubleTerm * (uint32_t) (sigB>>32))<<28)
|
||||
- (uint_fast64_t) doubleTerm * ((uint32_t) sigB>>4);
|
||||
q = (((uint32_t) (rem>>32) * (uint_fast64_t) recip32)>>32) + 4;
|
||||
sigZ = ((uint_fast64_t) sig32Z<<32) + ((uint_fast64_t) q<<4);
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( (sigZ & 0x1FF) < 4<<4 ) {
|
||||
q &= ~7;
|
||||
sigZ &= ~(uint_fast64_t) 0x7F;
|
||||
doubleTerm = q<<1;
|
||||
rem =
|
||||
((rem - (uint_fast64_t) doubleTerm * (uint32_t) (sigB>>32))<<28)
|
||||
- (uint_fast64_t) doubleTerm * ((uint32_t) sigB>>4);
|
||||
if ( rem & UINT64_C( 0x8000000000000000 ) ) {
|
||||
sigZ -= 1<<7;
|
||||
} else {
|
||||
if ( rem ) sigZ |= 1;
|
||||
}
|
||||
}
|
||||
return softfloat_roundPackToF64( signZ, expZ, sigZ );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN:
|
||||
uiZ = softfloat_propagateNaNF64UI( uiA, uiB );
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF64UI;
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
infinity:
|
||||
uiZ = packToF64UI( signZ, 0x7FF, 0 );
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
zero:
|
||||
uiZ = packToF64UI( signZ, 0, 0 );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
66
src/common/softfloat/source/f64_eq.c
Normal file
66
src/common/softfloat/source/f64_eq.c
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f64_eq( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF64UI( uiA ) || isNaNF64UI( uiB ) ) {
|
||||
if (
|
||||
softfloat_isSigNaNF64UI( uiA ) || softfloat_isSigNaNF64UI( uiB )
|
||||
) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return (uiA == uiB) || ! ((uiA | uiB) & UINT64_C( 0x7FFFFFFFFFFFFFFF ));
|
||||
|
||||
}
|
||||
|
||||
61
src/common/softfloat/source/f64_eq_signaling.c
Normal file
61
src/common/softfloat/source/f64_eq_signaling.c
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f64_eq_signaling( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF64UI( uiA ) || isNaNF64UI( uiB ) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return false;
|
||||
}
|
||||
return (uiA == uiB) || ! ((uiA | uiB) & UINT64_C( 0x7FFFFFFFFFFFFFFF ));
|
||||
|
||||
}
|
||||
|
||||
51
src/common/softfloat/source/f64_isSignalingNaN.c
Normal file
51
src/common/softfloat/source/f64_isSignalingNaN.c
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f64_isSignalingNaN( float64_t a )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
|
||||
uA.f = a;
|
||||
return softfloat_isSigNaNF64UI( uA.ui );
|
||||
|
||||
}
|
||||
|
||||
67
src/common/softfloat/source/f64_le.c
Normal file
67
src/common/softfloat/source/f64_le.c
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f64_le( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
bool signA, signB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF64UI( uiA ) || isNaNF64UI( uiB ) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return false;
|
||||
}
|
||||
signA = signF64UI( uiA );
|
||||
signB = signF64UI( uiB );
|
||||
return
|
||||
(signA != signB)
|
||||
? signA || ! ((uiA | uiB) & UINT64_C( 0x7FFFFFFFFFFFFFFF ))
|
||||
: (uiA == uiB) || (signA ^ (uiA < uiB));
|
||||
|
||||
}
|
||||
|
||||
72
src/common/softfloat/source/f64_le_quiet.c
Normal file
72
src/common/softfloat/source/f64_le_quiet.c
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f64_le_quiet( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
bool signA, signB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF64UI( uiA ) || isNaNF64UI( uiB ) ) {
|
||||
if (
|
||||
softfloat_isSigNaNF64UI( uiA ) || softfloat_isSigNaNF64UI( uiB )
|
||||
) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
signA = signF64UI( uiA );
|
||||
signB = signF64UI( uiB );
|
||||
return
|
||||
(signA != signB)
|
||||
? signA || ! ((uiA | uiB) & UINT64_C( 0x7FFFFFFFFFFFFFFF ))
|
||||
: (uiA == uiB) || (signA ^ (uiA < uiB));
|
||||
|
||||
}
|
||||
|
||||
67
src/common/softfloat/source/f64_lt.c
Normal file
67
src/common/softfloat/source/f64_lt.c
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f64_lt( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
bool signA, signB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF64UI( uiA ) || isNaNF64UI( uiB ) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return false;
|
||||
}
|
||||
signA = signF64UI( uiA );
|
||||
signB = signF64UI( uiB );
|
||||
return
|
||||
(signA != signB)
|
||||
? signA && ((uiA | uiB) & UINT64_C( 0x7FFFFFFFFFFFFFFF ))
|
||||
: (uiA != uiB) && (signA ^ (uiA < uiB));
|
||||
|
||||
}
|
||||
|
||||
72
src/common/softfloat/source/f64_lt_quiet.c
Normal file
72
src/common/softfloat/source/f64_lt_quiet.c
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
bool f64_lt_quiet( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
bool signA, signB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
if ( isNaNF64UI( uiA ) || isNaNF64UI( uiB ) ) {
|
||||
if (
|
||||
softfloat_isSigNaNF64UI( uiA ) || softfloat_isSigNaNF64UI( uiB )
|
||||
) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
signA = signF64UI( uiA );
|
||||
signB = signF64UI( uiB );
|
||||
return
|
||||
(signA != signB)
|
||||
? signA && ((uiA | uiB) & UINT64_C( 0x7FFFFFFFFFFFFFFF ))
|
||||
: (uiA != uiB) && (signA ^ (uiA < uiB));
|
||||
|
||||
}
|
||||
|
||||
139
src/common/softfloat/source/f64_mul.c
Normal file
139
src/common/softfloat/source/f64_mul.c
Normal file
@@ -0,0 +1,139 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t f64_mul( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool signA;
|
||||
int_fast16_t expA;
|
||||
uint_fast64_t sigA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
bool signB;
|
||||
int_fast16_t expB;
|
||||
uint_fast64_t sigB;
|
||||
bool signZ;
|
||||
uint_fast64_t magBits;
|
||||
struct exp16_sig64 normExpSig;
|
||||
int_fast16_t expZ;
|
||||
struct uint128 sig128Z;
|
||||
uint_fast64_t sigZ, uiZ;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
signA = signF64UI( uiA );
|
||||
expA = expF64UI( uiA );
|
||||
sigA = fracF64UI( uiA );
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
signB = signF64UI( uiB );
|
||||
expB = expF64UI( uiB );
|
||||
sigB = fracF64UI( uiB );
|
||||
signZ = signA ^ signB;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA == 0x7FF ) {
|
||||
if ( sigA || ((expB == 0x7FF) && sigB) ) goto propagateNaN;
|
||||
magBits = expB | sigB;
|
||||
goto infArg;
|
||||
}
|
||||
if ( expB == 0x7FF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
magBits = expA | sigA;
|
||||
goto infArg;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! expA ) {
|
||||
if ( ! sigA ) goto zero;
|
||||
normExpSig = softfloat_normSubnormalF64Sig( sigA );
|
||||
expA = normExpSig.exp;
|
||||
sigA = normExpSig.sig;
|
||||
}
|
||||
if ( ! expB ) {
|
||||
if ( ! sigB ) goto zero;
|
||||
normExpSig = softfloat_normSubnormalF64Sig( sigB );
|
||||
expB = normExpSig.exp;
|
||||
sigB = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expZ = expA + expB - 0x3FF;
|
||||
sigA = (sigA | UINT64_C( 0x0010000000000000 ))<<10;
|
||||
sigB = (sigB | UINT64_C( 0x0010000000000000 ))<<11;
|
||||
sig128Z = softfloat_mul64To128( sigA, sigB );
|
||||
sigZ = sig128Z.v64 | (sig128Z.v0 != 0);
|
||||
if ( sigZ < UINT64_C( 0x4000000000000000 ) ) {
|
||||
--expZ;
|
||||
sigZ <<= 1;
|
||||
}
|
||||
return softfloat_roundPackToF64( signZ, expZ, sigZ );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN:
|
||||
uiZ = softfloat_propagateNaNF64UI( uiA, uiB );
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
infArg:
|
||||
if ( ! magBits ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF64UI;
|
||||
} else {
|
||||
uiZ = packToF64UI( signZ, 0x7FF, 0 );
|
||||
}
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
zero:
|
||||
uiZ = packToF64UI( signZ, 0, 0 );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
60
src/common/softfloat/source/f64_mulAdd.c
Normal file
60
src/common/softfloat/source/f64_mulAdd.c
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t f64_mulAdd( float64_t a, float64_t b, float64_t c )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
union ui64_f64 uC;
|
||||
uint_fast64_t uiC;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
uC.f = c;
|
||||
uiC = uC.ui;
|
||||
return softfloat_mulAddF64( uiA, uiB, uiC, 0 );
|
||||
|
||||
}
|
||||
|
||||
185
src/common/softfloat/source/f64_rem.c
Normal file
185
src/common/softfloat/source/f64_rem.c
Normal file
@@ -0,0 +1,185 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t f64_rem( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool signA;
|
||||
int_fast16_t expA;
|
||||
uint_fast64_t sigA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
int_fast16_t expB;
|
||||
uint_fast64_t sigB;
|
||||
struct exp16_sig64 normExpSig;
|
||||
uint64_t rem;
|
||||
int_fast16_t expDiff;
|
||||
uint32_t q, recip32;
|
||||
uint_fast64_t q64;
|
||||
uint64_t altRem, meanRem;
|
||||
bool signRem;
|
||||
uint_fast64_t uiZ;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
signA = signF64UI( uiA );
|
||||
expA = expF64UI( uiA );
|
||||
sigA = fracF64UI( uiA );
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
expB = expF64UI( uiB );
|
||||
sigB = fracF64UI( uiB );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA == 0x7FF ) {
|
||||
if ( sigA || ((expB == 0x7FF) && sigB) ) goto propagateNaN;
|
||||
goto invalid;
|
||||
}
|
||||
if ( expB == 0x7FF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
return a;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA < expB - 1 ) return a;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! expB ) {
|
||||
if ( ! sigB ) goto invalid;
|
||||
normExpSig = softfloat_normSubnormalF64Sig( sigB );
|
||||
expB = normExpSig.exp;
|
||||
sigB = normExpSig.sig;
|
||||
}
|
||||
if ( ! expA ) {
|
||||
if ( ! sigA ) return a;
|
||||
normExpSig = softfloat_normSubnormalF64Sig( sigA );
|
||||
expA = normExpSig.exp;
|
||||
sigA = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
rem = sigA | UINT64_C( 0x0010000000000000 );
|
||||
sigB |= UINT64_C( 0x0010000000000000 );
|
||||
expDiff = expA - expB;
|
||||
if ( expDiff < 1 ) {
|
||||
if ( expDiff < -1 ) return a;
|
||||
sigB <<= 9;
|
||||
if ( expDiff ) {
|
||||
rem <<= 8;
|
||||
q = 0;
|
||||
} else {
|
||||
rem <<= 9;
|
||||
q = (sigB <= rem);
|
||||
if ( q ) rem -= sigB;
|
||||
}
|
||||
} else {
|
||||
recip32 = softfloat_approxRecip32_1( sigB>>21 );
|
||||
/*--------------------------------------------------------------------
|
||||
| Changing the shift of `rem' here requires also changing the initial
|
||||
| subtraction from `expDiff'.
|
||||
*--------------------------------------------------------------------*/
|
||||
rem <<= 9;
|
||||
expDiff -= 30;
|
||||
/*--------------------------------------------------------------------
|
||||
| The scale of `sigB' affects how many bits are obtained during each
|
||||
| cycle of the loop. Currently this is 29 bits per loop iteration,
|
||||
| the maximum possible.
|
||||
*--------------------------------------------------------------------*/
|
||||
sigB <<= 9;
|
||||
for (;;) {
|
||||
q64 = (uint32_t) (rem>>32) * (uint_fast64_t) recip32;
|
||||
if ( expDiff < 0 ) break;
|
||||
q = (q64 + 0x80000000)>>32;
|
||||
rem <<= 29;
|
||||
rem -= q * (uint64_t) sigB;
|
||||
if ( rem & UINT64_C( 0x8000000000000000 ) ) rem += sigB;
|
||||
expDiff -= 29;
|
||||
}
|
||||
/*--------------------------------------------------------------------
|
||||
| (`expDiff' cannot be less than -29 here.)
|
||||
*--------------------------------------------------------------------*/
|
||||
q = (uint32_t) (q64>>32)>>(~expDiff & 31);
|
||||
rem = (rem<<(expDiff + 30)) - q * (uint64_t) sigB;
|
||||
if ( rem & UINT64_C( 0x8000000000000000 ) ) {
|
||||
altRem = rem + sigB;
|
||||
goto selectRem;
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
do {
|
||||
altRem = rem;
|
||||
++q;
|
||||
rem -= sigB;
|
||||
} while ( ! (rem & UINT64_C( 0x8000000000000000 )) );
|
||||
selectRem:
|
||||
meanRem = rem + altRem;
|
||||
if (
|
||||
(meanRem & UINT64_C( 0x8000000000000000 )) || (! meanRem && (q & 1))
|
||||
) {
|
||||
rem = altRem;
|
||||
}
|
||||
signRem = signA;
|
||||
if ( rem & UINT64_C( 0x8000000000000000 ) ) {
|
||||
signRem = ! signRem;
|
||||
rem = -rem;
|
||||
}
|
||||
return softfloat_normRoundPackToF64( signRem, expB, rem );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN:
|
||||
uiZ = softfloat_propagateNaNF64UI( uiA, uiB );
|
||||
goto uiZ;
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF64UI;
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
113
src/common/softfloat/source/f64_roundToInt.c
Normal file
113
src/common/softfloat/source/f64_roundToInt.c
Normal file
@@ -0,0 +1,113 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2017 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t f64_roundToInt( float64_t a, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
int_fast16_t exp;
|
||||
uint_fast64_t uiZ, lastBitMask, roundBitsMask;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
exp = expF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp <= 0x3FE ) {
|
||||
if ( ! (uiA & UINT64_C( 0x7FFFFFFFFFFFFFFF )) ) return a;
|
||||
if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
uiZ = uiA & packToF64UI( 1, 0, 0 );
|
||||
switch ( roundingMode ) {
|
||||
case softfloat_round_near_even:
|
||||
if ( ! fracF64UI( uiA ) ) break;
|
||||
/* fall through */
|
||||
case softfloat_round_near_maxMag:
|
||||
if ( exp == 0x3FE ) uiZ |= packToF64UI( 0, 0x3FF, 0 );
|
||||
break;
|
||||
case softfloat_round_min:
|
||||
if ( uiZ ) uiZ = packToF64UI( 1, 0x3FF, 0 );
|
||||
break;
|
||||
case softfloat_round_max:
|
||||
if ( ! uiZ ) uiZ = packToF64UI( 0, 0x3FF, 0 );
|
||||
break;
|
||||
}
|
||||
goto uiZ;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( 0x433 <= exp ) {
|
||||
if ( (exp == 0x7FF) && fracF64UI( uiA ) ) {
|
||||
uiZ = softfloat_propagateNaNF64UI( uiA, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uiZ = uiA;
|
||||
lastBitMask = (uint_fast64_t) 1<<(0x433 - exp);
|
||||
roundBitsMask = lastBitMask - 1;
|
||||
if ( roundingMode == softfloat_round_near_maxMag ) {
|
||||
uiZ += lastBitMask>>1;
|
||||
} else if ( roundingMode == softfloat_round_near_even ) {
|
||||
uiZ += lastBitMask>>1;
|
||||
if ( ! (uiZ & roundBitsMask) ) uiZ &= ~lastBitMask;
|
||||
} else if (
|
||||
roundingMode
|
||||
== (signF64UI( uiZ ) ? softfloat_round_min : softfloat_round_max)
|
||||
) {
|
||||
uiZ += roundBitsMask;
|
||||
}
|
||||
uiZ &= ~roundBitsMask;
|
||||
if ( exact && (uiZ != uiA) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
133
src/common/softfloat/source/f64_sqrt.c
Normal file
133
src/common/softfloat/source/f64_sqrt.c
Normal file
@@ -0,0 +1,133 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2017 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t f64_sqrt( float64_t a )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool signA;
|
||||
int_fast16_t expA;
|
||||
uint_fast64_t sigA, uiZ;
|
||||
struct exp16_sig64 normExpSig;
|
||||
int_fast16_t expZ;
|
||||
uint32_t sig32A, recipSqrt32, sig32Z;
|
||||
uint_fast64_t rem;
|
||||
uint32_t q;
|
||||
uint_fast64_t sigZ, shiftedSigZ;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
signA = signF64UI( uiA );
|
||||
expA = expF64UI( uiA );
|
||||
sigA = fracF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA == 0x7FF ) {
|
||||
if ( sigA ) {
|
||||
uiZ = softfloat_propagateNaNF64UI( uiA, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
if ( ! signA ) return a;
|
||||
goto invalid;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( signA ) {
|
||||
if ( ! (expA | sigA) ) return a;
|
||||
goto invalid;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! expA ) {
|
||||
if ( ! sigA ) return a;
|
||||
normExpSig = softfloat_normSubnormalF64Sig( sigA );
|
||||
expA = normExpSig.exp;
|
||||
sigA = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
| (`sig32Z' is guaranteed to be a lower bound on the square root of
|
||||
| `sig32A', which makes `sig32Z' also a lower bound on the square root of
|
||||
| `sigA'.)
|
||||
*------------------------------------------------------------------------*/
|
||||
expZ = ((expA - 0x3FF)>>1) + 0x3FE;
|
||||
expA &= 1;
|
||||
sigA |= UINT64_C( 0x0010000000000000 );
|
||||
sig32A = sigA>>21;
|
||||
recipSqrt32 = softfloat_approxRecipSqrt32_1( expA, sig32A );
|
||||
sig32Z = ((uint_fast64_t) sig32A * recipSqrt32)>>32;
|
||||
if ( expA ) {
|
||||
sigA <<= 8;
|
||||
sig32Z >>= 1;
|
||||
} else {
|
||||
sigA <<= 9;
|
||||
}
|
||||
rem = sigA - (uint_fast64_t) sig32Z * sig32Z;
|
||||
q = ((uint32_t) (rem>>2) * (uint_fast64_t) recipSqrt32)>>32;
|
||||
sigZ = ((uint_fast64_t) sig32Z<<32 | 1<<5) + ((uint_fast64_t) q<<3);
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( (sigZ & 0x1FF) < 0x22 ) {
|
||||
sigZ &= ~(uint_fast64_t) 0x3F;
|
||||
shiftedSigZ = sigZ>>6;
|
||||
rem = (sigA<<52) - shiftedSigZ * shiftedSigZ;
|
||||
if ( rem & UINT64_C( 0x8000000000000000 ) ) {
|
||||
--sigZ;
|
||||
} else {
|
||||
if ( rem ) sigZ |= 1;
|
||||
}
|
||||
}
|
||||
return softfloat_roundPackToF64( 0, expZ, sigZ );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF64UI;
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
65
src/common/softfloat/source/f64_sub.c
Normal file
65
src/common/softfloat/source/f64_sub.c
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t f64_sub( float64_t a, float64_t b )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool signA;
|
||||
union ui64_f64 uB;
|
||||
uint_fast64_t uiB;
|
||||
bool signB;
|
||||
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
signA = signF64UI( uiA );
|
||||
uB.f = b;
|
||||
uiB = uB.ui;
|
||||
signB = signF64UI( uiB );
|
||||
if ( signA == signB ) {
|
||||
return softfloat_subMagsF64( uiA, uiB, signA );
|
||||
} else {
|
||||
return softfloat_addMagsF64( uiA, uiB, signA );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
88
src/common/softfloat/source/f64_to_f32.c
Normal file
88
src/common/softfloat/source/f64_to_f32.c
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t f64_to_f32( float64_t a )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast64_t frac;
|
||||
struct commonNaN commonNaN;
|
||||
uint_fast32_t uiZ, frac32;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF64UI( uiA );
|
||||
exp = expF64UI( uiA );
|
||||
frac = fracF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp == 0x7FF ) {
|
||||
if ( frac ) {
|
||||
softfloat_f64UIToCommonNaN( uiA, &commonNaN );
|
||||
uiZ = softfloat_commonNaNToF32UI( &commonNaN );
|
||||
} else {
|
||||
uiZ = packToF32UI( sign, 0xFF, 0 );
|
||||
}
|
||||
goto uiZ;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
frac32 = softfloat_shortShiftRightJam64( frac, 22 );
|
||||
if ( ! (exp | frac32) ) {
|
||||
uiZ = packToF32UI( sign, 0, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
return softfloat_roundPackToF32( sign, exp - 0x381, frac32 | 0x40000000 );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
82
src/common/softfloat/source/f64_to_i32.c
Normal file
82
src/common/softfloat/source/f64_to_i32.c
Normal file
@@ -0,0 +1,82 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
int_fast32_t f64_to_i32( float64_t a, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast64_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF64UI( uiA );
|
||||
exp = expF64UI( uiA );
|
||||
sig = fracF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
#if (i32_fromNaN != i32_fromPosOverflow) || (i32_fromNaN != i32_fromNegOverflow)
|
||||
if ( (exp == 0x7FF) && sig ) {
|
||||
#if (i32_fromNaN == i32_fromPosOverflow)
|
||||
sign = 0;
|
||||
#elif (i32_fromNaN == i32_fromNegOverflow)
|
||||
sign = 1;
|
||||
#else
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return i32_fromNaN;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp ) sig |= UINT64_C( 0x0010000000000000 );
|
||||
shiftDist = 0x427 - exp;
|
||||
if ( 0 < shiftDist ) sig = softfloat_shiftRightJam64( sig, shiftDist );
|
||||
return softfloat_roundToI32( sign, sig, roundingMode, exact );
|
||||
|
||||
}
|
||||
|
||||
96
src/common/softfloat/source/f64_to_i32_r_minMag.c
Normal file
96
src/common/softfloat/source/f64_to_i32_r_minMag.c
Normal file
@@ -0,0 +1,96 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
int_fast32_t f64_to_i32_r_minMag( float64_t a, bool exact )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
int_fast16_t exp;
|
||||
uint_fast64_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
bool sign;
|
||||
int_fast32_t absZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
exp = expF64UI( uiA );
|
||||
sig = fracF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
shiftDist = 0x433 - exp;
|
||||
if ( 53 <= shiftDist ) {
|
||||
if ( exact && (exp | sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sign = signF64UI( uiA );
|
||||
if ( shiftDist < 22 ) {
|
||||
if (
|
||||
sign && (exp == 0x41E) && (sig < UINT64_C( 0x0000000000200000 ))
|
||||
) {
|
||||
if ( exact && sig ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return -0x7FFFFFFF - 1;
|
||||
}
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0x7FF) && sig ? i32_fromNaN
|
||||
: sign ? i32_fromNegOverflow : i32_fromPosOverflow;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sig |= UINT64_C( 0x0010000000000000 );
|
||||
absZ = sig>>shiftDist;
|
||||
if ( exact && ((uint_fast64_t) (uint_fast32_t) absZ<<shiftDist != sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return sign ? -absZ : absZ;
|
||||
|
||||
}
|
||||
|
||||
84
src/common/softfloat/source/f64_to_i64.c
Normal file
84
src/common/softfloat/source/f64_to_i64.c
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
int_fast64_t f64_to_i64( float64_t a, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast64_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
struct uint64_extra sigExtra;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF64UI( uiA );
|
||||
exp = expF64UI( uiA );
|
||||
sig = fracF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp ) sig |= UINT64_C( 0x0010000000000000 );
|
||||
shiftDist = 0x433 - exp;
|
||||
if ( shiftDist <= 0 ) {
|
||||
if ( shiftDist < -11 ) goto invalid;
|
||||
sigExtra.v = sig<<-shiftDist;
|
||||
sigExtra.extra = 0;
|
||||
} else {
|
||||
sigExtra = softfloat_shiftRightJam64Extra( sig, 0, shiftDist );
|
||||
}
|
||||
return
|
||||
softfloat_roundToI64(
|
||||
sign, sigExtra.v, sigExtra.extra, roundingMode, exact );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0x7FF) && fracF64UI( uiA ) ? i64_fromNaN
|
||||
: sign ? i64_fromNegOverflow : i64_fromPosOverflow;
|
||||
|
||||
}
|
||||
|
||||
100
src/common/softfloat/source/f64_to_i64_r_minMag.c
Normal file
100
src/common/softfloat/source/f64_to_i64_r_minMag.c
Normal file
@@ -0,0 +1,100 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
int_fast64_t f64_to_i64_r_minMag( float64_t a, bool exact )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast64_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
int_fast64_t absZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF64UI( uiA );
|
||||
exp = expF64UI( uiA );
|
||||
sig = fracF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
shiftDist = 0x433 - exp;
|
||||
if ( shiftDist <= 0 ) {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
if ( shiftDist < -10 ) {
|
||||
if ( uiA == packToF64UI( 1, 0x43E, 0 ) ) {
|
||||
return -INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1;
|
||||
}
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0x7FF) && sig ? i64_fromNaN
|
||||
: sign ? i64_fromNegOverflow : i64_fromPosOverflow;
|
||||
}
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
sig |= UINT64_C( 0x0010000000000000 );
|
||||
absZ = sig<<-shiftDist;
|
||||
} else {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
if ( 53 <= shiftDist ) {
|
||||
if ( exact && (exp | sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
sig |= UINT64_C( 0x0010000000000000 );
|
||||
absZ = sig>>shiftDist;
|
||||
if ( exact && (absZ<<shiftDist != sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
}
|
||||
return sign ? -absZ : absZ;
|
||||
|
||||
}
|
||||
|
||||
82
src/common/softfloat/source/f64_to_ui32.c
Normal file
82
src/common/softfloat/source/f64_to_ui32.c
Normal file
@@ -0,0 +1,82 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
uint_fast32_t f64_to_ui32( float64_t a, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast64_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF64UI( uiA );
|
||||
exp = expF64UI( uiA );
|
||||
sig = fracF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
#if (ui32_fromNaN != ui32_fromPosOverflow) || (ui32_fromNaN != ui32_fromNegOverflow)
|
||||
if ( (exp == 0x7FF) && sig ) {
|
||||
#if (ui32_fromNaN == ui32_fromPosOverflow)
|
||||
sign = 0;
|
||||
#elif (ui32_fromNaN == ui32_fromNegOverflow)
|
||||
sign = 1;
|
||||
#else
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return ui32_fromNaN;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp ) sig |= UINT64_C( 0x0010000000000000 );
|
||||
shiftDist = 0x427 - exp;
|
||||
if ( 0 < shiftDist ) sig = softfloat_shiftRightJam64( sig, shiftDist );
|
||||
return softfloat_roundToUI32( sign, sig, roundingMode, exact );
|
||||
|
||||
}
|
||||
|
||||
88
src/common/softfloat/source/f64_to_ui32_r_minMag.c
Normal file
88
src/common/softfloat/source/f64_to_ui32_r_minMag.c
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
uint_fast32_t f64_to_ui32_r_minMag( float64_t a, bool exact )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
int_fast16_t exp;
|
||||
uint_fast64_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
bool sign;
|
||||
uint_fast32_t z;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
exp = expF64UI( uiA );
|
||||
sig = fracF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
shiftDist = 0x433 - exp;
|
||||
if ( 53 <= shiftDist ) {
|
||||
if ( exact && (exp | sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sign = signF64UI( uiA );
|
||||
if ( sign || (shiftDist < 21) ) {
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0x7FF) && sig ? ui32_fromNaN
|
||||
: sign ? ui32_fromNegOverflow : ui32_fromPosOverflow;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sig |= UINT64_C( 0x0010000000000000 );
|
||||
z = sig>>shiftDist;
|
||||
if ( exact && ((uint_fast64_t) z<<shiftDist != sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
84
src/common/softfloat/source/f64_to_ui64.c
Normal file
84
src/common/softfloat/source/f64_to_ui64.c
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
uint_fast64_t f64_to_ui64( float64_t a, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
bool sign;
|
||||
int_fast16_t exp;
|
||||
uint_fast64_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
struct uint64_extra sigExtra;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
sign = signF64UI( uiA );
|
||||
exp = expF64UI( uiA );
|
||||
sig = fracF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( exp ) sig |= UINT64_C( 0x0010000000000000 );
|
||||
shiftDist = 0x433 - exp;
|
||||
if ( shiftDist <= 0 ) {
|
||||
if ( shiftDist < -11 ) goto invalid;
|
||||
sigExtra.v = sig<<-shiftDist;
|
||||
sigExtra.extra = 0;
|
||||
} else {
|
||||
sigExtra = softfloat_shiftRightJam64Extra( sig, 0, shiftDist );
|
||||
}
|
||||
return
|
||||
softfloat_roundToUI64(
|
||||
sign, sigExtra.v, sigExtra.extra, roundingMode, exact );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0x7FF) && fracF64UI( uiA ) ? ui64_fromNaN
|
||||
: sign ? ui64_fromNegOverflow : ui64_fromPosOverflow;
|
||||
|
||||
}
|
||||
|
||||
93
src/common/softfloat/source/f64_to_ui64_r_minMag.c
Normal file
93
src/common/softfloat/source/f64_to_ui64_r_minMag.c
Normal file
@@ -0,0 +1,93 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
uint_fast64_t f64_to_ui64_r_minMag( float64_t a, bool exact )
|
||||
{
|
||||
union ui64_f64 uA;
|
||||
uint_fast64_t uiA;
|
||||
int_fast16_t exp;
|
||||
uint_fast64_t sig;
|
||||
int_fast16_t shiftDist;
|
||||
bool sign;
|
||||
uint_fast64_t z;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
uA.f = a;
|
||||
uiA = uA.ui;
|
||||
exp = expF64UI( uiA );
|
||||
sig = fracF64UI( uiA );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
shiftDist = 0x433 - exp;
|
||||
if ( 53 <= shiftDist ) {
|
||||
if ( exact && (exp | sig) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sign = signF64UI( uiA );
|
||||
if ( sign ) goto invalid;
|
||||
if ( shiftDist <= 0 ) {
|
||||
if ( shiftDist < -11 ) goto invalid;
|
||||
z = (sig | UINT64_C( 0x0010000000000000 ))<<-shiftDist;
|
||||
} else {
|
||||
sig |= UINT64_C( 0x0010000000000000 );
|
||||
z = sig>>shiftDist;
|
||||
if ( exact && (uint64_t) (sig<<(-shiftDist & 63)) ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
}
|
||||
return z;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return
|
||||
(exp == 0x7FF) && sig ? ui64_fromNaN
|
||||
: sign ? ui64_fromNegOverflow : ui64_fromPosOverflow;
|
||||
|
||||
}
|
||||
|
||||
58
src/common/softfloat/source/i32_to_f32.c
Normal file
58
src/common/softfloat/source/i32_to_f32.c
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t i32_to_f32( int32_t a )
|
||||
{
|
||||
bool sign;
|
||||
union ui32_f32 uZ;
|
||||
uint_fast32_t absA;
|
||||
|
||||
sign = (a < 0);
|
||||
if ( ! (a & 0x7FFFFFFF) ) {
|
||||
uZ.ui = sign ? packToF32UI( 1, 0x9E, 0 ) : 0;
|
||||
return uZ.f;
|
||||
}
|
||||
absA = sign ? -(uint_fast32_t) a : (uint_fast32_t) a;
|
||||
return softfloat_normRoundPackToF32( sign, 0x9C, absA );
|
||||
|
||||
}
|
||||
|
||||
65
src/common/softfloat/source/i32_to_f64.c
Normal file
65
src/common/softfloat/source/i32_to_f64.c
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t i32_to_f64( int32_t a )
|
||||
{
|
||||
uint_fast64_t uiZ;
|
||||
bool sign;
|
||||
uint_fast32_t absA;
|
||||
int_fast8_t shiftDist;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
if ( ! a ) {
|
||||
uiZ = 0;
|
||||
} else {
|
||||
sign = (a < 0);
|
||||
absA = sign ? -(uint_fast32_t) a : (uint_fast32_t) a;
|
||||
shiftDist = softfloat_countLeadingZeros32( absA ) + 21;
|
||||
uiZ =
|
||||
packToF64UI(
|
||||
sign, 0x432 - shiftDist, (uint_fast64_t) absA<<shiftDist );
|
||||
}
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
70
src/common/softfloat/source/i64_to_f32.c
Normal file
70
src/common/softfloat/source/i64_to_f32.c
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t i64_to_f32( int64_t a )
|
||||
{
|
||||
bool sign;
|
||||
uint_fast64_t absA;
|
||||
int_fast8_t shiftDist;
|
||||
union ui32_f32 u;
|
||||
uint_fast32_t sig;
|
||||
|
||||
sign = (a < 0);
|
||||
absA = sign ? -(uint_fast64_t) a : (uint_fast64_t) a;
|
||||
shiftDist = softfloat_countLeadingZeros64( absA ) - 40;
|
||||
if ( 0 <= shiftDist ) {
|
||||
u.ui =
|
||||
a ? packToF32UI(
|
||||
sign, 0x95 - shiftDist, (uint_fast32_t) absA<<shiftDist )
|
||||
: 0;
|
||||
return u.f;
|
||||
} else {
|
||||
shiftDist += 7;
|
||||
sig =
|
||||
(shiftDist < 0)
|
||||
? softfloat_shortShiftRightJam64( absA, -shiftDist )
|
||||
: (uint_fast32_t) absA<<shiftDist;
|
||||
return softfloat_roundPackToF32( sign, 0x9C - shiftDist, sig );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
58
src/common/softfloat/source/i64_to_f64.c
Normal file
58
src/common/softfloat/source/i64_to_f64.c
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t i64_to_f64( int64_t a )
|
||||
{
|
||||
bool sign;
|
||||
union ui64_f64 uZ;
|
||||
uint_fast64_t absA;
|
||||
|
||||
sign = (a < 0);
|
||||
if ( ! (a & UINT64_C( 0x7FFFFFFFFFFFFFFF )) ) {
|
||||
uZ.ui = sign ? packToF64UI( 1, 0x43E, 0 ) : 0;
|
||||
return uZ.f;
|
||||
}
|
||||
absA = sign ? -(uint_fast64_t) a : (uint_fast64_t) a;
|
||||
return softfloat_normRoundPackToF64( sign, 0x43C, absA );
|
||||
|
||||
}
|
||||
|
||||
144
src/common/softfloat/source/include/internals.h
Normal file
144
src/common/softfloat/source/include/internals.h
Normal file
@@ -0,0 +1,144 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef internals_h
|
||||
#define internals_h 1
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "primitives.h"
|
||||
#include "softfloat_types.h"
|
||||
|
||||
union ui16_f16 { uint16_t ui; float16_t f; };
|
||||
union ui32_f32 { uint32_t ui; float32_t f; };
|
||||
union ui64_f64 { uint64_t ui; float64_t f; };
|
||||
|
||||
union extF80M_extF80 { struct extFloat80M fM; extFloat80_t f; };
|
||||
union ui128_f128 { struct uint128 ui; float128_t f; };
|
||||
|
||||
enum {
|
||||
softfloat_mulAdd_subC = 1,
|
||||
softfloat_mulAdd_subProd = 2
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast32_t softfloat_roundToUI32( bool, uint_fast64_t, uint_fast8_t, bool );
|
||||
|
||||
uint_fast64_t
|
||||
softfloat_roundToUI64(
|
||||
bool, uint_fast64_t, uint_fast64_t, uint_fast8_t, bool );
|
||||
|
||||
int_fast32_t softfloat_roundToI32( bool, uint_fast64_t, uint_fast8_t, bool );
|
||||
|
||||
int_fast64_t
|
||||
softfloat_roundToI64(
|
||||
bool, uint_fast64_t, uint_fast64_t, uint_fast8_t, bool );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define signF16UI( a ) ((bool) ((uint16_t) (a)>>15))
|
||||
#define expF16UI( a ) ((int_fast8_t) ((a)>>10) & 0x1F)
|
||||
#define fracF16UI( a ) ((a) & 0x03FF)
|
||||
#define packToF16UI( sign, exp, sig ) (((uint16_t) (sign)<<15) + ((uint16_t) (exp)<<10) + (sig))
|
||||
|
||||
#define isNaNF16UI( a ) (((~(a) & 0x7C00) == 0) && ((a) & 0x03FF))
|
||||
|
||||
float16_t softfloat_roundPackToF16( bool, int_fast16_t, uint_fast16_t );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define signF32UI( a ) ((bool) ((uint32_t) (a)>>31))
|
||||
#define expF32UI( a ) ((int_fast16_t) ((a)>>23) & 0xFF)
|
||||
#define fracF32UI( a ) ((a) & 0x007FFFFF)
|
||||
#define packToF32UI( sign, exp, sig ) (((uint32_t) (sign)<<31) + ((uint32_t) (exp)<<23) + (sig))
|
||||
|
||||
#define isNaNF32UI( a ) (((~(a) & 0x7F800000) == 0) && ((a) & 0x007FFFFF))
|
||||
|
||||
struct exp16_sig32 { int_fast16_t exp; uint_fast32_t sig; };
|
||||
struct exp16_sig32 softfloat_normSubnormalF32Sig( uint_fast32_t );
|
||||
|
||||
float32_t softfloat_roundPackToF32( bool, int_fast16_t, uint_fast32_t );
|
||||
float32_t softfloat_normRoundPackToF32( bool, int_fast16_t, uint_fast32_t );
|
||||
|
||||
float32_t softfloat_addMagsF32( uint_fast32_t, uint_fast32_t );
|
||||
float32_t softfloat_subMagsF32( uint_fast32_t, uint_fast32_t );
|
||||
float32_t
|
||||
softfloat_mulAddF32(
|
||||
uint_fast32_t, uint_fast32_t, uint_fast32_t, uint_fast8_t );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define signF64UI( a ) ((bool) ((uint64_t) (a)>>63))
|
||||
#define expF64UI( a ) ((int_fast16_t) ((a)>>52) & 0x7FF)
|
||||
#define fracF64UI( a ) ((a) & UINT64_C( 0x000FFFFFFFFFFFFF ))
|
||||
#define packToF64UI( sign, exp, sig ) ((uint64_t) (((uint_fast64_t) (sign)<<63) + ((uint_fast64_t) (exp)<<52) + (sig)))
|
||||
|
||||
#define isNaNF64UI( a ) (((~(a) & UINT64_C( 0x7FF0000000000000 )) == 0) && ((a) & UINT64_C( 0x000FFFFFFFFFFFFF )))
|
||||
|
||||
struct exp16_sig64 { int_fast16_t exp; uint_fast64_t sig; };
|
||||
struct exp16_sig64 softfloat_normSubnormalF64Sig( uint_fast64_t );
|
||||
|
||||
float64_t softfloat_roundPackToF64( bool, int_fast16_t, uint_fast64_t );
|
||||
float64_t softfloat_normRoundPackToF64( bool, int_fast16_t, uint_fast64_t );
|
||||
|
||||
float64_t softfloat_addMagsF64( uint_fast64_t, uint_fast64_t, bool );
|
||||
float64_t softfloat_subMagsF64( uint_fast64_t, uint_fast64_t, bool );
|
||||
float64_t
|
||||
softfloat_mulAddF64(
|
||||
uint_fast64_t, uint_fast64_t, uint_fast64_t, uint_fast8_t );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define signExtF80UI64( a64 ) ((bool) ((uint16_t) (a64)>>15))
|
||||
#define expExtF80UI64( a64 ) ((a64) & 0x7FFF)
|
||||
#define packToExtF80UI64( sign, exp ) ((uint_fast16_t) (sign)<<15 | (exp))
|
||||
|
||||
#define isNaNExtF80UI( a64, a0 ) ((((a64) & 0x7FFF) == 0x7FFF) && ((a0) & UINT64_C( 0x7FFFFFFFFFFFFFFF )))
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
*----------------------------------------------------------------------------*/
|
||||
#define signF128UI64( a64 ) ((bool) ((uint64_t) (a64)>>63))
|
||||
#define expF128UI64( a64 ) ((int_fast32_t) ((a64)>>48) & 0x7FFF)
|
||||
#define fracF128UI64( a64 ) ((a64) & UINT64_C( 0x0000FFFFFFFFFFFF ))
|
||||
#define packToF128UI64( sign, exp, sig64 ) (((uint_fast64_t) (sign)<<63) + ((uint_fast64_t) (exp)<<48) + (sig64))
|
||||
|
||||
#define isNaNF128UI( a64, a0 ) (((~(a64) & UINT64_C( 0x7FFF000000000000 )) == 0) && (a0 || ((a64) & UINT64_C( 0x0000FFFFFFFFFFFF ))))
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
83
src/common/softfloat/source/include/primitiveTypes.h
Normal file
83
src/common/softfloat/source/include/primitiveTypes.h
Normal file
@@ -0,0 +1,83 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef primitiveTypes_h
|
||||
#define primitiveTypes_h 1
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#ifdef LITTLEENDIAN
|
||||
struct uint128 { uint64_t v0, v64; };
|
||||
struct uint64_extra { uint64_t extra, v; };
|
||||
struct uint128_extra { uint64_t extra; struct uint128 v; };
|
||||
#else
|
||||
struct uint128 { uint64_t v64, v0; };
|
||||
struct uint64_extra { uint64_t v, extra; };
|
||||
struct uint128_extra { struct uint128 v; uint64_t extra; };
|
||||
#endif
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| These macros are used to isolate the differences in word order between big-
|
||||
| endian and little-endian platforms.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#ifdef LITTLEENDIAN
|
||||
#define wordIncr 1
|
||||
#define indexWord( total, n ) (n)
|
||||
#define indexWordHi( total ) ((total) - 1)
|
||||
#define indexWordLo( total ) 0
|
||||
#define indexMultiword( total, m, n ) (n)
|
||||
#define indexMultiwordHi( total, n ) ((total) - (n))
|
||||
#define indexMultiwordLo( total, n ) 0
|
||||
#define indexMultiwordHiBut( total, n ) (n)
|
||||
#define indexMultiwordLoBut( total, n ) 0
|
||||
#define INIT_UINTM4( v3, v2, v1, v0 ) { v0, v1, v2, v3 }
|
||||
#else
|
||||
#define wordIncr -1
|
||||
#define indexWord( total, n ) ((total) - 1 - (n))
|
||||
#define indexWordHi( total ) 0
|
||||
#define indexWordLo( total ) ((total) - 1)
|
||||
#define indexMultiword( total, m, n ) ((total) - 1 - (m))
|
||||
#define indexMultiwordHi( total, n ) 0
|
||||
#define indexMultiwordLo( total, n ) ((total) - (n))
|
||||
#define indexMultiwordHiBut( total, n ) 0
|
||||
#define indexMultiwordLoBut( total, n ) (n)
|
||||
#define INIT_UINTM4( v3, v2, v1, v0 ) { v3, v2, v1, v0 }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
282
src/common/softfloat/source/include/primitives.h
Normal file
282
src/common/softfloat/source/include/primitives.h
Normal file
@@ -0,0 +1,282 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef primitives_h
|
||||
#define primitives_h 1
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "primitiveTypes.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts 'a' right by the number of bits given in 'dist', which must be in
|
||||
| the range 1 to 63. If any nonzero bits are shifted off, they are "jammed"
|
||||
| into the least-significant bit of the shifted value by setting the least-
|
||||
| significant bit to 1. This shifted-and-jammed value is returned.
|
||||
*----------------------------------------------------------------------------*/
|
||||
INLINE
|
||||
uint64_t softfloat_shortShiftRightJam64( uint64_t a, uint_fast8_t dist )
|
||||
{ return a>>dist | ((a & (((uint_fast64_t) 1<<dist) - 1)) != 0); }
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts 'a' right by the number of bits given in 'dist', which must not
|
||||
| be zero. If any nonzero bits are shifted off, they are "jammed" into the
|
||||
| least-significant bit of the shifted value by setting the least-significant
|
||||
| bit to 1. This shifted-and-jammed value is returned.
|
||||
| The value of 'dist' can be arbitrarily large. In particular, if 'dist' is
|
||||
| greater than 32, the result will be either 0 or 1, depending on whether 'a'
|
||||
| is zero or nonzero.
|
||||
*----------------------------------------------------------------------------*/
|
||||
INLINE uint32_t softfloat_shiftRightJam32( uint32_t a, uint_fast16_t dist )
|
||||
{
|
||||
return
|
||||
(dist < 31) ? a>>dist | ((uint32_t) (a<<(-dist & 31)) != 0) : (a != 0);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts 'a' right by the number of bits given in 'dist', which must not
|
||||
| be zero. If any nonzero bits are shifted off, they are "jammed" into the
|
||||
| least-significant bit of the shifted value by setting the least-significant
|
||||
| bit to 1. This shifted-and-jammed value is returned.
|
||||
| The value of 'dist' can be arbitrarily large. In particular, if 'dist' is
|
||||
| greater than 64, the result will be either 0 or 1, depending on whether 'a'
|
||||
| is zero or nonzero.
|
||||
*----------------------------------------------------------------------------*/
|
||||
INLINE uint64_t softfloat_shiftRightJam64( uint64_t a, uint_fast32_t dist )
|
||||
{
|
||||
return
|
||||
(dist < 63) ? a>>dist | ((uint64_t) (a<<(-dist & 63)) != 0) : (a != 0);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| A constant table that translates an 8-bit unsigned integer (the array index)
|
||||
| into the number of leading 0 bits before the most-significant 1 of that
|
||||
| integer. For integer zero (index 0), the corresponding table element is 8.
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern const uint_least8_t softfloat_countLeadingZeros8[256];
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the number of leading 0 bits before the most-significant 1 bit of
|
||||
| 'a'. If 'a' is zero, 32 is returned.
|
||||
*----------------------------------------------------------------------------*/
|
||||
INLINE uint_fast8_t softfloat_countLeadingZeros32( uint32_t a )
|
||||
{
|
||||
uint_fast8_t count = 0;
|
||||
if ( a < 0x10000 ) {
|
||||
count = 16;
|
||||
a <<= 16;
|
||||
}
|
||||
if ( a < 0x1000000 ) {
|
||||
count += 8;
|
||||
a <<= 8;
|
||||
}
|
||||
count += softfloat_countLeadingZeros8[a>>24];
|
||||
return count;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the number of leading 0 bits before the most-significant 1 bit of
|
||||
| 'a'. If 'a' is zero, 64 is returned.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast8_t softfloat_countLeadingZeros64( uint64_t a );
|
||||
|
||||
extern const uint16_t softfloat_approxRecip_1k0s[16];
|
||||
extern const uint16_t softfloat_approxRecip_1k1s[16];
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns an approximation to the reciprocal of the number represented by 'a',
|
||||
| where 'a' is interpreted as an unsigned fixed-point number with one integer
|
||||
| bit and 31 fraction bits. The 'a' input must be "normalized", meaning that
|
||||
| its most-significant bit (bit 31) must be 1. Thus, if A is the value of
|
||||
| the fixed-point interpretation of 'a', then 1 <= A < 2. The returned value
|
||||
| is interpreted as a pure unsigned fraction, having no integer bits and 32
|
||||
| fraction bits. The approximation returned is never greater than the true
|
||||
| reciprocal 1/A, and it differs from the true reciprocal by at most 2.006 ulp
|
||||
| (units in the last place).
|
||||
*----------------------------------------------------------------------------*/
|
||||
#ifdef SOFTFLOAT_FAST_DIV64TO32
|
||||
#define softfloat_approxRecip32_1( a ) ((uint32_t) (UINT64_C( 0x7FFFFFFFFFFFFFFF ) / (uint32_t) (a)))
|
||||
#endif
|
||||
|
||||
extern const uint16_t softfloat_approxRecipSqrt_1k0s[16];
|
||||
extern const uint16_t softfloat_approxRecipSqrt_1k1s[16];
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns an approximation to the reciprocal of the square root of the number
|
||||
| represented by 'a', where 'a' is interpreted as an unsigned fixed-point
|
||||
| number either with one integer bit and 31 fraction bits or with two integer
|
||||
| bits and 30 fraction bits. The format of 'a' is determined by 'oddExpA',
|
||||
| which must be either 0 or 1. If 'oddExpA' is 1, 'a' is interpreted as
|
||||
| having one integer bit, and if 'oddExpA' is 0, 'a' is interpreted as having
|
||||
| two integer bits. The 'a' input must be "normalized", meaning that its
|
||||
| most-significant bit (bit 31) must be 1. Thus, if A is the value of the
|
||||
| fixed-point interpretation of 'a', it follows that 1 <= A < 2 when 'oddExpA'
|
||||
| is 1, and 2 <= A < 4 when 'oddExpA' is 0.
|
||||
| The returned value is interpreted as a pure unsigned fraction, having
|
||||
| no integer bits and 32 fraction bits. The approximation returned is never
|
||||
| greater than the true reciprocal 1/sqrt(A), and it differs from the true
|
||||
| reciprocal by at most 2.06 ulp (units in the last place). The approximation
|
||||
| returned is also always within the range 0.5 to 1; thus, the most-
|
||||
| significant bit of the result is always set.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint32_t softfloat_approxRecipSqrt32_1( unsigned int oddExpA, uint32_t a );
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The following functions are needed only when 'SOFTFLOAT_FAST_INT64' is
|
||||
| defined.
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts the 128 bits formed by concatenating 'a64' and 'a0' left by the
|
||||
| number of bits given in 'dist', which must be in the range 1 to 63.
|
||||
*----------------------------------------------------------------------------*/
|
||||
INLINE
|
||||
struct uint128
|
||||
softfloat_shortShiftLeft128( uint64_t a64, uint64_t a0, uint_fast8_t dist )
|
||||
{
|
||||
struct uint128 z;
|
||||
z.v64 = a64<<dist | a0>>(-dist & 63);
|
||||
z.v0 = a0<<dist;
|
||||
return z;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts the 128 bits formed by concatenating 'a64' and 'a0' right by the
|
||||
| number of bits given in 'dist', which must be in the range 1 to 63. If any
|
||||
| nonzero bits are shifted off, they are "jammed" into the least-significant
|
||||
| bit of the shifted value by setting the least-significant bit to 1. This
|
||||
| shifted-and-jammed value is returned.
|
||||
*----------------------------------------------------------------------------*/
|
||||
INLINE
|
||||
struct uint128
|
||||
softfloat_shortShiftRightJam128(
|
||||
uint64_t a64, uint64_t a0, uint_fast8_t dist )
|
||||
{
|
||||
uint_fast8_t negDist = -dist;
|
||||
struct uint128 z;
|
||||
z.v64 = a64>>dist;
|
||||
z.v0 =
|
||||
a64<<(negDist & 63) | a0>>dist
|
||||
| ((uint64_t) (a0<<(negDist & 63)) != 0);
|
||||
return z;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts the 128 bits formed by concatenating 'a' and 'extra' right by 64
|
||||
| _plus_ the number of bits given in 'dist', which must not be zero. This
|
||||
| shifted value is at most 64 nonzero bits and is returned in the 'v' field
|
||||
| of the 'struct uint64_extra' result. The 64-bit 'extra' field of the result
|
||||
| contains a value formed as follows from the bits that were shifted off: The
|
||||
| _last_ bit shifted off is the most-significant bit of the 'extra' field, and
|
||||
| the other 63 bits of the 'extra' field are all zero if and only if _all_but_
|
||||
| _the_last_ bits shifted off were all zero.
|
||||
| (This function makes more sense if 'a' and 'extra' are considered to form
|
||||
| an unsigned fixed-point number with binary point between 'a' and 'extra'.
|
||||
| This fixed-point value is shifted right by the number of bits given in
|
||||
| 'dist', and the integer part of this shifted value is returned in the 'v'
|
||||
| field of the result. The fractional part of the shifted value is modified
|
||||
| as described above and returned in the 'extra' field of the result.)
|
||||
*----------------------------------------------------------------------------*/
|
||||
INLINE
|
||||
struct uint64_extra
|
||||
softfloat_shiftRightJam64Extra(
|
||||
uint64_t a, uint64_t extra, uint_fast32_t dist )
|
||||
{
|
||||
struct uint64_extra z;
|
||||
if ( dist < 64 ) {
|
||||
z.v = a>>dist;
|
||||
z.extra = a<<(-dist & 63);
|
||||
} else {
|
||||
z.v = 0;
|
||||
z.extra = (dist == 64) ? a : (a != 0);
|
||||
}
|
||||
z.extra |= (extra != 0);
|
||||
return z;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Shifts the 128 bits formed by concatenating 'a64' and 'a0' right by the
|
||||
| number of bits given in 'dist', which must not be zero. If any nonzero bits
|
||||
| are shifted off, they are "jammed" into the least-significant bit of the
|
||||
| shifted value by setting the least-significant bit to 1. This shifted-and-
|
||||
| jammed value is returned.
|
||||
| The value of 'dist' can be arbitrarily large. In particular, if 'dist' is
|
||||
| greater than 128, the result will be either 0 or 1, depending on whether the
|
||||
| original 128 bits are all zeros.
|
||||
*----------------------------------------------------------------------------*/
|
||||
struct uint128
|
||||
softfloat_shiftRightJam128( uint64_t a64, uint64_t a0, uint_fast32_t dist );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the sum of the 128-bit integer formed by concatenating 'a64' and
|
||||
| 'a0' and the 128-bit integer formed by concatenating 'b64' and 'b0'. The
|
||||
| addition is modulo 2^128, so any carry out is lost.
|
||||
*----------------------------------------------------------------------------*/
|
||||
INLINE
|
||||
struct uint128
|
||||
softfloat_add128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 )
|
||||
{
|
||||
struct uint128 z;
|
||||
z.v0 = a0 + b0;
|
||||
z.v64 = a64 + b64 + (z.v0 < a0);
|
||||
return z;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the difference of the 128-bit integer formed by concatenating 'a64'
|
||||
| and 'a0' and the 128-bit integer formed by concatenating 'b64' and 'b0'.
|
||||
| The subtraction is modulo 2^128, so any borrow out (carry out) is lost.
|
||||
*----------------------------------------------------------------------------*/
|
||||
INLINE
|
||||
struct uint128
|
||||
softfloat_sub128( uint64_t a64, uint64_t a0, uint64_t b64, uint64_t b0 )
|
||||
{
|
||||
struct uint128 z;
|
||||
z.v0 = a0 - b0;
|
||||
z.v64 = a64 - b64;
|
||||
z.v64 -= (a0 < b0);
|
||||
return z;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Returns the 128-bit product of 'a' and 'b'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
struct uint128 softfloat_mul64To128( uint64_t a, uint64_t b );
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
167
src/common/softfloat/source/include/softfloat.h
Normal file
167
src/common/softfloat/source/include/softfloat.h
Normal file
@@ -0,0 +1,167 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
|
||||
/*============================================================================
|
||||
| Note: If SoftFloat is made available as a general library for programs to
|
||||
| use, it is strongly recommended that a platform-specific version of this
|
||||
| header, "softfloat.h", be created that folds in "softfloat_types.h" and that
|
||||
| eliminates all dependencies on compile-time macros.
|
||||
*============================================================================*/
|
||||
|
||||
|
||||
#ifndef softfloat_h
|
||||
#define softfloat_h 1
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "softfloat_types.h"
|
||||
|
||||
#ifndef THREAD_LOCAL
|
||||
#define THREAD_LOCAL
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software floating-point underflow tininess-detection mode.
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern THREAD_LOCAL uint_fast8_t softfloat_detectTininess;
|
||||
enum {
|
||||
softfloat_tininess_beforeRounding = 0,
|
||||
softfloat_tininess_afterRounding = 1
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software floating-point rounding mode. (Mode "odd" is supported only if
|
||||
| SoftFloat is compiled with macro 'SOFTFLOAT_ROUND_ODD' defined.)
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern THREAD_LOCAL uint_fast8_t softfloat_roundingMode;
|
||||
enum {
|
||||
softfloat_round_near_even = 0,
|
||||
softfloat_round_minMag = 1,
|
||||
softfloat_round_min = 2,
|
||||
softfloat_round_max = 3,
|
||||
softfloat_round_near_maxMag = 4,
|
||||
softfloat_round_odd = 5
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Software floating-point exception flags.
|
||||
*----------------------------------------------------------------------------*/
|
||||
extern THREAD_LOCAL uint_fast8_t softfloat_exceptionFlags;
|
||||
enum {
|
||||
softfloat_flag_inexact = 1,
|
||||
softfloat_flag_underflow = 2,
|
||||
softfloat_flag_overflow = 4,
|
||||
softfloat_flag_infinite = 8,
|
||||
softfloat_flag_invalid = 16
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Routine to raise any or all of the software floating-point exception flags.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void softfloat_raiseFlags( uint_fast8_t );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Integer-to-floating-point conversion routines.
|
||||
*----------------------------------------------------------------------------*/
|
||||
float32_t ui32_to_f32( uint32_t );
|
||||
float64_t ui32_to_f64( uint32_t );
|
||||
float32_t ui64_to_f32( uint64_t );
|
||||
float64_t ui64_to_f64( uint64_t );
|
||||
float32_t i32_to_f32( int32_t );
|
||||
float64_t i32_to_f64( int32_t );
|
||||
float32_t i64_to_f32( int64_t );
|
||||
float64_t i64_to_f64( int64_t );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| 32-bit (single-precision) floating-point operations.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast32_t f32_to_ui32( float32_t, uint_fast8_t, bool );
|
||||
uint_fast64_t f32_to_ui64( float32_t, uint_fast8_t, bool );
|
||||
int_fast32_t f32_to_i32( float32_t, uint_fast8_t, bool );
|
||||
int_fast64_t f32_to_i64( float32_t, uint_fast8_t, bool );
|
||||
uint_fast32_t f32_to_ui32_r_minMag( float32_t, bool );
|
||||
uint_fast64_t f32_to_ui64_r_minMag( float32_t, bool );
|
||||
int_fast32_t f32_to_i32_r_minMag( float32_t, bool );
|
||||
int_fast64_t f32_to_i64_r_minMag( float32_t, bool );
|
||||
float16_t f32_to_f16( float32_t );
|
||||
float64_t f32_to_f64( float32_t );
|
||||
float32_t f32_roundToInt( float32_t, uint_fast8_t, bool );
|
||||
float32_t f32_add( float32_t, float32_t );
|
||||
float32_t f32_sub( float32_t, float32_t );
|
||||
float32_t f32_mul( float32_t, float32_t );
|
||||
float32_t f32_mulAdd( float32_t, float32_t, float32_t );
|
||||
float32_t f32_div( float32_t, float32_t );
|
||||
float32_t f32_rem( float32_t, float32_t );
|
||||
float32_t f32_sqrt( float32_t );
|
||||
bool f32_eq( float32_t, float32_t );
|
||||
bool f32_le( float32_t, float32_t );
|
||||
bool f32_lt( float32_t, float32_t );
|
||||
bool f32_eq_signaling( float32_t, float32_t );
|
||||
bool f32_le_quiet( float32_t, float32_t );
|
||||
bool f32_lt_quiet( float32_t, float32_t );
|
||||
bool f32_isSignalingNaN( float32_t );
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| 64-bit (double-precision) floating-point operations.
|
||||
*----------------------------------------------------------------------------*/
|
||||
uint_fast32_t f64_to_ui32( float64_t, uint_fast8_t, bool );
|
||||
uint_fast64_t f64_to_ui64( float64_t, uint_fast8_t, bool );
|
||||
int_fast32_t f64_to_i32( float64_t, uint_fast8_t, bool );
|
||||
int_fast64_t f64_to_i64( float64_t, uint_fast8_t, bool );
|
||||
uint_fast32_t f64_to_ui32_r_minMag( float64_t, bool );
|
||||
uint_fast64_t f64_to_ui64_r_minMag( float64_t, bool );
|
||||
int_fast32_t f64_to_i32_r_minMag( float64_t, bool );
|
||||
int_fast64_t f64_to_i64_r_minMag( float64_t, bool );
|
||||
float32_t f64_to_f32( float64_t );
|
||||
float64_t f64_roundToInt( float64_t, uint_fast8_t, bool );
|
||||
float64_t f64_add( float64_t, float64_t );
|
||||
float64_t f64_sub( float64_t, float64_t );
|
||||
float64_t f64_mul( float64_t, float64_t );
|
||||
float64_t f64_mulAdd( float64_t, float64_t, float64_t );
|
||||
float64_t f64_div( float64_t, float64_t );
|
||||
float64_t f64_rem( float64_t, float64_t );
|
||||
float64_t f64_sqrt( float64_t );
|
||||
bool f64_eq( float64_t, float64_t );
|
||||
bool f64_le( float64_t, float64_t );
|
||||
bool f64_lt( float64_t, float64_t );
|
||||
bool f64_eq_signaling( float64_t, float64_t );
|
||||
bool f64_le_quiet( float64_t, float64_t );
|
||||
bool f64_lt_quiet( float64_t, float64_t );
|
||||
bool f64_isSignalingNaN( float64_t );
|
||||
|
||||
#endif
|
||||
|
||||
81
src/common/softfloat/source/include/softfloat_types.h
Normal file
81
src/common/softfloat/source/include/softfloat_types.h
Normal file
@@ -0,0 +1,81 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2017 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef softfloat_types_h
|
||||
#define softfloat_types_h 1
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| Types used to pass 16-bit, 32-bit, 64-bit, and 128-bit floating-point
|
||||
| arguments and results to/from functions. These types must be exactly
|
||||
| 16 bits, 32 bits, 64 bits, and 128 bits in size, respectively. Where a
|
||||
| platform has "native" support for IEEE-Standard floating-point formats,
|
||||
| the types below may, if desired, be defined as aliases for the native types
|
||||
| (typically 'float' and 'double', and possibly 'long double').
|
||||
*----------------------------------------------------------------------------*/
|
||||
typedef struct { uint16_t v; } float16_t;
|
||||
typedef struct { uint32_t v; } float32_t;
|
||||
typedef struct { uint64_t v; } float64_t;
|
||||
typedef struct { uint64_t v[2]; } float128_t;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The format of an 80-bit extended floating-point number in memory. This
|
||||
| structure must contain a 16-bit field named 'signExp' and a 64-bit field
|
||||
| named 'signif'.
|
||||
*----------------------------------------------------------------------------*/
|
||||
#ifdef LITTLEENDIAN
|
||||
struct extFloat80M { uint64_t signif; uint16_t signExp; };
|
||||
#else
|
||||
struct extFloat80M { uint16_t signExp; uint64_t signif; };
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
| The type used to pass 80-bit extended floating-point arguments and
|
||||
| results to/from functions. This type must have size identical to
|
||||
| 'struct extFloat80M'. Type 'extFloat80_t' can be defined as an alias for
|
||||
| 'struct extFloat80M'. Alternatively, if a platform has "native" support
|
||||
| for IEEE-Standard 80-bit extended floating-point, it may be possible,
|
||||
| if desired, to define 'extFloat80_t' as an alias for the native type
|
||||
| (presumably either 'long double' or a nonstandard compiler-intrinsic type).
|
||||
| In that case, the 'signif' and 'signExp' fields of 'struct extFloat80M'
|
||||
| must align exactly with the locations in memory of the sign, exponent, and
|
||||
| significand of the native type.
|
||||
*----------------------------------------------------------------------------*/
|
||||
typedef struct extFloat80M extFloat80_t;
|
||||
|
||||
#endif
|
||||
|
||||
126
src/common/softfloat/source/s_addMagsF32.c
Normal file
126
src/common/softfloat/source/s_addMagsF32.c
Normal file
@@ -0,0 +1,126 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
|
||||
float32_t softfloat_addMagsF32( uint_fast32_t uiA, uint_fast32_t uiB )
|
||||
{
|
||||
int_fast16_t expA;
|
||||
uint_fast32_t sigA;
|
||||
int_fast16_t expB;
|
||||
uint_fast32_t sigB;
|
||||
int_fast16_t expDiff;
|
||||
uint_fast32_t uiZ;
|
||||
bool signZ;
|
||||
int_fast16_t expZ;
|
||||
uint_fast32_t sigZ;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expA = expF32UI( uiA );
|
||||
sigA = fracF32UI( uiA );
|
||||
expB = expF32UI( uiB );
|
||||
sigB = fracF32UI( uiB );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expDiff = expA - expB;
|
||||
if ( ! expDiff ) {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
if ( ! expA ) {
|
||||
uiZ = uiA + sigB;
|
||||
goto uiZ;
|
||||
}
|
||||
if ( expA == 0xFF ) {
|
||||
if ( sigA | sigB ) goto propagateNaN;
|
||||
uiZ = uiA;
|
||||
goto uiZ;
|
||||
}
|
||||
signZ = signF32UI( uiA );
|
||||
expZ = expA;
|
||||
sigZ = 0x01000000 + sigA + sigB;
|
||||
if ( ! (sigZ & 1) && (expZ < 0xFE) ) {
|
||||
uiZ = packToF32UI( signZ, expZ, sigZ>>1 );
|
||||
goto uiZ;
|
||||
}
|
||||
sigZ <<= 6;
|
||||
} else {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
signZ = signF32UI( uiA );
|
||||
sigA <<= 6;
|
||||
sigB <<= 6;
|
||||
if ( expDiff < 0 ) {
|
||||
if ( expB == 0xFF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
uiZ = packToF32UI( signZ, 0xFF, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
expZ = expB;
|
||||
sigA += expA ? 0x20000000 : sigA;
|
||||
sigA = softfloat_shiftRightJam32( sigA, -expDiff );
|
||||
} else {
|
||||
if ( expA == 0xFF ) {
|
||||
if ( sigA ) goto propagateNaN;
|
||||
uiZ = uiA;
|
||||
goto uiZ;
|
||||
}
|
||||
expZ = expA;
|
||||
sigB += expB ? 0x20000000 : sigB;
|
||||
sigB = softfloat_shiftRightJam32( sigB, expDiff );
|
||||
}
|
||||
sigZ = 0x20000000 + sigA + sigB;
|
||||
if ( sigZ < 0x40000000 ) {
|
||||
--expZ;
|
||||
sigZ <<= 1;
|
||||
}
|
||||
}
|
||||
return softfloat_roundPackToF32( signZ, expZ, sigZ );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN:
|
||||
uiZ = softfloat_propagateNaNF32UI( uiA, uiB );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
128
src/common/softfloat/source/s_addMagsF64.c
Normal file
128
src/common/softfloat/source/s_addMagsF64.c
Normal file
@@ -0,0 +1,128 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
|
||||
float64_t
|
||||
softfloat_addMagsF64( uint_fast64_t uiA, uint_fast64_t uiB, bool signZ )
|
||||
{
|
||||
int_fast16_t expA;
|
||||
uint_fast64_t sigA;
|
||||
int_fast16_t expB;
|
||||
uint_fast64_t sigB;
|
||||
int_fast16_t expDiff;
|
||||
uint_fast64_t uiZ;
|
||||
int_fast16_t expZ;
|
||||
uint_fast64_t sigZ;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expA = expF64UI( uiA );
|
||||
sigA = fracF64UI( uiA );
|
||||
expB = expF64UI( uiB );
|
||||
sigB = fracF64UI( uiB );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expDiff = expA - expB;
|
||||
if ( ! expDiff ) {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
if ( ! expA ) {
|
||||
uiZ = uiA + sigB;
|
||||
goto uiZ;
|
||||
}
|
||||
if ( expA == 0x7FF ) {
|
||||
if ( sigA | sigB ) goto propagateNaN;
|
||||
uiZ = uiA;
|
||||
goto uiZ;
|
||||
}
|
||||
expZ = expA;
|
||||
sigZ = UINT64_C( 0x0020000000000000 ) + sigA + sigB;
|
||||
sigZ <<= 9;
|
||||
} else {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
sigA <<= 9;
|
||||
sigB <<= 9;
|
||||
if ( expDiff < 0 ) {
|
||||
if ( expB == 0x7FF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
uiZ = packToF64UI( signZ, 0x7FF, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
expZ = expB;
|
||||
if ( expA ) {
|
||||
sigA += UINT64_C( 0x2000000000000000 );
|
||||
} else {
|
||||
sigA <<= 1;
|
||||
}
|
||||
sigA = softfloat_shiftRightJam64( sigA, -expDiff );
|
||||
} else {
|
||||
if ( expA == 0x7FF ) {
|
||||
if ( sigA ) goto propagateNaN;
|
||||
uiZ = uiA;
|
||||
goto uiZ;
|
||||
}
|
||||
expZ = expA;
|
||||
if ( expB ) {
|
||||
sigB += UINT64_C( 0x2000000000000000 );
|
||||
} else {
|
||||
sigB <<= 1;
|
||||
}
|
||||
sigB = softfloat_shiftRightJam64( sigB, expDiff );
|
||||
}
|
||||
sigZ = UINT64_C( 0x2000000000000000 ) + sigA + sigB;
|
||||
if ( sigZ < UINT64_C( 0x4000000000000000 ) ) {
|
||||
--expZ;
|
||||
sigZ <<= 1;
|
||||
}
|
||||
}
|
||||
return softfloat_roundPackToF64( signZ, expZ, sigZ );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN:
|
||||
uiZ = softfloat_propagateNaNF64UI( uiA, uiB );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
74
src/common/softfloat/source/s_approxRecipSqrt32_1.c
Normal file
74
src/common/softfloat/source/s_approxRecipSqrt32_1.c
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "primitives.h"
|
||||
|
||||
#ifndef softfloat_approxRecipSqrt32_1
|
||||
|
||||
extern const uint16_t softfloat_approxRecipSqrt_1k0s[];
|
||||
extern const uint16_t softfloat_approxRecipSqrt_1k1s[];
|
||||
|
||||
uint32_t softfloat_approxRecipSqrt32_1( unsigned int oddExpA, uint32_t a )
|
||||
{
|
||||
int index;
|
||||
uint16_t eps, r0;
|
||||
uint_fast32_t ESqrR0;
|
||||
uint32_t sigma0;
|
||||
uint_fast32_t r;
|
||||
uint32_t sqrSigma0;
|
||||
|
||||
index = (a>>27 & 0xE) + oddExpA;
|
||||
eps = (uint16_t) (a>>12);
|
||||
r0 = softfloat_approxRecipSqrt_1k0s[index]
|
||||
- ((softfloat_approxRecipSqrt_1k1s[index] * (uint_fast32_t) eps)
|
||||
>>20);
|
||||
ESqrR0 = (uint_fast32_t) r0 * r0;
|
||||
if ( ! oddExpA ) ESqrR0 <<= 1;
|
||||
sigma0 = ~(uint_fast32_t) (((uint32_t) ESqrR0 * (uint_fast64_t) a)>>23);
|
||||
r = ((uint_fast32_t) r0<<16) + ((r0 * (uint_fast64_t) sigma0)>>25);
|
||||
sqrSigma0 = ((uint_fast64_t) sigma0 * sigma0)>>32;
|
||||
r += ((uint32_t) ((r>>1) + (r>>3) - ((uint_fast32_t) r0<<14))
|
||||
* (uint_fast64_t) sqrSigma0)
|
||||
>>48;
|
||||
if ( ! (r & 0x80000000) ) r = 0x80000000;
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
49
src/common/softfloat/source/s_approxRecipSqrt_1Ks.c
Normal file
49
src/common/softfloat/source/s_approxRecipSqrt_1Ks.c
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "primitives.h"
|
||||
|
||||
const uint16_t softfloat_approxRecipSqrt_1k0s[16] = {
|
||||
0xB4C9, 0xFFAB, 0xAA7D, 0xF11C, 0xA1C5, 0xE4C7, 0x9A43, 0xDA29,
|
||||
0x93B5, 0xD0E5, 0x8DED, 0xC8B7, 0x88C6, 0xC16D, 0x8424, 0xBAE1
|
||||
};
|
||||
const uint16_t softfloat_approxRecipSqrt_1k1s[16] = {
|
||||
0xA5A5, 0xEA42, 0x8C21, 0xC62D, 0x788F, 0xAA7F, 0x6928, 0x94B6,
|
||||
0x5CC7, 0x8335, 0x52A6, 0x74E2, 0x4A3E, 0x68FE, 0x432B, 0x5EFD
|
||||
};
|
||||
|
||||
73
src/common/softfloat/source/s_countLeadingZeros64.c
Normal file
73
src/common/softfloat/source/s_countLeadingZeros64.c
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
|
||||
#ifndef softfloat_countLeadingZeros64
|
||||
|
||||
#define softfloat_countLeadingZeros64 softfloat_countLeadingZeros64
|
||||
#include "primitives.h"
|
||||
|
||||
uint_fast8_t softfloat_countLeadingZeros64( uint64_t a )
|
||||
{
|
||||
uint_fast8_t count;
|
||||
uint32_t a32;
|
||||
|
||||
count = 0;
|
||||
a32 = a>>32;
|
||||
if ( ! a32 ) {
|
||||
count = 32;
|
||||
a32 = a;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
| From here, result is current count + count leading zeros of `a32'.
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( a32 < 0x10000 ) {
|
||||
count += 16;
|
||||
a32 <<= 16;
|
||||
}
|
||||
if ( a32 < 0x1000000 ) {
|
||||
count += 8;
|
||||
a32 <<= 8;
|
||||
}
|
||||
count += softfloat_countLeadingZeros8[a32>>24];
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
59
src/common/softfloat/source/s_countLeadingZeros8.c
Normal file
59
src/common/softfloat/source/s_countLeadingZeros8.c
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "primitives.h"
|
||||
|
||||
const uint_least8_t softfloat_countLeadingZeros8[256] = {
|
||||
8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
67
src/common/softfloat/source/s_mul64To128.c
Normal file
67
src/common/softfloat/source/s_mul64To128.c
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "primitiveTypes.h"
|
||||
#include "primitives.h"
|
||||
|
||||
#ifndef softfloat_mul64To128
|
||||
|
||||
struct uint128 softfloat_mul64To128( uint64_t a, uint64_t b )
|
||||
{
|
||||
uint32_t a32, a0, b32, b0;
|
||||
struct uint128 z;
|
||||
uint64_t mid1, mid;
|
||||
|
||||
a32 = a>>32;
|
||||
a0 = a;
|
||||
b32 = b>>32;
|
||||
b0 = b;
|
||||
z.v0 = (uint_fast64_t) a0 * b0;
|
||||
mid1 = (uint_fast64_t) a32 * b0;
|
||||
mid = mid1 + (uint_fast64_t) a0 * b32;
|
||||
z.v64 = (uint_fast64_t) a32 * b32;
|
||||
z.v64 += (uint_fast64_t) (mid < mid1)<<32 | mid>>32;
|
||||
mid <<= 32;
|
||||
z.v0 += mid;
|
||||
z.v64 += (z.v0 < mid);
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
224
src/common/softfloat/source/s_mulAddF32.c
Normal file
224
src/common/softfloat/source/s_mulAddF32.c
Normal file
@@ -0,0 +1,224 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t
|
||||
softfloat_mulAddF32(
|
||||
uint_fast32_t uiA, uint_fast32_t uiB, uint_fast32_t uiC, uint_fast8_t op )
|
||||
{
|
||||
bool signA;
|
||||
int_fast16_t expA;
|
||||
uint_fast32_t sigA;
|
||||
bool signB;
|
||||
int_fast16_t expB;
|
||||
uint_fast32_t sigB;
|
||||
bool signC;
|
||||
int_fast16_t expC;
|
||||
uint_fast32_t sigC;
|
||||
bool signProd;
|
||||
uint_fast32_t magBits, uiZ;
|
||||
struct exp16_sig32 normExpSig;
|
||||
int_fast16_t expProd;
|
||||
uint_fast64_t sigProd;
|
||||
bool signZ;
|
||||
int_fast16_t expZ;
|
||||
uint_fast32_t sigZ;
|
||||
int_fast16_t expDiff;
|
||||
uint_fast64_t sig64Z, sig64C;
|
||||
int_fast8_t shiftDist;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
signA = signF32UI( uiA );
|
||||
expA = expF32UI( uiA );
|
||||
sigA = fracF32UI( uiA );
|
||||
signB = signF32UI( uiB );
|
||||
expB = expF32UI( uiB );
|
||||
sigB = fracF32UI( uiB );
|
||||
signC = signF32UI( uiC ) ^ (op == softfloat_mulAdd_subC);
|
||||
expC = expF32UI( uiC );
|
||||
sigC = fracF32UI( uiC );
|
||||
signProd = signA ^ signB ^ (op == softfloat_mulAdd_subProd);
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA == 0xFF ) {
|
||||
if ( sigA || ((expB == 0xFF) && sigB) ) goto propagateNaN_ABC;
|
||||
magBits = expB | sigB;
|
||||
goto infProdArg;
|
||||
}
|
||||
if ( expB == 0xFF ) {
|
||||
if ( sigB ) goto propagateNaN_ABC;
|
||||
magBits = expA | sigA;
|
||||
goto infProdArg;
|
||||
}
|
||||
if ( expC == 0xFF ) {
|
||||
if ( sigC ) {
|
||||
uiZ = 0;
|
||||
goto propagateNaN_ZC;
|
||||
}
|
||||
uiZ = uiC;
|
||||
goto uiZ;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! expA ) {
|
||||
if ( ! sigA ) goto zeroProd;
|
||||
normExpSig = softfloat_normSubnormalF32Sig( sigA );
|
||||
expA = normExpSig.exp;
|
||||
sigA = normExpSig.sig;
|
||||
}
|
||||
if ( ! expB ) {
|
||||
if ( ! sigB ) goto zeroProd;
|
||||
normExpSig = softfloat_normSubnormalF32Sig( sigB );
|
||||
expB = normExpSig.exp;
|
||||
sigB = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expProd = expA + expB - 0x7E;
|
||||
sigA = (sigA | 0x00800000)<<7;
|
||||
sigB = (sigB | 0x00800000)<<7;
|
||||
sigProd = (uint_fast64_t) sigA * sigB;
|
||||
if ( sigProd < UINT64_C( 0x2000000000000000 ) ) {
|
||||
--expProd;
|
||||
sigProd <<= 1;
|
||||
}
|
||||
signZ = signProd;
|
||||
if ( ! expC ) {
|
||||
if ( ! sigC ) {
|
||||
expZ = expProd - 1;
|
||||
sigZ = softfloat_shortShiftRightJam64( sigProd, 31 );
|
||||
goto roundPack;
|
||||
}
|
||||
normExpSig = softfloat_normSubnormalF32Sig( sigC );
|
||||
expC = normExpSig.exp;
|
||||
sigC = normExpSig.sig;
|
||||
}
|
||||
sigC = (sigC | 0x00800000)<<6;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expDiff = expProd - expC;
|
||||
if ( signProd == signC ) {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
if ( expDiff <= 0 ) {
|
||||
expZ = expC;
|
||||
sigZ = sigC + softfloat_shiftRightJam64( sigProd, 32 - expDiff );
|
||||
} else {
|
||||
expZ = expProd;
|
||||
sig64Z =
|
||||
sigProd
|
||||
+ softfloat_shiftRightJam64(
|
||||
(uint_fast64_t) sigC<<32, expDiff );
|
||||
sigZ = softfloat_shortShiftRightJam64( sig64Z, 32 );
|
||||
}
|
||||
if ( sigZ < 0x40000000 ) {
|
||||
--expZ;
|
||||
sigZ <<= 1;
|
||||
}
|
||||
} else {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
sig64C = (uint_fast64_t) sigC<<32;
|
||||
if ( expDiff < 0 ) {
|
||||
signZ = signC;
|
||||
expZ = expC;
|
||||
sig64Z = sig64C - softfloat_shiftRightJam64( sigProd, -expDiff );
|
||||
} else if ( ! expDiff ) {
|
||||
expZ = expProd;
|
||||
sig64Z = sigProd - sig64C;
|
||||
if ( ! sig64Z ) goto completeCancellation;
|
||||
if ( sig64Z & UINT64_C( 0x8000000000000000 ) ) {
|
||||
signZ = ! signZ;
|
||||
sig64Z = -sig64Z;
|
||||
}
|
||||
} else {
|
||||
expZ = expProd;
|
||||
sig64Z = sigProd - softfloat_shiftRightJam64( sig64C, expDiff );
|
||||
}
|
||||
shiftDist = softfloat_countLeadingZeros64( sig64Z ) - 1;
|
||||
expZ -= shiftDist;
|
||||
shiftDist -= 32;
|
||||
if ( shiftDist < 0 ) {
|
||||
sigZ = softfloat_shortShiftRightJam64( sig64Z, -shiftDist );
|
||||
} else {
|
||||
sigZ = (uint_fast32_t) sig64Z<<shiftDist;
|
||||
}
|
||||
}
|
||||
roundPack:
|
||||
return softfloat_roundPackToF32( signZ, expZ, sigZ );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN_ABC:
|
||||
uiZ = softfloat_propagateNaNF32UI( uiA, uiB );
|
||||
goto propagateNaN_ZC;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
infProdArg:
|
||||
if ( magBits ) {
|
||||
uiZ = packToF32UI( signProd, 0xFF, 0 );
|
||||
if ( expC != 0xFF ) goto uiZ;
|
||||
if ( sigC ) goto propagateNaN_ZC;
|
||||
if ( signProd == signC ) goto uiZ;
|
||||
}
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF32UI;
|
||||
propagateNaN_ZC:
|
||||
uiZ = softfloat_propagateNaNF32UI( uiZ, uiC );
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
zeroProd:
|
||||
uiZ = uiC;
|
||||
if ( ! (expC | sigC) && (signProd != signC) ) {
|
||||
completeCancellation:
|
||||
uiZ =
|
||||
packToF32UI(
|
||||
(softfloat_roundingMode == softfloat_round_min), 0, 0 );
|
||||
}
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
243
src/common/softfloat/source/s_mulAddF64.c
Normal file
243
src/common/softfloat/source/s_mulAddF64.c
Normal file
@@ -0,0 +1,243 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
|
||||
float64_t
|
||||
softfloat_mulAddF64(
|
||||
uint_fast64_t uiA, uint_fast64_t uiB, uint_fast64_t uiC, uint_fast8_t op )
|
||||
{
|
||||
bool signA;
|
||||
int_fast16_t expA;
|
||||
uint_fast64_t sigA;
|
||||
bool signB;
|
||||
int_fast16_t expB;
|
||||
uint_fast64_t sigB;
|
||||
bool signC;
|
||||
int_fast16_t expC;
|
||||
uint_fast64_t sigC;
|
||||
bool signZ;
|
||||
uint_fast64_t magBits, uiZ;
|
||||
struct exp16_sig64 normExpSig;
|
||||
int_fast16_t expZ;
|
||||
struct uint128 sig128Z;
|
||||
uint_fast64_t sigZ;
|
||||
int_fast16_t expDiff;
|
||||
struct uint128 sig128C;
|
||||
int_fast8_t shiftDist;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
signA = signF64UI( uiA );
|
||||
expA = expF64UI( uiA );
|
||||
sigA = fracF64UI( uiA );
|
||||
signB = signF64UI( uiB );
|
||||
expB = expF64UI( uiB );
|
||||
sigB = fracF64UI( uiB );
|
||||
signC = signF64UI( uiC ) ^ (op == softfloat_mulAdd_subC);
|
||||
expC = expF64UI( uiC );
|
||||
sigC = fracF64UI( uiC );
|
||||
signZ = signA ^ signB ^ (op == softfloat_mulAdd_subProd);
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( expA == 0x7FF ) {
|
||||
if ( sigA || ((expB == 0x7FF) && sigB) ) goto propagateNaN_ABC;
|
||||
magBits = expB | sigB;
|
||||
goto infProdArg;
|
||||
}
|
||||
if ( expB == 0x7FF ) {
|
||||
if ( sigB ) goto propagateNaN_ABC;
|
||||
magBits = expA | sigA;
|
||||
goto infProdArg;
|
||||
}
|
||||
if ( expC == 0x7FF ) {
|
||||
if ( sigC ) {
|
||||
uiZ = 0;
|
||||
goto propagateNaN_ZC;
|
||||
}
|
||||
uiZ = uiC;
|
||||
goto uiZ;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( ! expA ) {
|
||||
if ( ! sigA ) goto zeroProd;
|
||||
normExpSig = softfloat_normSubnormalF64Sig( sigA );
|
||||
expA = normExpSig.exp;
|
||||
sigA = normExpSig.sig;
|
||||
}
|
||||
if ( ! expB ) {
|
||||
if ( ! sigB ) goto zeroProd;
|
||||
normExpSig = softfloat_normSubnormalF64Sig( sigB );
|
||||
expB = normExpSig.exp;
|
||||
sigB = normExpSig.sig;
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expZ = expA + expB - 0x3FE;
|
||||
sigA = (sigA | UINT64_C( 0x0010000000000000 ))<<10;
|
||||
sigB = (sigB | UINT64_C( 0x0010000000000000 ))<<10;
|
||||
sig128Z = softfloat_mul64To128( sigA, sigB );
|
||||
if ( sig128Z.v64 < UINT64_C( 0x2000000000000000 ) ) {
|
||||
--expZ;
|
||||
sig128Z =
|
||||
softfloat_add128(
|
||||
sig128Z.v64, sig128Z.v0, sig128Z.v64, sig128Z.v0 );
|
||||
}
|
||||
if ( ! expC ) {
|
||||
if ( ! sigC ) {
|
||||
--expZ;
|
||||
sigZ = sig128Z.v64<<1 | (sig128Z.v0 != 0);
|
||||
goto roundPack;
|
||||
}
|
||||
normExpSig = softfloat_normSubnormalF64Sig( sigC );
|
||||
expC = normExpSig.exp;
|
||||
sigC = normExpSig.sig;
|
||||
}
|
||||
sigC = (sigC | UINT64_C( 0x0010000000000000 ))<<9;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expDiff = expZ - expC;
|
||||
if ( expDiff < 0 ) {
|
||||
expZ = expC;
|
||||
if ( (signZ == signC) || (expDiff < -1) ) {
|
||||
sig128Z.v64 = softfloat_shiftRightJam64( sig128Z.v64, -expDiff );
|
||||
} else {
|
||||
sig128Z =
|
||||
softfloat_shortShiftRightJam128( sig128Z.v64, sig128Z.v0, 1 );
|
||||
}
|
||||
} else if ( expDiff ) {
|
||||
sig128C = softfloat_shiftRightJam128( sigC, 0, expDiff );
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( signZ == signC ) {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
if ( expDiff <= 0 ) {
|
||||
sigZ = (sigC + sig128Z.v64) | (sig128Z.v0 != 0);
|
||||
} else {
|
||||
sig128Z =
|
||||
softfloat_add128(
|
||||
sig128Z.v64, sig128Z.v0, sig128C.v64, sig128C.v0 );
|
||||
sigZ = sig128Z.v64 | (sig128Z.v0 != 0);
|
||||
}
|
||||
if ( sigZ < UINT64_C( 0x4000000000000000 ) ) {
|
||||
--expZ;
|
||||
sigZ <<= 1;
|
||||
}
|
||||
} else {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
if ( expDiff < 0 ) {
|
||||
signZ = signC;
|
||||
sig128Z = softfloat_sub128( sigC, 0, sig128Z.v64, sig128Z.v0 );
|
||||
} else if ( ! expDiff ) {
|
||||
sig128Z.v64 = sig128Z.v64 - sigC;
|
||||
if ( ! (sig128Z.v64 | sig128Z.v0) ) goto completeCancellation;
|
||||
if ( sig128Z.v64 & UINT64_C( 0x8000000000000000 ) ) {
|
||||
signZ = ! signZ;
|
||||
sig128Z = softfloat_sub128( 0, 0, sig128Z.v64, sig128Z.v0 );
|
||||
}
|
||||
} else {
|
||||
sig128Z =
|
||||
softfloat_sub128(
|
||||
sig128Z.v64, sig128Z.v0, sig128C.v64, sig128C.v0 );
|
||||
}
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
if ( ! sig128Z.v64 ) {
|
||||
expZ -= 64;
|
||||
sig128Z.v64 = sig128Z.v0;
|
||||
sig128Z.v0 = 0;
|
||||
}
|
||||
shiftDist = softfloat_countLeadingZeros64( sig128Z.v64 ) - 1;
|
||||
expZ -= shiftDist;
|
||||
if ( shiftDist < 0 ) {
|
||||
sigZ = softfloat_shortShiftRightJam64( sig128Z.v64, -shiftDist );
|
||||
} else {
|
||||
sig128Z =
|
||||
softfloat_shortShiftLeft128(
|
||||
sig128Z.v64, sig128Z.v0, shiftDist );
|
||||
sigZ = sig128Z.v64;
|
||||
}
|
||||
sigZ |= (sig128Z.v0 != 0);
|
||||
}
|
||||
roundPack:
|
||||
return softfloat_roundPackToF64( signZ, expZ, sigZ );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN_ABC:
|
||||
uiZ = softfloat_propagateNaNF64UI( uiA, uiB );
|
||||
goto propagateNaN_ZC;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
infProdArg:
|
||||
if ( magBits ) {
|
||||
uiZ = packToF64UI( signZ, 0x7FF, 0 );
|
||||
if ( expC != 0x7FF ) goto uiZ;
|
||||
if ( sigC ) goto propagateNaN_ZC;
|
||||
if ( signZ == signC ) goto uiZ;
|
||||
}
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF64UI;
|
||||
propagateNaN_ZC:
|
||||
uiZ = softfloat_propagateNaNF64UI( uiZ, uiC );
|
||||
goto uiZ;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
zeroProd:
|
||||
uiZ = uiC;
|
||||
if ( ! (expC | sigC) && (signZ != signC) ) {
|
||||
completeCancellation:
|
||||
uiZ =
|
||||
packToF64UI(
|
||||
(softfloat_roundingMode == softfloat_round_min), 0, 0 );
|
||||
}
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
|
||||
58
src/common/softfloat/source/s_normRoundPackToF32.c
Normal file
58
src/common/softfloat/source/s_normRoundPackToF32.c
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
|
||||
float32_t
|
||||
softfloat_normRoundPackToF32( bool sign, int_fast16_t exp, uint_fast32_t sig )
|
||||
{
|
||||
int_fast8_t shiftDist;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
shiftDist = softfloat_countLeadingZeros32( sig ) - 1;
|
||||
exp -= shiftDist;
|
||||
if ( (7 <= shiftDist) && ((unsigned int) exp < 0xFD) ) {
|
||||
uZ.ui = packToF32UI( sign, sig ? exp : 0, sig<<(shiftDist - 7) );
|
||||
return uZ.f;
|
||||
} else {
|
||||
return softfloat_roundPackToF32( sign, exp, sig<<shiftDist );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
58
src/common/softfloat/source/s_normRoundPackToF64.c
Normal file
58
src/common/softfloat/source/s_normRoundPackToF64.c
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
|
||||
float64_t
|
||||
softfloat_normRoundPackToF64( bool sign, int_fast16_t exp, uint_fast64_t sig )
|
||||
{
|
||||
int_fast8_t shiftDist;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
shiftDist = softfloat_countLeadingZeros64( sig ) - 1;
|
||||
exp -= shiftDist;
|
||||
if ( (10 <= shiftDist) && ((unsigned int) exp < 0x7FD) ) {
|
||||
uZ.ui = packToF64UI( sign, sig ? exp : 0, sig<<(shiftDist - 10) );
|
||||
return uZ.f;
|
||||
} else {
|
||||
return softfloat_roundPackToF64( sign, exp, sig<<shiftDist );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
52
src/common/softfloat/source/s_normSubnormalF32Sig.c
Normal file
52
src/common/softfloat/source/s_normSubnormalF32Sig.c
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
|
||||
struct exp16_sig32 softfloat_normSubnormalF32Sig( uint_fast32_t sig )
|
||||
{
|
||||
int_fast8_t shiftDist;
|
||||
struct exp16_sig32 z;
|
||||
|
||||
shiftDist = softfloat_countLeadingZeros32( sig ) - 8;
|
||||
z.exp = 1 - shiftDist;
|
||||
z.sig = sig<<shiftDist;
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
52
src/common/softfloat/source/s_normSubnormalF64Sig.c
Normal file
52
src/common/softfloat/source/s_normSubnormalF64Sig.c
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
|
||||
struct exp16_sig64 softfloat_normSubnormalF64Sig( uint_fast64_t sig )
|
||||
{
|
||||
int_fast8_t shiftDist;
|
||||
struct exp16_sig64 z;
|
||||
|
||||
shiftDist = softfloat_countLeadingZeros64( sig ) - 11;
|
||||
z.exp = 1 - shiftDist;
|
||||
z.sig = sig<<shiftDist;
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
113
src/common/softfloat/source/s_roundPackToF16.c
Normal file
113
src/common/softfloat/source/s_roundPackToF16.c
Normal file
@@ -0,0 +1,113 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2017 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float16_t
|
||||
softfloat_roundPackToF16( bool sign, int_fast16_t exp, uint_fast16_t sig )
|
||||
{
|
||||
uint_fast8_t roundingMode;
|
||||
bool roundNearEven;
|
||||
uint_fast8_t roundIncrement, roundBits;
|
||||
bool isTiny;
|
||||
uint_fast16_t uiZ;
|
||||
union ui16_f16 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
roundingMode = softfloat_roundingMode;
|
||||
roundNearEven = (roundingMode == softfloat_round_near_even);
|
||||
roundIncrement = 0x8;
|
||||
if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
|
||||
roundIncrement =
|
||||
(roundingMode
|
||||
== (sign ? softfloat_round_min : softfloat_round_max))
|
||||
? 0xF
|
||||
: 0;
|
||||
}
|
||||
roundBits = sig & 0xF;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( 0x1D <= (unsigned int) exp ) {
|
||||
if ( exp < 0 ) {
|
||||
/*----------------------------------------------------------------
|
||||
*----------------------------------------------------------------*/
|
||||
isTiny =
|
||||
(softfloat_detectTininess == softfloat_tininess_beforeRounding)
|
||||
|| (exp < -1) || (sig + roundIncrement < 0x8000);
|
||||
sig = softfloat_shiftRightJam32( sig, -exp );
|
||||
exp = 0;
|
||||
roundBits = sig & 0xF;
|
||||
if ( isTiny && roundBits ) {
|
||||
softfloat_raiseFlags( softfloat_flag_underflow );
|
||||
}
|
||||
} else if ( (0x1D < exp) || (0x8000 <= sig + roundIncrement) ) {
|
||||
/*----------------------------------------------------------------
|
||||
*----------------------------------------------------------------*/
|
||||
softfloat_raiseFlags(
|
||||
softfloat_flag_overflow | softfloat_flag_inexact );
|
||||
uiZ = packToF16UI( sign, 0x1F, 0 ) - ! roundIncrement;
|
||||
goto uiZ;
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sig = (sig + roundIncrement)>>4;
|
||||
if ( roundBits ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
#ifdef SOFTFLOAT_ROUND_ODD
|
||||
if ( roundingMode == softfloat_round_odd ) {
|
||||
sig |= 1;
|
||||
goto packReturn;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
sig &= ~(uint_fast16_t) (! (roundBits ^ 8) & roundNearEven);
|
||||
if ( ! sig ) exp = 0;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
packReturn:
|
||||
uiZ = packToF16UI( sign, exp, sig );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
113
src/common/softfloat/source/s_roundPackToF32.c
Normal file
113
src/common/softfloat/source/s_roundPackToF32.c
Normal file
@@ -0,0 +1,113 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2017 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t
|
||||
softfloat_roundPackToF32( bool sign, int_fast16_t exp, uint_fast32_t sig )
|
||||
{
|
||||
uint_fast8_t roundingMode;
|
||||
bool roundNearEven;
|
||||
uint_fast8_t roundIncrement, roundBits;
|
||||
bool isTiny;
|
||||
uint_fast32_t uiZ;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
roundingMode = softfloat_roundingMode;
|
||||
roundNearEven = (roundingMode == softfloat_round_near_even);
|
||||
roundIncrement = 0x40;
|
||||
if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
|
||||
roundIncrement =
|
||||
(roundingMode
|
||||
== (sign ? softfloat_round_min : softfloat_round_max))
|
||||
? 0x7F
|
||||
: 0;
|
||||
}
|
||||
roundBits = sig & 0x7F;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( 0xFD <= (unsigned int) exp ) {
|
||||
if ( exp < 0 ) {
|
||||
/*----------------------------------------------------------------
|
||||
*----------------------------------------------------------------*/
|
||||
isTiny =
|
||||
(softfloat_detectTininess == softfloat_tininess_beforeRounding)
|
||||
|| (exp < -1) || (sig + roundIncrement < 0x80000000);
|
||||
sig = softfloat_shiftRightJam32( sig, -exp );
|
||||
exp = 0;
|
||||
roundBits = sig & 0x7F;
|
||||
if ( isTiny && roundBits ) {
|
||||
softfloat_raiseFlags( softfloat_flag_underflow );
|
||||
}
|
||||
} else if ( (0xFD < exp) || (0x80000000 <= sig + roundIncrement) ) {
|
||||
/*----------------------------------------------------------------
|
||||
*----------------------------------------------------------------*/
|
||||
softfloat_raiseFlags(
|
||||
softfloat_flag_overflow | softfloat_flag_inexact );
|
||||
uiZ = packToF32UI( sign, 0xFF, 0 ) - ! roundIncrement;
|
||||
goto uiZ;
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sig = (sig + roundIncrement)>>7;
|
||||
if ( roundBits ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
#ifdef SOFTFLOAT_ROUND_ODD
|
||||
if ( roundingMode == softfloat_round_odd ) {
|
||||
sig |= 1;
|
||||
goto packReturn;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
sig &= ~(uint_fast32_t) (! (roundBits ^ 0x40) & roundNearEven);
|
||||
if ( ! sig ) exp = 0;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
packReturn:
|
||||
uiZ = packToF32UI( sign, exp, sig );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
117
src/common/softfloat/source/s_roundPackToF64.c
Normal file
117
src/common/softfloat/source/s_roundPackToF64.c
Normal file
@@ -0,0 +1,117 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2017 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t
|
||||
softfloat_roundPackToF64( bool sign, int_fast16_t exp, uint_fast64_t sig )
|
||||
{
|
||||
uint_fast8_t roundingMode;
|
||||
bool roundNearEven;
|
||||
uint_fast16_t roundIncrement, roundBits;
|
||||
bool isTiny;
|
||||
uint_fast64_t uiZ;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
roundingMode = softfloat_roundingMode;
|
||||
roundNearEven = (roundingMode == softfloat_round_near_even);
|
||||
roundIncrement = 0x200;
|
||||
if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
|
||||
roundIncrement =
|
||||
(roundingMode
|
||||
== (sign ? softfloat_round_min : softfloat_round_max))
|
||||
? 0x3FF
|
||||
: 0;
|
||||
}
|
||||
roundBits = sig & 0x3FF;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
if ( 0x7FD <= (uint16_t) exp ) {
|
||||
if ( exp < 0 ) {
|
||||
/*----------------------------------------------------------------
|
||||
*----------------------------------------------------------------*/
|
||||
isTiny =
|
||||
(softfloat_detectTininess == softfloat_tininess_beforeRounding)
|
||||
|| (exp < -1)
|
||||
|| (sig + roundIncrement < UINT64_C( 0x8000000000000000 ));
|
||||
sig = softfloat_shiftRightJam64( sig, -exp );
|
||||
exp = 0;
|
||||
roundBits = sig & 0x3FF;
|
||||
if ( isTiny && roundBits ) {
|
||||
softfloat_raiseFlags( softfloat_flag_underflow );
|
||||
}
|
||||
} else if (
|
||||
(0x7FD < exp)
|
||||
|| (UINT64_C( 0x8000000000000000 ) <= sig + roundIncrement)
|
||||
) {
|
||||
/*----------------------------------------------------------------
|
||||
*----------------------------------------------------------------*/
|
||||
softfloat_raiseFlags(
|
||||
softfloat_flag_overflow | softfloat_flag_inexact );
|
||||
uiZ = packToF64UI( sign, 0x7FF, 0 ) - ! roundIncrement;
|
||||
goto uiZ;
|
||||
}
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
sig = (sig + roundIncrement)>>10;
|
||||
if ( roundBits ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
#ifdef SOFTFLOAT_ROUND_ODD
|
||||
if ( roundingMode == softfloat_round_odd ) {
|
||||
sig |= 1;
|
||||
goto packReturn;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
sig &= ~(uint_fast64_t) (! (roundBits ^ 0x200) & roundNearEven);
|
||||
if ( ! sig ) exp = 0;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
packReturn:
|
||||
uiZ = packToF64UI( sign, exp, sig );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
84
src/common/softfloat/source/s_roundToI32.c
Normal file
84
src/common/softfloat/source/s_roundToI32.c
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
int_fast32_t
|
||||
softfloat_roundToI32(
|
||||
bool sign, uint_fast64_t sig, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
bool roundNearEven;
|
||||
uint_fast16_t roundIncrement, roundBits;
|
||||
uint_fast32_t sig32;
|
||||
union { uint32_t ui; int32_t i; } uZ;
|
||||
int_fast32_t z;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
roundNearEven = (roundingMode == softfloat_round_near_even);
|
||||
roundIncrement = 0x800;
|
||||
if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
|
||||
roundIncrement =
|
||||
(roundingMode
|
||||
== (sign ? softfloat_round_min : softfloat_round_max))
|
||||
? 0xFFF
|
||||
: 0;
|
||||
}
|
||||
roundBits = sig & 0xFFF;
|
||||
sig += roundIncrement;
|
||||
if ( sig & UINT64_C( 0xFFFFF00000000000 ) ) goto invalid;
|
||||
sig32 = sig>>12;
|
||||
sig32 &= ~(uint_fast32_t) (! (roundBits ^ 0x800) & roundNearEven);
|
||||
uZ.ui = sign ? -sig32 : sig32;
|
||||
z = uZ.i;
|
||||
if ( z && ((z < 0) ^ sign) ) goto invalid;
|
||||
if ( exact && roundBits ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return z;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return sign ? i32_fromNegOverflow : i32_fromPosOverflow;
|
||||
|
||||
}
|
||||
|
||||
89
src/common/softfloat/source/s_roundToI64.c
Normal file
89
src/common/softfloat/source/s_roundToI64.c
Normal file
@@ -0,0 +1,89 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
int_fast64_t
|
||||
softfloat_roundToI64(
|
||||
bool sign,
|
||||
uint_fast64_t sig,
|
||||
uint_fast64_t sigExtra,
|
||||
uint_fast8_t roundingMode,
|
||||
bool exact
|
||||
)
|
||||
{
|
||||
bool roundNearEven, doIncrement;
|
||||
union { uint64_t ui; int64_t i; } uZ;
|
||||
int_fast64_t z;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
roundNearEven = (roundingMode == softfloat_round_near_even);
|
||||
doIncrement = (UINT64_C( 0x8000000000000000 ) <= sigExtra);
|
||||
if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
|
||||
doIncrement =
|
||||
(roundingMode
|
||||
== (sign ? softfloat_round_min : softfloat_round_max))
|
||||
&& sigExtra;
|
||||
}
|
||||
if ( doIncrement ) {
|
||||
++sig;
|
||||
if ( ! sig ) goto invalid;
|
||||
sig &=
|
||||
~(uint_fast64_t)
|
||||
(! (sigExtra & UINT64_C( 0x7FFFFFFFFFFFFFFF ))
|
||||
& roundNearEven);
|
||||
}
|
||||
uZ.ui = sign ? -sig : sig;
|
||||
z = uZ.i;
|
||||
if ( z && ((z < 0) ^ sign) ) goto invalid;
|
||||
if ( exact && sigExtra ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return z;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return sign ? i64_fromNegOverflow : i64_fromPosOverflow;
|
||||
|
||||
}
|
||||
|
||||
80
src/common/softfloat/source/s_roundToUI32.c
Normal file
80
src/common/softfloat/source/s_roundToUI32.c
Normal file
@@ -0,0 +1,80 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
uint_fast32_t
|
||||
softfloat_roundToUI32(
|
||||
bool sign, uint_fast64_t sig, uint_fast8_t roundingMode, bool exact )
|
||||
{
|
||||
bool roundNearEven;
|
||||
uint_fast16_t roundIncrement, roundBits;
|
||||
uint_fast32_t z;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
roundNearEven = (roundingMode == softfloat_round_near_even);
|
||||
roundIncrement = 0x800;
|
||||
if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
|
||||
roundIncrement =
|
||||
(roundingMode
|
||||
== (sign ? softfloat_round_min : softfloat_round_max))
|
||||
? 0xFFF
|
||||
: 0;
|
||||
}
|
||||
roundBits = sig & 0xFFF;
|
||||
sig += roundIncrement;
|
||||
if ( sig & UINT64_C( 0xFFFFF00000000000 ) ) goto invalid;
|
||||
z = sig>>12;
|
||||
z &= ~(uint_fast32_t) (! (roundBits ^ 0x800) & roundNearEven);
|
||||
if ( sign && z ) goto invalid;
|
||||
if ( exact && roundBits ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return z;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return sign ? ui32_fromNegOverflow : ui32_fromPosOverflow;
|
||||
|
||||
}
|
||||
|
||||
85
src/common/softfloat/source/s_roundToUI64.c
Normal file
85
src/common/softfloat/source/s_roundToUI64.c
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the
|
||||
University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
uint_fast64_t
|
||||
softfloat_roundToUI64(
|
||||
bool sign,
|
||||
uint_fast64_t sig,
|
||||
uint_fast64_t sigExtra,
|
||||
uint_fast8_t roundingMode,
|
||||
bool exact
|
||||
)
|
||||
{
|
||||
bool roundNearEven, doIncrement;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
roundNearEven = (roundingMode == softfloat_round_near_even);
|
||||
doIncrement = (UINT64_C( 0x8000000000000000 ) <= sigExtra);
|
||||
if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
|
||||
doIncrement =
|
||||
(roundingMode
|
||||
== (sign ? softfloat_round_min : softfloat_round_max))
|
||||
&& sigExtra;
|
||||
}
|
||||
if ( doIncrement ) {
|
||||
++sig;
|
||||
if ( ! sig ) goto invalid;
|
||||
sig &=
|
||||
~(uint_fast64_t)
|
||||
(! (sigExtra & UINT64_C( 0x7FFFFFFFFFFFFFFF ))
|
||||
& roundNearEven);
|
||||
}
|
||||
if ( sign && sig ) goto invalid;
|
||||
if ( exact && sigExtra ) {
|
||||
softfloat_exceptionFlags |= softfloat_flag_inexact;
|
||||
}
|
||||
return sig;
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
invalid:
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
return sign ? ui64_fromNegOverflow : ui64_fromPosOverflow;
|
||||
|
||||
}
|
||||
|
||||
70
src/common/softfloat/source/s_shiftRightJam128.c
Normal file
70
src/common/softfloat/source/s_shiftRightJam128.c
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "primitiveTypes.h"
|
||||
#include "primitives.h"
|
||||
|
||||
#ifndef softfloat_shiftRightJam128
|
||||
|
||||
struct uint128
|
||||
softfloat_shiftRightJam128( uint64_t a64, uint64_t a0, uint_fast32_t dist )
|
||||
{
|
||||
uint_fast8_t u8NegDist;
|
||||
struct uint128 z;
|
||||
|
||||
if ( dist < 64 ) {
|
||||
u8NegDist = -dist;
|
||||
z.v64 = a64>>dist;
|
||||
z.v0 =
|
||||
a64<<(u8NegDist & 63) | a0>>dist
|
||||
| ((uint64_t) (a0<<(u8NegDist & 63)) != 0);
|
||||
} else {
|
||||
z.v64 = 0;
|
||||
z.v0 =
|
||||
(dist < 127)
|
||||
? a64>>(dist & 63)
|
||||
| (((a64 & (((uint_fast64_t) 1<<(dist & 63)) - 1)) | a0)
|
||||
!= 0)
|
||||
: ((a64 | a0) != 0);
|
||||
}
|
||||
return z;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
143
src/common/softfloat/source/s_subMagsF32.c
Normal file
143
src/common/softfloat/source/s_subMagsF32.c
Normal file
@@ -0,0 +1,143 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t softfloat_subMagsF32( uint_fast32_t uiA, uint_fast32_t uiB )
|
||||
{
|
||||
int_fast16_t expA;
|
||||
uint_fast32_t sigA;
|
||||
int_fast16_t expB;
|
||||
uint_fast32_t sigB;
|
||||
int_fast16_t expDiff;
|
||||
uint_fast32_t uiZ;
|
||||
int_fast32_t sigDiff;
|
||||
bool signZ;
|
||||
int_fast8_t shiftDist;
|
||||
int_fast16_t expZ;
|
||||
uint_fast32_t sigX, sigY;
|
||||
union ui32_f32 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expA = expF32UI( uiA );
|
||||
sigA = fracF32UI( uiA );
|
||||
expB = expF32UI( uiB );
|
||||
sigB = fracF32UI( uiB );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expDiff = expA - expB;
|
||||
if ( ! expDiff ) {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
if ( expA == 0xFF ) {
|
||||
if ( sigA | sigB ) goto propagateNaN;
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF32UI;
|
||||
goto uiZ;
|
||||
}
|
||||
sigDiff = sigA - sigB;
|
||||
if ( ! sigDiff ) {
|
||||
uiZ =
|
||||
packToF32UI(
|
||||
(softfloat_roundingMode == softfloat_round_min), 0, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
if ( expA ) --expA;
|
||||
signZ = signF32UI( uiA );
|
||||
if ( sigDiff < 0 ) {
|
||||
signZ = ! signZ;
|
||||
sigDiff = -sigDiff;
|
||||
}
|
||||
shiftDist = softfloat_countLeadingZeros32( sigDiff ) - 8;
|
||||
expZ = expA - shiftDist;
|
||||
if ( expZ < 0 ) {
|
||||
shiftDist = expA;
|
||||
expZ = 0;
|
||||
}
|
||||
uiZ = packToF32UI( signZ, expZ, sigDiff<<shiftDist );
|
||||
goto uiZ;
|
||||
} else {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
signZ = signF32UI( uiA );
|
||||
sigA <<= 7;
|
||||
sigB <<= 7;
|
||||
if ( expDiff < 0 ) {
|
||||
/*----------------------------------------------------------------
|
||||
*----------------------------------------------------------------*/
|
||||
signZ = ! signZ;
|
||||
if ( expB == 0xFF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
uiZ = packToF32UI( signZ, 0xFF, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
expZ = expB - 1;
|
||||
sigX = sigB | 0x40000000;
|
||||
sigY = sigA + (expA ? 0x40000000 : sigA);
|
||||
expDiff = -expDiff;
|
||||
} else {
|
||||
/*----------------------------------------------------------------
|
||||
*----------------------------------------------------------------*/
|
||||
if ( expA == 0xFF ) {
|
||||
if ( sigA ) goto propagateNaN;
|
||||
uiZ = uiA;
|
||||
goto uiZ;
|
||||
}
|
||||
expZ = expA - 1;
|
||||
sigX = sigA | 0x40000000;
|
||||
sigY = sigB + (expB ? 0x40000000 : sigB);
|
||||
}
|
||||
return
|
||||
softfloat_normRoundPackToF32(
|
||||
signZ, expZ, sigX - softfloat_shiftRightJam32( sigY, expDiff )
|
||||
);
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN:
|
||||
uiZ = softfloat_propagateNaNF32UI( uiA, uiB );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
141
src/common/softfloat/source/s_subMagsF64.c
Normal file
141
src/common/softfloat/source/s_subMagsF64.c
Normal file
@@ -0,0 +1,141 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t
|
||||
softfloat_subMagsF64( uint_fast64_t uiA, uint_fast64_t uiB, bool signZ )
|
||||
{
|
||||
int_fast16_t expA;
|
||||
uint_fast64_t sigA;
|
||||
int_fast16_t expB;
|
||||
uint_fast64_t sigB;
|
||||
int_fast16_t expDiff;
|
||||
uint_fast64_t uiZ;
|
||||
int_fast64_t sigDiff;
|
||||
int_fast8_t shiftDist;
|
||||
int_fast16_t expZ;
|
||||
uint_fast64_t sigZ;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expA = expF64UI( uiA );
|
||||
sigA = fracF64UI( uiA );
|
||||
expB = expF64UI( uiB );
|
||||
sigB = fracF64UI( uiB );
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
expDiff = expA - expB;
|
||||
if ( ! expDiff ) {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
if ( expA == 0x7FF ) {
|
||||
if ( sigA | sigB ) goto propagateNaN;
|
||||
softfloat_raiseFlags( softfloat_flag_invalid );
|
||||
uiZ = defaultNaNF64UI;
|
||||
goto uiZ;
|
||||
}
|
||||
sigDiff = sigA - sigB;
|
||||
if ( ! sigDiff ) {
|
||||
uiZ =
|
||||
packToF64UI(
|
||||
(softfloat_roundingMode == softfloat_round_min), 0, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
if ( expA ) --expA;
|
||||
if ( sigDiff < 0 ) {
|
||||
signZ = ! signZ;
|
||||
sigDiff = -sigDiff;
|
||||
}
|
||||
shiftDist = softfloat_countLeadingZeros64( sigDiff ) - 11;
|
||||
expZ = expA - shiftDist;
|
||||
if ( expZ < 0 ) {
|
||||
shiftDist = expA;
|
||||
expZ = 0;
|
||||
}
|
||||
uiZ = packToF64UI( signZ, expZ, sigDiff<<shiftDist );
|
||||
goto uiZ;
|
||||
} else {
|
||||
/*--------------------------------------------------------------------
|
||||
*--------------------------------------------------------------------*/
|
||||
sigA <<= 10;
|
||||
sigB <<= 10;
|
||||
if ( expDiff < 0 ) {
|
||||
/*----------------------------------------------------------------
|
||||
*----------------------------------------------------------------*/
|
||||
signZ = ! signZ;
|
||||
if ( expB == 0x7FF ) {
|
||||
if ( sigB ) goto propagateNaN;
|
||||
uiZ = packToF64UI( signZ, 0x7FF, 0 );
|
||||
goto uiZ;
|
||||
}
|
||||
sigA += expA ? UINT64_C( 0x4000000000000000 ) : sigA;
|
||||
sigA = softfloat_shiftRightJam64( sigA, -expDiff );
|
||||
sigB |= UINT64_C( 0x4000000000000000 );
|
||||
expZ = expB;
|
||||
sigZ = sigB - sigA;
|
||||
} else {
|
||||
/*----------------------------------------------------------------
|
||||
*----------------------------------------------------------------*/
|
||||
if ( expA == 0x7FF ) {
|
||||
if ( sigA ) goto propagateNaN;
|
||||
uiZ = uiA;
|
||||
goto uiZ;
|
||||
}
|
||||
sigB += expB ? UINT64_C( 0x4000000000000000 ) : sigB;
|
||||
sigB = softfloat_shiftRightJam64( sigB, expDiff );
|
||||
sigA |= UINT64_C( 0x4000000000000000 );
|
||||
expZ = expA;
|
||||
sigZ = sigA - sigB;
|
||||
}
|
||||
return softfloat_normRoundPackToF64( signZ, expZ - 1, sigZ );
|
||||
}
|
||||
/*------------------------------------------------------------------------
|
||||
*------------------------------------------------------------------------*/
|
||||
propagateNaN:
|
||||
uiZ = softfloat_propagateNaNF64UI( uiA, uiB );
|
||||
uiZ:
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
49
src/common/softfloat/source/softfloat_state.c
Normal file
49
src/common/softfloat/source/softfloat_state.c
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All Rights Reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "specialize.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
#ifndef THREAD_LOCAL
|
||||
#define THREAD_LOCAL
|
||||
#endif
|
||||
|
||||
THREAD_LOCAL uint_fast8_t softfloat_roundingMode = softfloat_round_near_even;
|
||||
THREAD_LOCAL uint_fast8_t softfloat_detectTininess = init_detectTininess;
|
||||
THREAD_LOCAL uint_fast8_t softfloat_exceptionFlags = 0;
|
||||
57
src/common/softfloat/source/ui32_to_f32.c
Normal file
57
src/common/softfloat/source/ui32_to_f32.c
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All Rights Reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t ui32_to_f32( uint32_t a )
|
||||
{
|
||||
union ui32_f32 uZ;
|
||||
|
||||
if ( ! a ) {
|
||||
uZ.ui = 0;
|
||||
return uZ.f;
|
||||
}
|
||||
if ( a & 0x80000000 ) {
|
||||
return softfloat_roundPackToF32( 0, 0x9D, a>>1 | (a & 1) );
|
||||
} else {
|
||||
return softfloat_normRoundPackToF32( 0, 0x9C, a );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
59
src/common/softfloat/source/ui32_to_f64.c
Normal file
59
src/common/softfloat/source/ui32_to_f64.c
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All Rights Reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t ui32_to_f64( uint32_t a )
|
||||
{
|
||||
uint_fast64_t uiZ;
|
||||
int_fast8_t shiftDist;
|
||||
union ui64_f64 uZ;
|
||||
|
||||
if ( ! a ) {
|
||||
uiZ = 0;
|
||||
} else {
|
||||
shiftDist = softfloat_countLeadingZeros32( a ) + 21;
|
||||
uiZ =
|
||||
packToF64UI( 0, 0x432 - shiftDist, (uint_fast64_t) a<<shiftDist );
|
||||
}
|
||||
uZ.ui = uiZ;
|
||||
return uZ.f;
|
||||
|
||||
}
|
||||
|
||||
64
src/common/softfloat/source/ui64_to_f32.c
Normal file
64
src/common/softfloat/source/ui64_to_f32.c
Normal file
@@ -0,0 +1,64 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
|
||||
California. All Rights Reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float32_t ui64_to_f32( uint64_t a )
|
||||
{
|
||||
int_fast8_t shiftDist;
|
||||
union ui32_f32 u;
|
||||
uint_fast32_t sig;
|
||||
|
||||
shiftDist = softfloat_countLeadingZeros64( a ) - 40;
|
||||
if ( 0 <= shiftDist ) {
|
||||
u.ui =
|
||||
a ? packToF32UI(
|
||||
0, 0x95 - shiftDist, (uint_fast32_t) a<<shiftDist )
|
||||
: 0;
|
||||
return u.f;
|
||||
} else {
|
||||
shiftDist += 7;
|
||||
sig =
|
||||
(shiftDist < 0) ? softfloat_shortShiftRightJam64( a, -shiftDist )
|
||||
: (uint_fast32_t) a<<shiftDist;
|
||||
return softfloat_roundPackToF32( 0, 0x9C - shiftDist, sig );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
59
src/common/softfloat/source/ui64_to_f64.c
Normal file
59
src/common/softfloat/source/ui64_to_f64.c
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
/*============================================================================
|
||||
|
||||
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
|
||||
Package, Release 3d, by John R. Hauser.
|
||||
|
||||
Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
|
||||
All Rights Reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions, and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions, and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the University nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform.h"
|
||||
#include "internals.h"
|
||||
#include "softfloat.h"
|
||||
|
||||
float64_t ui64_to_f64( uint64_t a )
|
||||
{
|
||||
union ui64_f64 uZ;
|
||||
|
||||
if ( ! a ) {
|
||||
uZ.ui = 0;
|
||||
return uZ.f;
|
||||
}
|
||||
if ( a & UINT64_C( 0x8000000000000000 ) ) {
|
||||
return
|
||||
softfloat_roundPackToF64(
|
||||
0, 0x43D, softfloat_shortShiftRightJam64( a, 1 ) );
|
||||
} else {
|
||||
return softfloat_normRoundPackToF64( 0, 0x43C, a );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user