pkarashchenko commented on code in PR #6482:
URL: https://github.com/apache/incubator-nuttx/pull/6482#discussion_r907041715


##########
include/endian.h:
##########
@@ -51,23 +51,40 @@
 
 /* Common byte swapping macros */
 
-#define __SWAP_UINT16_ISMACRO 1
-#undef  __SWAP_UINT32_ISMACRO
-
-#ifdef __SWAP_UINT16_ISMACRO
+#ifdef CONFIG_HAVE_BUILTIN_BSWAP16
+#  define __swap_uint16 __builtin_bswap16
+#else
 #  define __swap_uint16(n) \
     (uint16_t)(((((uint16_t)(n)) & 0x00ff) << 8) | \
                ((((uint16_t)(n)) >> 8) & 0x00ff))
 #endif
 
-#ifdef __SWAP_UINT32_ISMACRO
+#ifdef CONFIG_HAVE_BUILTIN_BSWAP32
+#  define __swap_uint32 __builtin_bswap32
+#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
 
+#ifdef CONFIG_HAVE_LONG_LONG
+#  ifdef CONFIG_HAVE_BUILTIN_BSWAP64
+#    define __swap_uint64 __builtin_bswap64
+#  else
+#    define __swap_uint64(n) \
+        (uint64_t)(((((uint64_t)(n)) & 0x00000000000000ffULL) << 56) | \
+                ((((uint64_t)(n)) & 0x000000000000ff00ULL) << 40) | \
+                ((((uint64_t)(n)) & 0x0000000000ff0000ULL) << 24) | \
+                ((((uint64_t)(n)) & 0x00000000ff000000ULL) <<  8) | \
+                ((((uint64_t)(n)) & 0x000000ff00000000ULL) >>  8) | \
+                ((((uint64_t)(n)) & 0x0000ff0000000000ULL) >> 24) | \
+                ((((uint64_t)(n)) & 0x00ff000000000000ULL) >> 40) | \
+                ((((uint64_t)(n)) & 0xff00000000000000ULL) >> 56))

Review Comment:
   ```suggestion
           (uint64_t)(((((uint64_t)(n)) & 0x00000000000000ffULL) << 56) | \
                      ((((uint64_t)(n)) & 0x000000000000ff00ULL) << 40) | \
                      ((((uint64_t)(n)) & 0x0000000000ff0000ULL) << 24) | \
                      ((((uint64_t)(n)) & 0x00000000ff000000ULL) <<  8) | \
                      ((((uint64_t)(n)) & 0x000000ff00000000ULL) >>  8) | \
                      ((((uint64_t)(n)) & 0x0000ff0000000000ULL) >> 24) | \
                      ((((uint64_t)(n)) & 0x00ff000000000000ULL) >> 40) | \
                      ((((uint64_t)(n)) & 0xff00000000000000ULL) >> 56))
   ```



-- 
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

Reply via email to