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.
Beta Was this translation helpful? Give feedback.
All reactions