Difference in SIMD and non-SIMD process_token tokens
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 66/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- performance
Research direction
Start at the step function in html5ever/src/tokenizer/mod.rs, comparing the small_char_set! used by pop_except_from (via BufferQueue) with the trailing-byte loop in data_state_simd_fast_path, which skips stopping at \n. Decide which path matches the HTML tokenizer spec, then align the two so process_token receives identical tokens with SIMD forced off (patch is_x86_feature_detected! to false). Done when both paths produce the same token stream; verify with cargo test and the tokenizer test suite.
Written by the indexing model from the issue text.
Description
Summary
SIMD and non-SIMD paths produce different process_token calls.
As the maintainers of html5ever do you think this inconsistency is a bug or normal behaviour?
How it was discovered
The lychee test fails on riscv machine:
https://github.com/lycheeverse/lychee/issues/2263
Inside lychee-lib/src/extract/html/html5ever.rs process_token recieves
different tokens (example in the issue is given). This incosistency breaks tests.
Reason behind it
The step function inside html5ever/src/tokenizer/mod.rs contains following lines:
// ...
let set = small_char_set!('\r' '\0' '&' '<' '\n' );
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
// ...
let result = unsafe { self.data_state_simd_fast_path(&mut front_buffer) };
// ...
#[cfg(not(any(
target_arch = "x86",
target_arch = "x86_64",
target_arch = "aarch64"
)))]
let set_result = self.pop_except_from(input, set);
// ...
SIMD path
Note how data_state_simd_fast_path processes remaining bytes:
// ...
// Process any remaining bytes (less than STRIDE)
while let Some(c) = input.as_bytes().get(i) {
if matches!(*c, b'<' | b'&' | b'\r' | b'\0') {
break;
}
if *c == b'\n' {
n_newlines += 1;
}
i += 1;
}
// ...
non-SIMD path
Note how pop_except_from processes bytes:
let d = input.pop_except_from(set);
input is BufferQueue and set is small_char_set!('\r' '\0' '&' '<' '\n' ). So countrary to the SIMD part this pop stops after \n.
How to reproduce
I was able to reproduce this issue on x86_64 machine by turning SIMD off.
- git clone https://github.com/lycheeverse/lychee && cd lychee
- cargo vendor # don't forget to change .cargo/config.toml
- patch html5ever
--- a/vendor/html5ever/src/tokenizer/mod.rs
+++ b/vendor/html5ever/src/tokenizer/mod.rs
@@ -1921,7 +1921,7 @@ impl<Sink: TokenSink> Tokenizer<Sink> {
fn is_supported_simd_feature_detected() -> bool {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
- is_x86_feature_detected!("sse2")
+ false
}
#[cfg(target_arch = "aarch64")]
- Fix checksums
sed -i -e 's/"files":{[^}]*}/"files":{}/' \
./vendor/html5ever/.cargo-checksum.json
cargo test --frozen -p lychee-lib --lib html5ever::tests::test_include_verbatim
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 291
- Avg merge
- 8h 21m
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from servo/html5ever
-
rcdom: selectedcontent lookup reads self.data, option clone never runsPossibly taken @jdm claimed this 47 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
servo/html5ever#776 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Maintainers usually reply within 1 day
-
Support processing instructions `<?target data>`Possibly taken @Delta-official claimed this 8 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
servo/html5ever#789 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
servo/html5ever#788 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
servo/html5ever#768 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 90/100
fastrevmd-lab/rustmistmcp#161 ·
-
arch-audit refactor
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
SocketDev/socket-patch#1011 ·
Maintainers usually reply within 1 day
-
bug user-priority/P2
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 1 day
-
opencode: an unanswered --version probe launches opencode 2 without per-session service isolationOpen
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
security-advisory
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
MinBZK/regelrecht#1686 ·
Maintainers usually reply within 1 day