Separate detection of GCC builtin bswap() functions for 16b and 32b
This commit is contained in:
parent
cd271d709c
commit
01d9e3a3f7
@ -30,8 +30,12 @@ endif()
|
|||||||
|
|
||||||
# Have builtin byte swap functions ?
|
# Have builtin byte swap functions ?
|
||||||
if(CMAKE_COMPILER_IS_GNUCC)
|
if(CMAKE_COMPILER_IS_GNUCC)
|
||||||
|
# __builtin_bswap16() is missing in x86 GCC version prior to v4.7
|
||||||
|
# See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624
|
||||||
|
check_c_source_compiles("int main() { return (int)__builtin_bswap16(0x1122); }"
|
||||||
|
FOUG_HAVE_GCC_BUILTIN_BSWAP16_FUNC)
|
||||||
check_c_source_compiles("int main() { return (int)__builtin_bswap32(0x11223344); }"
|
check_c_source_compiles("int main() { return (int)__builtin_bswap32(0x11223344); }"
|
||||||
FOUG_HAVE_GCC_BUILTIN_BSWAP_FUNC)
|
FOUG_HAVE_GCC_BUILTIN_BSWAP32_FUNC)
|
||||||
elseif(MSVC)
|
elseif(MSVC)
|
||||||
check_c_source_compiles("#include <stdlib.h>
|
check_c_source_compiles("#include <stdlib.h>
|
||||||
int main() { return (int)_byteswap_ulong(0x11223344); }"
|
int main() { return (int)_byteswap_ulong(0x11223344); }"
|
||||||
|
@ -11,8 +11,12 @@
|
|||||||
#cmakedefine FOUG_HAVE_STRTOF_FUNC
|
#cmakedefine FOUG_HAVE_STRTOF_FUNC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FOUG_HAVE_GCC_BUILTIN_BSWAP_FUNC
|
#ifndef FOUG_HAVE_GCC_BUILTIN_BSWAP16_FUNC
|
||||||
#cmakedefine FOUG_HAVE_GCC_BUILTIN_BSWAP_FUNC
|
#cmakedefine FOUG_HAVE_GCC_BUILTIN_BSWAP16_FUNC
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FOUG_HAVE_GCC_BUILTIN_BSWAP32_FUNC
|
||||||
|
#cmakedefine FOUG_HAVE_GCC_BUILTIN_BSWAP32_FUNC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FOUG_HAVE_MSVC_BUILTIN_BSWAP_FUNC
|
#ifndef FOUG_HAVE_MSVC_BUILTIN_BSWAP_FUNC
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
/*! Returns \p val with the order of bytes reversed, uses compiler builtin functions if available */
|
/*! Returns \p val with the order of bytes reversed, uses compiler builtin functions if available */
|
||||||
FOUG_INLINE static uint16_t foug_uint16_bswap(uint16_t val)
|
FOUG_INLINE static uint16_t foug_uint16_bswap(uint16_t val)
|
||||||
{
|
{
|
||||||
#ifdef FOUG_HAVE_GCC_BUILTIN_BSWAP_FUNC
|
#ifdef FOUG_HAVE_GCC_BUILTIN_BSWAP16_FUNC
|
||||||
return __builtin_bswap16(val);
|
return __builtin_bswap16(val);
|
||||||
#elif defined(FOUG_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
|
#elif defined(FOUG_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
|
||||||
return _byteswap_ushort(val);
|
return _byteswap_ushort(val);
|
||||||
@ -24,7 +24,7 @@ FOUG_INLINE static uint16_t foug_uint16_bswap(uint16_t val)
|
|||||||
/*! Returns \p val with the order of bytes reversed, uses compiler builtin functions if available */
|
/*! Returns \p val with the order of bytes reversed, uses compiler builtin functions if available */
|
||||||
FOUG_INLINE static uint32_t foug_uint32_bswap(uint32_t val)
|
FOUG_INLINE static uint32_t foug_uint32_bswap(uint32_t val)
|
||||||
{
|
{
|
||||||
#ifdef FOUG_HAVE_GCC_BUILTIN_BSWAP_FUNC
|
#ifdef FOUG_HAVE_GCC_BUILTIN_BSWAP32_FUNC
|
||||||
return __builtin_bswap32(val);
|
return __builtin_bswap32(val);
|
||||||
#elif defined(FOUG_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
|
#elif defined(FOUG_HAVE_MSVC_BUILTIN_BSWAP_FUNC)
|
||||||
return _byteswap_ulong(val);
|
return _byteswap_ulong(val);
|
||||||
|
Loading…
Reference in New Issue
Block a user