From 279bbc52872d6fcf8eaf205a4874b9814fdebd0a Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 29 Jun 2021 22:42:47 +0800 Subject: [PATCH] work around compiler bug https://github.com/rust-lang/rust/issues/86693 thanks @xobs for the work-around! --- src/scalar.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/scalar.rs b/src/scalar.rs index 05b4381..2963e79 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -915,8 +915,14 @@ impl Scalar { let mut naf = [0i8; 256]; - let mut x_u64 = [0u64; 5]; - LittleEndian::read_u64_into(&self.bytes, &mut x_u64[0..4]); + #[repr(align(32))] + struct AlignedU64Slice([u64; N]); + + let mut x_u64 = AlignedU64Slice([0u64; 5]); + LittleEndian::read_u64_into(&self.bytes, &mut x_u64.0[0..4]); + + #[cfg(feature = "betrusted")] + log::trace!("x_u64: {:?}", x_u64.0); let width = 1 << w; let window_mask = width - 1; @@ -930,10 +936,10 @@ impl Scalar { let bit_buf: u64; if bit_idx < 64 - w { // This window's bits are contained in a single u64 - bit_buf = x_u64[u64_idx] >> bit_idx; + bit_buf = x_u64.0[u64_idx] >> bit_idx; } else { // Combine the current u64's bits with the bits from the next u64 - bit_buf = (x_u64[u64_idx] >> bit_idx) | (x_u64[1+u64_idx] << (64 - bit_idx)); + bit_buf = (x_u64.0[u64_idx] >> bit_idx) | (x_u64.0[1+u64_idx] << (64 - bit_idx)); } // Add the carry into the current window @@ -949,9 +955,17 @@ impl Scalar { } if window < width/2 { + #[cfg(feature = "betrusted")] + log::trace!("carry 0 width {} naf[{}] = {}; c.{} bb.{:x} wm.{} idx64.{} idxbit.{} xu64[0].{:x}", width, pos, window, + carry, bit_buf, window_mask, u64_idx, bit_idx, x_u64.0[0], + ); carry = 0; naf[pos] = window as i8; } else { + #[cfg(feature = "betrusted")] + 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), + carry, bit_buf, window_mask, u64_idx, bit_idx, x_u64.0[0] + ); carry = 1; naf[pos] = (window as i8).wrapping_sub(width as i8); }