-
Notifications
You must be signed in to change notification settings - Fork 3
Add LIMIT, ROUNDED_DIV, and SIZEOF macros #14
base: master
Are you sure you want to change the base?
Conversation
Also improve the "safer" versions of LOG2 and CTZ by setting their parameters to the type (unsigned int) required by their underlying builtins. And add some comments and adjust whitespace.
@@ -1,6 +1,6 @@ | |||
/* | |||
* | |||
* Copyright (c) 2012-2018 Nest Labs, Inc. | |||
* Copyright (c) 2012-2019 Nest Labs, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should add a new "Copyright (c) 2019 Google LLC" line since Nest Labs is no more as a corporate entity.
#ifndef LOG2 | ||
#define LOG2(x) LOG2_INNER(x, __COUNTER__) | ||
#define LOG2_INNER(x, C) ({ __typeof__(x) _CC(_x, C) = (x); (_CC(_x, C) != 0) ? 31 - __builtin_clz(_CC(_x, C)) : -1; }) | ||
#define LOG2_INNER(x, C) ({ unsigned int _CC(_x, C) = (x); (_CC(_x, C) != 0) ? 31 - __builtin_clz(_CC(_x, C)) : -1; }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change and the one below on 157 seem unrelated. What was the genesis of these? Regardless, they should probably be in a separate PR if they are unrelated to the addition of LIMIT, ROUNDED_DIV, and SIZEOF.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, these two changes are unrelated to the others. And they're unfinished, too. I'll pull them out into a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit tests for these new macros.
Also improve the "safer" versions of LOG2 and CTZ by setting their parameters to the type (unsigned int) that is required by their underlying builtins. And add some comments, and adjust whitespace.