Coverage Report

Created: 2025-11-16 06:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/crypto-bigint-0.5.5/src/limb/shr.rs
Line
Count
Source
1
//! Limb right bitshift
2
3
use crate::{Limb, Word};
4
use core::ops::{Shr, ShrAssign};
5
6
impl Limb {
7
    /// Computes `self >> rhs`.
8
    /// Panics if `rhs` overflows `Limb::BITS`.
9
    #[inline(always)]
10
0
    pub const fn shr(self, rhs: Self) -> Self {
11
0
        Limb(self.0 >> rhs.0)
12
0
    }
13
}
14
15
impl Shr for Limb {
16
    type Output = Self;
17
18
    #[inline(always)]
19
0
    fn shr(self, rhs: Self) -> Self::Output {
20
0
        self.shr(rhs)
21
0
    }
22
}
23
24
impl Shr<usize> for Limb {
25
    type Output = Self;
26
27
    #[inline(always)]
28
0
    fn shr(self, rhs: usize) -> Self::Output {
29
0
        self.shr(Limb(rhs as Word))
30
0
    }
31
}
32
33
impl ShrAssign for Limb {
34
    #[inline(always)]
35
0
    fn shr_assign(&mut self, other: Self) {
36
0
        *self = self.shr(other);
37
0
    }
38
}
39
40
impl ShrAssign<usize> for Limb {
41
    #[inline(always)]
42
0
    fn shr_assign(&mut self, other: usize) {
43
0
        *self = self.shr(Limb(other as Word));
44
0
    }
45
}
46
47
#[cfg(test)]
48
mod tests {
49
    use crate::Limb;
50
51
    #[test]
52
    fn shr1() {
53
        assert_eq!(Limb(2) >> 1, Limb(1));
54
    }
55
56
    #[test]
57
    fn shr2() {
58
        assert_eq!(Limb(16) >> 2, Limb(4));
59
    }
60
61
    #[test]
62
    fn shr_assign1() {
63
        let mut l = Limb::ONE;
64
        l >>= 1;
65
        assert_eq!(l, Limb::ZERO);
66
    }
67
68
    #[test]
69
    fn shr_assign2() {
70
        let mut l = Limb(32);
71
        l >>= 2;
72
        assert_eq!(l, Limb(8));
73
    }
74
}