From 78aaf1753df8f6ffafc9a82decae7ff89d277e1d Mon Sep 17 00:00:00 2001 From: Jim Date: Sun, 19 Jun 2011 08:56:11 -0400 Subject: [PATCH] Add an inline swab option to swap.h --- swap.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/swap.h b/swap.h index 1072bff..64f5acc 100644 --- a/swap.h +++ b/swap.h @@ -1,5 +1,15 @@ #include +/*** Another swap option: +#include +inline uint32_t bswap2(uint32_t val) +{ +__asm__("bswap %0" : "+r" (val)); +return val; +} +See: http://objectmix.com/asm-x86-asm-370/69484-x86-inline-assembly-bswap.html +***/ + #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) # error Either __BIG_ENDIAN__ or __LITTLE_ENDIAN__ must be defined. #endif