Skip to content

[opt](expr) use compiler builtin for int128 multiplication overflow checks - #66476

Open
Mryange wants to merge 1 commit into
apache:masterfrom
Mryange:opt-int128-mul-overflow
Open

[opt](expr) use compiler builtin for int128 multiplication overflow checks#66476
Mryange wants to merge 1 commit into
apache:masterfrom
Mryange:opt-int128-mul-overflow

Conversation

@Mryange

@Mryange Mryange commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Checked int128 multiplication used a division-based software implementation. On x86-64, this
generated a call to the expensive __udivti3 helper in the decimal multiplication path.

This change uses __builtin_mul_overflow, allowing the compiler to emit inline multiplication and
carry instructions without a runtime helper call. It also adds boundary coverage and 10,000
deterministic random input pairs that validate both the overflow flag and low 128 result bits against
an Int256 oracle.

For the query-like DECIMAL64(10,7) * DECIMAL128(38,2) -> DECIMAL128(38,9) benchmark with 65,536
items per batch, using aggregate CPU mean from five repetitions:

Path Before After Improvement
Production, including precision-38 check 21.32 ns/item 6.32 ns/item 70.34%
Native overflow check only 21.06 ns/item 4.13 ns/item 80.37%

Release note

None

Check List (For Author)

  • Test: Manual test
    • Release benchmark build: sh build.sh --benchmark -j48
    • Benchmark correctness validation against Int256 oracle
    • clang-format 16 check
  • Behavior changed: No
  • Does this need documentation: No

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary: Replace division-based signed int128 multiplication overflow detection with __builtin_mul_overflow. The previous implementation generated an expensive 128-bit division helper on the decimal multiplication path, while the compiler builtin lowers to inline arithmetic on x86-64. In the Decimal64 by Decimal128 query-like benchmark, CPU time decreased from 21.32 ns/item to 6.32 ns/item, a 70.34% reduction. Boundary combinations and deterministic random inputs are checked against an Int256 oracle.

### Release note

None

### Check List (For Author)

- Test: Manual test
    - Release benchmark build: sh build.sh --benchmark -j48
    - Benchmark correctness validation against Int256 oracle
    - Generated-code inspection
    - clang-format 16 check
- Behavior changed: No
- Does this need documentation: No
@Mryange Mryange changed the title [improvement](be) Optimize int128 multiplication overflow checks [opt](expr) use compiler builtin for int128 multiplication overflow checks Aug 5, 2026
@Mryange
Mryange force-pushed the opt-int128-mul-overflow branch from a19d9c2 to f07206d Compare August 5, 2026 09:47
@Mryange

Mryange commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

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