From abaa9f7aceecf5bb1dd988c7dee2e9a94aa570a4 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 29 Jul 2024 23:45:28 +0400 Subject: [PATCH 1/7] add big-endian support to five8_const --- crates/five8_const/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/five8_const/src/lib.rs b/crates/five8_const/src/lib.rs index 78f9c43..75a8b1f 100644 --- a/crates/five8_const/src/lib.rs +++ b/crates/five8_const/src/lib.rs @@ -139,12 +139,20 @@ const fn truncate_and_swap_u64s_const( // 4 5 6 7 12 13 14 15 20 21 22 23 etc let binary_u8_idx = i * 8; let out_idx = i * 4; + #[cfg(target_endian = "little")] unsafe { out[out_idx] = *binary_u8.add(binary_u8_idx + 3); out[out_idx + 1] = *binary_u8.add(binary_u8_idx + 2); out[out_idx + 2] = *binary_u8.add(binary_u8_idx + 1); out[out_idx + 3] = *binary_u8.add(binary_u8_idx); } + #[cfg(target_endian = "big")] + unsafe { + out[out_idx] = *binary_u8.add(binary_u8_idx + 4); + out[out_idx + 1] = *binary_u8.add(binary_u8_idx + 5); + out[out_idx + 2] = *binary_u8.add(binary_u8_idx + 6); + out[out_idx + 3] = *binary_u8.add(binary_u8_idx + 7); + } i += 1 } out From 71511efe91ffb8cf39517c6f4ea6271c5a9687e8 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 29 Jul 2024 23:45:36 +0400 Subject: [PATCH 2/7] fix miri support --- crates/five8/src/decode.rs | 4 ++++ crates/five8/src/encode.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/crates/five8/src/decode.rs b/crates/five8/src/decode.rs index 4a75dfe..98770d6 100644 --- a/crates/five8/src/decode.rs +++ b/crates/five8/src/decode.rs @@ -277,7 +277,9 @@ fn truncate_and_swap_u64s_registers< mod tests { #[cfg(target_feature = "avx2")] use core::arch::x86_64::{_mm256_shuffle_epi32, _mm256_unpacklo_epi64}; + #[cfg(not(miri))] use prop::array::uniform32; + #[cfg(not(miri))] use proptest::prelude::*; use super::*; @@ -468,6 +470,7 @@ mod tests { println!("out3: {out3:?}"); } + #[cfg(not(miri))] proptest! { #[test] fn proptest_decode_32(key in uniform32(0u8..)) { @@ -481,6 +484,7 @@ mod tests { } } + #[cfg(not(miri))] proptest! { #[test] fn proptest_decode_64(first_half in uniform32(0u8..), second_half in uniform32(0u8..)) { diff --git a/crates/five8/src/encode.rs b/crates/five8/src/encode.rs index 27879c5..ca1f139 100644 --- a/crates/five8/src/encode.rs +++ b/crates/five8/src/encode.rs @@ -822,7 +822,9 @@ mod tests { #[cfg(target_feature = "avx2")] use core::array::from_fn; use five8_core::{BASE58_ENCODED_32_MAX_LEN, BASE58_ENCODED_64_MAX_LEN}; + #[cfg(not(miri))] use prop::array::uniform32; + #[cfg(not(miri))] use proptest::prelude::*; use super::*; @@ -1017,6 +1019,7 @@ mod tests { ); } + #[cfg(not(miri))] proptest! { #[test] fn proptest_encode_32(key in uniform32(0u8..)) { @@ -1028,6 +1031,7 @@ mod tests { } } + #[cfg(not(miri))] proptest! { #[test] fn proptest_encode_64(first_half in uniform32(0u8..), second_half in uniform32(0u8..)) { From 3a1766e0aaa6af360a4857052d38cce8f7b66f54 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 29 Jul 2024 23:45:40 +0400 Subject: [PATCH 3/7] add ci checks --- .github/workflows/lint.yml | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..f585032 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,71 @@ +name: Rust CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + cargo-fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: rustfmt + - name: Check Formatting + run: cargo fmt -- --check + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Clippy Lint + run: RUSTFLAGS="-D warnings" cargo clippy --locked --tests + + clippy-native-cpu: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Clippy Lint + run: RUSTFLAGS="-D warnings -C target-cpu=native" cargo clippy --locked --tests + + clippy-all-features: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Clippy Lint + run: RUSTFLAGS="-D warnings" cargo clippy --all-features --locked --tests + + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Run tests + run: cargo test + + tests-native-cpu: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Run tests + run: RUSTFLAGS='-C target-cpu=native' cargo test -F std + + tests-miri-big-endian: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Install Miri + run: | + rustup toolchain install nightly --component miri + rustup override set nightly + cargo miri setup + - name: Run tests + run: cargo +nightly miri test --target s390x-unknown-linux-gnu -F std From 0cebc179eed0039f5ae36feaf9e1caf30258666e Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 29 Jul 2024 23:48:20 +0400 Subject: [PATCH 4/7] remove --locked --- .github/workflows/lint.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f585032..c62400a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rust-lang/setup-rust-toolchain@v1 - name: Clippy Lint - run: RUSTFLAGS="-D warnings" cargo clippy --locked --tests + run: RUSTFLAGS="-D warnings" cargo clippy --tests clippy-native-cpu: runs-on: ubuntu-latest @@ -31,7 +31,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rust-lang/setup-rust-toolchain@v1 - name: Clippy Lint - run: RUSTFLAGS="-D warnings -C target-cpu=native" cargo clippy --locked --tests + run: RUSTFLAGS="-D warnings -C target-cpu=native" cargo clippy --tests clippy-all-features: runs-on: ubuntu-latest @@ -39,7 +39,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rust-lang/setup-rust-toolchain@v1 - name: Clippy Lint - run: RUSTFLAGS="-D warnings" cargo clippy --all-features --locked --tests + run: RUSTFLAGS="-D warnings" cargo clippy --all-features --tests tests: runs-on: ubuntu-latest From 836a2029add6894a40f04a18c37f4919580033a8 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 29 Jul 2024 23:51:16 +0400 Subject: [PATCH 5/7] clippy --- crates/five8/src/encode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/five8/src/encode.rs b/crates/five8/src/encode.rs index ca1f139..7494f95 100644 --- a/crates/five8/src/encode.rs +++ b/crates/five8/src/encode.rs @@ -792,7 +792,7 @@ fn intermediate_to_base58_32( ) } #[cfg(target_feature = "avx2")] - intermediate_to_base58_32_avx(&intermediate, in_leading_0s, out) + intermediate_to_base58_32_avx(intermediate, in_leading_0s, out) } #[inline(always)] From 9a21c17798ce9b5232d1e0d9b1102adf44c2b2c0 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 29 Jul 2024 23:53:33 +0400 Subject: [PATCH 6/7] fix clippy lint in tests --- crates/five8/src/avx.rs | 4 ++-- crates/five8/src/decode.rs | 2 +- crates/five8/src/encode.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/five8/src/avx.rs b/crates/five8/src/avx.rs index 9c638b9..ffdeeae 100644 --- a/crates/five8/src/avx.rs +++ b/crates/five8/src/avx.rs @@ -423,14 +423,14 @@ mod tests { for i in 0..90 { in_.0[16 * (i / 10) + (i % 10)] = i as u8 + 1; } - let in_ptr = in_.0.as_ptr() as *const u8; + let in_ptr = in_.0.as_ptr(); let a = wuc_ld(in_ptr); let b = wuc_ld(unsafe { in_ptr.offset(32) }); let c = wuc_ld(unsafe { in_ptr.offset(64) }); let d = wuc_ld(unsafe { in_ptr.offset(96) }); let e = wuc_ld(unsafe { in_ptr.offset(128) }); let (out0, out1, out2) = ten_per_slot_down_64(a, b, c, d, e); - let out_ptr = out.0.as_mut_ptr() as *mut u8; + let out_ptr = out.0.as_mut_ptr(); wuc_st(out_ptr, out0); wuc_st(unsafe { out_ptr.offset(32) }, out1); wuc_st(unsafe { out_ptr.offset(64) }, out2); diff --git a/crates/five8/src/decode.rs b/crates/five8/src/decode.rs index 98770d6..3a3caf6 100644 --- a/crates/five8/src/decode.rs +++ b/crates/five8/src/decode.rs @@ -357,7 +357,7 @@ mod tests { 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 0, 1, 0, 0, 0, 0, 0, 127, ]; let mut out = [0u8; 32]; - let err = decode_32(&encoded, &mut out).unwrap_err(); + let err = decode_32(encoded, &mut out).unwrap_err(); assert_eq!(err, DecodeError::InvalidChar(0)); } diff --git a/crates/five8/src/encode.rs b/crates/five8/src/encode.rs index 7494f95..e432ffc 100644 --- a/crates/five8/src/encode.rs +++ b/crates/five8/src/encode.rs @@ -845,7 +845,7 @@ mod tests { expected_len: u8, encoded: &str, ) { - assert_eq!(&encode_32_to_string(&bytes, len, buf), encoded); + assert_eq!(&encode_32_to_string(bytes, len, buf), encoded); assert_eq!(*len, expected_len); let mut decoded = [0u8; 32]; decode_32(encoded.as_bytes(), &mut decoded).unwrap(); @@ -859,7 +859,7 @@ mod tests { expected_len: u8, encoded: &str, ) { - assert_eq!(&encode_64_to_string(&bytes, len, buf), encoded); + assert_eq!(&encode_64_to_string(bytes, len, buf), encoded); assert_eq!(*len, expected_len); let mut decoded = [0u8; 64]; decode_64(encoded.as_bytes(), &mut decoded).unwrap(); @@ -871,7 +871,7 @@ mod tests { len: &mut u8, buf: &mut [u8; BASE58_ENCODED_64_MAX_LEN], ) -> String { - encode_64(&bytes, Some(len), buf); + encode_64(bytes, Some(len), buf); buf[..*len as usize].iter().map(|c| *c as char).collect() } From 2883e406e8f7d0bef53823212e7ef0ddf92c5ed4 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 29 Jul 2024 23:57:50 +0400 Subject: [PATCH 7/7] ignore missing_transmute_annotations --- crates/five8/src/decode.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/five8/src/decode.rs b/crates/five8/src/decode.rs index 3a3caf6..bbf9193 100644 --- a/crates/five8/src/decode.rs +++ b/crates/five8/src/decode.rs @@ -1,3 +1,4 @@ +#![allow(clippy::missing_transmute_annotations)] #[cfg(target_feature = "avx2")] use core::mem::transmute;