#[inline(always)]
pub fn rotl64(x: u64, n: u32) -> u64 {
let n = n & 63; x.rotate_left(n)
}
#[inline(always)]
pub fn rotr64(x: u64, n: u32) -> u64 {
let n = n & 63; x.rotate_right(n)
}
#[inline(always)]
pub fn rotl8(x: u8, n: u8) -> u8 {
let n = n & 7; x.rotate_left(n as u32)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_rotl64() {
assert_eq!(rotl64(0x0000000000000001, 1), 0x0000000000000002);
assert_eq!(rotl64(0x8000000000000000, 1), 0x0000000000000001);
assert_eq!(rotl64(0x1234567890ABCDEF, 0), 0x1234567890ABCDEF);
}
#[test]
fn test_rotr64() {
assert_eq!(rotr64(0x0000000000000002, 1), 0x0000000000000001);
assert_eq!(rotr64(0x0000000000000001, 1), 0x8000000000000000);
assert_eq!(rotr64(0x1234567890ABCDEF, 0), 0x1234567890ABCDEF);
}
#[test]
fn test_rotl8() {
assert_eq!(rotl8(0x01, 1), 0x02);
assert_eq!(rotl8(0x80, 1), 0x01);
assert_eq!(rotl8(0xFF, 4), 0xFF);
}
}