Add Optional 128-bit Integer Support to C++ Runtime#239
Open
AaronWebster wants to merge 4 commits intomasterfrom
Open
Add Optional 128-bit Integer Support to C++ Runtime#239AaronWebster wants to merge 4 commits intomasterfrom
AaronWebster wants to merge 4 commits intomasterfrom
Conversation
- Update prelude.emb to allow UInt and Int sizes up to 128 bits
(previously limited to 64 bits). Added documentation noting that
128-bit support requires platform support (__uint128_t/__int128_t).
- Update constraints_test.py to test with sizes > 128 bits now that
128-bit fields are valid.
- Add comprehensive unit tests for 128-bit integer support:
- emboss_bit_util_test.cc: ByteSwap, MaskToNBits, IsPowerOfTwo tests
- emboss_memory_util_test.cc: MemoryAccessor, BitBlock tests for
128-bit values including non-full-width (72, 96 bits) and
cross-64-bit-boundary operations
- emboss_prelude_test.cc: UIntView and IntView tests for 128-bit
read/write, sign extension, and CouldWriteValue
- Add int128_sizes_test.cc integration test for generated code with
128-bit integer fields (UInt128Sizes, Int128Sizes, big-endian
variants, and arrays).
- Update int128_sizes.emb documentation and remove AnonymousBits128
struct (128-bit bits types require separate implementation work).
|
|
||
| // Detect 128-bit integer support. | ||
| // __uint128_t and __int128_t are available on GCC and Clang on 64-bit targets. | ||
| #if !defined(EMBOSS_HAS_INT128) |
Collaborator
There was a problem hiding this comment.
For extensibility, we could define EMBOSS_INT128_T and EMBOSS_UINT128_T type macros defined to be __int128_t and __uint128_t if not already defined and we have __SIZEOF_INT128__. That way client code can supply or override these to enable 128-bit integer support with a custom type or a library type not called __int128_t (for example, absl::int128).
| #if !defined(EMBOSS_ALIAS_SAFE_POINTER_CAST) | ||
| #define EMBOSS_ALIAS_SAFE_POINTER_CAST(t, x) \ | ||
| reinterpret_cast<t __attribute__((__may_alias__)) *>((x)) | ||
| reinterpret_cast<t __attribute__((__may_alias__))*>((x)) |
Collaborator
There was a problem hiding this comment.
This seems unrelated? Should probably revert to not pollute the diff.
| #include <cstdint> | ||
| #include <type_traits> | ||
|
|
||
| #include "runtime/cpp/emboss_defines.h" |
Collaborator
There was a problem hiding this comment.
I think the relative import here should just be "emboss_defines.h" since it's in the same directory.
| @@ -0,0 +1,342 @@ | |||
| // Copyright 2024 Google LLC | |||
| @@ -1,13 +0,0 @@ | |||
| # Copyright 2019 Google LLC | |||
Collaborator
There was a problem hiding this comment.
I don't think we want to delete this copyright header
| @@ -0,0 +1,85 @@ | |||
| # Copyright 2024 Google LLC | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces support for 128-bit integers in the C++ runtime, enabling the handling of types larger than 64 bits (up to 128 bits) when the environment supports it, specifically gcc's __uint128_t and __int128_t.