Skip to content

Commit

Permalink
adapt tests to use baa
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Sep 12, 2024
1 parent 0f36325 commit db5d0ff
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 144 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion interp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ calyx-frontend = { path = "../calyx-frontend" }
btor2i = { path = "../tools/btor2/btor2i" }

ciborium = "0.2.2"
baa = { version = "0.4.1", features = ["bigint", "serde1", "fraction1"] }
baa = { version = "0.5.1", features = ["bigint", "serde1", "fraction1"] }

[dev-dependencies]
proptest = "1.0.0"
Expand Down
7 changes: 7 additions & 0 deletions interp/proptest-regressions/tests/values.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 8bfbc0242b84cd41283ecc9c000e88751215cf3bbef619b67f08dcb64f8ab602 # shrinks to input = 0
4 changes: 2 additions & 2 deletions interp/src/flatten/flat_ir/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,10 @@ impl PortValue {
PrintCode::Unsigned => format!("{}", v.to_big_uint()),
PrintCode::Signed => format!("{}", v.to_big_int()),
PrintCode::UFixed(num) => {
format!("{}", v.to_unsigned_fixed_point(num))
format!("{}", v.to_unsigned_fixed_point(num).unwrap())
}
PrintCode::SFixed(num) => {
format!("{}", v.to_signed_fixed_point(num))
format!("{}", v.to_signed_fixed_point(num).unwrap())
}
PrintCode::Binary => format!("{}", v.to_bit_str()),

Check failure on line 600 in interp/src/flatten/flat_ir/base.rs

View workflow job for this annotation

GitHub Actions / Check Formatting

useless use of `format!`
}
Expand Down
15 changes: 6 additions & 9 deletions interp/src/flatten/primitives/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub fn build_primitive(
SingleWidthType::Neq => Box::new(StdNeq::new(base_port)),
SingleWidthType::Ge => Box::new(StdGe::new(base_port)),
SingleWidthType::Le => Box::new(StdLe::new(base_port)),
SingleWidthType::Lsh => Box::new(StdLsh::new(base_port, *width)),
SingleWidthType::Rsh => Box::new(StdRsh::new(base_port, *width)),
SingleWidthType::Lsh => Box::new(StdLsh::new(base_port)),
SingleWidthType::Rsh => Box::new(StdRsh::new(base_port)),
SingleWidthType::Mux => Box::new(StdMux::new(base_port)),
SingleWidthType::Wire => Box::new(StdWire::new(base_port)),
SingleWidthType::SignedAdd => Box::new(StdAdd::new(base_port)),
Expand Down Expand Up @@ -83,7 +83,7 @@ pub fn build_primitive(
Box::new(Sqrt::<false>::new(base_port, *width, None))
}
SingleWidthType::UnsynMult => {
Box::new(StdUnsynMult::new(base_port, *width))
Box::new(StdUnsynMult::new(base_port))
}
SingleWidthType::UnsynDiv => {
Box::new(StdUnsynDiv::new(base_port, *width))
Expand All @@ -92,7 +92,7 @@ pub fn build_primitive(
Box::new(StdUnsynMod::new(base_port, *width))
}
SingleWidthType::UnsynSMult => {
Box::new(StdUnsynSmult::new(base_port, *width))
Box::new(StdUnsynSmult::new(base_port))
}
SingleWidthType::UnsynSDiv => {
Box::new(StdUnsynSdiv::new(base_port, *width))
Expand Down Expand Up @@ -142,18 +142,15 @@ pub fn build_primitive(
DoubleWidthType::Pad => Box::new(StdPad::new(base_port, *width2)),
},
CellPrototype::TripleWidth {
op,
width1,
width2,
width3,
op, width1, width2, ..
} => match op {
TripleWidthType::Cat => {
// Turns out under the assumption that the primitive is well formed,
// none of these parameter values are actually needed
Box::new(StdCat::new(base_port))
}
TripleWidthType::BitSlice => {
Box::new(StdBitSlice::new(base_port, *width1, *width2, *width3))
Box::new(StdBitSlice::new(base_port, *width1, *width2))
}
},

Expand Down
10 changes: 5 additions & 5 deletions interp/src/flatten/primitives/combinational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ comb_primitive!(StdFpSub(left [0], right [1]) -> (out [2]) {
});

// ===================== Shift Operations ======================
comb_primitive!(StdLsh[WIDTH](left [0], right [1]) -> (out [2]) {
comb_primitive!(StdLsh(left [0], right [1]) -> (out [2]) {
all_defined!(left, right);
Ok(Some(left.shift_left(right)))
});

comb_primitive!(StdRsh[WIDTH](left [0], right [1]) -> (out [2]) {
comb_primitive!(StdRsh(left [0], right [1]) -> (out [2]) {
all_defined!(left, right);
Ok(Some(left.shift_right(right)))
});
Expand Down Expand Up @@ -230,14 +230,14 @@ comb_primitive!(StdCat(left [0], right [1]) -> (out [2]) {
Ok(Some(left.concat(right).into()))

Check failure on line 230 in interp/src/flatten/primitives/combinational.rs

View workflow job for this annotation

GitHub Actions / Check Formatting

useless conversion to the same type: `baa::BitVecValue`
});

comb_primitive!(StdBitSlice[START_IDX, END_IDX, OUT_WIDTH](input [0]) -> (out [1]) {
comb_primitive!(StdBitSlice[START_IDX, END_IDX](input [0]) -> (out [1]) {
all_defined!(input);
let (msb, lsb) = (END_IDX, START_IDX);
Ok(Some(input.slice(msb, lsb)))
});

// ===================== Unsynthesizeable Operations ======================
comb_primitive!(StdUnsynMult[WIDTH](left [0], right [1]) -> (out [2]) {
comb_primitive!(StdUnsynMult(left [0], right [1]) -> (out [2]) {
all_defined!(left, right);
Ok(Some(left.mul(right)))
});
Expand All @@ -248,7 +248,7 @@ comb_primitive!(StdUnsynDiv[WIDTH](left [0], right [1]) -> (out [2]) {
Ok(Some(BitVecValue::from_big_uint(&res, WIDTH)))
});

comb_primitive!(StdUnsynSmult[WIDTH](left [0], right [1]) -> (out [2]) {
comb_primitive!(StdUnsynSmult(left [0], right [1]) -> (out [2]) {
all_defined!(left, right);
// FIXME: is there a difference for signed?
Ok(Some(left.mul(right)))
Expand Down
6 changes: 3 additions & 3 deletions interp/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ macro_rules! lit_or_id {
/// ```
macro_rules! port_bindings {
( $binds: ident; $( $port: ident -> ($val: tt, $width: tt) ),+ ) => {
$( let $port = $crate::values::BitVecValue::from($crate::lit_or_id!($val), $crate::lit_or_id!($width)); )+
$( let $port = baa::BitVecValue::from_u64($crate::lit_or_id!($val), $crate::lit_or_id!($width)); )+
let $binds = vec![ $( (calyx_ir::Id::from($crate::in_fix!($port)), &$port) ),+ ];
}
}

/// Helper macro to generate validation checks for the input passed to primitives
/// ```
/// # use interp::validate;
/// # use interp::values::BitVecValue;
/// # use baa::BitVecValue;
/// # let input = [("left", [4,4,4,4])];
/// # let inputs = &input;
/// # let width = 4;
Expand All @@ -73,7 +73,7 @@ macro_rules! validate {
/// primitives, does not error on unknown ports
/// ```
/// # use interp::validate_friendly;
/// # use interp::values::BitVecValue;
/// # use baa::BitVecValue;
/// # let input = [("left", [4,4,4,4])];
/// # let inputs = &input;
/// # let width = 4;
Expand Down
8 changes: 6 additions & 2 deletions interp/src/serialization/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ impl Entry {
match code {
PrintCode::Unsigned => val.to_u64().unwrap().into(),
PrintCode::Signed => val.to_i64().unwrap().into(),
PrintCode::UFixed(f) => val.to_unsigned_fixed_point(*f).into(),
PrintCode::SFixed(f) => val.to_signed_fixed_point(*f).into(),
PrintCode::UFixed(f) => {
val.to_unsigned_fixed_point(*f).unwrap().into()
}
PrintCode::SFixed(f) => {
val.to_signed_fixed_point(*f).unwrap().into()
}
PrintCode::Binary => Entry::Value(val.clone()),
}
}
Expand Down
Loading

0 comments on commit db5d0ff

Please sign in to comment.