Skip to content

Commit

Permalink
Merge pull request #58 from AndersTrier/AndersTrier/clippy
Browse files Browse the repository at this point in the history
More Clippy lints
  • Loading branch information
AndersTrier authored Nov 23, 2024
2 parents b7f1596 + e5923b1 commit 17c6523
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 148 deletions.
22 changes: 11 additions & 11 deletions src/algorithm.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ Encoding and decoding both have two variations:
and use similar setup than [main benchmarks],
except with maximum possible shard loss.

| original : recovery | Chunks | HighRateEncoder | LowRateEncoder | HighRateDecoder | LowRateDecoder |
| ------------------- | ------- | --------------- | -------------- | --------------- | -------------- |
| 1024 : 1024 | 1x 1024 | 175 MiB/s | 176 MiB/s | 76 MiB/s | 75 MiB/s |
| 1024 : 1025 (Low) | 2x 1024 | 140 | **153** | 47 | **59** |
| 1025 : 1024 (High) | 2x 1024 | **152** | 132 | **60** | 46 |
| 1024 : 2048 (Low) | 2x 1024 | 157 | **169** | 70 | 70 |
| 2048 : 1024 (High) | 2x 1024 | **167** | 151 | 69 | 68 |
| 1025 : 1025 | 1x 2048 | 125 | 126 | 44 | 43 |
| 1025 : 2048 (Low) | 1x 2048 | 144 | 144 | **65** **!!!** | 53 |
| 2048 : 1025 (High) | 1x 2048 | 144 | 145 | 53 | **62** **!!!** |
| 2048 : 2048 | 1x 2048 | 156 | 157 | 70 | 69 |
| original : recovery | Chunks | `HighRateEncoder` | `LowRateEncoder` | `HighRateDecoder` | `LowRateDecoder` |
| ------------------- | ------- | ----------------- | ---------------- | ----------------- | ---------------- |
| 1024 : 1024 | 1x 1024 | 175 MiB/s | 176 MiB/s | 76 MiB/s | 75 MiB/s |
| 1024 : 1025 (Low) | 2x 1024 | 140 | **153** | 47 | **59** |
| 1025 : 1024 (High) | 2x 1024 | **152** | 132 | **60** | 46 |
| 1024 : 2048 (Low) | 2x 1024 | 157 | **169** | 70 | 70 |
| 2048 : 1024 (High) | 2x 1024 | **167** | 151 | 69 | 68 |
| 1025 : 1025 | 1x 2048 | 125 | 126 | 44 | 43 |
| 1025 : 2048 (Low) | 1x 2048 | 144 | 144 | **65** **!!!** | 53 |
| 2048 : 1025 (High) | 1x 2048 | 144 | 145 | 53 | **62** **!!!** |
| 2048 : 2048 | 1x 2048 | 156 | 157 | 70 | 69 |

[main benchmarks]: crate#benchmarks

Expand Down
2 changes: 1 addition & 1 deletion src/decoder_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl<'a> Iterator for RestoredOriginal<'a> {
self.next_index = index + 1;
return Some((index, original));
}
index += 1
index += 1;
}
self.ended = true;
None
Expand Down
4 changes: 2 additions & 2 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! - [`Ssse3`]
//! - Optimized engine that takes advantage of the x86(-64) SSSE3 SIMD instructions.
//! - [`Neon`]
//! - Optimized engine that takes advantage of the AArch64 Neon SIMD instructions.
//! - Optimized engine that takes advantage of the `AArch64` Neon SIMD instructions.
//! - [`DefaultEngine`]
//! - Default engine which is used when no specific engine is given.
//! - Automatically selects best engine at runtime.
Expand Down Expand Up @@ -156,7 +156,7 @@ pub trait Engine {
where
Self: Sized,
{
utils::eval_poly(erasures, truncated_size)
utils::eval_poly(erasures, truncated_size);
}
}

Expand Down
46 changes: 23 additions & 23 deletions src/engine/engine_avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,30 @@ impl From<&Multiply128lutT> for LutAvx2 {
#[inline(always)]
fn from(lut: &Multiply128lutT) -> Self {
unsafe {
LutAvx2 {
Self {
t0_lo: _mm256_broadcastsi128_si256(_mm_loadu_si128(
&lut.lo[0] as *const u128 as *const __m128i,
std::ptr::from_ref::<u128>(&lut.lo[0]).cast::<__m128i>(),
)),
t1_lo: _mm256_broadcastsi128_si256(_mm_loadu_si128(
&lut.lo[1] as *const u128 as *const __m128i,
std::ptr::from_ref::<u128>(&lut.lo[1]).cast::<__m128i>(),
)),
t2_lo: _mm256_broadcastsi128_si256(_mm_loadu_si128(
&lut.lo[2] as *const u128 as *const __m128i,
std::ptr::from_ref::<u128>(&lut.lo[2]).cast::<__m128i>(),
)),
t3_lo: _mm256_broadcastsi128_si256(_mm_loadu_si128(
&lut.lo[3] as *const u128 as *const __m128i,
std::ptr::from_ref::<u128>(&lut.lo[3]).cast::<__m128i>(),
)),
t0_hi: _mm256_broadcastsi128_si256(_mm_loadu_si128(
&lut.hi[0] as *const u128 as *const __m128i,
std::ptr::from_ref::<u128>(&lut.hi[0]).cast::<__m128i>(),
)),
t1_hi: _mm256_broadcastsi128_si256(_mm_loadu_si128(
&lut.hi[1] as *const u128 as *const __m128i,
std::ptr::from_ref::<u128>(&lut.hi[1]).cast::<__m128i>(),
)),
t2_hi: _mm256_broadcastsi128_si256(_mm_loadu_si128(
&lut.hi[2] as *const u128 as *const __m128i,
std::ptr::from_ref::<u128>(&lut.hi[2]).cast::<__m128i>(),
)),
t3_hi: _mm256_broadcastsi128_si256(_mm_loadu_si128(
&lut.hi[3] as *const u128 as *const __m128i,
std::ptr::from_ref::<u128>(&lut.hi[3]).cast::<__m128i>(),
)),
}
}
Expand All @@ -146,7 +146,7 @@ impl Avx2 {
let lut_avx2 = LutAvx2::from(lut);

for chunk in x.iter_mut() {
let x_ptr = chunk.as_mut_ptr() as *mut __m256i;
let x_ptr = chunk.as_mut_ptr().cast::<__m256i>();
unsafe {
let x_lo = _mm256_loadu_si256(x_ptr);
let x_hi = _mm256_loadu_si256(x_ptr.add(1));
Expand Down Expand Up @@ -211,9 +211,9 @@ impl Avx2 {
impl Avx2 {
// Implementation of LEO_FFTB_256
#[inline(always)]
fn fftb_256(&self, x: &mut [u8; 64], y: &mut [u8; 64], lut_avx2: LutAvx2) {
let x_ptr = x.as_mut_ptr() as *mut __m256i;
let y_ptr = y.as_mut_ptr() as *mut __m256i;
fn fftb_256(x: &mut [u8; 64], y: &mut [u8; 64], lut_avx2: LutAvx2) {
let x_ptr = x.as_mut_ptr().cast::<__m256i>();
let y_ptr = y.as_mut_ptr().cast::<__m256i>();

unsafe {
let mut x_lo = _mm256_loadu_si256(x_ptr);
Expand Down Expand Up @@ -242,7 +242,7 @@ impl Avx2 {
let lut_avx2 = LutAvx2::from(lut);

for (x_chunk, y_chunk) in zip(x.iter_mut(), y.iter_mut()) {
self.fftb_256(x_chunk, y_chunk, lut_avx2);
Self::fftb_256(x_chunk, y_chunk, lut_avx2);
}
}

Expand Down Expand Up @@ -319,7 +319,7 @@ impl Avx2 {
let log_m23 = self.skew[base + dist * 2];

for i in r..r + dist {
self.fft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02)
self.fft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02);
}

r += dist4;
Expand All @@ -340,7 +340,7 @@ impl Avx2 {
if log_m == GF_MODULUS {
utils::xor(y, x);
} else {
self.fft_butterfly_partial(x, y, log_m)
self.fft_butterfly_partial(x, y, log_m);
}

r += 2;
Expand All @@ -355,9 +355,9 @@ impl Avx2 {
impl Avx2 {
// Implementation of LEO_IFFTB_256
#[inline(always)]
fn ifftb_256(&self, x: &mut [u8; 64], y: &mut [u8; 64], lut_avx2: LutAvx2) {
let x_ptr = x.as_mut_ptr() as *mut __m256i;
let y_ptr = y.as_mut_ptr() as *mut __m256i;
fn ifftb_256(x: &mut [u8; 64], y: &mut [u8; 64], lut_avx2: LutAvx2) {
let x_ptr = x.as_mut_ptr().cast::<__m256i>();
let y_ptr = y.as_mut_ptr().cast::<__m256i>();

unsafe {
let mut x_lo = _mm256_loadu_si256(x_ptr);
Expand Down Expand Up @@ -385,7 +385,7 @@ impl Avx2 {
let lut_avx2 = LutAvx2::from(lut);

for (x_chunk, y_chunk) in zip(x.iter_mut(), y.iter_mut()) {
self.ifftb_256(x_chunk, y_chunk, lut_avx2);
Self::ifftb_256(x_chunk, y_chunk, lut_avx2);
}
}

Expand Down Expand Up @@ -436,7 +436,7 @@ impl Avx2 {
skew_delta: usize,
) {
// Drop unsafe privileges
self.ifft_private(data, pos, size, truncated_size, skew_delta)
self.ifft_private(data, pos, size, truncated_size, skew_delta);
}

#[inline(always)]
Expand All @@ -462,7 +462,7 @@ impl Avx2 {
let log_m23 = self.skew[base + dist * 2];

for i in r..r + dist {
self.ifft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02)
self.ifft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02);
}

r += dist4;
Expand Down Expand Up @@ -497,7 +497,7 @@ impl Avx2 {
impl Avx2 {
#[target_feature(enable = "avx2")]
unsafe fn eval_poly_avx2(erasures: &mut [GfElement; GF_ORDER], truncated_size: usize) {
utils::eval_poly(erasures, truncated_size)
utils::eval_poly(erasures, truncated_size);
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/engine/engine_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ impl DefaultEngine {
/// 2. [`Ssse3`]
/// 3. [`NoSimd`]
///
/// On AArch64 the engine is chosen in the following order of preference:
/// On `AArch64` the engine is chosen in the following order of preference:
/// 1. [`Neon`]
/// 2. [`NoSimd`]
pub fn new() -> Self {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
if is_x86_feature_detected!("avx2") {
return DefaultEngine(Box::new(Avx2::new()));
return Self(Box::new(Avx2::new()));
}

if is_x86_feature_detected!("ssse3") {
return DefaultEngine(Box::new(Ssse3::new()));
return Self(Box::new(Ssse3::new()));
}
}

#[cfg(target_arch = "aarch64")]
{
if std::arch::is_aarch64_feature_detected!("neon") {
return DefaultEngine(Box::new(Neon::new()));
return Self(Box::new(Neon::new()));
}
}

DefaultEngine(Box::new(NoSimd::new()))
Self(Box::new(NoSimd::new()))
}
}

Expand All @@ -67,7 +67,7 @@ impl Engine for DefaultEngine {
truncated_size: usize,
skew_delta: usize,
) {
self.0.fft(data, pos, size, truncated_size, skew_delta)
self.0.fft(data, pos, size, truncated_size, skew_delta);
}

fn ifft(
Expand All @@ -78,11 +78,11 @@ impl Engine for DefaultEngine {
truncated_size: usize,
skew_delta: usize,
) {
self.0.ifft(data, pos, size, truncated_size, skew_delta)
self.0.ifft(data, pos, size, truncated_size, skew_delta);
}

fn mul(&self, x: &mut [[u8; 64]], log_m: GfElement) {
self.0.mul(x, log_m)
self.0.mul(x, log_m);
}

fn eval_poly(erasures: &mut [GfElement; GF_ORDER], truncated_size: usize) {
Expand All @@ -104,6 +104,6 @@ impl Engine for DefaultEngine {
}
}

NoSimd::eval_poly(erasures, truncated_size)
NoSimd::eval_poly(erasures, truncated_size);
}
}
8 changes: 4 additions & 4 deletions src/engine/engine_naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl Engine for Naive {
fn mul(&self, x: &mut [[u8; 64]], log_m: GfElement) {
for chunk in x.iter_mut() {
for i in 0..32 {
let lo = chunk[i] as GfElement;
let hi = chunk[i + 32] as GfElement;
let lo = GfElement::from(chunk[i]);
let hi = GfElement::from(chunk[i + 32]);
let prod = tables::mul(lo | (hi << 8), log_m, self.exp, self.log);
chunk[i] = prod as u8;
chunk[i + 32] = (prod >> 8) as u8;
Expand Down Expand Up @@ -136,8 +136,8 @@ impl Naive {

for (x_chunk, y_chunk) in std::iter::zip(x.iter_mut(), y.iter()) {
for i in 0..32 {
let lo = y_chunk[i] as GfElement;
let hi = y_chunk[i + 32] as GfElement;
let lo = GfElement::from(y_chunk[i]);
let hi = GfElement::from(y_chunk[i + 32]);
let prod = tables::mul(lo | (hi << 8), log_m, self.exp, self.log);
x_chunk[i] ^= prod as u8;
x_chunk[i + 32] ^= (prod >> 8) as u8;
Expand Down
26 changes: 13 additions & 13 deletions src/engine/engine_neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ impl Neon {
let mut prod_hi: uint8x16_t;

unsafe {
let t0_lo = vld1q_u8(&lut.lo[0] as *const u128 as *const u8);
let t1_lo = vld1q_u8(&lut.lo[1] as *const u128 as *const u8);
let t2_lo = vld1q_u8(&lut.lo[2] as *const u128 as *const u8);
let t3_lo = vld1q_u8(&lut.lo[3] as *const u128 as *const u8);
let t0_lo = vld1q_u8(std::ptr::from_ref::<u128>(&lut.lo[0]).cast::<u8>());
let t1_lo = vld1q_u8(std::ptr::from_ref::<u128>(&lut.lo[1]).cast::<u8>());
let t2_lo = vld1q_u8(std::ptr::from_ref::<u128>(&lut.lo[2]).cast::<u8>());
let t3_lo = vld1q_u8(std::ptr::from_ref::<u128>(&lut.lo[3]).cast::<u8>());

let t0_hi = vld1q_u8(&lut.hi[0] as *const u128 as *const u8);
let t1_hi = vld1q_u8(&lut.hi[1] as *const u128 as *const u8);
let t2_hi = vld1q_u8(&lut.hi[2] as *const u128 as *const u8);
let t3_hi = vld1q_u8(&lut.hi[3] as *const u128 as *const u8);
let t0_hi = vld1q_u8(std::ptr::from_ref::<u128>(&lut.hi[0]).cast::<u8>());
let t1_hi = vld1q_u8(std::ptr::from_ref::<u128>(&lut.hi[1]).cast::<u8>());
let t2_hi = vld1q_u8(std::ptr::from_ref::<u128>(&lut.hi[2]).cast::<u8>());
let t3_hi = vld1q_u8(std::ptr::from_ref::<u128>(&lut.hi[3]).cast::<u8>());

let clr_mask = vdupq_n_u8(0x0f);

Expand Down Expand Up @@ -296,7 +296,7 @@ impl Neon {
let log_m23 = self.skew[base + dist * 2];

for i in r..r + dist {
self.fft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02)
self.fft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02);
}

r += dist4;
Expand All @@ -317,7 +317,7 @@ impl Neon {
if log_m == GF_MODULUS {
utils::xor(y, x);
} else {
self.fft_butterfly_partial(x, y, log_m)
self.fft_butterfly_partial(x, y, log_m);
}

r += 2;
Expand Down Expand Up @@ -422,7 +422,7 @@ impl Neon {
skew_delta: usize,
) {
// Drop unsafe privileges
self.ifft_private(data, pos, size, truncated_size, skew_delta)
self.ifft_private(data, pos, size, truncated_size, skew_delta);
}

#[inline(always)]
Expand All @@ -448,7 +448,7 @@ impl Neon {
let log_m23 = self.skew[base + dist * 2];

for i in r..r + dist {
self.ifft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02)
self.ifft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02);
}

r += dist4;
Expand Down Expand Up @@ -483,7 +483,7 @@ impl Neon {
impl Neon {
#[target_feature(enable = "neon")]
unsafe fn eval_poly_neon(erasures: &mut [GfElement; GF_ORDER], truncated_size: usize) {
utils::eval_poly(erasures, truncated_size)
utils::eval_poly(erasures, truncated_size);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/engine/engine_nosimd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl NoSimd {
let log_m23 = self.skew[base + dist * 2];

for i in r..r + dist {
self.fft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02)
self.fft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02);
}

r += dist4;
Expand All @@ -203,7 +203,7 @@ impl NoSimd {
if log_m == GF_MODULUS {
utils::xor(y, x);
} else {
self.fft_butterfly_partial(x, y, log_m)
self.fft_butterfly_partial(x, y, log_m);
}

r += 2;
Expand Down Expand Up @@ -283,7 +283,7 @@ impl NoSimd {
let log_m23 = self.skew[base + dist * 2];

for i in r..r + dist {
self.ifft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02)
self.ifft_butterfly_two_layers(data, pos + i, dist, log_m01, log_m23, log_m02);
}

r += dist4;
Expand Down
Loading

0 comments on commit 17c6523

Please sign in to comment.