use super::super::*;
#[test]
#[ignore]
fn shuffle2x_vs_normal_layout_throughput_movie_1080p() {
use std::time::Instant;
const SLICE_SIZE: usize = 806_912;
const TOTAL_SLICES: usize = 1997;
const RECOVERY_COUNT: usize = 200;
const EXPONENT_START: u32 = 0;
const REPS: u32 = 5;
fn xorshift_fill(seed: u64, buf: &mut [u8]) {
let mut state = seed | 1;
for chunk in buf.chunks_mut(8) {
state ^= state << 13;
state ^= state >> 7;
state ^= state << 17;
let bytes = state.to_le_bytes();
chunk.copy_from_slice(&bytes[..chunk.len()]);
}
}
let slices: Vec<Vec<u8>> = (0..TOTAL_SLICES)
.map(|i| {
let mut buf = vec![0u8; SLICE_SIZE];
xorshift_fill(0x9E3779B97F4A7C15 ^ (i as u64), &mut buf);
buf
})
.collect();
#[cfg(target_arch = "x86_64")]
assert!(
!std::is_x86_feature_detected!("gfni"),
"this comparison is meaningless on GFNI hardware: Normal layout \
would auto-dispatch to the GFNI kernel instead of plain AVX2, \
breaking the kernel-held-fixed premise of this test"
);
#[cfg(target_arch = "x86_64")]
assert!(
std::is_x86_feature_detected!("avx2"),
"need AVX2 for a meaningful Shuffle2x-vs-Normal comparison"
);
let run_normal = || {
let mut enc =
RecoveryEncoder::new(SLICE_SIZE, TOTAL_SLICES, EXPONENT_START, RECOVERY_COUNT);
for s in &slices {
enc.add_slice(s.clone());
}
let _ = enc.finish();
};
let run_shuffle2x = || {
let mut enc = RecoveryEncoder::new_shuffle2x(
SLICE_SIZE,
TOTAL_SLICES,
EXPONENT_START,
RECOVERY_COUNT,
);
for s in &slices {
enc.add_slice(s.clone());
}
let _ = enc.finish();
};
run_normal();
run_shuffle2x();
let mut normal_ms: Vec<f64> = Vec::with_capacity(REPS as usize);
let mut s2x_ms: Vec<f64> = Vec::with_capacity(REPS as usize);
for _ in 0..REPS {
let t = Instant::now();
run_normal();
normal_ms.push(t.elapsed().as_secs_f64() * 1000.0);
}
for _ in 0..REPS {
let t = Instant::now();
run_shuffle2x();
s2x_ms.push(t.elapsed().as_secs_f64() * 1000.0);
}
fn median(mut v: Vec<f64>) -> f64 {
v.sort_by(|a, b| a.partial_cmp(b).unwrap());
v[v.len() / 2]
}
let input_mib = (SLICE_SIZE * TOTAL_SLICES) as f64 / (1024.0 * 1024.0);
let normal_med_ms = median(normal_ms);
let s2x_med_ms = median(s2x_ms);
let normal_mibs = input_mib / (normal_med_ms / 1000.0);
let s2x_mibs = input_mib / (s2x_med_ms / 1000.0);
eprintln!(
"\n== Normal vs Shuffle2x, movie-1080p geometry, {input_mib:.1} MiB, {REPS} reps ==\n\
Normal+AVX2: {normal_med_ms:.1} ms median -> {normal_mibs:.1} MiB/s\n\
Shuffle2x+AVX2: {s2x_med_ms:.1} ms median -> {s2x_mibs:.1} MiB/s\n\
Shuffle2x vs Normal: {:+.1}%\n",
(s2x_mibs / normal_mibs - 1.0) * 100.0
);
}
#[test]
#[ignore]
fn altmap_vs_shuffle2x_layout_throughput_movie_1080p() {
use std::time::Instant;
const SLICE_SIZE: usize = 806_912;
const TOTAL_SLICES: usize = 1997;
const RECOVERY_COUNT: usize = 200;
const EXPONENT_START: u32 = 0;
const REPS: u32 = 5;
fn xorshift_fill(seed: u64, buf: &mut [u8]) {
let mut state = seed | 1;
for chunk in buf.chunks_mut(8) {
state ^= state << 13;
state ^= state >> 7;
state ^= state << 17;
let bytes = state.to_le_bytes();
chunk.copy_from_slice(&bytes[..chunk.len()]);
}
}
let slices: Vec<Vec<u8>> = (0..TOTAL_SLICES)
.map(|i| {
let mut buf = vec![0u8; SLICE_SIZE];
xorshift_fill(0x9E3779B97F4A7C15 ^ (i as u64), &mut buf);
buf
})
.collect();
#[cfg(target_arch = "x86_64")]
assert!(
!std::is_x86_feature_detected!("gfni"),
"ALTMAP has no kernel on GFNI hardware (try_new_altmap falls back \
to Normal there), so this comparison needs a non-GFNI AVX2 host"
);
#[cfg(target_arch = "x86_64")]
assert!(
std::is_x86_feature_detected!("avx2"),
"need AVX2 for both the Shuffle2x and ALTMAP kernels"
);
let run_shuffle2x = || {
let mut enc = RecoveryEncoder::new_shuffle2x(
SLICE_SIZE,
TOTAL_SLICES,
EXPONENT_START,
RECOVERY_COUNT,
);
for s in &slices {
enc.add_slice(s.clone());
}
let _ = enc.finish();
};
let run_altmap = || {
let mut enc =
RecoveryEncoder::new_altmap(SLICE_SIZE, TOTAL_SLICES, EXPONENT_START, RECOVERY_COUNT);
for s in &slices {
enc.add_slice(s.clone());
}
let _ = enc.finish();
};
run_shuffle2x();
run_altmap();
let mut s2x_ms: Vec<f64> = Vec::with_capacity(REPS as usize);
let mut altmap_ms: Vec<f64> = Vec::with_capacity(REPS as usize);
for _ in 0..REPS {
let t = Instant::now();
run_shuffle2x();
s2x_ms.push(t.elapsed().as_secs_f64() * 1000.0);
let t = Instant::now();
run_altmap();
altmap_ms.push(t.elapsed().as_secs_f64() * 1000.0);
}
fn median(mut v: Vec<f64>) -> f64 {
v.sort_by(|a, b| a.partial_cmp(b).unwrap());
v[v.len() / 2]
}
let input_mib = (SLICE_SIZE * TOTAL_SLICES) as f64 / (1024.0 * 1024.0);
let s2x_med_ms = median(s2x_ms);
let altmap_med_ms = median(altmap_ms);
let s2x_mibs = input_mib / (s2x_med_ms / 1000.0);
let altmap_mibs = input_mib / (altmap_med_ms / 1000.0);
eprintln!(
"\n== Shuffle2x vs ALTMAP (hoisted), movie-1080p geometry, {input_mib:.1} MiB, \
{REPS} reps ==\n\
Shuffle2x+AVX2: {s2x_med_ms:.1} ms median -> {s2x_mibs:.1} MiB/s\n\
ALTMAP+AVX2: {altmap_med_ms:.1} ms median -> {altmap_mibs:.1} MiB/s\n\
ALTMAP vs Shuffle2x: {:+.1}%\n",
(altmap_mibs / s2x_mibs - 1.0) * 100.0
);
}
#[test]
#[ignore]
fn shuffle2x_avx2_vs_normal_gfni_layout_throughput_movie_1080p() {
use std::time::Instant;
const SLICE_SIZE: usize = 806_912;
const TOTAL_SLICES: usize = 1997;
const RECOVERY_COUNT: usize = 200;
const EXPONENT_START: u32 = 0;
const REPS: u32 = 7;
fn xorshift_fill(seed: u64, buf: &mut [u8]) {
let mut state = seed | 1;
for chunk in buf.chunks_mut(8) {
state ^= state << 13;
state ^= state >> 7;
state ^= state << 17;
let bytes = state.to_le_bytes();
chunk.copy_from_slice(&bytes[..chunk.len()]);
}
}
let slices: Vec<Vec<u8>> = (0..TOTAL_SLICES)
.map(|i| {
let mut buf = vec![0u8; SLICE_SIZE];
xorshift_fill(0x9E3779B97F4A7C15 ^ (i as u64), &mut buf);
buf
})
.collect();
#[cfg(target_arch = "x86_64")]
assert!(
std::is_x86_feature_detected!("gfni"),
"this test compares Shuffle2x+AVX2 against Normal's *GFNI* \
kernel specifically — on non-GFNI hardware Normal would fall \
back to plain AVX2 and this would just re-measure the sibling \
test above. Run shuffle2x_vs_normal_layout_throughput_movie_1080p \
instead on non-GFNI hardware."
);
let run_normal = || {
let mut enc =
RecoveryEncoder::new(SLICE_SIZE, TOTAL_SLICES, EXPONENT_START, RECOVERY_COUNT);
for s in &slices {
enc.add_slice(s.clone());
}
let _ = enc.finish();
};
let run_shuffle2x = || {
let mut enc = RecoveryEncoder::new_shuffle2x(
SLICE_SIZE,
TOTAL_SLICES,
EXPONENT_START,
RECOVERY_COUNT,
);
for s in &slices {
enc.add_slice(s.clone());
}
let _ = enc.finish();
};
run_normal();
run_shuffle2x();
let mut normal_ms: Vec<f64> = Vec::with_capacity(REPS as usize);
let mut s2x_ms: Vec<f64> = Vec::with_capacity(REPS as usize);
for _ in 0..REPS {
let t = Instant::now();
run_normal();
normal_ms.push(t.elapsed().as_secs_f64() * 1000.0);
let t = Instant::now();
run_shuffle2x();
s2x_ms.push(t.elapsed().as_secs_f64() * 1000.0);
}
fn median(mut v: Vec<f64>) -> f64 {
v.sort_by(|a, b| a.partial_cmp(b).unwrap());
v[v.len() / 2]
}
let input_mib = (SLICE_SIZE * TOTAL_SLICES) as f64 / (1024.0 * 1024.0);
let normal_med_ms = median(normal_ms);
let s2x_med_ms = median(s2x_ms);
let normal_mibs = input_mib / (normal_med_ms / 1000.0);
let s2x_mibs = input_mib / (s2x_med_ms / 1000.0);
eprintln!(
"\n== Normal+GFNI vs Shuffle2x+AVX2, movie-1080p geometry, {input_mib:.1} MiB, \
{REPS} interleaved reps ==\n\
Normal (auto/GFNI): {normal_med_ms:.1} ms median -> {normal_mibs:.1} MiB/s\n\
Shuffle2x+AVX2: {s2x_med_ms:.1} ms median -> {s2x_mibs:.1} MiB/s\n\
Shuffle2x vs Normal+GFNI: {:+.1}%\n",
(s2x_mibs / normal_mibs - 1.0) * 100.0
);
}