Coverage Report

Created: 2026-10-28 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/base64-simd-0.8.0/src/check.rs
Line
Count
Source
1
use crate::alsw::{STANDARD_ALSW_CHECK_X2, URL_SAFE_ALSW_CHECK_X2};
2
use crate::decode::{decode_ascii4, decode_ascii8, decode_extra};
3
use crate::decode::{STANDARD_DECODE_TABLE, URL_SAFE_DECODE_TABLE};
4
use crate::{Config, Error, Kind};
5
6
use vsimd::alsw::AlswLut;
7
use vsimd::vector::V256;
8
use vsimd::SIMD256;
9
10
use core::ptr::null_mut;
11
12
#[inline]
13
0
pub(crate) unsafe fn check_fallback(mut src: *const u8, mut n: usize, config: Config) -> Result<(), Error> {
14
0
    let kind = config.kind;
15
0
    let forgiving = config.extra.forgiving();
16
17
0
    let table = match kind {
18
0
        Kind::Standard => STANDARD_DECODE_TABLE.as_ptr(),
19
0
        Kind::UrlSafe => URL_SAFE_DECODE_TABLE.as_ptr(),
20
    };
21
22
    unsafe {
23
        // n*3/4 >= 6+2
24
0
        while n >= 11 {
25
0
            decode_ascii8::<false>(src, null_mut(), table)?;
26
0
            src = src.add(8);
27
0
            n -= 8;
28
        }
29
30
0
        while n >= 4 {
31
0
            decode_ascii4::<false>(src, null_mut(), table)?;
32
0
            src = src.add(4);
33
0
            n -= 4;
34
        }
35
36
0
        decode_extra::<false>(n, src, null_mut(), table, forgiving)
37
    }
38
0
}
39
40
#[inline(always)]
41
0
pub(crate) unsafe fn check_simd<S: SIMD256>(
42
0
    s: S,
43
0
    mut src: *const u8,
44
0
    mut n: usize,
45
0
    config: Config,
46
0
) -> Result<(), Error> {
47
0
    let kind = config.kind;
48
49
0
    let check_lut = match kind {
50
0
        Kind::Standard => STANDARD_ALSW_CHECK_X2,
51
0
        Kind::UrlSafe => URL_SAFE_ALSW_CHECK_X2,
52
    };
53
54
    unsafe {
55
        // n*3/4 >= 24+4
56
0
        while n >= 38 {
57
0
            let x = s.v256_load_unaligned(src);
58
0
            let is_valid = check_ascii32(s, x, check_lut);
59
0
            ensure!(is_valid);
60
0
            src = src.add(32);
61
0
            n -= 32;
62
        }
63
64
0
        check_fallback(src, n, config)
65
    }
66
0
}
Unexecuted instantiation: base64_simd::check::check_simd::<vsimd::isa::AVX2>
Unexecuted instantiation: base64_simd::check::check_simd::<vsimd::isa::SSSE3>
67
68
#[inline(always)]
69
0
fn check_ascii32<S: SIMD256>(s: S, x: V256, check: AlswLut<V256>) -> bool {
70
0
    vsimd::alsw::check_ascii_xn(s, x, check)
71
0
}
Unexecuted instantiation: base64_simd::check::check_ascii32::<vsimd::isa::AVX2>
Unexecuted instantiation: base64_simd::check::check_ascii32::<vsimd::isa::SSSE3>