Skip to content

Add Optional 128-bit Integer Support to C++ Runtime#239

Open
AaronWebster wants to merge 4 commits intomasterfrom
int128-runtime-support
Open

Add Optional 128-bit Integer Support to C++ Runtime#239
AaronWebster wants to merge 4 commits intomasterfrom
int128-runtime-support

Conversation

@AaronWebster
Copy link
Collaborator

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.

AaronWebster and others added 4 commits December 3, 2025 13:27
- 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).
@AaronWebster AaronWebster self-assigned this Jan 29, 2026
@AaronWebster AaronWebster added the enhancement New feature or request label Jan 29, 2026

// 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated? Should probably revert to not pollute the diff.

#include <cstdint>
#include <type_traits>

#include "runtime/cpp/emboss_defines.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2024 -> 2026

@@ -1,13 +0,0 @@
# Copyright 2019 Google LLC
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to delete this copyright header

@@ -0,0 +1,85 @@
# Copyright 2024 Google LLC
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2024 -> 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants