Lol -- "Like cttz, but extra-unsafe (...)" https://doc.rust-lang.org/std/intrinsics/fn.cttz_nonzero.html …
-
Show this thread
-
Anyway, found the definition of "<integer>.trailing_zeros()" in the source https://github.com/rust-lang/rust/blob/8ec22e7ec7ed0da2add0763d239e77c5474f3d4a/src/libcore/intrinsics.rs#L1408 … Which in turn is compiled into this LLVM code: https://llvm.org/docs/LangRef.html#llvm-cttz-intrinsic … There doesn't appear to be any "intrinsic" available in either to count "trailing ones".
1 reply 0 retweets 0 likesShow this thread -
This is the fastest I can get this by the way (thanks to
@sadisticsystems for suggestion). I'm don't think there might be a way to speed things up further. Kind of wish `.trailing_ones()` could be a thing. Maybe this would make for a good RFC? https://godbolt.org/z/7g8ZM5 pic.twitter.com/krXHJ06lcK
3 replies 0 retweets 1 likeShow this thread -
Replying to @yoshuawuyts @sadisticsystems
with ` -C target-cpu=native` it'll use the tzcnt instruction (on whatever machine godbolt runs at least)
1 reply 0 retweets 2 likes -
Replying to @killercup @sadisticsystems
Woahhhh! Had no idea that was a thing; makes a lot of sense tho!pic.twitter.com/bhhFtXXqAv
2 replies 0 retweets 0 likes -
Replying to @yoshuawuyts @sadisticsystems
and now you made me look up intrinsics
how about bsr for your "trailing ones" problem? https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=bit_scan&expand=392,393,400,401 …1 reply 0 retweets 1 like -
Replying to @killercup
Hmm, if I'm reading that correctly it would return a different result. E.g. 0b0101 Result: 3 Expected: 1
1 reply 0 retweets 0 likes -
Replying to @yoshuawuyts
Ah, you're right. Sorry. So it's back to negation and bsf/tzcnt
1 reply 0 retweets 1 like
Wrote an RFC covering everything we've talked about! :D https://internals.rust-lang.org/t/pre-rfc-leading-ones-trailing-ones/8762 …
-
-
Replying to @yoshuawuyts
very cool! (i think in the examples you meant to use trailing_zeros instead of count_zeros? and fun -- i recall learning what ~42 does in js!)
1 reply 0 retweets 1 like -
Replying to @killercup @yoshuawuyts
btw forgot to post this last night (haven't read all of it yet but seems interesting if you're into that sort of thing) https://arxiv.org/pdf/1611.07612.pdf …
0 replies 0 retweets 1 like
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.