Skip to content

Commit

Permalink
[cider] minor bug in fxp mult (#2283)
Browse files Browse the repository at this point in the history
Corrects a regression introduced in #2281. Adds some better error
reporting for the data dumps.
  • Loading branch information
EclecticGriffin authored Sep 16, 2024
1 parent d195989 commit c66451d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion interp/src/flatten/primitives/stateful/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl<const DEPTH: usize> Primitive for FxpMultPipe<DEPTH> {
2 * (self.frac_width + self.int_width),
)
.slice(
2 * self.frac_width + self.int_width,
(2 * self.frac_width + self.int_width) - 1,
self.frac_width,
)
})
Expand Down
25 changes: 21 additions & 4 deletions interp/src/serialization/data_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,19 @@ impl DataDump {
declaration: MemoryDeclaration,
data: T,
) {
self.header.memories.push(declaration);
let old_len = self.data.len();
self.data.extend(data);
let new_len = self.data.len();
let data_segment = new_len - old_len;
assert_eq!(
declaration.byte_count(),
data_segment,
"Data segment size does not match the memory declaration {:?}. Expected {} bytes, but got {}",
declaration,
declaration.byte_count(),
data_segment
);
self.header.memories.push(declaration);
}

pub fn push_reg<T: IntoIterator<Item = u8>>(
Expand Down Expand Up @@ -282,7 +293,10 @@ impl DataDump {
// instead to avoid allowing incorrect/malformed data files
let amount_read = reader.read_to_end(&mut data)?;
if amount_read != header.data_size() {
return Err(SerializationError::MalformedData);
return Err(SerializationError::MalformedData {
expected_size: header.data_size(),
given_size: amount_read,
});
}

Ok(DataDump { header, data })
Expand Down Expand Up @@ -327,9 +341,12 @@ pub enum SerializationError {
MalformedHeader,

#[error(
"Malformed data dump, data section does not match header description"
"Malformed data dump, data section does not match header description. Expected {expected_size} bytes, but got {given_size} bytes"
)]
MalformedData,
MalformedData {
expected_size: usize,
given_size: usize,
},

#[error("Input is not a valid data dump")]
InvalidMagicNumber,
Expand Down

0 comments on commit c66451d

Please sign in to comment.