Skip to content

Instantly share code, notes, and snippets.

@djg djg/alu.rs
Created Aug 16, 2019

Embed
What would you like to do?
Proposed FHDL in Rust
struct Alu {
pub sel: Signal,
pub a: Signal,
pub b: Signal,
pub o: Signal,
pub co: Signal,
}
impl Alu {
#[fhdl]
pub fn new(width: u16) -> Self {
Alu {
sel: signal!(2),
a: signal!(width),
b: signal!(width),
o: signal!(width),
co: signal!(),
}
}
#[fhdl]
pub fn fragment(&self) {
#[comb]
if self.sel == 0x0 {
self.o = self.a | self.b
} else if self.sel == 0x1 {
self.o = self.a & self.b
} else if self.sel == 0x2 {
self.o = self.a ^ self.b
} else {
cat!(self.o, self.co) = self.a - self.b
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.