-
-
Notifications
You must be signed in to change notification settings - Fork 124
[WIP] SIMD support for x86/x86_64 #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
seanmonstar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super impressive!
| // ASCII codes to accept URI string. | ||
| // i.e. A-Z a-z 0-9 !#$%&'*+-._();:@=,/?[]~ | ||
| // TODO: Make a stricter checking for URI string? | ||
| static URI_MAP: [bool; 256] = byte_map![ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just cause I'm curious, why is this different from just parsing as a token?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From RFC7230 Section 3.2.6, we can get the formalize description of token:
token = 1*tchar
tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
/ "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
/ DIGIT / ALPHA
; any VCHAR, except delimiters
Current is_token(b: u8) -> bool; is not satisfy this def, I think that should be changed.
For URI matching, depends on the safeguard requirement, the accepted charset may differ, IMO, we should be careful here, maybe we can provide a strict mode, which is an optional feature here? That's why I extract a URI_MAP here.
src/lib.rs
Outdated
| // TODO: Make a stricter checking for URI string? | ||
| static URI_MAP: [bool; 256] = byte_map![ | ||
| 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this indentation difference intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My fault, I should check my editor config.
|
|
||
| static HEADER_VALUE_MAP: [bool; 256] = byte_map![ | ||
| 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, | ||
| 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes! Just checked, this was previously allowing Backspace instead of Horizontal Tab 😢
Thanks for the fix!
| } | ||
|
|
||
| #[cfg(feature = "nightly")] | ||
| #[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "avx2"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if a user has enabled the nightly feature, but their compile target doesn't support these? We'd need match_url_char_32 versions for those too, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this previous, we need to add an SSE4.2 version here? Is it reasonable?
I think the completed constaints should be:
nightly AND (x86 OR x86_64) AND AVX2=> enable AVX2 support;nightly AND (x86 OR x86_64) AND SSE4.2=> enable SSE4.2 support;- otherwise, use the fallback implementation.
But this will cause a rather lengthy #[cfg(...)], I don't know how to simply it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, its probably reasonable. Not too worried about complicated cfg attributes.
|
Oh, not required, but it'd be neat to see also what the bench results are without |
|
I'm so sorry I forgot about this! Just a few quick questions:
|
|
@seanmonstar The |
| let ptr = buf.as_ptr(); | ||
|
|
||
| #[allow(non_snake_case, overflowing_literals)] | ||
| unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you didn't catch it, there's an accidental indentation here
|
I've taken what was started here and got it working and running tests in #40. Thanks so much! |
Simple bench result
With AVX2
Bench with
RUSTFLAGS="-C target-feature=+avx2,+bmi" cargo bench --features=nightlyWith SSE4.2
Bench with
RUSTFLAGS="-C target-feature=+sse42,+bmi" cargo bench --features=nightlyWithout SIMD
Bench with
cargo benchYou may get a different mileage, depends on the specified platform.