Skip to content
This repository was archived by the owner on Nov 10, 2021. It is now read-only.

Add LIMIT, ROUNDED_DIV, and SIZEOF macros #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

aiw-google
Copy link
Contributor

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.

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.
@aiw-google aiw-google requested a review from gerickson November 14, 2019 01:53
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2012-2018 Nest Labs, Inc.
* Copyright (c) 2012-2019 Nest Labs, Inc.
Copy link
Contributor

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; })
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@gerickson gerickson left a 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants