More endianness for platforms
authorJens Axboe <axboe@kernel.dk>
Tue, 4 Oct 2011 12:45:20 +0000 (14:45 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 4 Oct 2011 12:45:20 +0000 (14:45 +0200)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
SERVER-TODO
os/os-freebsd.h
os/os-solaris.h
os/os-windows.h
os/os.h

index 8b048cba5d419f3349f0670010c6dd3f69911e6d..3395c493ae3790745cbf827da02bc339120382af 100644 (file)
@@ -1,2 +1,2 @@
 - Passing of float/doubles
 - Passing of float/doubles
-- Passing of text
+- Endianness coverage
index 317d403f3bd3f228deeaf7d45f00312986c65be3..1a4f11319b70fe118f2bdac80594362a22d7438b 100644 (file)
@@ -5,6 +5,7 @@
 #include <sys/sysctl.h>
 #include <sys/disk.h>
 #include <sys/thr.h>
 #include <sys/sysctl.h>
 #include <sys/disk.h>
 #include <sys/thr.h>
+#include <sys/endian.h>
 
 #include "../file.h"
 
 
 #include "../file.h"
 
 
 #define OS_MAP_ANON            MAP_ANON
 
 
 #define OS_MAP_ANON            MAP_ANON
 
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define FIO_LITTLE_ENDIAN
+#else
+#define FIO_BIG_ENDIAN
+#endif
+
+#define fio_swap16(x)  bswap16(x)
+#define fio_swap32(x)  bswap32(x)
+#define fio_swap64(x)  bswap64(x)
+
 typedef off_t off64_t;
 
 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
 typedef off_t off64_t;
 
 static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
index c0d3c30f82ba2e93b458d96bb1c5d9ef238eafd8..ef37e499c26105e96ce16740c62198340384d7eb 100644 (file)
@@ -8,6 +8,7 @@
 #include <sys/pset.h>
 #include <sys/mman.h>
 #include <sys/dkio.h>
 #include <sys/pset.h>
 #include <sys/mman.h>
 #include <sys/dkio.h>
+#include <sys/byteorder.h>
 
 #include "../file.h"
 
 
 #include "../file.h"
 
 #define OS_MAP_ANON            MAP_ANON
 #define OS_RAND_MAX            2147483648UL
 
 #define OS_MAP_ANON            MAP_ANON
 #define OS_RAND_MAX            2147483648UL
 
+#if defined(_BIG_ENDIAN)
+#define FIO_BIG_ENDIAN
+#else
+#define FIO_LITTLE_ENDIAN
+#endif
+
+#define fio_swap16(x)  BSWAP_16(x)
+#define fio_swap32(x)  BSWAP_32(x)
+#define fio_swap64(x)  BSWAP_64(x)
+
 struct solaris_rand_seed {
        unsigned short r[3];
 };
 struct solaris_rand_seed {
        unsigned short r[3];
 };
index db4127b3a2e35eed0fa796eec671e7334ad2f21e..4af212d9d195a2a44e0f88bb7f9ce187bc14738c 100644 (file)
@@ -5,6 +5,7 @@
 #include <errno.h>\r
 #include <windows.h>\r
 #include <psapi.h>\r
 #include <errno.h>\r
 #include <windows.h>\r
 #include <psapi.h>\r
+#include <stdlib.h>\r
 \r
 #include "../smalloc.h"\r
 #include "../file.h"\r
 \r
 #include "../smalloc.h"\r
 #include "../file.h"\r
 \r
 #define FIO_PREFERRED_ENGINE   "windowsaio"\r
 \r
 \r
 #define FIO_PREFERRED_ENGINE   "windowsaio"\r
 \r
+#define FIO_LITTLE_ENDIAN\r
+#define fio_swap16(x)  _byteswap_ushort(x)\r
+#define fio_swap32(x)  _byteswap_ulong(x)\r
+#define fio_swap64(x)  _byteswap_uint64(x)\r
+\r
 typedef off_t off64_t;\r
 \r
 typedef struct {\r
 typedef off_t off64_t;\r
 \r
 typedef struct {\r
diff --git a/os/os.h b/os/os.h
index 2eb38e87afda20dae2b52ebd65d1dfc146247e23..33baf73264e6e7b47b5213fd12ae3bc57f52a2b9 100644 (file)
--- a/os/os.h
+++ b/os/os.h
@@ -115,6 +115,30 @@ typedef unsigned long os_cpu_mask_t;
 #define FIO_MAX_JOBS           2048
 #endif
 
 #define FIO_MAX_JOBS           2048
 #endif
 
+#if 0
+static inline uint16 fio_swap16(uint16_t val)
+{
+       return (val << 8) | (val >> 8);
+}
+
+static inline uint32_t bswap_32(uint32_t val)
+{
+       val = ((val & 0xff00ff00UL) >> 8) | ((val & 0x00ff00ffUL) << 8);
+
+       return (val >> 16) | (val << 16);
+}
+
+static inline uint64_t bswap_64(uint64_t x)
+{
+       val = ((val & 0xff00ff00ff00ff00ULL) >> 8) |
+             ((val & 0x00ff00ff00ff00ffULL) << 8);
+       val = ((val & 0xffff0000ffff0000ULL) >> 16) |
+             ((val & 0x0000ffff0000ffffULL) << 16);
+
+       return (val >> 32) | (val << 32);
+}
+#endif
+
 #ifndef FIO_HAVE_BLKTRACE
 static inline int is_blktrace(const char *fname)
 {
 #ifndef FIO_HAVE_BLKTRACE
 static inline int is_blktrace(const char *fname)
 {