Skip to content

Commit

Permalink
some tweaks to the data converter for future use with fixed point
Browse files Browse the repository at this point in the history
  • Loading branch information
EclecticGriffin committed Jun 18, 2024
1 parent f3de2df commit d5712fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tools/cider-data-converter/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn convert_to_data_dump(json: &JsonData) -> DataDump {
let mut data_dump = DataDump::new_empty();

for (name, entry) in json.0.iter() {
let width = &entry.format.width;
let width = &entry.format.get_width();
let data: Box<dyn Iterator<Item = u8>> = match &entry.data {
DataVec::Id1(v1) => Box::new(v1.iter().flat_map(|val| {
// chopping off the upper bits
Expand Down Expand Up @@ -133,10 +133,11 @@ mod tests {
prop_compose! {
fn arb_format_info()(width in 1_u64..=64) -> FormatInfo {
FormatInfo {
width,
width: Some(width),
is_signed: false,
numeric_type: NumericType::Bitnum,
int_width: None,
frac_width: None,
}
}
}
Expand Down Expand Up @@ -173,7 +174,7 @@ mod tests {
let arb_format_info = arb_format_info();
let dim = dim_generator();
(arb_format_info, dim).prop_flat_map(|(format, dimensions)| {
arb_data(format.width, dimensions).prop_map(move |x| {
arb_data(format.get_width(), dimensions).prop_map(move |x| {
JsonDataEntry {
data: x,
format: format.clone(),
Expand Down
20 changes: 19 additions & 1 deletion tools/cider-data-converter/src/json_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,35 @@ use serde::{self, Deserialize, Serialize};
#[serde(rename_all = "lowercase")]
pub enum NumericType {
Bitnum,
#[serde(alias = "fixed_point")]
Fixed,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct FormatInfo {
pub numeric_type: NumericType,
pub is_signed: bool,
pub width: u64,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub width: Option<u64>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub int_width: Option<u64>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub frac_width: Option<u64>,
}

impl FormatInfo {
pub fn get_width(&self) -> u64 {
if let Some(w) = self.width {
w
} else if self.int_width.is_some() && self.frac_width.is_some() {
self.int_width.unwrap() + self.frac_width.unwrap()
} else {
panic!("Either width or int_width and frac_width must be set")
}
}
}

// this is stupid
Expand Down

0 comments on commit d5712fa

Please sign in to comment.