Skip to content

Support i64.mul_wide_s and i64.mul_wide_u from Wide Arithmetic proposal#8652

Open
stevenfontanella wants to merge 3 commits intomainfrom
wide-arithmetic-mul
Open

Support i64.mul_wide_s and i64.mul_wide_u from Wide Arithmetic proposal#8652
stevenfontanella wants to merge 3 commits intomainfrom
wide-arithmetic-mul

Conversation

@stevenfontanella
Copy link
Copy Markdown
Member

@stevenfontanella stevenfontanella commented Apr 28, 2026

Part of #8544. Unit tests were written by Gemini and double-checked against python with this script.

TODO: Move the existing 128 add/sub logic from the interpreter into int128.h.

@stevenfontanella stevenfontanella changed the base branch from main to wide-arithmetic April 28, 2026 17:56
Comment thread src/ir/cost.h Outdated
Base automatically changed from wide-arithmetic to main April 28, 2026 23:57
@stevenfontanella stevenfontanella force-pushed the wide-arithmetic-mul branch 2 times, most recently from eb019af to 64dad92 Compare April 29, 2026 20:05
@stevenfontanella stevenfontanella changed the title [WIP] Wide arithmetic mul Support i64.mul_wide_s and i64.mul_wide_u from Wide Arithmetic proposal Apr 29, 2026
@stevenfontanella stevenfontanella force-pushed the wide-arithmetic-mul branch 6 times, most recently from 3fabe33 to 60966ed Compare April 29, 2026 21:35
@stevenfontanella stevenfontanella marked this pull request as ready for review April 29, 2026 22:59
@stevenfontanella stevenfontanella requested a review from a team as a code owner April 29, 2026 22:59
@stevenfontanella stevenfontanella requested review from tlively and removed request for a team April 29, 2026 22:59
Comment thread src/support/int128.cpp Outdated
Comment thread src/support/int128.h Outdated
Comment thread src/support/int128.cpp Outdated
Comment thread src/support/int128.cpp
Comment thread test/gtest/int128.cpp Outdated
Comment thread test/gtest/int128.cpp Outdated
Comment thread test/gtest/int128.cpp
Comment thread src/support/int128.cpp
Comment on lines +97 to +107
uint64_t highOfLow = (lowLow >> 32) + lowHigh;

// We might have a carry into the next 32 (the low of the high), mask it out
// now so we can add highLow.
uint64_t carry = highOfLow >> 32;

// This is also guaranteed to not overflow by the same logic.
highOfLow = (highOfLow & 0xffffffff) + highLow;

// highOfLow might have exceeded 32 bits again, carry it again
uint64_t carry2 = highOfLow >> 32;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we calculate carry and carry2 separately? It seems that if we started with highOfLow = (lowLow >> 32) + lowHigh + highLow, then we could just calculate a single combined carry. Does that open us up to overflow problems?

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.

4 participants