mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
Add wuffs_base__uxx__rotate_etc functions
This commit is contained in:
1 parent
a12771373e
commit
d8796aa6d9
8 files changed
+139
-35
No files matched your search
@@ -804,6 +804,56 @@ wuffs_base__u64__max(uint64_t x, uint64_t y) {
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_left(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return (x << n) | (x >> (8 - n));
|
||||
}
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_right(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return (x >> n) | (x << (8 - n));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_left(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return (x << n) | (x >> (16 - n));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_right(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return (x >> n) | (x << (16 - n));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_left(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return (x << n) | (x >> (32 - n));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_right(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return (x >> n) | (x << (32 - n));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_left(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return (x << n) | (x >> (64 - n));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_right(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return (x >> n) | (x << (64 - n));
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms
|
||||
// are per https://locklessinc.com/articles/sat_arithmetic/
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user