Remove and replace obselete HexByteDecoderA implementation with HexByteDecoderB

This commit is contained in:
Michael Pfaff 2022-11-01 17:22:59 -04:00
parent a9ede8828c
commit 46b7fc3fea
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
2 changed files with 14 additions and 59 deletions

View File

@ -359,7 +359,6 @@ pub fn bench_micro_hex_byte(c: &mut Criterion) {
});
bench_decoder::<HexByteDecoderA>(c, stringify!(HexByteDecoderA));
bench_decoder::<HexByteDecoderB>(c, stringify!(HexByteDecoderB));
}
pub fn bench_nano_hex_digit(c: &mut Criterion) {
@ -399,7 +398,6 @@ pub fn bench_nano_hex_byte(c: &mut Criterion) {
}
bench_decoder::<HexByteDecoderA>(c, stringify!(HexByteDecoderA));
bench_decoder::<HexByteDecoderB>(c, stringify!(HexByteDecoderB));
}
criterion_group!(

View File

@ -152,48 +152,13 @@ pub trait HexByteSimdDecoder {
pub struct HexByteDecoderA;
impl const HexByteDecoder for HexByteDecoderA {
#[inline(always)]
fn decode_unpacked(hi: u8, lo: u8) -> u16 {
let hi = hex_digit(hi) as u16;
let lo = hex_digit(lo) as u16;
// might these these masks allow the ORs the be pipelined more efficiently?
(hi << 4) | (lo & 0xf) | ((lo & 0xf0) << 8)
}
#[inline(always)]
fn decode_packed([hi, lo]: &[u8; 2]) -> u16 {
let hi = hex_digit(*hi) as u16;
let lo = hex_digit(*lo) as u16;
(hi << 4) | (lo & 0xf) | ((lo & 0xf0) << 8)
}
}
impl HexByteSimdDecoder for HexByteDecoderA {
#[inline(always)]
fn decode_simd(hi_los: [u8; DIGIT_BATCH_SIZE]) -> Option<Simd<u8, WIDE_BATCH_SIZE>> {
let hex_digits = hex_digit_simd::<DIGIT_BATCH_SIZE>(Simd::from_array(hi_los));
if ((hex_digits & simd::splat_n::<DIGIT_BATCH_SIZE>(INVALID_BIT))
.simd_ne(simd::splat_0u8::<DIGIT_BATCH_SIZE>()))
.any()
{
return None;
}
let msb = simd_swizzle!(hex_digits, MSB_INDICES);
let lsb = simd_swizzle!(hex_digits, LSB_INDICES);
Some((msb << simd::splat_n::<WIDE_BATCH_SIZE>(4)) | lsb)
}
}
pub struct HexByteDecoderB;
impl const HexByteDecoder for HexByteDecoderB {
util::defer_impl! {
=> HexByteDecoderA;
//fn decode_unpacked(hi: u8, lo: u8) -> u16;
//fn decode_packed(hi_lo: &[u8; 2]) -> u16;
}
// util::defer_impl! {
// => HexByteDecoderA;
//
// fn decode_unpacked(hi: u8, lo: u8) -> u16;
//
// fn decode_packed(hi_lo: &[u8; 2]) -> u16;
// }
#[inline(always)]
fn decode_unpacked(hi: u8, lo: u8) -> u16 {
@ -351,12 +316,12 @@ macro_rules! merge_hex_digits_into_bytes_inline {
}};
}
impl HexByteSimdDecoder for HexByteDecoderB {
util::defer_impl! {
=> HexByteDecoderA;
//fn decode_simd(hi_los: [u8; DIGIT_BATCH_SIZE]) -> Option<Simd<u8, WIDE_BATCH_SIZE>>;
}
impl HexByteSimdDecoder for HexByteDecoderA {
// util::defer_impl! {
// => HexByteDecoderA;
//
// fn decode_simd(hi_los: [u8; DIGIT_BATCH_SIZE]) -> Option<Simd<u8, WIDE_BATCH_SIZE>>;
// }
#[inline(always)]
fn decode_simd(hi_los: [u8; DIGIT_BATCH_SIZE]) -> Option<Simd<u8, WIDE_BATCH_SIZE>> {
@ -372,7 +337,7 @@ impl HexByteSimdDecoder for HexByteDecoderB {
}
}
pub type HBD = HexByteDecoderB;
pub type HBD = HexByteDecoderA;
pub mod conv {
use core::simd::{LaneCount, Simd, SupportedLaneCount};
@ -699,10 +664,8 @@ mod test {
assert_eq!(hex_byte(hb[0], hb[1]), Some(*b));
assert_eq!(HexByteDecoderA::decode_unpacked(hb[0], hb[1]), *b as u16);
assert_eq!(HexByteDecoderB::decode_unpacked(hb[0], hb[1]), *b as u16);
assert_eq!(HexByteDecoderA::decode_packed(hb), *b as u16);
assert_eq!(HexByteDecoderB::decode_packed(hb), *b as u16);
}
const HEX_BYTES_INVALID: &[[u8; 2]] = &[
@ -721,13 +684,8 @@ mod test {
HexByteDecoderA::decode_unpacked(hb[0], hb[1]) & WIDE_INVALID_BIT,
0
);
assert_ne!(
HexByteDecoderB::decode_unpacked(hb[0], hb[1]) & WIDE_INVALID_BIT,
0
);
assert_ne!(HexByteDecoderA::decode_packed(hb) & WIDE_INVALID_BIT, 0);
assert_ne!(HexByteDecoderB::decode_packed(hb) & WIDE_INVALID_BIT, 0);
}
}
@ -759,7 +717,6 @@ mod test {
println!("bytes: {bytes:04x?}");
}
assert_eq!(HexByteDecoderA::decode_simd(hex_bytes), Some(bytes));
assert_eq!(HexByteDecoderB::decode_simd(hex_bytes), Some(bytes));
/*const HEX_BYTES_INVALID: &[[u8; 2]] = &[
['f' as u8, 'g' as u8],