1 2 /*============================================================================ 3 4 This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic 5 Package, Release 3a, by John R. Hauser. 6 7 Copyright 2011, 2012, 2013, 2014 The Regents of the University of California. 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions are met: 12 13 1. Redistributions of source code must retain the above copyright notice, 14 this list of conditions, and the following disclaimer. 15 16 2. Redistributions in binary form must reproduce the above copyright notice, 17 this list of conditions, and the following disclaimer in the documentation 18 and/or other materials provided with the distribution. 19 20 3. Neither the name of the University nor the names of its contributors may 21 be used to endorse or promote products derived from this software without 22 specific prior written permission. 23 24 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE 27 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 35 =============================================================================*/ 36 37 38 /*============================================================================ 39 | Note: If SoftFloat is made available as a general library for programs to 40 | use, it is strongly recommended that a platform-specific version of this 41 | header, "softfloat.h", be created that folds in "softfloat_types.h" and that 42 | eliminates all dependencies on compile-time macros. 43 *============================================================================*/ 44 45 46 #ifndef softfloat_h 47 #define softfloat_h 1 48 49 #include <stdbool.h> 50 #include <stdint.h> 51 52 #include "softfloat_types.h" 53 54 /*---------------------------------------------------------------------------- 55 | Software floating-point underflow tininess-detection mode. 56 *----------------------------------------------------------------------------*/ 57 extern uint_fast8_t softfloat_detectTininess; 58 enum { 59 softfloat_tininess_beforeRounding = 0, 60 softfloat_tininess_afterRounding = 1 61 }; 62 63 /*---------------------------------------------------------------------------- 64 | Software floating-point rounding mode. 65 *----------------------------------------------------------------------------*/ 66 extern uint_fast8_t softfloat_roundingMode; 67 enum { 68 softfloat_round_near_even = 0, 69 softfloat_round_minMag = 1, 70 softfloat_round_min = 2, 71 softfloat_round_max = 3, 72 softfloat_round_near_maxMag = 4 73 }; 74 75 /*---------------------------------------------------------------------------- 76 | Software floating-point exception flags. 77 *----------------------------------------------------------------------------*/ 78 extern uint_fast8_t softfloat_exceptionFlags; 79 enum { 80 softfloat_flag_inexact = 1, 81 softfloat_flag_underflow = 2, 82 softfloat_flag_overflow = 4, 83 softfloat_flag_infinite = 8, 84 softfloat_flag_invalid = 16 85 }; 86 87 /*---------------------------------------------------------------------------- 88 | Routine to raise any or all of the software floating-point exception flags. 89 *----------------------------------------------------------------------------*/ 90 void softfloat_raiseFlags( uint_fast8_t ); 91 92 /*---------------------------------------------------------------------------- 93 | Integer-to-floating-point conversion routines. 94 *----------------------------------------------------------------------------*/ 95 float32_t ui32_to_f32( uint32_t ); 96 float64_t ui32_to_f64( uint32_t ); 97 #ifdef SOFTFLOAT_FAST_INT64 98 extFloat80_t ui32_to_extF80( uint32_t ); 99 float128_t ui32_to_f128( uint32_t ); 100 #endif 101 void ui32_to_extF80M( uint32_t, extFloat80_t * ); 102 void ui32_to_f128M( uint32_t, float128_t * ); 103 float32_t ui64_to_f32( uint64_t ); 104 float64_t ui64_to_f64( uint64_t ); 105 #ifdef SOFTFLOAT_FAST_INT64 106 extFloat80_t ui64_to_extF80( uint64_t ); 107 float128_t ui64_to_f128( uint64_t ); 108 #endif 109 void ui64_to_extF80M( uint64_t, extFloat80_t * ); 110 void ui64_to_f128M( uint64_t, float128_t * ); 111 float32_t i32_to_f32( int32_t ); 112 float64_t i32_to_f64( int32_t ); 113 #ifdef SOFTFLOAT_FAST_INT64 114 extFloat80_t i32_to_extF80( int32_t ); 115 float128_t i32_to_f128( int32_t ); 116 #endif 117 void i32_to_extF80M( int32_t, extFloat80_t * ); 118 void i32_to_f128M( int32_t, float128_t * ); 119 float32_t i64_to_f32( int64_t ); 120 float64_t i64_to_f64( int64_t ); 121 #ifdef SOFTFLOAT_FAST_INT64 122 extFloat80_t i64_to_extF80( int64_t ); 123 float128_t i64_to_f128( int64_t ); 124 #endif 125 void i64_to_extF80M( int64_t, extFloat80_t * ); 126 void i64_to_f128M( int64_t, float128_t * ); 127 128 /*---------------------------------------------------------------------------- 129 | 32-bit (single-precision) floating-point operations. 130 *----------------------------------------------------------------------------*/ 131 uint_fast32_t f32_to_ui32( float32_t, uint_fast8_t, bool ); 132 uint_fast64_t f32_to_ui64( float32_t, uint_fast8_t, bool ); 133 int_fast32_t f32_to_i32( float32_t, uint_fast8_t, bool ); 134 int_fast64_t f32_to_i64( float32_t, uint_fast8_t, bool ); 135 uint_fast32_t f32_to_ui32_r_minMag( float32_t, bool ); 136 uint_fast64_t f32_to_ui64_r_minMag( float32_t, bool ); 137 int_fast32_t f32_to_i32_r_minMag( float32_t, bool ); 138 int_fast64_t f32_to_i64_r_minMag( float32_t, bool ); 139 float64_t f32_to_f64( float32_t ); 140 #ifdef SOFTFLOAT_FAST_INT64 141 extFloat80_t f32_to_extF80( float32_t ); 142 float128_t f32_to_f128( float32_t ); 143 #endif 144 void f32_to_extF80M( float32_t, extFloat80_t * ); 145 void f32_to_f128M( float32_t, float128_t * ); 146 float32_t f32_roundToInt( float32_t, uint_fast8_t, bool ); 147 float32_t f32_add( float32_t, float32_t ); 148 float32_t f32_sub( float32_t, float32_t ); 149 float32_t f32_mul( float32_t, float32_t ); 150 float32_t f32_mulAdd( float32_t, float32_t, float32_t ); 151 float32_t f32_div( float32_t, float32_t ); 152 float32_t f32_rem( float32_t, float32_t ); 153 float32_t f32_sqrt( float32_t ); 154 bool f32_eq( float32_t, float32_t ); 155 bool f32_le( float32_t, float32_t ); 156 bool f32_lt( float32_t, float32_t ); 157 bool f32_eq_signaling( float32_t, float32_t ); 158 bool f32_le_quiet( float32_t, float32_t ); 159 bool f32_lt_quiet( float32_t, float32_t ); 160 bool f32_isSignalingNaN( float32_t ); 161 162 /*---------------------------------------------------------------------------- 163 | 64-bit (double-precision) floating-point operations. 164 *----------------------------------------------------------------------------*/ 165 uint_fast32_t f64_to_ui32( float64_t, uint_fast8_t, bool ); 166 uint_fast64_t f64_to_ui64( float64_t, uint_fast8_t, bool ); 167 int_fast32_t f64_to_i32( float64_t, uint_fast8_t, bool ); 168 int_fast64_t f64_to_i64( float64_t, uint_fast8_t, bool ); 169 uint_fast32_t f64_to_ui32_r_minMag( float64_t, bool ); 170 uint_fast64_t f64_to_ui64_r_minMag( float64_t, bool ); 171 int_fast32_t f64_to_i32_r_minMag( float64_t, bool ); 172 int_fast64_t f64_to_i64_r_minMag( float64_t, bool ); 173 float32_t f64_to_f32( float64_t ); 174 #ifdef SOFTFLOAT_FAST_INT64 175 extFloat80_t f64_to_extF80( float64_t ); 176 float128_t f64_to_f128( float64_t ); 177 #endif 178 void f64_to_extF80M( float64_t, extFloat80_t * ); 179 void f64_to_f128M( float64_t, float128_t * ); 180 float64_t f64_roundToInt( float64_t, uint_fast8_t, bool ); 181 float64_t f64_add( float64_t, float64_t ); 182 float64_t f64_sub( float64_t, float64_t ); 183 float64_t f64_mul( float64_t, float64_t ); 184 float64_t f64_mulAdd( float64_t, float64_t, float64_t ); 185 float64_t f64_div( float64_t, float64_t ); 186 float64_t f64_rem( float64_t, float64_t ); 187 float64_t f64_sqrt( float64_t ); 188 bool f64_eq( float64_t, float64_t ); 189 bool f64_le( float64_t, float64_t ); 190 bool f64_lt( float64_t, float64_t ); 191 bool f64_eq_signaling( float64_t, float64_t ); 192 bool f64_le_quiet( float64_t, float64_t ); 193 bool f64_lt_quiet( float64_t, float64_t ); 194 bool f64_isSignalingNaN( float64_t ); 195 196 /*---------------------------------------------------------------------------- 197 | Rounding precision for 80-bit extended double-precision floating-point. 198 | Valid values are 32, 64, and 80. 199 *----------------------------------------------------------------------------*/ 200 extern uint_fast8_t extF80_roundingPrecision; 201 202 /*---------------------------------------------------------------------------- 203 | 80-bit extended double-precision floating-point operations. 204 *----------------------------------------------------------------------------*/ 205 #ifdef SOFTFLOAT_FAST_INT64 206 uint_fast32_t extF80_to_ui32( extFloat80_t, uint_fast8_t, bool ); 207 uint_fast64_t extF80_to_ui64( extFloat80_t, uint_fast8_t, bool ); 208 int_fast32_t extF80_to_i32( extFloat80_t, uint_fast8_t, bool ); 209 int_fast64_t extF80_to_i64( extFloat80_t, uint_fast8_t, bool ); 210 uint_fast32_t extF80_to_ui32_r_minMag( extFloat80_t, bool ); 211 uint_fast64_t extF80_to_ui64_r_minMag( extFloat80_t, bool ); 212 int_fast32_t extF80_to_i32_r_minMag( extFloat80_t, bool ); 213 int_fast64_t extF80_to_i64_r_minMag( extFloat80_t, bool ); 214 float32_t extF80_to_f32( extFloat80_t ); 215 float64_t extF80_to_f64( extFloat80_t ); 216 float128_t extF80_to_f128( extFloat80_t ); 217 extFloat80_t extF80_roundToInt( extFloat80_t, uint_fast8_t, bool ); 218 extFloat80_t extF80_add( extFloat80_t, extFloat80_t ); 219 extFloat80_t extF80_sub( extFloat80_t, extFloat80_t ); 220 extFloat80_t extF80_mul( extFloat80_t, extFloat80_t ); 221 extFloat80_t extF80_div( extFloat80_t, extFloat80_t ); 222 extFloat80_t extF80_rem( extFloat80_t, extFloat80_t ); 223 extFloat80_t extF80_sqrt( extFloat80_t ); 224 bool extF80_eq( extFloat80_t, extFloat80_t ); 225 bool extF80_le( extFloat80_t, extFloat80_t ); 226 bool extF80_lt( extFloat80_t, extFloat80_t ); 227 bool extF80_eq_signaling( extFloat80_t, extFloat80_t ); 228 bool extF80_le_quiet( extFloat80_t, extFloat80_t ); 229 bool extF80_lt_quiet( extFloat80_t, extFloat80_t ); 230 bool extF80_isSignalingNaN( extFloat80_t ); 231 #endif 232 uint_fast32_t extF80M_to_ui32( const extFloat80_t *, uint_fast8_t, bool ); 233 uint_fast64_t extF80M_to_ui64( const extFloat80_t *, uint_fast8_t, bool ); 234 int_fast32_t extF80M_to_i32( const extFloat80_t *, uint_fast8_t, bool ); 235 int_fast64_t extF80M_to_i64( const extFloat80_t *, uint_fast8_t, bool ); 236 uint_fast32_t extF80M_to_ui32_r_minMag( const extFloat80_t *, bool ); 237 uint_fast64_t extF80M_to_ui64_r_minMag( const extFloat80_t *, bool ); 238 int_fast32_t extF80M_to_i32_r_minMag( const extFloat80_t *, bool ); 239 int_fast64_t extF80M_to_i64_r_minMag( const extFloat80_t *, bool ); 240 float32_t extF80M_to_f32( const extFloat80_t * ); 241 float64_t extF80M_to_f64( const extFloat80_t * ); 242 void extF80M_to_f128M( const extFloat80_t *, float128_t * ); 243 void 244 extF80M_roundToInt( 245 const extFloat80_t *, uint_fast8_t, bool, extFloat80_t * ); 246 void extF80M_add( const extFloat80_t *, const extFloat80_t *, extFloat80_t * ); 247 void extF80M_sub( const extFloat80_t *, const extFloat80_t *, extFloat80_t * ); 248 void extF80M_mul( const extFloat80_t *, const extFloat80_t *, extFloat80_t * ); 249 void extF80M_div( const extFloat80_t *, const extFloat80_t *, extFloat80_t * ); 250 void extF80M_rem( const extFloat80_t *, const extFloat80_t *, extFloat80_t * ); 251 void extF80M_sqrt( const extFloat80_t *, extFloat80_t * ); 252 bool extF80M_eq( const extFloat80_t *, const extFloat80_t * ); 253 bool extF80M_le( const extFloat80_t *, const extFloat80_t * ); 254 bool extF80M_lt( const extFloat80_t *, const extFloat80_t * ); 255 bool extF80M_eq_signaling( const extFloat80_t *, const extFloat80_t * ); 256 bool extF80M_le_quiet( const extFloat80_t *, const extFloat80_t * ); 257 bool extF80M_lt_quiet( const extFloat80_t *, const extFloat80_t * ); 258 bool extF80M_isSignalingNaN( const extFloat80_t * ); 259 260 /*---------------------------------------------------------------------------- 261 | 128-bit (quadruple-precision) floating-point operations. 262 *----------------------------------------------------------------------------*/ 263 #ifdef SOFTFLOAT_FAST_INT64 264 uint_fast32_t f128_to_ui32( float128_t, uint_fast8_t, bool ); 265 uint_fast64_t f128_to_ui64( float128_t, uint_fast8_t, bool ); 266 int_fast32_t f128_to_i32( float128_t, uint_fast8_t, bool ); 267 int_fast64_t f128_to_i64( float128_t, uint_fast8_t, bool ); 268 uint_fast32_t f128_to_ui32_r_minMag( float128_t, bool ); 269 uint_fast64_t f128_to_ui64_r_minMag( float128_t, bool ); 270 int_fast32_t f128_to_i32_r_minMag( float128_t, bool ); 271 int_fast64_t f128_to_i64_r_minMag( float128_t, bool ); 272 float32_t f128_to_f32( float128_t ); 273 float64_t f128_to_f64( float128_t ); 274 extFloat80_t f128_to_extF80( float128_t ); 275 float128_t f128_roundToInt( float128_t, uint_fast8_t, bool ); 276 float128_t f128_add( float128_t, float128_t ); 277 float128_t f128_sub( float128_t, float128_t ); 278 float128_t f128_mul( float128_t, float128_t ); 279 float128_t f128_mulAdd( float128_t, float128_t, float128_t ); 280 float128_t f128_div( float128_t, float128_t ); 281 float128_t f128_rem( float128_t, float128_t ); 282 float128_t f128_sqrt( float128_t ); 283 bool f128_eq( float128_t, float128_t ); 284 bool f128_le( float128_t, float128_t ); 285 bool f128_lt( float128_t, float128_t ); 286 bool f128_eq_signaling( float128_t, float128_t ); 287 bool f128_le_quiet( float128_t, float128_t ); 288 bool f128_lt_quiet( float128_t, float128_t ); 289 bool f128_isSignalingNaN( float128_t ); 290 #endif 291 uint_fast32_t f128M_to_ui32( const float128_t *, uint_fast8_t, bool ); 292 uint_fast64_t f128M_to_ui64( const float128_t *, uint_fast8_t, bool ); 293 int_fast32_t f128M_to_i32( const float128_t *, uint_fast8_t, bool ); 294 int_fast64_t f128M_to_i64( const float128_t *, uint_fast8_t, bool ); 295 uint_fast32_t f128M_to_ui32_r_minMag( const float128_t *, bool ); 296 uint_fast64_t f128M_to_ui64_r_minMag( const float128_t *, bool ); 297 int_fast32_t f128M_to_i32_r_minMag( const float128_t *, bool ); 298 int_fast64_t f128M_to_i64_r_minMag( const float128_t *, bool ); 299 float32_t f128M_to_f32( const float128_t * ); 300 float64_t f128M_to_f64( const float128_t * ); 301 void f128M_to_extF80M( const float128_t *, extFloat80_t * ); 302 void f128M_roundToInt( const float128_t *, uint_fast8_t, bool, float128_t * ); 303 void f128M_add( const float128_t *, const float128_t *, float128_t * ); 304 void f128M_sub( const float128_t *, const float128_t *, float128_t * ); 305 void f128M_mul( const float128_t *, const float128_t *, float128_t * ); 306 void 307 f128M_mulAdd( 308 const float128_t *, const float128_t *, const float128_t *, float128_t * 309 ); 310 void f128M_div( const float128_t *, const float128_t *, float128_t * ); 311 void f128M_rem( const float128_t *, const float128_t *, float128_t * ); 312 void f128M_sqrt( const float128_t *, float128_t * ); 313 bool f128M_eq( const float128_t *, const float128_t * ); 314 bool f128M_le( const float128_t *, const float128_t * ); 315 bool f128M_lt( const float128_t *, const float128_t * ); 316 bool f128M_eq_signaling( const float128_t *, const float128_t * ); 317 bool f128M_le_quiet( const float128_t *, const float128_t * ); 318 bool f128M_lt_quiet( const float128_t *, const float128_t * ); 319 bool f128M_isSignalingNaN( const float128_t * ); 320 321 #endif 322 323