-
Notifications
You must be signed in to change notification settings - Fork 202
Add native __int128 casts for bignum types #527
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,13 @@ | |
| #include <string> | ||
| #include <string_view> | ||
|
|
||
|
|
||
| #if defined(__SIZEOF_INT128__) | ||
| #define CH_CPP_HAS_INT128 1 | ||
| #else | ||
| #define CH_CPP_HAS_INT128 0 | ||
| #endif | ||
|
|
||
| /** | ||
| * This file contains declarations and definitions of the types and API used for wide | ||
| * (128-, 256- bit) integers. It first declares the Int128 and UInt128, implementation of which | ||
|
|
@@ -66,6 +73,12 @@ struct UInt128 { | |
| bool operator<=(const UInt128& other) const { return !(other < *this); } | ||
| bool operator>=(const UInt128& other) const { return !(*this < other); } | ||
|
|
||
| #if CH_CPP_HAS_INT128 | ||
| explicit operator unsigned __int128() const { | ||
| return ((unsigned __int128)limbs[1] << 64 | limbs[0]); | ||
| } | ||
| #endif | ||
|
|
||
| // The value as two 64-bit limbs in little-endian order: | ||
| // `limbs[0]` is the low 64 bits and `limbs[1]` is the high 64 bits | ||
| uint64_t limbs[2]; | ||
|
|
@@ -104,6 +117,12 @@ struct Int128 { | |
| bool operator<=(const Int128& other) const { return !(other < *this); } | ||
| bool operator>=(const Int128& other) const { return !(*this < other); } | ||
|
|
||
| #if CH_CPP_HAS_INT128 | ||
| explicit operator __int128() const { | ||
| return (__int128)((unsigned __int128)limbs[1] << 64 | limbs[0]); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No specific reason, normally I stick to |
||
| } | ||
| #endif | ||
|
|
||
| // The value as two 64-bit limbs in little-endian order: | ||
| // `limbs[0]` is the low 64 bits and `limbs[1]` is the high 64 bits | ||
| uint64_t limbs[2]; | ||
|
|
||
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.
not an expert. why not cpp style
static_casthere? instead of C-style cast? Curious.