-
Notifications
You must be signed in to change notification settings - Fork 50
include/float8.h:NextPowerOfTwo; infinite values
#290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
The original NextPowerOfTwo function (before this pull request) just allows sizes from: 0 through sizeof(int64_t), which can break extended long long and intmax_t types (on architectures where those have more than 8 bytes, which standard C++ does allow).
Now allows sizes from: 0 through LLONG_MAX (so that NextPowerOfTwo has more possible future uses; it is common practice to allow the most possible future uses, as long as to do so does not introduce excessive lines of code (but this pull request reduces the total lines of code)).
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.
Now, NextPowerOfTwo<Size>::value just equals the input value if the input value is a power of two. If the input value is not a power of 2, ::value equals the next power of 2.
Test shows that for all supported input values of the original function, that this new version of the function gives similar output values:
int main() {
for(int input = 1; 9 > input; ++input) {
std::cout << "NextPowerOfTwo<" << std::to_string(input) << "> == " << NextPowerOfTwo<1>::value << std::endl;
}
return 0;
}
before and after, which now shows similar values for the original versus new.
+`ml_dtypes/include/float8.h:MostSignificantBit`; `constexpr` version of `clz` opcode. *`ml_dtypes/include/float8.h:NextPowerOfTwo`; replace long list of hardcoded values with `2 << MostSignificantBit<Size>`, which extends `NextPowerOfTwo` (was limited to integer sizes, now is less code plus is general use).
`MostSignificantBit`; `s/unsigned int/long long/` `NextPowerOfTwo`; `s/int/long long/` Ensures that those functions allowed the most possible amount of values.
ml_dtypes/include/float8.h:MostSignificantBit;constexprversion ofclzopcode.ml_dtypes/include/float8.h:NextPowerOfTwo; replace long list of hardcoded values with2 << MostSignificantBit<Size>, which extendsNextPowerOfTwo(was limited to integer sizes, now is less code plus is general use).