1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Use compiler intrinsics to swap bytes

This commit is contained in:
Matias Fontanini
2016-02-18 20:35:37 -08:00
parent bd31b3648f
commit 5c22cc7985
5 changed files with 50 additions and 6 deletions

View File

@@ -142,3 +142,4 @@ cxx11_check_feature("decltype" HAS_CXX11_DECLTYPE)
cxx11_check_feature("declval" HAS_CXX11_DECLVAL)
cxx11_check_feature("initializer_list" HAS_CXX11_INITIALIZER_LIST)
cxx11_check_feature("rvalue-references" HAS_CXX11_RVALUE_REFERENCES)
cxx11_check_feature("builtin-swap" HAS_GCC_BUILTIN_SWAP)

View File

@@ -0,0 +1,8 @@
#include <stdint.h>
int main() {
uint16_t u16 = __builtin_bswap16(0x9812U);
uint32_t u32 = __builtin_bswap32(0x9812ad81U);
uint64_t u64 = __builtin_bswap64(0x9812ad81f61a890dU);
return (u16 > 0 && u32 > 0 && u64 > 0) ? 0 : 1;
}