Skip to content

Instantly share code, notes, and snippets.

@djg
Created August 16, 2019 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djg/3542fae75e4ea9679ee2d9b04a809a5a to your computer and use it in GitHub Desktop.
Save djg/3542fae75e4ea9679ee2d9b04a809a5a to your computer and use it in GitHub Desktop.
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