Add generic __builtin_bswap32 function
authorEddie Hung <eddie@fpgeh.com>
Fri, 28 Jun 2019 16:59:47 +0000 (09:59 -0700)
committerEddie Hung <eddie@fpgeh.com>
Fri, 28 Jun 2019 16:59:47 +0000 (09:59 -0700)
backends/aiger/xaiger.cc

index d373ca77e1f02a32f69af5196b62d099fa38212d..eb3d475695b7f18d08e3f80d9ba5a37c86e5058f 100644 (file)
 #elif defined(__APPLE__)
 #include <libkern/OSByteOrder.h>
 #define __builtin_bswap32 OSSwapInt32
+#elif !defined(__GNUC__)
+#include <cstdint>
+inline uint32_t __builtin_bswap32(uint32_t x)
+{
+       // https://stackoverflow.com/a/27796212
+       register uint32_t value = number_to_be_reversed;
+       uint8_t lolo = (value >> 0) & 0xFF;
+       uint8_t lohi = (value >> 8) & 0xFF;
+       uint8_t hilo = (value >> 16) & 0xFF;
+       uint8_t hihi = (value >> 24) & 0xFF;
+       return (hihi << 24)
+               | (hilo << 16)
+               | (lohi << 8)
+               | (lolo << 0);
+}
 #endif
 
 #include "kernel/yosys.h"