ethnum/intrinsics/native/
shl.rs1use crate::uint::U256;
4use core::mem::MaybeUninit;
5
6#[inline]
7pub fn shl2(r: &mut U256, a: u32) {
8 debug_assert!(a < 256, "shl intrinsic called with overflowing shift");
9
10 let (hi, lo) = if a == 0 {
11 return;
12 } else if a < 128 {
13 ((r.high() << a) | (r.low() >> (128 - a)), r.low() << a)
14 } else {
15 (r.low() << (a & 0x7f), 0)
16 };
17
18 *r = U256::from_words(hi, lo);
19}
20
21#[inline]
22pub fn shl3(r: &mut MaybeUninit<U256>, a: &U256, b: u32) {
23 debug_assert!(b < 256, "shl intrinsic called with overflowing shift");
24
25 let (hi, lo) = if b == 0 {
26 (*a.high(), *a.low())
27 } else if b < 128 {
28 ((a.high() << b) | (a.low() >> (128 - b)), a.low() << b)
29 } else {
30 (a.low() << (b & 0x7f), 0)
31 };
32
33 r.write(U256::from_words(hi, lo));
34}