forked from verificarlo/verificarlo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de4a0d9
commit 7d16ef1
Showing
3 changed files
with
420 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#ifndef __FLOAT_CONST_H__ | ||
#define __FLOAT_CONST_H__ | ||
|
||
// Round to nearest using cast | ||
// Works for standard type, aka double to float, if the ieee rounding flag is | ||
// set to nearest WARNING: For quad to double we notice that the behavior is | ||
// always round toward zero | ||
#define NEAREST_FLOAT(x) ((float)(x)) | ||
#define NEAREST_DOUBLE(x) ((double)(x)) | ||
|
||
// Quad precision sign encoding size | ||
#define QUAD_SIGN_SIZE 1 | ||
// Quad precision quiet nan bit encoding size | ||
#define QUAD_QUIET_NAN_SIZE 1 | ||
// Quad precision exponent encoding size | ||
#define QUAD_EXP_SIZE 15 | ||
// Quad precision pseudo mantissa encoding size | ||
#define QUAD_PMAN_SIZE 112 | ||
// Quad precision pseudo mantissa encoding size in the word containing the 64 | ||
// msb | ||
#define QUAD_HX_PMAN_SIZE 48 | ||
// Quad precison pseudo mantissa encoding size in the word containing the 64 lsb | ||
#define QUAD_LX_PMAN_SIZE 64 | ||
// Quad precision pseudo mantissa encoding size for quiet nan in the word | ||
// containing the 64 msb | ||
#define QUAD_HX_PMAN_QNAN_SIZE 47 | ||
// Quad precison pseudo mantissa encoding size for quiet nan in the word | ||
// containing the 64 lsb | ||
#define QUAD_LX_PMAN_QNAN_SIZE 64 | ||
// Quad precison mantissa size | ||
#define QUAD_PREC 113 | ||
// Quad precison exponent complement | ||
#define QUAD_EXP_COMP 16383 | ||
// Quad precison max exponent | ||
#define QUAD_EXP_MAX 16383 | ||
// Quad precison min exponent | ||
#define QUAD_EXP_MIN 16382 | ||
// Quad precison infinite exponent | ||
#define QUAD_EXP_INF 0x7FFF | ||
// Quad precison mask to remove the sign bit | ||
#define QUAD_HX_ERASE_SIGN 0x7fffffffffffffffULL | ||
// Quad precison 64 msb to encode plus infinity | ||
#define QINF_hx 0x7fff000000000000ULL | ||
// Quad precison 64 msb to encode minus infinity | ||
#define QMINF_hx 0x7fff000000000000ULL | ||
// Quad precison 64 lsb to encode plus infinity | ||
#define QINF_lx 0x0000000000000000ULL | ||
// Quad precison 64 lsb to encode minus infinity | ||
#define QMINF_lx 0x0000000000000000ULL | ||
// Quad precision pseudo mantissa msb set to one | ||
#define QUAD_HX_PMAN_MSB 0x0000800000000000ULL | ||
|
||
// Double precision encoding size | ||
#define DOUBLE_SIGN_SIZE 1 | ||
// Double precision expoenent encoding size | ||
#define DOUBLE_EXP_SIZE 11 | ||
// Double precision pseudo-mantissa encoding size | ||
#define DOUBLE_PMAN_SIZE 52 | ||
// Double precision mantissa size | ||
#define DOUBLE_PREC 53 | ||
// Double precison exponent complement | ||
#define DOUBLE_EXP_COMP 1023 | ||
// Double precison max exponent for normal number | ||
#define DOUBLE_NORMAL_EXP_MAX 1023 | ||
// Double precison max exponent | ||
#define DOUBLE_EXP_MAX 1024 | ||
// Double precison min exponent | ||
#define DOUBLE_EXP_MIN 1022 | ||
// Double precison infinite exponent | ||
#define DOUBLE_EXP_INF 0x7FF | ||
// Double precision plus infinity encoding | ||
#define DOUBLE_PLUS_INF 0x7FF0000000000000ULL | ||
// Double precision pseudo matissa msb set to one | ||
#define DOUBLE_PMAN_MSB 0x0008000000000000ULL | ||
// Double precision mask to erase sign bit | ||
#define DOUBLE_ERASE_SIGN 0x7fffffffffffffffULL | ||
// Double precision mask to extract sign bit | ||
#define DOUBLE_GET_SIGN 0x8000000000000000ULL | ||
// Double precision mask to extract the exponent | ||
#define DOUBLE_GET_EXP 0x7ff0000000000000ULL | ||
// Double precision mask to extract the pseudo mantissa | ||
#define DOUBLE_GET_PMAN 0x000fffffffffffffULL | ||
// Double precision high part mantissa | ||
#define DOUBLE_PMAN_HIGH_SIZE 20 | ||
// Double precision low part mantissa | ||
#define DOUBLE_PMAN_LOW_SIZE 32 | ||
// Double precision mask of 1 | ||
#define DOUBLE_MASK_ONE 0xffffffffffffffffULL | ||
|
||
// single precision encoding size | ||
#define FLOAT_SIGN_SIZE 1 | ||
// Single precision exponent encoding size | ||
#define FLOAT_EXP_SIZE 8 | ||
// Single precision pseudo mantisa encoding size | ||
#define FLOAT_PMAN_SIZE 23 | ||
// single precision mantissa size | ||
#define FLOAT_PREC 24 | ||
// single precison exponent complement | ||
#define FLOAT_EXP_COMP 127 | ||
// single precison max exponent for normal number | ||
#define FLOAT_NORMAL_EXP_MAX 127 | ||
// single precison max exponent | ||
#define FLOAT_EXP_MAX 128 | ||
// single precison min exponent | ||
#define FLOAT_EXP_MIN 126 | ||
// single precison infinite exponent | ||
#define FLOAT_EXP_INF 0xFF | ||
// single precision plus infinity encoding | ||
#define FLOAT_PLUS_INF 0x7F800000 | ||
// Single precision pseudo matissa msb set to one | ||
#define FLOAT_PMAN_MSB 0x00400000 | ||
// Single precision mask to erase sign bit | ||
#define FLOAT_ERASE_SIGN 0x7fffffff | ||
// Single precision mask to extract sign bit | ||
#define FLOAT_GET_SIGN 0x80000000 | ||
// Single precision mask to extract the exponent | ||
#define FLOAT_GET_EXP 0x7F800000 | ||
// Single precision mask to extract the pseudo mantissa | ||
#define FLOAT_GET_PMAN 0x007fffff | ||
// Single precision mask of 1 | ||
#define FLOAT_MASK_ONE 0xffffffffULL | ||
|
||
// Sign encoding size | ||
#define SIGN_SIZE 1 | ||
// 64bit word with msb set to 1 | ||
#define WORD64_MSB 0x8000000000000000ULL | ||
|
||
#endif /* __FLOAT_CONST_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
#ifndef __FLOAT_STRUCT_H_ | ||
#define __FLOAT_STRUCT_H_ | ||
|
||
#include "float_const.h" | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
/* import from <quadmath-imp.h> */ | ||
|
||
/* Frankly, if you have __float128, you have 64-bit integers, right? */ | ||
#ifndef UINT64_C | ||
#error "No way!" | ||
#endif | ||
|
||
/* Main union type we use to manipulate the floating-point type. */ | ||
|
||
typedef union { | ||
__float128 f128; | ||
__uint128_t u128; | ||
__int128_t i128; | ||
|
||
/* Generic fields */ | ||
__float128 type; | ||
__int128_t i; | ||
__uint128_t u; | ||
|
||
struct | ||
#ifdef __MINGW32__ | ||
/* On mingw targets the ms-bitfields option is active by default. | ||
Therefore enforce gnu-bitfield style. */ | ||
__attribute__((gcc_struct)) | ||
#endif | ||
{ | ||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
unsigned sign : QUAD_SIGN_SIZE; | ||
unsigned exponent : QUAD_EXP_SIZE; | ||
uint64_t mant_high : QUAD_HX_PMAN_SIZE; | ||
uint64_t mant_low : QUAD_LX_PMAN_SIZE; | ||
#else | ||
uint64_t mant_low : QUAD_LX_PMAN_SIZE; | ||
uint64_t mant_high : QUAD_HX_PMAN_SIZE; | ||
unsigned exponent : QUAD_EXP_SIZE; | ||
unsigned sign : QUAD_SIGN_SIZE; | ||
#endif | ||
} ieee; | ||
|
||
struct | ||
#ifdef __MINGW32__ | ||
/* On mingw targets the ms-bitfields option is active by default. | ||
Therefore enforce gnu-bitfield style. */ | ||
__attribute__((gcc_struct)) | ||
#endif | ||
{ | ||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
__uint128_t sign : QUAD_SIGN_SIZE; | ||
__uint128_t exponent : QUAD_EXP_SIZE; | ||
__uint128_t mantissa : QUAD_PMAN_SIZE; | ||
#else | ||
__uint128_t mantissa : QUAD_PMAN_SIZE; | ||
__uint128_t exponent : QUAD_EXP_SIZE; | ||
__uint128_t sign : QUAD_SIGN_SIZE; | ||
#endif | ||
} ieee128; | ||
|
||
struct { | ||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
uint64_t high; | ||
uint64_t low; | ||
#else | ||
uint64_t low; | ||
uint64_t high; | ||
#endif | ||
} words64; | ||
|
||
struct { | ||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
uint32_t w0; | ||
uint32_t w1; | ||
uint32_t w2; | ||
uint32_t w3; | ||
#else | ||
uint32_t w3; | ||
uint32_t w2; | ||
uint32_t w1; | ||
uint32_t w0; | ||
#endif | ||
} words32; | ||
|
||
struct | ||
#ifdef __MINGW32__ | ||
/* Make sure we are using gnu-style bitfield handling. */ | ||
__attribute__((gcc_struct)) | ||
#endif | ||
{ | ||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
uint64_t sign : QUAD_SIGN_SIZE; | ||
uint64_t exponent : QUAD_EXP_SIZE; | ||
uint64_t quiet_nan : QUAD_QUIET_NAN_SIZE; | ||
uint64_t mant_high : QUAD_HX_PMAN_QNAN_SIZE; | ||
uint64_t mant_low : QUAD_LX_PMAN_QNAN_SIZE; | ||
#else | ||
uint64_t mant_low : QUAD_LX_PMAN_QNAN_SIZE; | ||
uint64_t mant_high : QUAD_HX_PMAN_QNAN_SIZE; | ||
uint64_t quiet_nan : QUAD_QUIET_NAN_SIZE; | ||
uint64_t exponent : QUAD_EXP_SIZE; | ||
uint64_t sign : QUAD_SIGN_SIZE; | ||
#endif | ||
} nan; | ||
|
||
} binary128; | ||
|
||
typedef union { | ||
|
||
double f64; | ||
uint64_t u64; | ||
int64_t s64; | ||
uint32_t u32[2]; | ||
|
||
/* Generic fields */ | ||
double type; | ||
uint64_t u; | ||
|
||
struct { | ||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
uint64_t sign : DOUBLE_SIGN_SIZE; | ||
uint64_t exponent : DOUBLE_EXP_SIZE; | ||
uint64_t mantissa : DOUBLE_PMAN_SIZE; | ||
#endif | ||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | ||
uint64_t mantissa : DOUBLE_PMAN_SIZE; | ||
uint64_t exponent : DOUBLE_EXP_SIZE; | ||
uint64_t sign : DOUBLE_SIGN_SIZE; | ||
#endif | ||
} ieee; | ||
|
||
struct { | ||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
uint32_t sign : DOUBLE_SIGN_SIZE; | ||
uint32_t exponent : DOUBLE_EXP_SIZE; | ||
uint32_t mantissa_high : DOUBLE_PMAN_HIGH_SIZE; | ||
uint32_t mantissa_low : DOUBLE_PMAN_LOW_SIZE; | ||
#endif | ||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | ||
#if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
uint32_t mantissa_high : DOUBLE_PMAN_HIGH_SIZE; | ||
uint32_t exponent : DOUBLE_EXP_SIZE; | ||
uint32_t sign : DOUBLE_SIGN_SIZE; | ||
uint32_t mantissa_low : DOUBLE_PMAN_LOW_SIZE; | ||
#else | ||
uint32_t mantissa_low : DOUBLE_PMAN_LOW_SIZE; | ||
uint32_t mantissa_high : DOUBLE_PMAN_HIGH_SIZE; | ||
uint32_t exponent : DOUBLE_EXP_SIZE; | ||
uint32_t sign : DOUBLE_SIGN_SIZE; | ||
#endif | ||
#endif | ||
} ieee32; | ||
|
||
} binary64; | ||
|
||
typedef union { | ||
|
||
float f32; | ||
uint32_t u32; | ||
int32_t s32; | ||
|
||
/* Generic fields */ | ||
float type; | ||
uint32_t u; | ||
|
||
struct { | ||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
uint32_t sign : FLOAT_SIGN_SIZE; | ||
uint32_t exponent : FLOAT_EXP_SIZE; | ||
uint32_t mantissa : FLOAT_PMAN_SIZE; | ||
#endif | ||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | ||
uint32_t mantissa : FLOAT_PMAN_SIZE; | ||
uint32_t exponent : FLOAT_EXP_SIZE; | ||
uint32_t sign : FLOAT_SIGN_SIZE; | ||
#endif | ||
} ieee; | ||
|
||
} binary32; | ||
|
||
#define QUADFP_NAN 0 | ||
#define QUADFP_INFINITE 1 | ||
#define QUADFP_ZERO 2 | ||
#define QUADFP_SUBNORMAL 3 | ||
#define QUADFP_NORMAL 4 | ||
#define fpclassifyq(x) \ | ||
__builtin_fpclassify(QUADFP_NAN, QUADFP_INFINITE, QUADFP_NORMAL, \ | ||
QUADFP_SUBNORMAL, QUADFP_ZERO, x) | ||
|
||
#endif /* __FLOAT_STRUCT_H_ */ |
Oops, something went wrong.