pkarashchenko commented on code in PR #6482: URL: https://github.com/apache/incubator-nuttx/pull/6482#discussion_r904858886
########## include/endian.h: ########## @@ -52,21 +52,50 @@ /* Common byte swapping macros */ #define __SWAP_UINT16_ISMACRO 1 -#undef __SWAP_UINT32_ISMACRO +#define __SWAP_UINT32_ISMACRO 1 +#define __SWAP_UINT64_ISMACRO 1 + #ifdef __SWAP_UINT16_ISMACRO -# define __swap_uint16(n) \ +# ifdef CONFIG_HAVE_BUILTIN_BSWAP16 +# define __swap_uint16(n) ((uint16_t)__builtin_bswap16((uint32_t)(n))) +# else +# define __swap_uint16(n) \ (uint16_t)(((((uint16_t)(n)) & 0x00ff) << 8) | \ ((((uint16_t)(n)) >> 8) & 0x00ff)) +# endif #endif #ifdef __SWAP_UINT32_ISMACRO +#ifdef CONFIG_HAVE_BUILTIN_BSWAP32 +# define __swap_uint32(n) \ + ((uint32_t)__builtin_bswap32((uint32_t)(n))) +#else # define __swap_uint32(n) \ (uint32_t)(((((uint32_t)(n)) & 0x000000ffUL) << 24) | \ ((((uint32_t)(n)) & 0x0000ff00UL) << 8) | \ ((((uint32_t)(n)) & 0x00ff0000UL) >> 8) | \ ((((uint32_t)(n)) & 0xff000000UL) >> 24)) #endif +#endif + +#ifdef __SWAP_UINT64_ISMACRO && CONFIG_HAVE_LONG_LONG +#ifdef CONFIG_HAVE_BUILTIN_BSWAP64 +# define __swap_uint64(n) \ + ((uint64_t)__builtin_bswap64((uint64_t)(n))) Review Comment: ```suggestion # define __swap_uint64 __builtin_bswap64 ``` ########## include/endian.h: ########## @@ -52,21 +52,50 @@ /* Common byte swapping macros */ #define __SWAP_UINT16_ISMACRO 1 -#undef __SWAP_UINT32_ISMACRO +#define __SWAP_UINT32_ISMACRO 1 +#define __SWAP_UINT64_ISMACRO 1 + #ifdef __SWAP_UINT16_ISMACRO -# define __swap_uint16(n) \ +# ifdef CONFIG_HAVE_BUILTIN_BSWAP16 +# define __swap_uint16(n) ((uint16_t)__builtin_bswap16((uint32_t)(n))) +# else +# define __swap_uint16(n) \ (uint16_t)(((((uint16_t)(n)) & 0x00ff) << 8) | \ ((((uint16_t)(n)) >> 8) & 0x00ff)) +# endif #endif #ifdef __SWAP_UINT32_ISMACRO +#ifdef CONFIG_HAVE_BUILTIN_BSWAP32 +# define __swap_uint32(n) \ + ((uint32_t)__builtin_bswap32((uint32_t)(n))) Review Comment: ```suggestion # define __swap_uint32 __builtin_bswap32 ``` ########## include/nuttx/compiler.h: ########## @@ -69,6 +69,36 @@ # undef CONFIG_HAVE_CXX14 #endif +#if defined(__cplusplus) && __cplusplus >= 201703L +# define CONFIG_HAVE_CXX17 1 +#else +# undef CONFIG_HAVE_CXX17 +#endif + + +/* Check for intrinsics */ +#ifdef __has_builtin +# if __has_builtin(__builtin_bswap16) +# define CONFIG_HAVE_BUILTIN_BSWAP16 1 +# endif +# if __has_builtin(__builtin_bswap32) +# define CONFIG_HAVE_BUILTIN_BSWAP32 1 +# endif +# if __has_builtin(__builtin_bswap64) && defined(CONFIG_HAVE_LONG_LONG) +# define CONFIG_HAVE_BUILTIN_BSWAP64 1 +# endif +# if __has_builtin(__builtin_ctz) +# define CONFIG_HAVE_BUILTIN_CTZ 1 +# endif +# if __has_builtin(__builtin_clz) +# define CONFIG_HAVE_BUILTIN_CLZ 1 +# endif +# if __has_builtin(__builtin_popcount) +# define CONFIG_HAVE_BUILTIN_POPCOUNT 1 +# endif +#endif Review Comment: I think Clag also defines `__GNUC__` ########## include/endian.h: ########## @@ -52,21 +52,50 @@ /* Common byte swapping macros */ #define __SWAP_UINT16_ISMACRO 1 -#undef __SWAP_UINT32_ISMACRO +#define __SWAP_UINT32_ISMACRO 1 +#define __SWAP_UINT64_ISMACRO 1 + #ifdef __SWAP_UINT16_ISMACRO -# define __swap_uint16(n) \ +# ifdef CONFIG_HAVE_BUILTIN_BSWAP16 +# define __swap_uint16(n) ((uint16_t)__builtin_bswap16((uint32_t)(n))) Review Comment: ```suggestion # define __swap_uint16 __builtin_bswap16 ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org