pkarashchenko commented on code in PR #12427: URL: https://github.com/apache/nuttx/pull/12427#discussion_r1623337897
########## include/nuttx/lib/math32.h: ########## @@ -52,11 +52,15 @@ #define FLS2(n) ((n) & 0x2 ? 1 + FLS1 ((n) >> 1) : FLS1 (n)) #define FLS1(n) ((n) & 0x1 ? 1 : 0) +/* Checks if an integer is power of two at compile time */ + +#define IS_POWER_OF_2(n) ((n) > 0 && ((n) & (n - 1)) == 0) + /* Returns round up and round down value of log2(n). Note: it can be used at * compile time. */ -#define LOG2_CEIL(n) ((n) & (n - 1) ? FLS(n) : FLS(n) - 1) +#define LOG2_CEIL(n) (IS_POWER_OF_2(n) ? FLS(n) - 1 : FLS(n)) Review Comment: I think this change can be dropped now -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
