Move IEEE754 support code to lib/
authorJens Axboe <axboe@kernel.dk>
Thu, 13 Oct 2011 12:12:40 +0000 (14:12 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 13 Oct 2011 12:12:40 +0000 (14:12 +0200)
It's not strictly core code.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Makefile
ieee754.c [deleted file]
ieee754.h [deleted file]
iolog.h
lib/ieee754.c [new file with mode: 0644]
lib/ieee754.h [new file with mode: 0644]
server.c
stat.c

index 8b8898c..6a3f85b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,9 +12,9 @@ UNAME  := $(shell uname)
 SOURCE = gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \
                eta.c verify.c memory.c io_u.c parse.c mutex.c options.c \
                rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \
-               lib/num2str.c $(wildcard crc/*.c) engines/cpu.c \
+               lib/num2str.c lib/ieee754.c $(wildcard crc/*.c) engines/cpu.c \
                engines/mmap.c engines/sync.c engines/null.c engines/net.c \
-               memalign.c server.c client.c iolog.c ieee754.c
+               memalign.c server.c client.c iolog.c
 
 ifeq ($(UNAME), Linux)
   SOURCE += diskutil.c fifo.c blktrace.c helpers.c cgroup.c trim.c \
diff --git a/ieee754.c b/ieee754.c
deleted file mode 100644 (file)
index c7742a2..0000000
--- a/ieee754.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Shamelessly lifted from Beej's Guide to Network Programming, found here:
- *
- * http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#serialization
- *
- * Below code was granted to the public domain.
- */
-#include <inttypes.h>
-#include "ieee754.h"
-
-uint64_t pack754(long double f, unsigned bits, unsigned expbits)
-{
-       long double fnorm;
-       int shift;
-       long long sign, exp, significand;
-       unsigned significandbits = bits - expbits - 1; // -1 for sign bit
-
-       // get this special case out of the way
-       if (f == 0.0)
-               return 0;
-
-       // check sign and begin normalization
-       if (f < 0) {
-               sign = 1;
-               fnorm = -f;
-       } else {
-               sign = 0;
-               fnorm = f;
-       }
-
-       // get the normalized form of f and track the exponent
-       shift = 0;
-       while (fnorm >= 2.0) {
-               fnorm /= 2.0;
-               shift++;
-       }
-       while (fnorm < 1.0) {
-               fnorm *= 2.0;
-               shift--;
-       }
-       fnorm = fnorm - 1.0;
-
-       // calculate the binary form (non-float) of the significand data
-       significand = fnorm * ((1LL << significandbits) + 0.5f);
-
-       // get the biased exponent
-       exp = shift + ((1 << (expbits - 1)) - 1); // shift + bias
-
-       // return the final answer
-       return (sign << (bits - 1)) | (exp << (bits-expbits - 1)) | significand;
-}
-
-long double unpack754(uint64_t i, unsigned bits, unsigned expbits)
-{
-       long double result;
-       long long shift;
-       unsigned bias;
-       unsigned significandbits = bits - expbits - 1; // -1 for sign bit
-
-       if (i == 0)
-               return 0.0;
-
-       // pull the significand
-       result = (i & ((1LL << significandbits) - 1)); // mask
-       result /= (1LL << significandbits); // convert back to float
-       result += 1.0f; // add the one back on
-
-       // deal with the exponent
-       bias = (1 << (expbits - 1)) - 1;
-       shift = ((i >> significandbits) & ((1LL << expbits) - 1)) - bias;
-       while (shift > 0) {
-               result *= 2.0;
-               shift--;
-       }
-       while (shift < 0) {
-               result /= 2.0;
-               shift++;
-       }
-
-       // sign it
-       result *= (i >> (bits - 1)) & 1 ? -1.0 : 1.0;
-
-       return result;
-}
diff --git a/ieee754.h b/ieee754.h
deleted file mode 100644 (file)
index 5af9518..0000000
--- a/ieee754.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef FIO_IEEE754_H
-#define FIO_IEEE754_H
-
-#include <inttypes.h>
-
-extern uint64_t pack754(long double f, unsigned bits, unsigned expbits);
-extern long double unpack754(uint64_t i, unsigned bits, unsigned expbits);
-
-#define fio_double_to_uint64(val)      pack754((val), 64, 11)
-#define fio_uint64_to_double(val)      unpack754((val), 64, 11)
-
-typedef struct fio_fp64 {
-       union {
-               uint64_t i;
-               double f;
-               uint8_t filler[16];
-       } u;
-} fio_fp64_t;
-
-#endif
diff --git a/iolog.h b/iolog.h
index a523d4d..53bb66c 100644 (file)
--- a/iolog.h
+++ b/iolog.h
@@ -1,7 +1,7 @@
 #ifndef FIO_IOLOG_H
 #define FIO_IOLOG_H
 
-#include "ieee754.h"
+#include "lib/ieee754.h"
 
 /*
  * Use for maintaining statistics
diff --git a/lib/ieee754.c b/lib/ieee754.c
new file mode 100644 (file)
index 0000000..c7742a2
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Shamelessly lifted from Beej's Guide to Network Programming, found here:
+ *
+ * http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#serialization
+ *
+ * Below code was granted to the public domain.
+ */
+#include <inttypes.h>
+#include "ieee754.h"
+
+uint64_t pack754(long double f, unsigned bits, unsigned expbits)
+{
+       long double fnorm;
+       int shift;
+       long long sign, exp, significand;
+       unsigned significandbits = bits - expbits - 1; // -1 for sign bit
+
+       // get this special case out of the way
+       if (f == 0.0)
+               return 0;
+
+       // check sign and begin normalization
+       if (f < 0) {
+               sign = 1;
+               fnorm = -f;
+       } else {
+               sign = 0;
+               fnorm = f;
+       }
+
+       // get the normalized form of f and track the exponent
+       shift = 0;
+       while (fnorm >= 2.0) {
+               fnorm /= 2.0;
+               shift++;
+       }
+       while (fnorm < 1.0) {
+               fnorm *= 2.0;
+               shift--;
+       }
+       fnorm = fnorm - 1.0;
+
+       // calculate the binary form (non-float) of the significand data
+       significand = fnorm * ((1LL << significandbits) + 0.5f);
+
+       // get the biased exponent
+       exp = shift + ((1 << (expbits - 1)) - 1); // shift + bias
+
+       // return the final answer
+       return (sign << (bits - 1)) | (exp << (bits-expbits - 1)) | significand;
+}
+
+long double unpack754(uint64_t i, unsigned bits, unsigned expbits)
+{
+       long double result;
+       long long shift;
+       unsigned bias;
+       unsigned significandbits = bits - expbits - 1; // -1 for sign bit
+
+       if (i == 0)
+               return 0.0;
+
+       // pull the significand
+       result = (i & ((1LL << significandbits) - 1)); // mask
+       result /= (1LL << significandbits); // convert back to float
+       result += 1.0f; // add the one back on
+
+       // deal with the exponent
+       bias = (1 << (expbits - 1)) - 1;
+       shift = ((i >> significandbits) & ((1LL << expbits) - 1)) - bias;
+       while (shift > 0) {
+               result *= 2.0;
+               shift--;
+       }
+       while (shift < 0) {
+               result /= 2.0;
+               shift++;
+       }
+
+       // sign it
+       result *= (i >> (bits - 1)) & 1 ? -1.0 : 1.0;
+
+       return result;
+}
diff --git a/lib/ieee754.h b/lib/ieee754.h
new file mode 100644 (file)
index 0000000..5af9518
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef FIO_IEEE754_H
+#define FIO_IEEE754_H
+
+#include <inttypes.h>
+
+extern uint64_t pack754(long double f, unsigned bits, unsigned expbits);
+extern long double unpack754(uint64_t i, unsigned bits, unsigned expbits);
+
+#define fio_double_to_uint64(val)      pack754((val), 64, 11)
+#define fio_uint64_to_double(val)      unpack754((val), 64, 11)
+
+typedef struct fio_fp64 {
+       union {
+               uint64_t i;
+               double f;
+               uint8_t filler[16];
+       } u;
+} fio_fp64_t;
+
+#endif
index 9cbe555..e7a9057 100644 (file)
--- a/server.c
+++ b/server.c
@@ -20,7 +20,7 @@
 #include "fio.h"
 #include "server.h"
 #include "crc/crc16.h"
-#include "ieee754.h"
+#include "lib/ieee754.h"
 
 #include "fio_version.h"
 
diff --git a/stat.c b/stat.c
index 558464f..a053c8b 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -9,7 +9,7 @@
 
 #include "fio.h"
 #include "diskutil.h"
-#include "ieee754.h"
+#include "lib/ieee754.h"
 
 void update_rusage_stat(struct thread_data *td)
 {