4 ms·
.NET Core 3 (in preview, due out Sep 23) includes support for popcount as part of the BitOperations class: https://docs.microsoft.com/en-us/dotnet/api/system.nu
by jongalloway2 7y ago
.NET Core 3 (in preview, due out Sep 23) includes support for popcount as part of the BitOperations class: https://docs.microsoft.com/en-us/dotnet/api/system.numerics.bitoperations https://docs.microsoft.com/en-us/dotnet/api/system.numerics..... There's a recent post describing hardware intrinsics in .NET Core: https://devblogs.microsoft.com/dotnet/hardware-intrinsics-in-net-core/ https://devblogs.microsoft.com/dotnet/hardware-intrinsics-in...
There are a lot of potential use cases, but one of the early discussions was around quickly scanning for known HTTP headers. You can see that in use here: https://github.com/aspnet/AspNetCore/blob/caa910ceeba5f2b2c02c47a23ead0ca31caea6f0/src/Servers/Kestrel/shared/KnownHeaders.cs#L646 https://github.com/aspnet/AspNetCore/blob/caa910ceeba5f2b2c0...
If you really need help falling asleep, here's the discussion going back to 2015: https://github.com/dotnet/corefx/issues/2209 https://github.com/dotnet/corefx/issues/2209
Disclaimers:
Microsoft employee, Nazgûl
- omgtehlion 7y agoCool! It would be nice to get bitscanforward/reverse too. I created this library long ago to get popcnt on desktop .net: https://github.com/omgtehlion/netintrinsics https://github.com/omgtehlion/netintrinsics Blog post with more details (in Russian): https://m.habr.com/ru/post/239619/ https://m.habr.com/ru/post/239619/ EDIT: found lzcnt/tzcnt on a linked page, thanks! But what about bswap or I'm asking too much? ))
- non-entity 7y ago.NET is getting some really cool stuff lately. Sadly, it'll likely be irrelevant to me for the time to come
- vaibhavsagar 7y agoGHC also includes a `popCount` function that is implemented in terms of the built-in instruction: https://haskell-works.github.io/posts/2018-08-22-pdep-and-pext-bit-manipulation-functions.html#availability-on-ghc https://haskell-works.github.io/posts/2018-08-22-pdep-and-pe...