From 232f9b73353e0322fe135d3029beecedaed7a17b Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 4 Oct 2011 14:45:20 +0200 Subject: [PATCH 1/1] More endianness for platforms Signed-off-by: Jens Axboe --- SERVER-TODO | 2 +- os/os-freebsd.h | 11 +++++++++++ os/os-solaris.h | 11 +++++++++++ os/os-windows.h | 6 ++++++ os/os.h | 24 ++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/SERVER-TODO b/SERVER-TODO index 8b048cba..3395c493 100644 --- a/SERVER-TODO +++ b/SERVER-TODO @@ -1,2 +1,2 @@ - Passing of float/doubles -- Passing of text +- Endianness coverage diff --git a/os/os-freebsd.h b/os/os-freebsd.h index 317d403f..1a4f1131 100644 --- a/os/os-freebsd.h +++ b/os/os-freebsd.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "../file.h" @@ -18,6 +19,16 @@ #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) diff --git a/os/os-solaris.h b/os/os-solaris.h index c0d3c30f..ef37e499 100644 --- a/os/os-solaris.h +++ b/os/os-solaris.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "../file.h" @@ -24,6 +25,16 @@ #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]; }; diff --git a/os/os-windows.h b/os/os-windows.h index db4127b3..4af212d9 100644 --- a/os/os-windows.h +++ b/os/os-windows.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "../smalloc.h" #include "../file.h" @@ -26,6 +27,11 @@ #define FIO_PREFERRED_ENGINE "windowsaio" +#define FIO_LITTLE_ENDIAN +#define fio_swap16(x) _byteswap_ushort(x) +#define fio_swap32(x) _byteswap_ulong(x) +#define fio_swap64(x) _byteswap_uint64(x) + typedef off_t off64_t; typedef struct { diff --git a/os/os.h b/os/os.h index 2eb38e87..33baf732 100644 --- 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 +#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) { -- 2.25.1