Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler-rt] Add missing carry to 128x128->256 wide multiply #97257

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler-rt/lib/builtins/fp_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,11 @@ static __inline void wideMultiply(rep_t a, rep_t b, rep_t *hi, rep_t *lo) {
(sum2 & Word_FullMask) + ((sum3 << 32) & Word_HiMask);

*lo = r0 + (r1 << 64);
// The addition above can overflow, in which case `*lo` will be less than
// `r0`. Carry any overflow into `hi`.
const bool carry = *lo < r0;
*hi = (r1 >> 64) + (sum1 >> 96) + (sum2 >> 64) + (sum3 >> 32) + sum4 +
(sum5 << 32) + (sum6 << 64);
(sum5 << 32) + (sum6 << 64) + carry;
}
#undef Word_1
#undef Word_2
Expand Down
6 changes: 6 additions & 0 deletions compiler-rt/test/builtins/Unit/multf3_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ int main()
UINT64_C(0x0),
UINT64_C(0x0)))
return 1;
// test carry between lo and hi in widening multiply
if (test__multf3(0x0.7fffffffffffffffffffffffffffp-16382L,
0x1.7fffffffffffffffffffffffffffp+1L,
UINT64_C(0x00017fffffffffff),
UINT64_C(0xfffffffffffffffc)))
return 1;

#else
printf("skipped\n");
Expand Down
Loading