Created
August 16, 2019 10:20
-
-
Save djg/c4a8ed552b4e0e8d5f2883d4224143cb to your computer and use it in GitHub Desktop.
Proposed FHDL in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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