Alternative conditional implementation of strlen #4493
alexcu2718
started this conversation in
Show and tell
Replies: 2 comments 1 reply
-
|
If this work is derived (partially) from glibc source, then it is against libc crate license, I think? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thanks for sharing your code - though I'm not sure exactly what you would be proposing for this crate, |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I'm quite new to programming and Rust in general, as forewarning!
I read the guidelines but honestly I couldn't read through too much,
Anyway the reason I post here today is because I wanted to share a really interesting function I made and I don't want to let it go to waste in some stupid crate noone will ever use.
It's a (conditionally) constant version of strlen, only when used in context on dirent64 structure's, it has no branches and using SWAR(simd within a register) to do the operation in one go. I didn't study computer science but sometimes mathematicians swap hats.
(You can probably add some safe wrappers where appropriate too)
It's probably got some snags, it's obviously Linux specific, I'm not sure about weird architectures, those are easy to feature flag away. Luckily due to no intrinsics it's not specifically architecture bound. I've not tested it enough(though to be fair, if this even compiles, it likely works!)
THERE ARE LIKELY A LOT OF CASES WHERE IT WONT WORK
However, I'm posting this here because I thought it would be of interest, especially being in readdir etc.
I apologise if this is in the wrong place, kinda happy and don't know enough.
Of course, it wouldn't be complete without benchmarks.
You can find my repo at
https://github.com/alexcu2718/fdf
then git clone ... and cargo bench.
strlen_comparison/dirent_const_time_single/case_1 time: [1.0157 ns 1.0208 ns 1.0260 ns] thrpt: [8.7716 Gelem/s 8.8162 Gelem/s 8.8611 Gelem/s] change: time: [−24.104% −23.281% −22.455%] (p = 0.00 < 0.05) thrpt: [+28.957% +30.346% +31.759%] Performance has improved. Found 12 outliers among 500 measurements (2.40%) 10 (2.00%) high mild 2 (0.40%) high severe strlen_comparison/libc_strlen_single/case_1 time: [2.2868 ns 2.3168 ns 2.3488 ns] thrpt: [3.8318 Gelem/s 3.8846 Gelem/s 3.9356 Gelem/s] change: time: [+2.6941% +3.4345% +4.2209%] (p = 0.00 < 0.05) thrpt: [−4.0499% −3.3205% −2.6234%] Performance has regressed. ## LONGESTSTRINGS(240~) strlen_comparison/dirent_const_time_single/case_8 time: [1.0524 ns 1.0571 ns 1.0618 ns] thrpt: [8.4765 Gelem/s 8.5142 Gelem/s 8.5523 Gelem/s] change: time: [−47.073% −46.039% −45.017%] (p = 0.00 < 0.05) thrpt: [+81.875% +85.319% +88.938%] Performance has improved. Found 2 outliers among 500 measurements (0.40%) 1 (0.20%) high mild 1 (0.20%) high severe strlen_comparison/libc_strlen_single/case_8 time: [4.1926 ns 4.2135 ns 4.2376 ns] thrpt: [2.1238 Gelem/s 2.1360 Gelem/s 2.1466 Gelem/s] change: time: [−33.151% −32.598% −32.052%] (p = 0.00 < 0.05) thrpt: [+47.170% +48.363% +49.592%]Beta Was this translation helpful? Give feedback.
All reactions