machine_check/types/
bitvector.rs1use std::{
2 fmt::Debug,
3 ops::{Add, BitAnd, BitOr, BitXor, Mul, Not, Shl, Sub},
4};
5
6use mck::{
7 concr::{self, IntoMck},
8 forward::{Bitwise, HwArith, HwShift},
9};
10
11use crate::{Signed, Unsigned};
12
13#[derive(Clone, Copy, Hash, PartialEq, Eq)]
21pub struct Bitvector<const L: u32>(pub(super) concr::Bitvector<L>);
22
23impl<const L: u32> Bitvector<L> {
24 pub fn new(value: u64) -> Self {
28 Bitvector(concr::Bitvector::new(value))
29 }
30}
31impl<const L: u32> Not for Bitvector<L> {
34 type Output = Self;
35
36 fn not(self) -> Self::Output {
38 Self(self.0.bit_not())
39 }
40}
41
42impl<const L: u32> BitAnd<Bitvector<L>> for Bitvector<L> {
43 type Output = Self;
44
45 fn bitand(self, rhs: Bitvector<L>) -> Self::Output {
47 Self(self.0.bit_and(rhs.0))
48 }
49}
50impl<const L: u32> BitOr<Bitvector<L>> for Bitvector<L> {
51 type Output = Self;
52
53 fn bitor(self, rhs: Bitvector<L>) -> Self::Output {
55 Self(self.0.bit_or(rhs.0))
56 }
57}
58impl<const L: u32> BitXor<Bitvector<L>> for Bitvector<L> {
59 type Output = Self;
60
61 fn bitxor(self, rhs: Bitvector<L>) -> Self::Output {
63 Self(self.0.bit_xor(rhs.0))
64 }
65}
66
67impl<const L: u32> Add<Bitvector<L>> for Bitvector<L> {
70 type Output = Self;
71
72 fn add(self, rhs: Bitvector<L>) -> Self::Output {
74 Self(self.0.add(rhs.0))
75 }
76}
77
78impl<const L: u32> Sub<Bitvector<L>> for Bitvector<L> {
79 type Output = Self;
80
81 fn sub(self, rhs: Bitvector<L>) -> Self::Output {
83 Self(self.0.sub(rhs.0))
84 }
85}
86
87impl<const L: u32> Mul<Bitvector<L>> for Bitvector<L> {
88 type Output = Self;
89
90 fn mul(self, rhs: Bitvector<L>) -> Self::Output {
92 Self(self.0.mul(rhs.0))
93 }
94}
95
96impl<const L: u32> Shl<Bitvector<L>> for Bitvector<L> {
98 type Output = Self;
99
100 fn shl(self, rhs: Bitvector<L>) -> Self::Output {
111 Self(self.0.logic_shl(rhs.0))
112 }
113}
114
115impl<const L: u32> From<Unsigned<L>> for Bitvector<L> {
117 fn from(value: Unsigned<L>) -> Self {
119 Self(value.0)
120 }
121}
122
123impl<const L: u32> From<Signed<L>> for Bitvector<L> {
124 fn from(value: Signed<L>) -> Self {
126 Self(value.0)
127 }
128}
129
130impl<const L: u32> Debug for Bitvector<L> {
131 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
132 std::fmt::Debug::fmt(&self.0, f)
133 }
134}
135
136#[doc(hidden)]
139impl<const L: u32> IntoMck for Bitvector<L> {
140 type Type = mck::concr::Bitvector<L>;
141
142 fn into_mck(self) -> Self::Type {
143 self.0
144 }
145}