CI
This commit is contained in:
76
external/portable_endian_bswap.h
vendored
76
external/portable_endian_bswap.h
vendored
@@ -5,6 +5,7 @@
|
||||
// an example on how to get the endian conversion functions on different platforms.
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
|
||||
|
||||
@@ -114,64 +115,17 @@
|
||||
|
||||
#endif
|
||||
|
||||
// Adapted from Google's CityHash source code:
|
||||
//
|
||||
// https://github.com/google/cityhash/blob/8af9b8c2b889d80c22d6bc26ba0df1afb79a30db/src/city.cc#L50
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
#include <stdlib.h>
|
||||
#define bswap_16(x) _byteswap_ushort(x)
|
||||
#define bswap_32(x) _byteswap_ulong(x)
|
||||
#define bswap_64(x) _byteswap_uint64(x)
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
// Mac OS X / Darwin features
|
||||
#include <libkern/OSByteOrder.h>
|
||||
#define bswap_16(x) OSSwapInt16(x)
|
||||
#define bswap_32(x) OSSwapInt32(x)
|
||||
#define bswap_64(x) OSSwapInt64(x)
|
||||
|
||||
#elif defined(__sun) || defined(sun)
|
||||
|
||||
#include <sys/byteorder.h>
|
||||
#define bswap_16(x) BSWAP_16(x)
|
||||
#define bswap_32(x) BSWAP_32(x)
|
||||
#define bswap_64(x) BSWAP_64(x)
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
|
||||
#include <sys/endian.h>
|
||||
#define bswap_16(x) bswap16(x)
|
||||
#define bswap_32(x) bswap32(x)
|
||||
#define bswap_64(x) bswap64(x)
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
|
||||
#include <sys/types.h>
|
||||
#define bswap_16(x) swap16(x)
|
||||
#define bswap_32(x) swap32(x)
|
||||
#define bswap_64(x) swap64(x)
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/bswap.h>
|
||||
#if defined(__BSWAP_RENAME) && !defined(__bswap_32)
|
||||
#define bswap_16(x) bswap16(x)
|
||||
#define bswap_32(x) bswap32(x)
|
||||
#define bswap_64(x) bswap64(x)
|
||||
#endif
|
||||
|
||||
#elif __has_builtin(__builtin_bswap16) && __has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64)
|
||||
|
||||
#define bswap_16(x) __builtin_bswap16(x)
|
||||
#define bswap_32(x) __builtin_bswap32(x)
|
||||
#define bswap_64(x) __builtin_bswap64(x)
|
||||
|
||||
#else
|
||||
|
||||
#include <byteswap.h>
|
||||
|
||||
#endif
|
||||
#define bswap_16(x) (((x) & 0xFF00u) >> 8) | \
|
||||
(((x) & 0x00FFu) << 8)
|
||||
#define bswap_32(x) (((x) & 0xFF000000u) >> 24u) | \
|
||||
(((x) & 0x00FF0000u) >> 8u) | \
|
||||
(((x) & 0x0000FF00u) << 8u) | \
|
||||
(((x) & 0x000000FFu) << 24u)
|
||||
#define bswap_64(x) (((x) & 0xFF00000000000000u) >> 56u) | \
|
||||
(((x) & 0x00FF000000000000u) >> 40u) | \
|
||||
(((x) & 0x0000FF0000000000u) >> 24u) | \
|
||||
(((x) & 0x000000FF00000000u) >> 8u) | \
|
||||
(((x) & 0x00000000FF000000u) << 8u) | \
|
||||
(((x) & 0x0000000000FF0000u) << 24u) | \
|
||||
(((x) & 0x000000000000FF00u) << 40u) | \
|
||||
(((x) & 0x00000000000000FFu) << 56u)
|
||||
|
||||
Reference in New Issue
Block a user