aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-07-15 03:19:46 +0200
committerMattias Andrée <maandree@kth.se>2017-07-15 03:19:46 +0200
commit48ca891887e8260be43ae641b35c4129fd4d2093 (patch)
tree6d2215646d8378f2ac07b51098abe9351859141b
parentFix warnings (diff)
downloadblind-48ca891887e8260be43ae641b35c4129fd4d2093.tar.gz
blind-48ca891887e8260be43ae641b35c4129fd4d2093.tar.bz2
blind-48ca891887e8260be43ae641b35c4129fd4d2093.tar.xz
Generate USING_BINARY{32,64}
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--.gitignore2
-rw-r--r--Makefile12
-rw-r--r--TODO1
-rw-r--r--src/blind-from-portable.c3
-rw-r--r--src/blind-to-portable.c3
-rw-r--r--src/common.h1
-rw-r--r--src/generate-macros.c22
7 files changed, 34 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index 62daebd..7c536da 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,8 @@
*.swp
*.o
*.out
+/platform.h
+/generate-macros
/blind-*
!/blind-rotate-90
!/blind-rotate-180
diff --git a/Makefile b/Makefile
index 33ff068..4852381 100644
--- a/Makefile
+++ b/Makefile
@@ -155,9 +155,15 @@ all: $(BIN)
%: %.o $(COMMON_OBJ)
$(CC) -o $@ $^ $(LDFLAGS)
-%.o: src/%.c src/*.h src/*/*.h
+%.o: src/%.c src/*.h src/*/*.h platform.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+generate-macros: src/generate-macros.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $< $(LDFLAGS)
+
+platform.h: generate-macros
+ ./generate-macros > platform.h
+
install: all
mkdir -p -- "$(DESTDIR)$(PREFIX)/bin"
cp -f -- $(BIN) "$(DESTDIR)$(PREFIX)/bin"
@@ -196,9 +202,9 @@ dist:
rm -rf "blind-$(VERSION)"
clean:
- -rm -f $(BIN) *.o blind-$(VERSION).tar.gz
+ -rm -f $(BIN) *.o blind-$(VERSION).tar.gz platform.h generate-macros
-rm -rf "blind-$(VERSION)"
.PHONY: all install uninstall dist clean
-.PRECIOUS: $(COMMON_OBJ)
+.PRECIOUS: $(COMMON_OBJ) platform.h
diff --git a/TODO b/TODO
index 3762ca1..9288654 100644
--- a/TODO
+++ b/TODO
@@ -56,7 +56,6 @@ blind-arithm: add support for multiple streams
Add [-j jobs] to blind-from-video and blind-to-video.
-Generate a header file with the appropriate values for USING_BINARY32, USING_BINARY64.
long double is slightly faster than long.
long double (xyza q) could be added as another format.
unsigned char (xyza 8) could be added as another format, it's probably good for previewing
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 <stdint.h>
+#include <stdio.h>
+
+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;
+}