use super::*;
use core::mem::size_of;
#[test]
fn a_plan_is_priced_by_its_runs_and_its_footprint() {
let avx512 = HostClass::X86_64Avx512;
let row = copy_ns_per_element_of(avx512);
for (n, measured) in [
(64usize, (0.65, 0.68)),
(128, (0.78, 0.78)),
(256, (0.90, 0.94)),
(512, (3.09, 3.24)),
(1024, (2.91, 3.07)),
] {
let bytes = 2 * n * n * size_of::<f64>();
let rate = copy_ns_per_element_for_plan(avx512, bytes, 1);
assert!(
(measured.0 / 1.25..=measured.1 * 1.25).contains(&rate),
"{n} x {n}: the plan prices itself at {rate} ns per element, outside 1.25x \
of the {measured:?} measured"
);
}
assert_eq!(
copy_ns_per_element_for_plan(avx512, COPY_L2_BYTES, 1),
row + COPY_NS_PER_RUN_RESIDENT
);
assert_eq!(
copy_ns_per_element_for_plan(avx512, COPY_L2_BYTES + 1, 1),
COPY_BEYOND_L2_NS_PER_RUN
);
assert_eq!(
copy_ns_per_element_for_plan(avx512, 4 << 20, 16),
row + (COPY_BEYOND_L2_NS_PER_RUN - row) / 16.0
);
for run_len in [1usize, 2, 7, 64, 1024, usize::MAX] {
assert!(copy_ns_per_element_for_plan(avx512, 4 << 20, run_len) >= row);
}
for class in [
HostClass::Aarch64Apple,
HostClass::X86_64Avx2,
HostClass::X86_64Scalar,
HostClass::Aarch64,
HostClass::Generic,
] {
for (bytes, run_len) in [(0usize, 1usize), (4 << 20, 1), (usize::MAX >> 8, 1_000_000)] {
assert_eq!(
copy_ns_per_element_for_plan(class, bytes, run_len),
copy_ns_per_element_of(class),
"{} has no per-run term",
class.name()
);
}
}
}