diff --git a/Cargo.toml b/Cargo.toml index 033f321..89d072a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,17 +4,10 @@ description = "A Rust library containing Galois-field types and utilities" authors = ["Christopher Haster "] 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 # diff --git a/Makefile b/Makefile index 8dc3334..0d1b14c 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index c341a9e..fe089d3 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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::*; @@ -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. @@ -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 @@ -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, diff --git a/gf256-macros/src/common.rs b/gf256-macros/src/common.rs index e4116aa..ce41488 100644 --- a/gf256-macros/src/common.rs +++ b/gf256-macros/src/common.rs @@ -36,7 +36,6 @@ pub(crate) fn xmul_predicate() -> TokenStream { target_feature="pclmulqdq" ), all( - feature="nightly", target_arch="aarch64", target_feature="neon" ) diff --git a/src/crc.rs b/src/crc.rs index 7ea13f8..343bd2e 100644 --- a/src/crc.rs +++ b/src/crc.rs @@ -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 diff --git a/src/gf.rs b/src/gf.rs index 5ba8ae1..a35a2ea 100644 --- a/src/gf.rs +++ b/src/gf.rs @@ -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 @@ -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 //! ``` //! diff --git a/src/lfsr.rs b/src/lfsr.rs index 6d860e4..47c5da6 100644 --- a/src/lfsr.rs +++ b/src/lfsr.rs @@ -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 diff --git a/src/lib.rs b/src/lib.rs index ddc751e..d26ed6e 100644 --- a/src/lib.rs +++ b/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] diff --git a/src/p.rs b/src/p.rs index 4e99f28..df855fa 100644 --- a/src/p.rs +++ b/src/p.rs @@ -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 diff --git a/src/raid.rs b/src/raid.rs index 29d20b3..bc83947 100644 --- a/src/raid.rs +++ b/src/raid.rs @@ -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 diff --git a/src/rs.rs b/src/rs.rs index a98bb00..ff9431c 100644 --- a/src/rs.rs +++ b/src/rs.rs @@ -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 diff --git a/src/shamir.rs b/src/shamir.rs index 5d157b6..e009ec7 100644 --- a/src/shamir.rs +++ b/src/shamir.rs @@ -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 diff --git a/src/xmul.rs b/src/xmul.rs index b7f5a17..c2e9c7d 100644 --- a/src/xmul.rs +++ b/src/xmul.rs @@ -34,7 +34,6 @@ pub const HAS_XMUL: bool = { ), all( not(feature="no-xmul"), - feature="nightly", target_arch="aarch64", target_feature="neon" ) @@ -59,7 +58,6 @@ pub const HAS_XMUL: bool = { ), all( not(feature="no-xmul"), - feature="nightly", target_arch="aarch64", target_feature="neon" ) @@ -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" ))] { @@ -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" ) @@ -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" ))] { @@ -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" ) @@ -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" ))] { @@ -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" ) @@ -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" ))] { @@ -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" ) @@ -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" ))] { @@ -327,7 +316,6 @@ mod test { ), all( not(feature="no-xmul"), - feature="nightly", target_arch="aarch64", target_feature="neon" )