crypto_bigint/limb/
shl.rs1use crate::{Limb, Word};
4use core::ops::{Shl, ShlAssign};
5
6impl Limb {
7 #[inline(always)]
10 pub const fn shl(self, rhs: Self) -> Self {
11 Limb(self.0 << rhs.0)
12 }
13}
14
15impl Shl for Limb {
16 type Output = Self;
17
18 #[inline(always)]
19 fn shl(self, rhs: Self) -> Self::Output {
20 self.shl(rhs)
21 }
22}
23
24impl Shl<usize> for Limb {
25 type Output = Self;
26
27 #[inline(always)]
28 fn shl(self, rhs: usize) -> Self::Output {
29 self.shl(Limb(rhs as Word))
30 }
31}
32
33impl ShlAssign for Limb {
34 #[inline(always)]
35 fn shl_assign(&mut self, other: Self) {
36 *self = self.shl(other);
37 }
38}
39
40impl ShlAssign<usize> for Limb {
41 #[inline(always)]
42 fn shl_assign(&mut self, other: usize) {
43 *self = self.shl(Limb(other as Word));
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use crate::Limb;
50
51 #[test]
52 fn shl1() {
53 assert_eq!(Limb(1) << 1, Limb(2));
54 }
55
56 #[test]
57 fn shl2() {
58 assert_eq!(Limb(1) << 2, Limb(4));
59 }
60
61 #[test]
62 fn shl_assign1() {
63 let mut l = Limb(1);
64 l <<= 1;
65 assert_eq!(l, Limb(2));
66 }
67
68 #[test]
69 fn shl_assign2() {
70 let mut l = Limb(1);
71 l <<= 2;
72 assert_eq!(l, Limb(4));
73 }
74}