Skip to content

V3.99: supporting cross-platform BlockType == uint64_t#511

Merged
Ravenwater merged 12 commits intomainfrom
v3.99
Feb 24, 2026
Merged

V3.99: supporting cross-platform BlockType == uint64_t#511
Ravenwater merged 12 commits intomainfrom
v3.99

Conversation

@Ravenwater
Copy link
Contributor

@Ravenwater Ravenwater commented Feb 24, 2026

Supporting uint64_t blocktype across the different platforms.

Summary by CodeRabbit

Release Notes v3.99

  • Bug Fixes

    • Fixed incorrect bit access in posit operations that caused out-of-bounds errors
    • Corrected sign bit extraction in reciprocal computations
    • Improved fused multiply-accumulate operators for better accuracy
  • Documentation

    • Added comprehensive guides for all number system types (Posit, Areal, CFLoat, Fixed-Point, Intervals, Complex, and more)
    • Included quick-start examples and best-practice usage patterns for each type
  • Performance

    • Optimized 64-bit arithmetic with platform-specific carry handling
    • Enhanced MSVC compatibility for mathematical constants

Ravenwater and others added 12 commits February 23, 2026 16:06
blockbinary::operator[] is a block/limb index accessor, not a bit
index accessor. Four locations used it with bit indices, causing
stack-buffer-overflow for posit configurations where fbits > nrBlocks
(e.g., posit<16,1,uint8_t> with fbits=12 and only 2 blocks).

Fixed positFraction::operator<<, get_fixed_point(), denormalize(),
and posit reciprocal sign extraction to use _block.test(bitIndex).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Why/what/how markdown guides for each of the 29 number systems
with regression tests, covering integer, fixed-point, rational,
configurable floats, posit family, logarithmic, multi-component
extended precision, block-scaled AI formats, interval arithmetic,
and compressed floating-point. Includes README.md index with
category tables and selection guide.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
0x0Fu is a 32-bit unsigned int, so shifting it by nibbleIndexInWord*4
when nibbleIndexInWord >= 8 (i.e., shift >= 32) is undefined behavior.
On MSVC this caused corrupt to_hex() output and cascading test failures
in bb_uint64_limbs. Fix by casting to bt before shifting, ensuring the
shift operates on the block type width.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
_umul128, _addcarry_u64, and _subborrow_u64 write results through
pointer parameters. When these pointers were derived from reference
parameters via reinterpret_cast, the MSVC optimizer could lose the
writes after inlining, causing mul128 to always return hi=0. This
produced systematically wrong multiplication results (block[1] only
contained the addcarry carry-out bit, not the mul128 high product).

Fix: use local variables for all intrinsic output pointers, then
assign to the reference parameters after the intrinsic returns.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…dcarry

The multiplication loop accumulated carries as full 64-bit values
(hi + c1) then passed them as carry_in to addcarry(). On MSVC,
_addcarry_u64 truncates carry_in to unsigned char, silently losing
the upper bits. Split into two separate addcarry calls each with
carry_in=0 so the multi-bit carry is added as a regular operand.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Posit: add long double constructor/operator= in the #else branch of
LONG_DOUBLE_SUPPORT so MSVC (where long double is a distinct type but
same precision as double) no longer hits ambiguous overload resolution.

Directives: define _USE_MATH_DEFINES for MSVC so M_PI is available
from <cmath> without per-file defines.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove redundant long double constructor/assignment in posit #else branch
that caused ambiguous overload on MSVC where long double == double.
Replace ternary with if-constexpr helper in zfp_codec encode/decode to
avoid C4293 warning when N == 64.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…r overload resolution

MSVC treats long double and double as distinct types for overload
resolution despite identical representation. Without explicit long
double overloads, assignment from long double is ambiguous among
float/double/integer candidates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Ravenwater Ravenwater self-assigned this Feb 24, 2026
@Ravenwater Ravenwater merged commit 4475600 into main Feb 24, 2026
31 of 34 checks passed
@Ravenwater Ravenwater deleted the v3.99 branch February 24, 2026 01:39
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e6e678 and e7c55a6.

📒 Files selected for processing (52)
  • .github/workflows/cmake.yml
  • CHANGELOG.md
  • CMakeLists.txt
  • docs/number-systems/README.md
  • docs/number-systems/areal.md
  • docs/number-systems/bfloat16.md
  • docs/number-systems/cfloat.md
  • docs/number-systems/complex.md
  • docs/number-systems/dbns.md
  • docs/number-systems/dd.md
  • docs/number-systems/dd_cascade.md
  • docs/number-systems/dfloat.md
  • docs/number-systems/e8m0.md
  • docs/number-systems/fixpnt.md
  • docs/number-systems/integer.md
  • docs/number-systems/interval.md
  • docs/number-systems/lns.md
  • docs/number-systems/microfloat.md
  • docs/number-systems/mxfloat.md
  • docs/number-systems/nvblock.md
  • docs/number-systems/posit.md
  • docs/number-systems/posit1.md
  • docs/number-systems/posito.md
  • docs/number-systems/qd.md
  • docs/number-systems/qd_cascade.md
  • docs/number-systems/quire.md
  • docs/number-systems/rational.md
  • docs/number-systems/sorn.md
  • docs/number-systems/takum.md
  • docs/number-systems/td_cascade.md
  • docs/number-systems/unum2.md
  • docs/number-systems/valid.md
  • docs/number-systems/zfpblock.md
  • docs/sessions/2026-02-13_arm64_mingw_cross_compilation_ci.md
  • include/sw/universal/internal/blockbinary/blockbinary.hpp
  • include/sw/universal/internal/blockdecimal/blockdecimal.hpp
  • include/sw/universal/internal/blockfraction/blockfraction.hpp
  • include/sw/universal/internal/blocksignificand/blocksignificand.hpp
  • include/sw/universal/internal/blocktype/carry.hpp
  • include/sw/universal/number/integer/integer_impl.hpp
  • include/sw/universal/number/posit/positFraction.hpp
  • include/sw/universal/number/posit/posit_impl.hpp
  • include/sw/universal/number/zfpblock/zfp_codec.hpp
  • include/sw/universal/utility/directives.hpp
  • internal/blockbinary/arithmetic/uint64_limbs.cpp
  • static/integer/binary/api/api.cpp
  • static/sorn/api.cpp
  • static/sorn/api/api.cpp
  • static/sorn/arithmetic/addition.cpp
  • static/sorn/arithmetic/division.cpp
  • static/sorn/arithmetic/multiplication.cpp
  • static/sorn/arithmetic/subtraction.cpp

📝 Walkthrough

Walkthrough

Version bump to v3.99 with bug fixes for blockbinary bit-access misuse and reciprocal sign extraction. Adds 64-bit limb carry intrinsics for multi-block arithmetic optimization. Introduces extensive documentation for Universal's number system types and new validation tests for uint64_t limb configurations.

Changes

Cohort / File(s) Summary
Version and Build Configuration
.github/workflows/cmake.yml, CMakeLists.txt
Updated GitHub Actions workflow and version number from v3.98 to v3.99, with no logic changes.
Carry Propagation Intrinsics
include/sw/universal/internal/blocktype/carry.hpp
New platform-abstracted helper functions for 64-bit carry operations: addcarry(), subborrow(), mul128() with MSVC and GCC/Clang intrinsics paths, plus portable fallback implementations.
Block Type Carry Optimizations
include/sw/universal/internal/blockbinary/blockbinary.hpp, blockdecimal/blockdecimal.hpp, blockfraction/blockfraction.hpp, blocksignificand/blocksignificand.hpp
Added conditional 64-bit limb paths using carry intrinsics for addition and multiplication; updated nibble mask construction for type consistency. Non-64-bit paths unchanged.
Integer Arithmetic Optimization
include/sw/universal/number/integer/integer_impl.hpp
Integrated 64-bit carry intrinsics (addcarry, mul128) into addition and multiplication paths; maintains existing fallback for non-64-bit blocks.
Posit Bit-Access Fixes
include/sw/universal/number/posit/positFraction.hpp, posit_impl.hpp
Replaced blockbinary operator[] with test() method for bit reading; added MSVC long double overload handling. Fixes stack-buffer-overflow in operator<< and reciprocal sign extraction.
ZFP Codec Utility
include/sw/universal/number/zfpblock/zfp_codec.hpp
Added constexpr zfp_lowbits_mask() utility to avoid undefined-behavior shift when N == 64; updated encode/decode bitplane logic.
Build Directives
include/sw/universal/utility/directives.hpp
Added MSVC-specific _USE_MATH_DEFINES guard to enable math constants (M_PI, etc.) on MSVC builds.
Number Systems Documentation
docs/number-systems/README.md, areal.md, bfloat16.md, cfloat.md, complex.md, dbns.md, dd.md, dd_cascade.md, dfloat.md, e8m0.md, fixpnt.md, integer.md, interval.md, lns.md, microfloat.md, mxfloat.md, nvblock.md, posit.md, posit1.md, posito.md, qd.md, qd_cascade.md, quire.md, rational.md, sorn.md, takum.md, td_cascade.md, unum2.md, valid.md, zfpblock.md
Comprehensive new documentation for 31 number system types with usage examples, properties, problem statements, and C++ code snippets; master README organizes types by category.
Change Log and Session Notes
CHANGELOG.md, docs/sessions/2026-02-13_arm64_mingw_cross_compilation_ci.md
Documented fixes for blockbinary operator[] misuse, reciprocal sign extraction, and atomic fused operator rewrites with test verification results.
Block Type Validation Tests
internal/blockbinary/arithmetic/uint64_limbs.cpp
New 603-line functional test suite validating 64-bit limb blockbinary against 8-bit limb variants across addition, subtraction, multiplication, division, carry/borrow propagation, and exhaustive small-width scenarios.
Integer API and SORN Examples
static/integer/binary/api/api.cpp, static/sorn/api.cpp, static/sorn/api/api.cpp, static/sorn/arithmetic/addition.cpp, division.cpp, multiplication.cpp, subtraction.cpp
Refactored integer API output formatting and updated 1024-bit test from uint32_t to uint64_t limbs; removed and relocated SORN API test file; updated SPDX license headers across SORN arithmetic files.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐰 Carry the precision far and wide,
Sixty-four-bit limbs stride with pride,
Bit by bit, we fixed what broke,
Thirty-one number systems: no joke!
v3.99 hops forth with intrinsics so bright!

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v3.99

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 22332889654

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 278 of 358 (77.65%) changed or added relevant lines in 8 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.06%) to 84.716%

Changes Missing Coverage Covered Lines Changed/Added Lines %
include/sw/universal/internal/blockbinary/blockbinary.hpp 29 31 93.55%
include/sw/universal/number/integer/integer_impl.hpp 28 30 93.33%
internal/blockbinary/arithmetic/uint64_limbs.cpp 189 265 71.32%
Totals Coverage Status
Change from base Build 22321403113: -0.06%
Covered Lines: 37221
Relevant Lines: 43936

💛 - Coveralls

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