--- nono/lib/bitops.h 2026/04/29 17:04:57 1.1 +++ nono/lib/bitops.h 2026/04/29 17:05:08 1.1.1.2 @@ -4,6 +4,10 @@ // Licensed under nono-license.txt // +// +// 各種ビット操作 +// + #pragma once #include "header.h" @@ -26,6 +30,19 @@ bitrev(uint8 x) return bitrev_table[x]; } +// 右ローテート +static inline uint32 +ROR32(uint32 a, int n) +{ + // TODO: 各種コンパイラごとにビルトインがあったりなかったりするらしい + n &= 31; + if (n == 0) { + return a; + } else { + return (a >> n) | (a << (32 - n)); + } +} + // mask で指定したいずれかのビットが 0 -> 1 に変化したら true static constexpr bool bit_rising(uint before, uint after, uint mask)