Skip to content

Commit

Permalink
Removed nightly feature flag now that neon intrinsics are (sort of) s…
Browse files Browse the repository at this point in the history
…table

Note, neon still requires a nightly compiler to enable, this just means we
don't need an explicit flag to detect this. And this code should "just work"
when neon becomes stable. The state of things is a bit confusing.

SIMD in Rust: rust-lang/rust#48556
NEON in Rust: rust-lang/rust#90972
  • Loading branch information
geky committed May 8, 2022
1 parent 83c44d3 commit 1e870c2
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 80 deletions.
9 changes: 1 addition & 8 deletions Cargo.toml
Expand Up @@ -4,17 +4,10 @@ description = "A Rust library containing Galois-field types and utilities"
authors = ["Christopher Haster <chaster@utexas.edu>"]
repository = "https://github.com/geky/gf256"
version = "0.2.0"
edition = "2018"
edition = "2021"
license = "BSD-3-Clause"

[features]
# Enables features only found on a nightly compiler
#
# This is required to leverage pmull on aarch64, tracking issue:
# https://github.com/rust-lang/rust/issues/48556
#
nightly = []

# Disable carry-less multiplication instructions, forcing the use
# of naive bitwise implementations
#
Expand Down
69 changes: 34 additions & 35 deletions Makefile
Expand Up @@ -2,59 +2,58 @@
override RUSTFLAGS += -Ctarget-cpu=native

# this indirection is so commands with env are easily copied on the terminal
override ENV += RUSTFLAGS="$(RUSTFLAGS)"
CARGO ?= RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly

.PHONY: all build
all build:
$(ENV) cargo +nightly build --features nightly,thread-rng,lfsr,crc,shamir,raid,rs
$(CARGO) build --features thread-rng,lfsr,crc,shamir,raid,rs

.PHONY: test
test:
$(ENV) cargo +nightly test --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --lib
$(ENV) cargo +nightly test --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example find-p
$(ENV) cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example find-p -- -w9 -n4 -m1 -q
$(ENV) cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example lfsr
$(ENV) cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example crc
$(ENV) cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example shamir
$(ENV) cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example raid
$(ENV) cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example rs
$(CARGO) test --features thread-rng,lfsr,crc,shamir,raid,rs --lib
$(CARGO) test --features thread-rng,lfsr,crc,shamir,raid,rs --example find-p
$(CARGO) run --features thread-rng,lfsr,crc,shamir,raid,rs --example find-p -- -w9 -n4 -m1 -q
$(CARGO) run --features thread-rng,lfsr,crc,shamir,raid,rs --example lfsr
$(CARGO) run --features thread-rng,lfsr,crc,shamir,raid,rs --example crc
$(CARGO) run --features thread-rng,lfsr,crc,shamir,raid,rs --example shamir
$(CARGO) run --features thread-rng,lfsr,crc,shamir,raid,rs --example raid
$(CARGO) run --features thread-rng,lfsr,crc,shamir,raid,rs --example rs

.PHONY: test-configs
test-configs:
$(ENV) cargo test --lib
$(ENV) cargo test --features thread-rng,lfsr,crc,shamir,raid,rs --lib
$(ENV) cargo test --features no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --lib
$(ENV) cargo test --features no-tables,thread-rng,lfsr,crc,shamir,raid,rs --lib
$(ENV) cargo test --features small-tables,thread-rng,lfsr,crc,shamir,raid,rs --lib
$(ENV) cargo +nightly test --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --lib
$(CARGO) test --lib
$(CARGO) test --features thread-rng,lfsr,crc,shamir,raid,rs --lib
$(CARGO) test --features no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --lib
$(CARGO) test --features no-tables,thread-rng,lfsr,crc,shamir,raid,rs --lib
$(CARGO) test --features small-tables,thread-rng,lfsr,crc,shamir,raid,rs --lib

.PHONY: docs
docs:
$(ENV) cargo +nightly doc --no-deps --features nightly,thread-rng,lfsr,crc,shamir,raid,rs
$(ENV) cargo +nightly test --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --doc
$(CARGO) doc --no-deps --features thread-rng,lfsr,crc,shamir,raid,rs
$(CARGO) test --features thread-rng,lfsr,crc,shamir,raid,rs --doc

.PHONY: bench
bench:
$(ENV) cargo +nightly bench --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --bench xmul -- --noplot
$(ENV) cargo +nightly bench --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --bench gf -- --noplot
$(ENV) cargo +nightly bench --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --bench find-p -- --noplot
$(ENV) cargo +nightly bench --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --bench lfsr -- --noplot
$(ENV) cargo +nightly bench --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --bench crc -- --noplot
$(ENV) cargo +nightly bench --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --bench shamir -- --noplot
$(ENV) cargo +nightly bench --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --bench raid -- --noplot
$(ENV) cargo +nightly bench --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --bench rs -- --noplot
$(CARGO) bench --features thread-rng,lfsr,crc,shamir,raid,rs --bench xmul -- --noplot
$(CARGO) bench --features thread-rng,lfsr,crc,shamir,raid,rs --bench gf -- --noplot
$(CARGO) bench --features thread-rng,lfsr,crc,shamir,raid,rs --bench find-p -- --noplot
$(CARGO) bench --features thread-rng,lfsr,crc,shamir,raid,rs --bench lfsr -- --noplot
$(CARGO) bench --features thread-rng,lfsr,crc,shamir,raid,rs --bench crc -- --noplot
$(CARGO) bench --features thread-rng,lfsr,crc,shamir,raid,rs --bench shamir -- --noplot
$(CARGO) bench --features thread-rng,lfsr,crc,shamir,raid,rs --bench raid -- --noplot
$(CARGO) bench --features thread-rng,lfsr,crc,shamir,raid,rs --bench rs -- --noplot

.PHONY: bench-no-xmul
bench-no-xmul:
$(ENV) cargo +nightly bench --features nightly,no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench xmul -- --noplot
$(ENV) cargo +nightly bench --features nightly,no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench gf -- --noplot
$(ENV) cargo +nightly bench --features nightly,no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench find-p -- --noplot
$(ENV) cargo +nightly bench --features nightly,no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench lfsr -- --noplot
$(ENV) cargo +nightly bench --features nightly,no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench crc -- --noplot
$(ENV) cargo +nightly bench --features nightly,no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench shamir -- --noplot
$(ENV) cargo +nightly bench --features nightly,no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench raid -- --noplot
$(ENV) cargo +nightly bench --features nightly,no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench rs -- --noplot
$(CARGO) bench --features no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench xmul -- --noplot
$(CARGO) bench --features no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench gf -- --noplot
$(CARGO) bench --features no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench find-p -- --noplot
$(CARGO) bench --features no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench lfsr -- --noplot
$(CARGO) bench --features no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench crc -- --noplot
$(CARGO) bench --features no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench shamir -- --noplot
$(CARGO) bench --features no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench raid -- --noplot
$(CARGO) bench --features no-xmul,thread-rng,lfsr,crc,shamir,raid,rs --bench rs -- --noplot

.PHONY: clean
clean:
$(ENV) cargo clean
$(CARGO) clean
12 changes: 3 additions & 9 deletions README.md
Expand Up @@ -151,7 +151,7 @@ assert_ne!(a + a, gf256(2)*a);
Finite-fields can be very useful for applying high-level math onto machine
words, since machine words (`u8`, `u16`, `u32`, etc) are inherently finite.
Normally we just ignore this until an integer overflow occurs and then we just
waive our hands around wailing that math has failed us.
wave our hands around wailing that math has failed us.

In Rust this has the fun side-effect that the Galois-field types are incapable
of overflowing, so Galois-field types don't need the set of overflowing
Expand Down Expand Up @@ -331,8 +331,6 @@ Carry-less multiplication:

gf256 takes advantage of these instructions when possible. However, at the time
of writing, `pmull` support in Rust is only available on [nightly][nightly].
To take advantage of `pmull` on aarch64 you will need to use a nightly compiler
and enable gf256's `nightly` feature ([tracking issue](https://github.com/rust-lang/rust/issues/48556)).

``` rust
# use ::gf256::*;
Expand All @@ -358,7 +356,7 @@ let b = if gf256::HAS_XMUL {
};
```

gf256 also leverages the hardware accelrated [carry-less addition][xor]
gf256 also leverages the hardware accelerated [carry-less addition][xor]
instructions, sometimes called polynomial addition, or simply xor. But this
is much less notable.

Expand Down Expand Up @@ -445,10 +443,6 @@ evaluated before use, and you use this library at your own risk.

## Features

- `nightly` - Enable features only found on a nightly compiler

This is required to leverage `pmull` on aarch64 ([tracking issue](https://github.com/rust-lang/rust/issues/48556))

- `no-xmul` - Disables carry-less multiplication instructions, forcing the use
of naive bitwise implementations

Expand All @@ -459,7 +453,7 @@ evaluated before use, and you use this library at your own risk.

This may be useful on memory constrained devices

- `small-tables` - Limits lookup tables to "small tables", tables with <16
- `small-tables` - Limits lookup tables to "small tables", tables with <=16
elements

This provides a compromise between full 256-byte tables and no-tables,
Expand Down
1 change: 0 additions & 1 deletion gf256-macros/src/common.rs
Expand Up @@ -36,7 +36,6 @@ pub(crate) fn xmul_predicate() -> TokenStream {
target_feature="pclmulqdq"
),
all(
feature="nightly",
target_arch="aarch64",
target_feature="neon"
)
Expand Down
2 changes: 1 addition & 1 deletion src/crc.rs
Expand Up @@ -21,7 +21,7 @@
//! [`examples/crc.rs`][crc-example]:
//!
//! ``` bash
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example crc
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo run --features thread-rng,lfsr,crc,shamir,raid,rs --example crc
//!
//! testing crc("Hello World!")
//! naive_crc => 0x1c291ca3
Expand Down
4 changes: 2 additions & 2 deletions src/gf.rs
Expand Up @@ -511,7 +511,7 @@
//! bit-width. Note you need a 5-bit irreducible polynomial for a 4-bit field:
//!
//! ``` bash
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo +nightly run --release --features nightly --example find-p -- --width=5 -m=1
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo run --release --example find-p -- --width=5 -m=1
//! polynomial=0x13, generator=0x2
//! polynomial=0x19, generator=0x2
//! polynomial=0x1f, generator=0x3
Expand All @@ -521,7 +521,7 @@
//! their generators up to 65-bits:
//!
//! ``` bash
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo +nightly run --release --features nightly --example find-p -- --width=65 -m=1 -n=1
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo --release --example find-p -- --width=65 -m=1 -n=1
//! polynomial=0x1000000000000001b, generator=0x2
//! ```
//!
Expand Down
2 changes: 1 addition & 1 deletion src/lfsr.rs
Expand Up @@ -29,7 +29,7 @@
//! [`examples/lfsr.rs`][lfsr-example]:
//!
//! ``` bash
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example lfsr
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo run --features thread-rng,lfsr,crc,shamir,raid,rs --example lfsr
//!
//! testing lfsr64
//! lfsr64_naive => 0000000000000001000000000000001b00000000000001450000000000001db7
Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
@@ -1,12 +1,6 @@
#![doc=include_str!("../README.md")]


// Enable stdsimd for pmull on aarch64
#![cfg_attr(
all(not(feature="no-xmul"), feature="nightly", target_arch="aarch64"),
feature(stdsimd)
)]

// We don't really need std
#![no_std]

Expand Down
3 changes: 1 addition & 2 deletions src/p.rs
Expand Up @@ -96,8 +96,7 @@
//! implementation.
//!
//! Note that at the time of writing, aarch64 [`pmull`][pmull] support is only
//! available on a [nightly][nightly] compiler, and requires gf256's `nightly`
//! feature to be enabled ([tracking issue](https://github.com/rust-lang/rust/issues/48556)).
//! available on a [nightly][nightly] compiler.
//!
//! gf256 also exposes the flag [`HAS_XMUL`], which can be used to choose
//! algorithms based on whether or not hardware accelerated carry-less
Expand Down
2 changes: 1 addition & 1 deletion src/raid.rs
Expand Up @@ -44,7 +44,7 @@
//! [`examples/raid.rs`][raid-example]:
//!
//! ``` bash
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example raid
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo run --features thread-rng,lfsr,crc,shamir,raid,rs --example raid
//!
//! testing raid5("Hello World?")
//! format => Hello World?U)_< 48656c6c6f20576f726c643f55295f3c
Expand Down
2 changes: 1 addition & 1 deletion src/rs.rs
Expand Up @@ -33,7 +33,7 @@
//! [`examples/rs.rs`][rs-example]:
//!
//! ``` bash
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example rs
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo run --features thread-rng,lfsr,crc,shamir,raid,rs --example rs
//!
//! testing rs("Hello World!")
//! dimension = (255,223), 16 errors, 32 erasures
Expand Down
2 changes: 1 addition & 1 deletion src/shamir.rs
Expand Up @@ -27,7 +27,7 @@
//! [`examples/shamir.rs`][shamir-example]:
//!
//! ``` bash
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo +nightly run --features nightly,thread-rng,lfsr,crc,shamir,raid,rs --example shamir
//! $ RUSTFLAGS="-Ctarget-cpu=native" cargo run --features thread-rng,lfsr,crc,shamir,raid,rs --example shamir
//!
//! testing shamir("Hello World!")
//! generate share1 => .....uT4.z.O. 019ddb829d755434f77ae84ffd
Expand Down
12 changes: 0 additions & 12 deletions src/xmul.rs
Expand Up @@ -34,7 +34,6 @@ pub const HAS_XMUL: bool = {
),
all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
)
Expand All @@ -59,7 +58,6 @@ pub const HAS_XMUL: bool = {
),
all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
)
Expand All @@ -83,7 +81,6 @@ pub fn xmul8(a: u8, b: u8) -> (u8, u8) {
}
} else if #[cfg(all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
))] {
Expand All @@ -109,7 +106,6 @@ pub fn xmul8(a: u8, b: u8) -> (u8, u8) {
),
all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
)
Expand All @@ -133,7 +129,6 @@ pub fn xmul16(a: u16, b: u16) -> (u16, u16) {
}
} else if #[cfg(all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
))] {
Expand All @@ -159,7 +154,6 @@ pub fn xmul16(a: u16, b: u16) -> (u16, u16) {
),
all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
)
Expand All @@ -183,7 +177,6 @@ pub fn xmul32(a: u32, b: u32) -> (u32, u32) {
}
} else if #[cfg(all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
))] {
Expand All @@ -209,7 +202,6 @@ pub fn xmul32(a: u32, b: u32) -> (u32, u32) {
),
all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
)
Expand All @@ -234,7 +226,6 @@ pub fn xmul64(a: u64, b: u64) -> (u64, u64) {
}
} else if #[cfg(all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
))] {
Expand All @@ -260,7 +251,6 @@ pub fn xmul64(a: u64, b: u64) -> (u64, u64) {
),
all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
)
Expand Down Expand Up @@ -296,7 +286,6 @@ pub fn xmul128(a: u128, b: u128) -> (u128, u128) {
}
} else if #[cfg(all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
))] {
Expand Down Expand Up @@ -327,7 +316,6 @@ mod test {
),
all(
not(feature="no-xmul"),
feature="nightly",
target_arch="aarch64",
target_feature="neon"
)
Expand Down

0 comments on commit 1e870c2

Please sign in to comment.