Repository navigation
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-x86_32Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.
Description
/// ```rust
/// assert_eq!(fixed::i124f4_wrapping_mul(3 << 4, 2 << 4), 6 << 4);
/// ```
#[inline]
pub fn i124f4_wrapping_mul(lhs: i128, rhs: i128) -> i128 {
let (ans, _) = mul_overflow(lhs, rhs, 4);
ans
}
#[inline]
fn mul_overflow(lhs: i128, rhs: i128, frac_nbits: u32) -> (i128, bool) {
let (lh, ll) = hi_lo(lhs);
let (rh, rl) = hi_lo(rhs);
let ll_rl = ll.wrapping_mul(rl);
let lh_rl = lh.wrapping_mul(rl);
let ll_rh = ll.wrapping_mul(rh);
let lh_rh = lh.wrapping_mul(rh);
let col01 = ll_rl as u128;
let (col01_hi, col01_lo) = (col01 >> 64, col01 & !(!0 << 64));
let partial_col12 = lh_rl + col01_hi as i128;
let (col12, carry_col3) = carrying_add(partial_col12, ll_rh);
let (col12_hi, col12_lo) = hi_lo(col12);
let ans01 = shift_lo_up_unsigned(col12_lo) + col01_lo;
let ans23 = lh_rh + col12_hi + shift_lo_up(carry_col3);
let ret = combine_lo_then_shl(ans23, ans01, frac_nbits);
println!(
"combine_lo_then_shl({}, {}, {}) -> ({}, {})",
ans23, ans01, frac_nbits, ret.0, ret.1
);
ret
}
#[inline]
fn hi_lo(this: i128) -> (i128, i128) {
(this >> 64, this & !(!0 << 64))
}
#[inline]
fn combine_lo_then_shl(this: i128, lo: u128, shift: u32) -> (i128, bool) {
if shift == 128 {
(this, false)
} else if shift == 0 {
let ans = lo as i128;
(ans, this != if ans < 0 { -1 } else { 0 })
} else {
let lo = (lo >> shift) as i128;
let hi = this << (128 - shift);
let ans = lo | hi;
(ans, this >> shift != if ans < 0 { -1 } else { 0 })
}
}
#[inline]
fn carrying_add(this: i128, rhs: i128) -> (i128, i128) {
let (sum, overflow) = this.overflowing_add(rhs);
let carry = if overflow {
if sum < 0 {
1
} else {
-1
}
} else {
0
};
(sum, carry)
}
#[inline]
fn shift_lo_up(this: i128) -> i128 {
debug_assert!(this >> 64 == 0);
this << 64
}
#[inline]
fn shift_lo_up_unsigned(this: i128) -> u128 {
debug_assert!(this >> 64 == 0);
(this << 64) as u128
}The test passes for 1.46.0 i686 stable release builds, for i686 beta/nightly debug builds, and for x86_64 beta/nightly release builds, but fails for i686 beta/nightly release builds.
CI logs from this code on GitLab:
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-x86_32Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.
Activity
tspiteri commentedon Aug 28, 2020
The
println!printscombine_lo_then_shl(0, 1536, 4) -> (1536, true), butcombine_lo_then_shl(0, 1536, 4)should return(96, false).LeSeulArtichaut commentedon Aug 28, 2020
Let's try to find the culprit for this regression. Trying to reduce the example would be nice too.
@rustbot ping cleanup
rustbot commentedon Aug 28, 2020
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good
"Cleanup ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3
cc @AminArria @camelid @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke
Dylan-DPC-zz commentedon Aug 29, 2020
Marking this as P-critical based on the wg-prioritization discussion
tspiteri commentedon Aug 29, 2020
I have a reduced test case.
Note that if I move the doc test to a lib test, I cannot trigger this bug. On i686 beta/nightly release test, the doc test fails with:
bazis somehow returning(128, true)instead of(8, false).https://gitlab.com/tspiteri/rust76042/-/pipelines/183379486
tmiasko commentedon Aug 29, 2020
Minimized:
5 remaining items
tspiteri commentedon Sep 24, 2020
I cannot reproduce the failure with rustc 1.48.0-nightly (8b40853 2020-09-23) which includes #77063.
LeSeulArtichaut commentedon Sep 24, 2020
Letting this issue open to track a beta backport of #77063.
Also, it might be good to have add a test in the suite for this issue. @tspiteri Would you mind filing a PR with your reproduction? Otherwise I can do it myself.
tspiteri commentedon Sep 24, 2020
@LeSeulArtichaut I don't know how to write this kind of test PR, please go ahead.
Add regression test for issue #76042
tspiteri commentedon Sep 30, 2020
Now the beta is working fine as well for me.
Rollup merge of rust-lang#77151 - rust-lang:LeSeulArtichaut-patch-1, …
Auto merge of rust-lang#79017 - GuillaumeGomez:rollup-5orhudd, r=Guil…