Skip to content

Commit 2d58e61

Browse files
authored
polyval: unify state for intrinsics backends (#299)
Instead of having each intrinsics backend (i.e. `avx2`, `neon`) define its own `State`, this defines a single `ExpandedKey` struct that can be shared between both intrinsics backends and a fallback software implementation, all defined in terms of `FieldElement`, as well as a common `State` struct. The `State` struct replacing the old union becomes a good place to put `InitToken`, so we don't need to have a dummy `InitToken` for the soft backend. The `soft` backend now is only compiled in if we're not using intrinsics whatsoever, and uses a much more compact implementation which stores `h` directly instead of a powers-of-H expansion, intended for low-power targets where resource conservation is more important than performance.
1 parent 48e5f64 commit 2d58e61

File tree

9 files changed

+617
-682
lines changed

9 files changed

+617
-682
lines changed

polyval/src/backend.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
mod soft;
2-
31
cpubits::cfg_if! {
4-
if #[cfg(all(target_arch = "aarch64", not(polyval_backend = "soft")))] {
5-
// PMULL/NEON backend for aarch64
6-
mod autodetect;
7-
mod neon;
8-
pub(crate) use autodetect::State;
9-
pub(crate) use neon::InitToken;
10-
} else if #[cfg(all(
11-
any(target_arch = "x86_64", target_arch = "x86"),
2+
if #[cfg(all(
3+
any(target_arch = "aarch64", target_arch = "x86_64", target_arch = "x86"),
124
not(polyval_backend = "soft")
135
))] {
14-
// CLMUL/AVX2 backend for x86/x86-64
15-
mod autodetect;
16-
mod avx2;
17-
pub(crate) use autodetect::State;
18-
pub(crate) use avx2::InitToken;
6+
mod intrinsics;
7+
pub(crate) use intrinsics::State;
198
} else {
209
// "soft" pure Rust portable fallback implementation for other targets
21-
pub(crate) use soft::{State, InitToken};
10+
mod soft;
11+
pub(crate) use soft::State;
2212
}
2313
}

polyval/src/backend/autodetect.rs

Lines changed: 0 additions & 88 deletions
This file was deleted.

polyval/src/backend/avx2.rs

Lines changed: 0 additions & 262 deletions
This file was deleted.

0 commit comments

Comments
 (0)