Skip to content

Commit

Permalink
enable alsw tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine committed Jun 8, 2023
1 parent 92be937 commit 9baa5bf
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 56 deletions.
10 changes: 8 additions & 2 deletions crates/base32-simd/src/alsw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ pub const BASE32HEX_ALSW_DECODE_X2: AlswLut<V256> = Base32HexAlsw::decode_lut().
mod algorithm {
use super::*;

#[cfg_attr(
any(miri, not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))),
ignore
)]
#[test]
#[ignore]
fn base32_alsw() {
Base32Alsw::test_check();
Base32Alsw::test_decode();
}

#[cfg_attr(
any(miri, not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))),
ignore
)]
#[test]
#[ignore]
fn base32hex_alsw() {
Base32HexAlsw::test_check();
Base32HexAlsw::test_decode();
Expand Down
34 changes: 32 additions & 2 deletions crates/base64-simd/src/alsw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,47 @@ pub const URL_SAFE_ALSW_DECODE_X2: AlswLut<V256> = UrlSafeAlsw::decode_lut().x2(
mod algorithm {
use super::*;

#[cfg_attr(
any(miri, not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))),
ignore
)]
#[test]
#[ignore]
fn standard_alsw() {
StandardAlsw::test_check();
StandardAlsw::test_decode();
}

#[cfg_attr(
any(miri, not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))),
ignore
)]
#[test]
#[ignore]
fn url_safe_alsw() {
UrlSafeAlsw::test_check();
UrlSafeAlsw::test_decode();
}

#[cfg(feature = "std")]
#[test]
#[ignore]
fn debug_standard_alsw_check() {
let hash = &StandardAlsw::CHECK_HASH;
let offset = &StandardAlsw::CHECK_OFFSET;
let is_primary = |c: u8| StandardAlsw::decode(c) != 0xff;

vsimd::tools::print_fn_table(is_primary, |c: u8| vsimd::alsw::hash(hash, c));
vsimd::tools::print_fn_table(is_primary, |c: u8| vsimd::alsw::check(hash, offset, c));
}

#[cfg(feature = "std")]
#[test]
#[ignore]
fn debug_standard_alsw_decode() {
let hash = &StandardAlsw::DECODE_HASH;
let offset = &StandardAlsw::DECODE_OFFSET;
let is_primary = |c: u8| StandardAlsw::decode(c) != 0xff;

vsimd::tools::print_fn_table(is_primary, |c: u8| vsimd::alsw::hash(hash, c));
vsimd::tools::print_fn_table(is_primary, |c: u8| vsimd::alsw::decode(hash, offset, c));
}
}
5 changes: 4 additions & 1 deletion crates/base64-simd/src/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ mod tests {

#[cfg(test)]
mod algorithm {
#[cfg_attr(
any(miri, not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))),
ignore
)]
#[test]
#[ignore]
fn is_ascii_whitespace() {
for x in 0..=255u8 {
let m1 = (x.wrapping_sub(0x89) as i8) < (-128 + 5);
Expand Down
43 changes: 0 additions & 43 deletions crates/vsimd/src/algorithm.rs

This file was deleted.

17 changes: 16 additions & 1 deletion crates/vsimd/src/alsw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@
// Inspired by <https://gist.github.com/aqrit/a2ccea48d7cac7e9d4d99f19d4759666>
//

use crate::algorithm::{avgr, lookup};
use crate::pod::POD;
use crate::table::u8x16xn_lookup;
use crate::vector::{V128, V256};
use crate::Scalable;

use core::ops::Not;

#[inline]
#[must_use]
pub const fn lookup(lut: &[u8; 16], x: u8) -> u8 {
if x < 0x80 {
lut[(x & 0x0f) as usize]
} else {
0
}
}

#[inline]
#[must_use]
pub const fn avgr(a: u8, b: u8) -> u8 {
((a as u16 + b as u16 + 1) >> 1) as u8
}

#[inline]
#[must_use]
pub const fn hash(hash_lut: &[u8; 16], c: u8) -> u8 {
Expand Down
14 changes: 11 additions & 3 deletions crates/vsimd/src/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ pub fn to_ascii_uppercase<S: Scalable<V>, V: POD>(s: S, x: V) -> V {

#[cfg(test)]
mod algorithm {
use crate::algorithm::*;
#[cfg(feature = "std")]
fn i8_lt(a: i8, b: i8) -> u8 {
if a < b {
0xff
} else {
0x00
}
}

#[cfg(feature = "std")]
#[test]
#[ignore]
fn convert_case() {
Expand All @@ -45,8 +53,8 @@ mod algorithm {
let to_upper = |c: u8| convert(c, b'a');
let to_lower = |c: u8| convert(c, b'A');

print_fn_table(|c| c.is_ascii_lowercase(), to_upper);
print_fn_table(|c| c.is_ascii_uppercase(), to_lower);
crate::tools::print_fn_table(|c| c.is_ascii_lowercase(), to_upper);
crate::tools::print_fn_table(|c| c.is_ascii_uppercase(), to_lower);

for c in 0..=255u8 {
assert_eq!(to_upper(c), c.to_ascii_uppercase());
Expand Down
10 changes: 8 additions & 2 deletions crates/vsimd/src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ mod algorithm {
use super::*;

#[test]
#[ignore]
#[cfg_attr(
any(miri, not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))),
ignore
)]
fn check() {
fn is_hex_v1(c: u8) -> bool {
matches!(c, b'0'..=b'9' | b'a'..=b'f' | b'A'..=b'F')
Expand All @@ -306,7 +309,10 @@ mod algorithm {
}

#[test]
#[ignore]
#[cfg_attr(
any(miri, not(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))),
ignore
)]
fn hex_alsw() {
HexAlsw::test_check();
HexAlsw::test_decode();
Expand Down
2 changes: 0 additions & 2 deletions crates/vsimd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ pub use self::simd256::SIMD256;
mod scalable;
pub use self::scalable::Scalable;

mod algorithm;

pub mod tools;

#[macro_use]
Expand Down
24 changes: 24 additions & 0 deletions crates/vsimd/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,27 @@ pub unsafe fn transmute_copy<A: Copy, B: Copy>(a: &A) -> B {
debug_assert!(core::mem::size_of::<A>() == core::mem::size_of::<B>());
*(a as *const A as *const B)
}

#[cfg(feature = "std")]
#[inline]
pub fn print_fn_table(is_primary: impl Fn(u8) -> bool, f: impl Fn(u8) -> u8) {
print!(" 0 1 2 3 4 5 6 7 8 9 A B C D E F");
for c in 0..=255u8 {
let val = f(c);

if c & 0x0f == 0 {
println!();
print!("{:x} | ", c >> 4);
}

if is_primary(c) {
print!("\x1b[1;31m{val:0>2X}\x1b[0m ");
} else if val >= 0x80 {
print!("\x1b[1;36m{val:0>2X}\x1b[0m ");
} else {
print!("\x1b[1;32m{val:0>2X}\x1b[0m ");
}
}
println!();
println!();
}

0 comments on commit 9baa5bf

Please sign in to comment.