Skip to content

Avoid zero-filling bigint buffers in the slow path (C++26 [[indeterminate]]) - #440

Merged
lemire merged 2 commits into
mainfrom
indeterminate-bigint
Nov 22, 2026
Merged

lemire merged 2 commits into
mainfrom
indeterminate-bigint

Conversation

@lemire

@lemire lemire commented Nov 21, 2026

Copy link
Copy Markdown
Member

The digit-comparison slow path (numbers with more than 19 significant digits whose rounding Eisel-Lemire cannot decide) puts several 500-byte stackvec buffers on the stack. They were being zeroed for nothing:

  • bigint() : vec() value-initialized vec. Because stackvec's default constructor was = default, this zeroed all 500 bytes on every construction, in every C++ standard.
  • With C++26 (P2795R5, erroneous behaviour), GCC 16 zero-fills locals that have no initializer, and so does -ftrivial-auto-var-init=zero in earlier modes. That adds memsets for z and zi in long_mul (zi on every pass through the loop) and for the bigints in digit_comparison.h.

stackvec only reads up to length, so none of these buffers needs zeroing.

Changes:

The common path is unchanged; it has no such buffers.

Benchmark: 5000 inputs that each sit exactly halfway between two doubles (about 175 digits), Xeon Gold 6338, ns per number:

main this PR change
GCC 16, C++20 735 708 -3.7%
GCC 16, C++26 752 709 -5.8%
clang 23, C++20 725 713 -1.7%
clang 23, C++26 725 708 -2.3%

Tests: the full suite passes with Apple clang (C++11, C++20, and C++26 with ASan/UBSan and -ftrivial-auto-var-init=pattern) and with GCC 16 (C++20 and C++26, which builds with -Weffc++ -Werror). Compile-time (constexpr) parsing of long, slow-path strings still works in C++20 and C++26.

…nate]])

bigint() : vec() value-initialized its stackvec, zeroing 500 bytes on
every construction because stackvec's default constructor was defaulted.
Give stackvec a user-provided constructor so that it does not.

Add FASTFLOAT_INDETERMINATE ([[indeterminate]] in C++26, otherwise
__attribute__((uninitialized))) and apply it to the stackvec/bigint
locals of the slow path, which C++26 (P2795R5) and
-ftrivial-auto-var-init would otherwise zero-fill. stackvec only reads
up to its length, so none of these buffers needs zeroing.
ubuntu-latest now maps to Ubuntu 26.04, whose sudo ignores -E. The
setup-alpine v1 action then loses its INPUT_* variables and fails with
"INPUT_APK_TOOLS_URL: unbound variable".
@lemire
lemire merged commit b9f7873 into main Nov 22, 2026
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants