From: Eddie Hung Date: Fri, 28 Jun 2019 16:59:47 +0000 (-0700) Subject: Add generic __builtin_bswap32 function X-Git-Tag: working-ls180~1237^2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=38d8806bd74b9bb448c7488ec571e197fe2f96d6;p=yosys.git Add generic __builtin_bswap32 function --- diff --git a/backends/aiger/xaiger.cc b/backends/aiger/xaiger.cc index d373ca77e..eb3d47569 100644 --- a/backends/aiger/xaiger.cc +++ b/backends/aiger/xaiger.cc @@ -25,6 +25,21 @@ #elif defined(__APPLE__) #include #define __builtin_bswap32 OSSwapInt32 +#elif !defined(__GNUC__) +#include +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"