Skip to content

Commit 2bbd3fd

Browse files
committed
--float-size for custom float size
1 parent e6ea9d8 commit 2bbd3fd

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/codegen/system_verilog.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use ibig::IBig;
66
use sus_proc_macro::get_builtin_type;
77

88
use crate::alloc::zip_eq;
9+
use crate::config::config;
910
use crate::latency::AbsLat;
1011
use crate::linker::{IsExtern, LinkInfo};
1112
use crate::prelude::*;
@@ -93,7 +94,10 @@ fn typ_to_declaration(mut typ: &ConcreteType, var_name: &str) -> String {
9394
}
9495
}
9596
get_builtin_type!("bool") => return format!(" {var_name}{array_string}"),
96-
get_builtin_type!("float") => return format!("[31:0] {var_name}{array_string}"),
97+
get_builtin_type!("float") => {
98+
let float_msb = config().float_size - 1;
99+
return format!("[{float_msb}:0] {var_name}{array_string}");
100+
}
97101
_ => todo!("Structs"),
98102
},
99103
ConcreteType::Array(arr) => {
@@ -214,9 +218,8 @@ impl<'g> CodeGenerationContext<'g> {
214218
matches!(cst, Value::Unset),
215219
"TODO: Generative non-Unset floats"
216220
);
217-
result
218-
.write_str("32'bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
219-
.unwrap();
221+
let float_size = config().float_size;
222+
write!(result, "{float_size}'x").unwrap();
220223
}
221224
_ => todo!("Structs"),
222225
},

src/config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ pub struct ConfigStruct {
6060
pub enabled_debug_paths: HashSet<String>,
6161
pub early_exit: EarlyExitUpTo,
6262
pub no_redump: bool,
63+
64+
/// Temporary, just because flopoco forces weirdly-sized floats, have it provide a struct in the future instead
65+
pub float_size: usize,
6366
}
6467

6568
pub const VERSION_INFO: &str = concat!(
@@ -153,6 +156,13 @@ fn command_builder() -> Command {
153156
}
154157
})
155158
)
159+
.arg(Arg::new("float-size")
160+
.long("float-size")
161+
.hide(true)
162+
.help("Set the size of floats - in bits. Makes no claims about the representation, that's up to the libraries")
163+
.value_parser(clap::value_parser!(usize))
164+
.default_value("32")
165+
)
156166
// Debug stuff
157167
.arg(Arg::new("debug")
158168
.long("debug")
@@ -242,6 +252,7 @@ where
242252
files,
243253
sus_home_override,
244254
no_redump: matches.get_flag("no-redump"),
255+
float_size: *matches.get_one("float-size").unwrap(),
245256
})
246257
}
247258

src/typing/concrete_type.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use ibig::IBig;
22
use ibig::UBig;
33
use sus_proc_macro::get_builtin_type;
44

5+
use crate::config;
56
use crate::linker::GlobalUUID;
67
use crate::prelude::*;
78
use crate::to_string::join_string_iter_formatter;
@@ -287,7 +288,7 @@ impl ConcreteType {
287288
bounds.bitwidth()
288289
}
289290
get_builtin_type!("bool") => 1,
290-
get_builtin_type!("float") => 32,
291+
get_builtin_type!("float") => config().float_size as u64,
291292
_other => todo!("Other Named Structs are not implemented yet"),
292293
}
293294
}

0 commit comments

Comments
 (0)