xiaoxiang781216 commented on code in PR #10892:
URL: https://github.com/apache/nuttx/pull/10892#discussion_r1354291443


##########
include/nuttx/bits.h:
##########
@@ -26,46 +26,47 @@
  ****************************************************************************/
 
 #include <assert.h>
-#include <inttypes.h>
-#include <stdint.h>
+#include <limits.h>
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
 #ifndef BITS_PER_BYTE
-# define BITS_PER_BYTE 8
+  #define BITS_PER_BYTE CHAR_BIT
 #endif
 
-#if UINTPTR_MAX > UINT32_MAX
-# define BITS_PER_LONG 64
-#else
-# define BITS_PER_LONG 32
+#ifndef BITS_PER_LONG
+#  define BITS_PER_LONG (sizeof(unsigned long) * BITS_PER_BYTE)
 #endif
 
 #ifndef BITS_PER_LONG_LONG
-# define BITS_PER_LONG_LONG 64
+#  define BITS_PER_LONG_LONG (sizeof(unsigned long long) * BITS_PER_BYTE)
 #endif
 
-#define BIT_MASK(nr)       (UINT32_C(1) << ((nr) % BITS_PER_LONG))
+#define BIT_BYTE_MASK(nr)  (1ul << ((nr) % BITS_PER_BYTE))
+#define BIT_WORD_MASK(nr)  (1ul << ((nr) % BITS_PER_LONG))
+#define BIT_BYTE(nr)       ((nr) / BITS_PER_BYTE)
 #define BIT_WORD(nr)       ((nr) / BITS_PER_LONG)
-#define BIT_ULL_MASK(nr)   (UINT64_C(1) << ((nr) % BITS_PER_LONG_LONG))
+#define BIT_ULL_MASK(nr)   (1ull << ((nr) % BITS_PER_LONG_LONG))

Review Comment:
   Since UL(unsigned long)/ULL(unsigned long long) maybe different from 
UINT32_C(uint32_t)/UINT64_C(uint64_t). It's especially for 64bit arch, unsigned 
long is most likely 64bit, which doesn't equal uint32_t at all.



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