ethnum/intrinsics/
signed.rs

1//! Module containing signed wrapping functions around various intrinsics that
2//! are agnostic to sign.
3//!
4//! This module can be helpful when using intrinsics directly.
5
6pub use super::{
7    add2 as uadd2, add3 as uadd3, ctlz as uctlz, cttz as ucttz, iaddc, idiv2, idiv3, imulc, irem2,
8    irem3, isubc, mul2 as umul2, mul3 as umul3, rol3 as urol3, ror3 as uror3, sar2 as isar2,
9    sar3 as isar3, shl2 as ushl2, shl3 as ushl3, shr2 as ushr2, shr3 as ushr3, sub2 as usub2,
10    sub3 as usub3, uaddc, udiv2, udiv3, umulc, urem2, urem3, usubc,
11};
12use crate::int::I256;
13use core::mem::MaybeUninit;
14
15#[inline]
16pub fn iadd2(r: &mut I256, a: &I256) {
17    super::add2(cast!(mut: r), cast!(ref: a));
18}
19
20#[inline]
21pub fn iadd3(r: &mut MaybeUninit<I256>, a: &I256, b: &I256) {
22    super::add3(cast!(uninit: r), cast!(ref: a), cast!(ref: b));
23}
24
25#[inline]
26pub fn isub2(r: &mut I256, a: &I256) {
27    super::sub2(cast!(mut: r), cast!(ref: a));
28}
29
30#[inline]
31pub fn isub3(r: &mut MaybeUninit<I256>, a: &I256, b: &I256) {
32    super::sub3(cast!(uninit: r), cast!(ref: a), cast!(ref: b));
33}
34
35#[inline]
36pub fn imul2(r: &mut I256, a: &I256) {
37    super::mul2(cast!(mut: r), cast!(ref: a));
38}
39
40#[inline]
41pub fn imul3(r: &mut MaybeUninit<I256>, a: &I256, b: &I256) {
42    super::mul3(cast!(uninit: r), cast!(ref: a), cast!(ref: b));
43}
44
45#[inline]
46pub fn ishl2(r: &mut I256, a: u32) {
47    super::shl2(cast!(mut: r), a);
48}
49
50#[inline]
51pub fn ishl3(r: &mut MaybeUninit<I256>, a: &I256, b: u32) {
52    super::shl3(cast!(uninit: r), cast!(ref: a), b);
53}
54
55#[inline]
56pub fn irol3(r: &mut MaybeUninit<I256>, a: &I256, b: u32) {
57    super::rol3(cast!(uninit: r), cast!(ref: a), b);
58}
59
60#[inline]
61pub fn iror3(r: &mut MaybeUninit<I256>, a: &I256, b: u32) {
62    super::ror3(cast!(uninit: r), cast!(ref: a), b);
63}
64
65#[inline]
66pub fn ictlz(a: &I256) -> u32 {
67    super::ctlz(cast!(ref: a))
68}
69
70#[inline]
71pub fn icttz(a: &I256) -> u32 {
72    super::cttz(cast!(ref: a))
73}
74
75#[cfg(test)]
76mod tests {
77    use super::*;
78    use crate::uint::U256;
79    use core::alloc::Layout;
80
81    #[test]
82    fn layout() {
83        assert_eq!(Layout::new::<I256>(), Layout::new::<U256>());
84    }
85}