From 48ca891887e8260be43ae641b35c4129fd4d2093 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 15 Jul 2017 03:19:46 +0200 Subject: Generate USING_BINARY{32,64} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/blind-from-portable.c | 3 --- src/blind-to-portable.c | 3 --- src/common.h | 1 + src/generate-macros.c | 22 ++++++++++++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 src/generate-macros.c (limited to 'src') diff --git a/src/blind-from-portable.c b/src/blind-from-portable.c index b9cc08d..5510df5 100644 --- a/src/blind-from-portable.c +++ b/src/blind-from-portable.c @@ -3,9 +3,6 @@ USAGE("[-s]") -#define USING_BINARY32 0 -#define USING_BINARY64 0 - #define CONV(ITYPE, SITYPE, OTYPE, EXPONENT, HA2EXPONENT, FRACTION)\ do {\ static int cache_i = 0;\ diff --git a/src/blind-to-portable.c b/src/blind-to-portable.c index 0a5a04e..39e3d58 100644 --- a/src/blind-to-portable.c +++ b/src/blind-to-portable.c @@ -9,9 +9,6 @@ USAGE("[-s]") -#define USING_BINARY32 0 -#define USING_BINARY64 0 - #define CONV(ITYPE, OTYPE, SOTYPE, EXPONENT, HA2EXPONENT, FRACTION)\ do {\ static int cache_i = 0;\ diff --git a/src/common.h b/src/common.h index db2c66e..a32f1a3 100644 --- a/src/common.h +++ b/src/common.h @@ -17,6 +17,7 @@ # pragma GCC diagnostic ignored "-Wfloat-conversion" #endif +#include "../platform.h" #include "stream.h" #include "util.h" #include "video-math.h" diff --git a/src/generate-macros.c b/src/generate-macros.c new file mode 100644 index 0000000..ef87ad5 --- /dev/null +++ b/src/generate-macros.c @@ -0,0 +1,22 @@ +#include +#include + +int +main(void) +{ + if (sizeof(float) == 4) { + unsigned long int a, b; + a = (unsigned long int)*(uint32_t *)&(float){ (float)(1. / 12.) }; + b = (unsigned long int)*(uint32_t *)&(float){ -(float)(1. / 12.) }; + printf("#define USING_BINARY32 %i\n", + a == 0x3daaaaabUL && b == 0xbdaaaaabUL); + } + if (sizeof(double) == 8) { + unsigned long long int a, b; + a = (unsigned long long int)*(uint64_t *)&(double){ 1. / 12. }; + b = (unsigned long long int)*(uint64_t *)&(double){ -1. / 12. }; + printf("#define USING_BINARY64 %i\n", + a == 0x3fb5555555555555ULL && b == 0xbfb5555555555555ULL); + } + return 0; +} -- cgit v1.2.3-70-g09d2