sp1_core_machine/bytes/
utils.rs

1/// Shifts a byte to the right and returns both the shifted byte and the bits that carried.
2pub const fn shr_carry(input: u8, rotation: u8) -> (u8, u8) {
3    let c_mod = rotation & 0x7;
4    if c_mod != 0 {
5        let res = input >> c_mod;
6        let carry = (input << (8 - c_mod)) >> (8 - c_mod);
7        (res, carry)
8    } else {
9        (input, 0u8)
10    }
11}
12
13#[cfg(test)]
14mod tests {
15    #![allow(clippy::print_stdout)]
16
17    use super::*;
18
19    /// Tests the `shr_carry` function.
20    #[test]
21    fn test_shr_carry() {
22        println!("{:?}", shr_carry(0, 2));
23    }
24}