Cover __APPLE__ too for little to big endian
authorEddie Hung <eddie@fpgeh.com>
Fri, 14 Jun 2019 19:40:51 +0000 (12:40 -0700)
committerEddie Hung <eddie@fpgeh.com>
Fri, 14 Jun 2019 19:40:51 +0000 (12:40 -0700)
backends/aiger/xaiger.cc
frontends/aiger/aigerparse.cc

index 7e22dca7f97d87ceca9a4dfa88a412ee63a77d76..7cb311736ecfcfb4209de6924b30f8e40de557c4 100644 (file)
  *
  */
 
+// https://stackoverflow.com/a/46137633
+#ifdef _MSC_VER
+#include <stdlib.h>
+#define __builtin_bswap32 _byteswap_ulong
+#elif defined(__APPLE__)
+#include <libkern/OSByteOrder.h>
+#define __builtin_bswap32 OSSwapInt32
+#endif
+
 #include "kernel/yosys.h"
 #include "kernel/sigtools.h"
 #include "kernel/utils.h"
@@ -27,11 +36,7 @@ PRIVATE_NAMESPACE_BEGIN
 
 inline int32_t to_big_endian(int32_t i32) {
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#ifdef _WIN32
-       return _byteswap_ulong(i32);
-#else
        return __builtin_bswap32(i32);
-#endif
 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
        return i32;
 #else
index 7d156fe039b05e3b3df6d89c71734ec52f55f561..d378a07b7ae4047ee26ea7276065a7580d8def2f 100644 (file)
 
 #ifdef _WIN32
 #include <libgen.h>
+#endif
+// https://stackoverflow.com/a/46137633
+#ifdef _MSC_VER
 #include <stdlib.h>
+#define __builtin_bswap32 _byteswap_ulong
+#elif defined(__APPLE__)
+#include <libkern/OSByteOrder.h>
+#define __builtin_bswap32 OSSwapInt32
 #endif
 #include <inttypes.h>
 
@@ -37,11 +44,7 @@ YOSYS_NAMESPACE_BEGIN
 
 inline int32_t from_big_endian(int32_t i32) {
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#ifdef _WIN32
-       return _byteswap_ulong(i32);
-#else
        return __builtin_bswap32(i32);
-#endif
 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
        return i32;
 #else