]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fundamental: prefer byte swap builtins over byte swapping manually
authorRose <83477269+AtariDreams@users.noreply.github.com>
Tue, 2 Jan 2024 20:24:58 +0000 (15:24 -0500)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 3 Jan 2024 06:11:55 +0000 (15:11 +0900)
This builtin reduces complexity and GCC/Clang have supported these builtins for a long time.

src/fundamental/sha256.c

index 4389e9e37c5a54b50ff9cdb812e4ced80ae64c33..4447ad8a66074afa585e179185b45804f3051ec7 100644 (file)
 
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 # define SWAP(n)                                                        \
-        (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+        __builtin_bswap32(n)
 # define SWAP64(n)                              \
-        (((n) << 56)                            \
-         | (((n) & 0xff00) << 40)               \
-         | (((n) & 0xff0000) << 24)             \
-         | (((n) & 0xff000000) << 8)            \
-         | (((n) >> 8) & 0xff000000)            \
-         | (((n) >> 24) & 0xff0000)             \
-         | (((n) >> 40) & 0xff00)               \
-         | ((n) >> 56))
+        __builtin_bswap64(n)
 #else
 # define SWAP(n) (n)
 # define SWAP64(n) (n)