Skip to content

Commit 279bbc5

Browse files
committed
work around compiler bug rust-lang/rust#86693
thanks @xobs for the work-around!
1 parent 1a79b76 commit 279bbc5

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/scalar.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,14 @@ impl Scalar {
915915

916916
let mut naf = [0i8; 256];
917917

918-
let mut x_u64 = [0u64; 5];
919-
LittleEndian::read_u64_into(&self.bytes, &mut x_u64[0..4]);
918+
#[repr(align(32))]
919+
struct AlignedU64Slice<const N: usize>([u64; N]);
920+
921+
let mut x_u64 = AlignedU64Slice([0u64; 5]);
922+
LittleEndian::read_u64_into(&self.bytes, &mut x_u64.0[0..4]);
923+
924+
#[cfg(feature = "betrusted")]
925+
log::trace!("x_u64: {:?}", x_u64.0);
920926

921927
let width = 1 << w;
922928
let window_mask = width - 1;
@@ -930,10 +936,10 @@ impl Scalar {
930936
let bit_buf: u64;
931937
if bit_idx < 64 - w {
932938
// This window's bits are contained in a single u64
933-
bit_buf = x_u64[u64_idx] >> bit_idx;
939+
bit_buf = x_u64.0[u64_idx] >> bit_idx;
934940
} else {
935941
// Combine the current u64's bits with the bits from the next u64
936-
bit_buf = (x_u64[u64_idx] >> bit_idx) | (x_u64[1+u64_idx] << (64 - bit_idx));
942+
bit_buf = (x_u64.0[u64_idx] >> bit_idx) | (x_u64.0[1+u64_idx] << (64 - bit_idx));
937943
}
938944

939945
// Add the carry into the current window
@@ -949,9 +955,17 @@ impl Scalar {
949955
}
950956

951957
if window < width/2 {
958+
#[cfg(feature = "betrusted")]
959+
log::trace!("carry 0 width {} naf[{}] = {}; c.{} bb.{:x} wm.{} idx64.{} idxbit.{} xu64[0].{:x}", width, pos, window,
960+
carry, bit_buf, window_mask, u64_idx, bit_idx, x_u64.0[0],
961+
);
952962
carry = 0;
953963
naf[pos] = window as i8;
954964
} else {
965+
#[cfg(feature = "betrusted")]
966+
log::trace!("carry 1 width {} naf[{}] = {}/{}; c.{} bb.{:x} wm.{} idx64.{} idxbit.{} xu64[0].{:x}", width, pos, window, (window as i8).wrapping_sub(width as i8),
967+
carry, bit_buf, window_mask, u64_idx, bit_idx, x_u64.0[0]
968+
);
955969
carry = 1;
956970
naf[pos] = (window as i8).wrapping_sub(width as i8);
957971
}

0 commit comments

Comments
 (0)