News for hackers. Stuff that matters.
Re:From Rust to reality: The hidden journey of fetch_max by tialaramex on Wednesday September 24, 2025 @08:31AM (#45359386)
The existence of platform specific hacks is not interesting. In reality what happens is that software which has at any point cared about being portable doesn't use them.

But yes stdc_count_ones is indeed the intrinsic you'd want here, and only a few years after I stopped writing C, so thanks for mentioning that.

std::popcount is C++ but it's also kinda miserable that it took until C++ 20 and yet they still only landed the unsigned integer types, even though C++ 20 also insists the signed integers have two's complement representation, so the signed integers do have these desirable properties in fact but you can't use that.

Re:From Rust to reality: The hidden journey of fetch_max by articulatepang on Wednesday September 24, 2025 @11:13AM (#45361519)
> In reality what happens is that software which has at any point cared about being portable doesn't use them.

I don't think this generalization is actually true. Fast portable software compiles conditionally based on the target platform, picking the fast platform-specific intrinsic, and falls back to a slow but guaranteed portable software implementation. This pattern is widespread in numerical linear algebra, media codecs, data compressors, encryption, graphics, etc.

Re:From Rust to reality: The hidden journey of fetch_max by toth on Wednesday September 24, 2025 @10:06AM (#45360609)
Maybe we are just quibbling over semantics but the compiler intrinsic here is '__builtin_popcount'. 'stdc_count_ones' is a standard library element that presumably will be implemented using the intrinsic.

And FWIW all major C/C++ have for a long time have had a an intrinsic for this. In clang it even has the same name, Visual Studio it's something like just '_popcount'. So it has long been easy to roll your own macro that works everywhere.

Re:From Rust to reality: The hidden journey of fetch_max by tialaramex on Wednesday September 24, 2025 @11:16AM (#45361567)
Yes, just semantics. But I don't think I can agree that because you could have ensured this works portably people actually did. That's not been my experience.

Yesterday I watched that "Sea of Thieves" C++ 14 to C++ 20 upgrade story on Youtube, that feels much more like what I've seen - code that shouldn't have worked but it did, kept alive by people whose priority is a working game.

Re:From Rust to reality: The hidden journey of fetch_max by gpderetta on Wednesday September 24, 2025 @10:55AM (#45361288)
__builtin_popcount is not platform specific.
Re:From Rust to reality: The hidden journey of fetch_max by tialaramex on Wednesday September 24, 2025 @11:18AM (#45361598)
OK, sure, vendor specific then. C23 does not promise this incantation, it's presumably a GCCism.