Skip to content

Commit 7485010

Browse files
committed
Debugging for a probable AVX2-related rustc bug
This commit contains `dbg!` statements which are narrowed down to be as close to the problem as possible. The following commands succeed: - `cargo test donna_self_test1 -- --test-threads=1 --nocapture` - `RUSTFLAGS="-Ctarget-cpu=haswell" cargo test donna_self_test1 --release -- --test-threads=1 --nocapture` The following command FAILS with a miscomputed output: - `cargo test donna_self_test1 --release -- --test-threads=1 --nocapture` Included in this commit are `dbg!` statements capturing the miscompiled output and comments with instructions about small tweaks which make the tests succeed under the conditions where it presently fails. These include: - Inserting a `dbg!` statement in the right place - Commenting out a `#[target_feature(enable = "avx2")]` attribute
1 parent 5de11d4 commit 7485010

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

poly1305/src/backend/avx2.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ impl State {
102102
}
103103

104104
/// Finalize output producing a [`Tag`]
105+
//
106+
// BUG!
107+
// Comment out `#[target_feature(...)]` to make the tests pass
108+
//
105109
#[target_feature(enable = "avx2")]
106110
pub(crate) unsafe fn finalize(&mut self) -> Tag {
107111
assert!(self.num_cached_blocks < 4);
@@ -131,7 +135,11 @@ impl State {
131135
if let Some(p) = p {
132136
c = c + p;
133137
}
134-
p = Some((c * self.r1).reduce());
138+
let tmp = c * self.r1;
139+
//dbg!(&tmp);
140+
// NOTE: this is the call site where miscompilation is happening
141+
p = Some(tmp.reduce());
142+
//dbg!(&p);
135143
self.num_cached_blocks -= 1;
136144
}
137145

@@ -144,15 +152,14 @@ impl State {
144152
p = Some((c * self.r1).reduce());
145153
}
146154

147-
dbg!(&self);
148-
149155
// Compute tag: p + k mod 2^128
150156
let mut tag = GenericArray::<u8, _>::default();
151157
let tag_int = if let Some(p) = p {
152158
self.k + p
153159
} else {
154160
self.k.into()
155161
};
162+
156163
tag_int.write(tag.as_mut_slice());
157164

158165
Tag::new(tag)

poly1305/src/backend/avx2/helpers.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ impl Unreduced130 {
455455

456456
// Carry chain
457457
let adc = |v1: __m256i, v0: __m256i| -> (__m256i, __m256i) {
458+
//
459+
// HEISENBUG! Uncomment this line to make the tests pass!
460+
//
461+
//dbg!(&v1, &v0);
462+
458463
// [t_3, t_2 % 2^26, t_1 % 2^26, t_0 % 2^26]
459464
// + [t_2 >> 26, t_1 >> 26, t_0 >> 26, 0 ]
460465
// = [
@@ -470,6 +475,11 @@ impl Unreduced130 {
470475
set02(2, 1, 0, 3),
471476
),
472477
);
478+
479+
// BUG!
480+
// This is the location closest to where miscompiled output is observed
481+
dbg!(&v1, &v0);
482+
473483
// [_, _, _, t_4]
474484
// + [
475485
// (t_2 % 2^26 + t_1 >> 26) >> 26,

0 commit comments

Comments
 (0)