mcandre / toys

code demos for newbies
https://github.com/mcandre/toys
30 stars 6 forks source link

sha2: s/__builtin_rotateright32/std::rotr/g #278

Closed mcandre closed 8 months ago

mcandre commented 2 years ago

Rotation functions may require delegation with macros.

mcandre commented 2 years ago

C++20 adds std::rotr in the <bit> library.

gcc (g++) said to support this as early as gcc (g++) v8.

Cannot find documentation for which clang version adds support for that.

Both clang and MSVC are said to have partial C++20 support, which isn't helpful. It just complicates everything.

mcandre commented 2 years ago

A quick test on godbolt reveals clang support for std::rotr as of at least v10.

When I try to do this in gcc (g++) however, the -std=c++20 flag is rejected until gcc 10[.1]. Which is unfortunately ahead of Ubuntu LTS gcc (g++).

mcandre commented 2 years ago

godbolt MSVC shows support for std::rotr as of v19.30.

We could add a caveat to the build documentation that any gcc (g++) version must be 10.1 or higher. But we wouldn't actually verify that locally, due to this version being missing from Ubuntu LTS at the moment.

The long term plan is to drop testing support for MSVC. It's been a hassle testing multiple compilers, polluting the Makefile/CMakelists.txt configuration with so many extra edge cases. Dropping MSVC will collapse the scripts to just gcc vs clang checks.

Still, it is good to adopt std::rotr instead of unnecessarily vendor locking onto compiler-specific intrinsics.

Pending gcc (g++) 10.1 or higher landing in both Debian stable and Ubuntu LTS.

Debian stable support is already there: https://packages.debian.org/bullseye/g++

Ubuntu strangely threw away its Hirsute 21.04 release as non-LTS. Perhaps Jammy will release soon.

https://packages.ubuntu.com/search?suite=jammy&searchon=names&keywords=g%2B%2B