From 6e16c3f18928e286fa97b38f51d482cca9e3370e Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Thu, 4 Dec 2025 11:30:05 -0500 Subject: [PATCH] Allow `set_units`/`set_cmd_units` to support floats properly (#349) --- sdc/Sdc.tcl | 2 +- tcl/CmdUtil.tcl | 4 ++-- test/regression_vars.tcl | 1 + test/set_units_float.ok | 7 +++++++ test/set_units_float.tcl | 21 +++++++++++++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 test/set_units_float.ok create mode 100644 test/set_units_float.tcl diff --git a/sdc/Sdc.tcl b/sdc/Sdc.tcl index d61b3ddd..ed568f8b 100644 --- a/sdc/Sdc.tcl +++ b/sdc/Sdc.tcl @@ -144,7 +144,7 @@ proc check_unit { unit key suffix key_var } { set arg_suffix [string range $value end-[expr $suffix_length - 1] end] if { [string match -nocase $arg_suffix $suffix] } { set arg_prefix [string range $value 0 end-$suffix_length] - if { [regexp "^(10*)?(\[Mkmunpf\])?$" $arg_prefix ignore mult prefix] } { + if { [regexp "^(10*\.?0*)?(\[Mkmunpf\])?$" $arg_prefix ignore mult prefix] } { if { $mult == "" } { set mult 1 } diff --git a/tcl/CmdUtil.tcl b/tcl/CmdUtil.tcl index deb4c51f..623432d0 100644 --- a/tcl/CmdUtil.tcl +++ b/tcl/CmdUtil.tcl @@ -167,13 +167,13 @@ proc set_unit_values { unit key suffix key_var } { set arg_suffix [string range $value end-[expr $suffix_length - 1] end] if { [string match -nocase $arg_suffix $suffix] } { set arg_prefix [string range $value 0 end-$suffix_length] - if { [regexp "^(10*)?(\[Mkmunpf\])?$" $arg_prefix ignore mult prefix] } { + if { [regexp "^(10*\.?0*)?(\[Mkmunpf\])?$" $arg_prefix ignore mult prefix] } { #puts "$arg_prefix '$mult' '$prefix'" if { $mult == "" } { set mult 1 } set scale [unit_prefix_scale $unit $prefix ] - set_cmd_unit_scale $unit $scale + set_cmd_unit_scale $unit [expr $scale * $mult] } else { sta_error 166 "unknown unit $unit prefix '${arg_prefix}'." } diff --git a/test/regression_vars.tcl b/test/regression_vars.tcl index f3eb42e9..a411e088 100644 --- a/test/regression_vars.tcl +++ b/test/regression_vars.tcl @@ -158,6 +158,7 @@ record_sta_tests { report_checks_src_attr report_json1 report_json2 + set_units_float suppress_msg verilog_attribute verilog_specify diff --git a/test/set_units_float.ok b/test/set_units_float.ok new file mode 100644 index 00000000..3ceac1cf --- /dev/null +++ b/test/set_units_float.ok @@ -0,0 +1,7 @@ + time 1ns + capacitance 1pF + resistance 1kohm + voltage 1v + current 1A + power 1W + distance 1um diff --git a/test/set_units_float.tcl b/test/set_units_float.tcl new file mode 100644 index 00000000..eb07181e --- /dev/null +++ b/test/set_units_float.tcl @@ -0,0 +1,21 @@ +# set_units with floating point numbers + +# start by setting the cmd units +set_cmd_units -capacitance 1000.0fF +set_cmd_units -resistance 1.0kohm +set_cmd_units -time 1.0ns +set_cmd_units -voltage 1.0v +set_cmd_units -current 1.0A +set_cmd_units -distance 1.0um + +# then check the units +set_units -capacitance 1.0pF +set_units -resistance 1.0kohm +set_units -time 1.0ns +set_units -voltage 1.0v +set_units -current 1.0A +set_units -power 1.0W +set_units -distance 1.0um + +# finally report the units +report_units