Browse Source

Fix swap() for ByteOrder.h (bsd, linux and non-intel archs)

Signed-off-by: falkTX <falktx@gmail.com>
tags/v2.1-alpha1-winvst
falkTX 6 years ago
parent
commit
71ff98225d
Signed by: falkTX <falktx@gmail.com> GPG Key ID: 2D3445A829213837
1 changed files with 22 additions and 4 deletions
  1. +22
    -4
      source/modules/water/memory/ByteOrder.h

+ 22
- 4
source/modules/water/memory/ByteOrder.h View File

@@ -28,7 +28,11 @@
#include "../water.h"
#ifdef CARLA_OS_MAC
#if defined(CARLA_OS_BSD)
# include <sys/endian.h>
#elif defined(CARLA_OS_LINUX)
# include <byteswap.h>
#elif defined(CARLA_OS_MAC)
# include <libkern/OSByteOrder.h>
#endif
@@ -146,14 +150,24 @@ private:
//==============================================================================
inline uint16 ByteOrder::swap (uint16 n) noexcept
{
#if defined(CARLA_OS_BSD)
return bswap16 (n);
#elif defined(CARLA_OS_LINUX)
return bswap_16 (n);
#else
return static_cast<uint16> ((n << 8) | (n >> 8));
#endif
}
inline uint32 ByteOrder::swap (uint32 n) noexcept
{
#ifdef CARLA_OS_MAC
#if defined(CARLA_OS_BSD)
return bswap32 (n);
#elif defined(CARLA_OS_LINUX)
return bswap_32 (n);
#elif defined(CARLA_OS_MAC)
return OSSwapInt32 (n);
#elif defined(CARLA_OS_WIN) || ! (defined (__arm__) || defined (__arm64__) || defined (__aarch64__))
#elif defined(__i386__) || defined(__x86_64__)
asm("bswap %%eax" : "=a"(n) : "a"(n));
return n;
#else
@@ -163,7 +177,11 @@ inline uint32 ByteOrder::swap (uint32 n) noexcept
inline uint64 ByteOrder::swap (uint64 value) noexcept
{
#ifdef CARLA_OS_MAC
#if defined(CARLA_OS_BSD)
return bswap64 (value);
#elif defined(CARLA_OS_LINUX)
return bswap_64 (value);
#elif defined(CARLA_OS_MAC)
return OSSwapInt64 (value);
#else
return (((uint64) swap ((uint32) value)) << 32) | swap ((uint32) (value >> 32));


Loading…
Cancel
Save