From 27c7402a0f9c7494d74e6cc3f9d9cb24e214a27d Mon Sep 17 00:00:00 2001 From: Maciej Kurc Date: Fri, 12 Feb 2021 15:29:30 +0100 Subject: [PATCH 1/8] Added specification on how EBLIF cell parameters should be interpreted. Signed-off-by: Maciej Kurc --- doc/src/vpr/file_formats.rst | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/src/vpr/file_formats.rst b/doc/src/vpr/file_formats.rst index dc215aed888..a6dd6e5aa4f 100644 --- a/doc/src/vpr/file_formats.rst +++ b/doc/src/vpr/file_formats.rst @@ -391,17 +391,34 @@ The ``.param`` statement allows parameters (e.g. primitive modes) to be tagged o .. note:: ``.param`` statements apply to the previous primitive instantiation. +Parameters can have one of the three available types. Type is inferred from the format in which a parameter is provided. + + * **string** + Whenever a parameter value is quoted it is considered to be a string. + + * **binary word** + Binary words are specified using strings of characters ``0`` and ``1``. No other characters are allowed. Number of characters denotes the word length. + + * **real number** + Real numbers are stored as decimals where the dot ``.`` character separates the integer and fractional part. Presence of the dot character implies that the value is to be treated as a real number. + For example: .. code-block:: none - .subckt dsp a=a_in b=b_in cin=c_in cout=c_out s=sum_out - .param mode adder + .subckt pll clk_in=gclk clk_out=pclk + .param feedback "internal" + .param multiplier 0.50 + .param power 001101 + +Would set the parameters ``feedback``, ``multipleir`` and ``power`` of the above ``pll`` ``.subckt`` to ``"internal"``, ``0.50`` and ``001101`` respectively. -Would set the parameter ``mode`` of the above ``dsp`` ``.subckt`` to ``adder``. +Interpretation of parameter values is out of scope of the BLIF format extension. ``.param`` statements propagate to ```` elements in the packed netlist. +Paramerer values propagate also to post-route Verilog netlist. Strings and real numbers are passed directly while binary words are prepended with the ``'b`` prefix where ``N`` denotes a binary word length. + .attr ~~~~~ The ``.attr`` statement allows attributes (e.g. source file/line) to be tagged on BLIF primitives. From c28468f838d5fcd78c57007359ae646475d0fcb4 Mon Sep 17 00:00:00 2001 From: Maciej Kurc Date: Fri, 12 Feb 2021 15:30:13 +0100 Subject: [PATCH 2/8] Added EBLIF parameter validation and fixed post-route verilog output Signed-off-by: Maciej Kurc --- vpr/src/base/netlist_writer.cpp | 10 ++++- vpr/src/base/read_blif.cpp | 71 +++++++++++++++++++++++++++++++++ vpr/src/base/read_blif.h | 4 ++ 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/vpr/src/base/netlist_writer.cpp b/vpr/src/base/netlist_writer.cpp index 19d7d0388cb..88ac03be3f9 100644 --- a/vpr/src/base/netlist_writer.cpp +++ b/vpr/src/base/netlist_writer.cpp @@ -20,6 +20,8 @@ #include "vpr_error.h" #include "vpr_types.h" +#include "read_blif.h" + #include "netlist_walker.h" #include "netlist_writer.h" @@ -625,7 +627,13 @@ class BlackBoxInst : public Instance { //Verilog parameters for (auto iter = params_.begin(); iter != params_.end(); ++iter) { - os << indent(depth + 1) << "." << iter->first << "(" << iter->second << ")"; + /* Prepend a prefix if needed */ + std::stringstream prefix; + if (is_binary_param(iter->second)) { + prefix << iter->second.length() << "'b"; + } + + os << indent(depth + 1) << "." << iter->first << "(" << prefix.str() << iter->second << ")"; if (iter != --params_.end()) { os << ","; } diff --git a/vpr/src/base/read_blif.cpp b/vpr/src/base/read_blif.cpp index d208ab98143..2425a18d239 100644 --- a/vpr/src/base/read_blif.cpp +++ b/vpr/src/base/read_blif.cpp @@ -386,6 +386,13 @@ struct BlifAllocCallback : public blifparse::Callback { parse_error(lineno_, ".param", "Supported only in extended BLIF format"); } + // Validate the parameter value + bool is_valid = is_string_param(value) || is_binary_param(value) || is_real_param(value); + + if (!is_valid) { + parse_error(lineno_, ".param", "Incorrect parameter value specification"); + } + curr_model().set_block_param(curr_block(), name, value); } @@ -666,6 +673,70 @@ vtr::LogicValue to_vtr_logic_value(blifparse::LogicValue val) { return new_val; } +bool is_string_param(const std::string& param) { + /* Empty param is considered a string */ + if (param.empty()) { + return true; + } + + /* There have to be at least 2 characters (the quotes) */ + if (param.length() < 2) { + return false; + } + + /* The first and the last characters must be quotes */ + size_t len = param.length(); + if (param[0] != '"' || param[len - 1] != '"') { + return false; + } + + /* There mustn't be any other quotes except for escaped ones */ + for (size_t i = 1; i < (len - 1); ++i) { + if (param[i] == '"' && param[i - 1] != '\\') { + return false; + } + } + + /* This is a string param */ + return true; +} + +bool is_binary_param(const std::string& param) { + /* Must be non-empty */ + if (param.empty()) { + return false; + } + + /* The string must contain only '0' and '1' */ + for (size_t i = 0; i < param.length(); ++i) { + if (param[i] != '0' && param[i] != '1') { + return false; + } + } + + /* This is a binary word param */ + return true; +} + +bool is_real_param(const std::string& param) { + const std::string chars = "012345678."; + + /* Must be non-empty */ + if (param.empty()) { + return false; + } + + /* The string mustn't contain any other chars that the expected ones */ + for (size_t i = 0; i < param.length(); ++i) { + if (chars.find(param[i]) == std::string::npos) { + return false; + } + } + + /* This is a real number param */ + return true; +} + AtomNetlist read_blif(e_circuit_format circuit_format, const char* blif_file, const t_model* user_models, diff --git a/vpr/src/base/read_blif.h b/vpr/src/base/read_blif.h index 819bb035e78..a11ba4ecb40 100644 --- a/vpr/src/base/read_blif.h +++ b/vpr/src/base/read_blif.h @@ -4,6 +4,10 @@ #include "atom_netlist_fwd.h" #include "read_circuit.h" +bool is_string_param(const std::string& param); +bool is_binary_param(const std::string& param); +bool is_real_param(const std::string& param); + AtomNetlist read_blif(e_circuit_format circuit_format, const char* blif_file, const t_model* user_models, From 9d31804b0dd3df1b3cc5c80f002006c154547706 Mon Sep 17 00:00:00 2001 From: Maciej Kurc Date: Mon, 15 Feb 2021 13:58:38 +0100 Subject: [PATCH 3/8] Updated documentation and code according to the review comments Signed-off-by: Maciej Kurc --- doc/src/vpr/file_formats.rst | 4 ++-- vpr/src/base/read_blif.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/src/vpr/file_formats.rst b/doc/src/vpr/file_formats.rst index a6dd6e5aa4f..3da7f4ccd68 100644 --- a/doc/src/vpr/file_formats.rst +++ b/doc/src/vpr/file_formats.rst @@ -411,13 +411,13 @@ For example: .param multiplier 0.50 .param power 001101 -Would set the parameters ``feedback``, ``multipleir`` and ``power`` of the above ``pll`` ``.subckt`` to ``"internal"``, ``0.50`` and ``001101`` respectively. +Would set the parameters ``feedback``, ``multiplier`` and ``power`` of the above ``pll`` ``.subckt`` to ``"internal"``, ``0.50`` and ``001101`` respectively. Interpretation of parameter values is out of scope of the BLIF format extension. ``.param`` statements propagate to ```` elements in the packed netlist. -Paramerer values propagate also to post-route Verilog netlist. Strings and real numbers are passed directly while binary words are prepended with the ``'b`` prefix where ``N`` denotes a binary word length. +Paramerer values propagate also to the post-route Verilog netlist, if it is generated. Strings and real numbers are passed directly while binary words are prepended with the ``'b`` prefix where ``N`` denotes a binary word length. .attr ~~~~~ diff --git a/vpr/src/base/read_blif.cpp b/vpr/src/base/read_blif.cpp index 2425a18d239..e6a97ac34ba 100644 --- a/vpr/src/base/read_blif.cpp +++ b/vpr/src/base/read_blif.cpp @@ -20,6 +20,7 @@ #include #include #include //std::isdigit +#include #include "blifparse.hpp" #include "atom_netlist.h" @@ -719,7 +720,7 @@ bool is_binary_param(const std::string& param) { } bool is_real_param(const std::string& param) { - const std::string chars = "012345678."; + const std::string real_chars = "0123456789."; /* Must be non-empty */ if (param.empty()) { @@ -728,11 +729,16 @@ bool is_real_param(const std::string& param) { /* The string mustn't contain any other chars that the expected ones */ for (size_t i = 0; i < param.length(); ++i) { - if (chars.find(param[i]) == std::string::npos) { + if (real_chars.find(param[i]) == std::string::npos) { return false; } } + /* There must only be a single dot */ + if (std::count(param.begin(), param.end(), '.') != 1) { + return false; + } + /* This is a real number param */ return true; } From 5de5dbbeb9a2fa12cec9b2b26cfbbc98cd708395 Mon Sep 17 00:00:00 2001 From: Maciej Kurc Date: Mon, 15 Feb 2021 13:59:04 +0100 Subject: [PATCH 4/8] Updated the strong_eblif_vpr test Signed-off-by: Maciej Kurc --- vtr_flow/benchmarks/tests/test_eblif.eblif | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vtr_flow/benchmarks/tests/test_eblif.eblif b/vtr_flow/benchmarks/tests/test_eblif.eblif index 744e91d65d9..f232fcc6c30 100644 --- a/vtr_flow/benchmarks/tests/test_eblif.eblif +++ b/vtr_flow/benchmarks/tests/test_eblif.eblif @@ -5,12 +5,16 @@ .names a b a_and_b 11 1 .cname lut_a_and_b -.param test_names_param "test_names_param_value" +.param test_names_param_str "test_names_param_str_value" +.param test_names_param_bin 00110101 +.param test_names_param_num 2.0 .attr test_names_attrib "test_names_param_attrib" .latch a_and_b dff_q re clk 0 .cname my_dff -.param test_latch_param "test_latch_param_value" +.param test_latch_param "test_latch_param_str_value" +.param test_latch_param_bin 00110101 +.param test_latch_param_num 2.0 .attr test_latch_attrib "test_latch_param_attrib" .conn dff_q o_dff From 9752d013d13360461e8339ef9a32d26cc0e2f9b9 Mon Sep 17 00:00:00 2001 From: Maciej Kurc Date: Wed, 17 Feb 2021 15:17:20 +0100 Subject: [PATCH 5/8] Changed EBLIF real number value validation code to use a regular expression. Signed-off-by: Maciej Kurc --- vpr/src/base/read_blif.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/vpr/src/base/read_blif.cpp b/vpr/src/base/read_blif.cpp index e6a97ac34ba..b86a6f06677 100644 --- a/vpr/src/base/read_blif.cpp +++ b/vpr/src/base/read_blif.cpp @@ -21,6 +21,7 @@ #include #include //std::isdigit #include +#include #include "blifparse.hpp" #include "atom_netlist.h" @@ -720,22 +721,14 @@ bool is_binary_param(const std::string& param) { } bool is_real_param(const std::string& param) { - const std::string real_chars = "0123456789."; - /* Must be non-empty */ if (param.empty()) { return false; } - /* The string mustn't contain any other chars that the expected ones */ - for (size_t i = 0; i < param.length(); ++i) { - if (real_chars.find(param[i]) == std::string::npos) { - return false; - } - } - - /* There must only be a single dot */ - if (std::count(param.begin(), param.end(), '.') != 1) { + /* The string must match the regular expression */ + static const std::regex real_number_expr("[+-]?([0-9]*\\.[0-9]+)|([0-9]+\\.[0-9]*)"); + if (!std::regex_match(param, real_number_expr)) { return false; } From 71fc191304c29e80ba4551587d4e5a7990248df4 Mon Sep 17 00:00:00 2001 From: Pawel Czarnecki Date: Fri, 21 Jan 2022 11:13:24 +0100 Subject: [PATCH 6/8] doc: vpr: file_formats: warn about unsupported parameters formats Signed-off-by: Pawel Czarnecki --- doc/src/vpr/file_formats.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/src/vpr/file_formats.rst b/doc/src/vpr/file_formats.rst index 3da7f4ccd68..24075a842e7 100644 --- a/doc/src/vpr/file_formats.rst +++ b/doc/src/vpr/file_formats.rst @@ -413,6 +413,8 @@ For example: Would set the parameters ``feedback``, ``multiplier`` and ``power`` of the above ``pll`` ``.subckt`` to ``"internal"``, ``0.50`` and ``001101`` respectively. +.. warning:: Integers in notation other than binary (e.g. decimal, hexadecimal) are not supported. Occurrence of params with digits other than 1 and 0 for binary words, not quoted (strings) or not separated with dot ``.`` (real numbers) are considered to be illegal. + Interpretation of parameter values is out of scope of the BLIF format extension. ``.param`` statements propagate to ```` elements in the packed netlist. From 996f3aac5048587352f96898650195630ae9e18e Mon Sep 17 00:00:00 2001 From: Pawel Czarnecki Date: Fri, 21 Jan 2022 13:28:13 +0100 Subject: [PATCH 7/8] vpr: base: blif parse: descriptive error message for params Signed-off-by: Pawel Czarnecki --- vpr/src/base/read_blif.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vpr/src/base/read_blif.cpp b/vpr/src/base/read_blif.cpp index b86a6f06677..5c473eea270 100644 --- a/vpr/src/base/read_blif.cpp +++ b/vpr/src/base/read_blif.cpp @@ -392,7 +392,8 @@ struct BlifAllocCallback : public blifparse::Callback { bool is_valid = is_string_param(value) || is_binary_param(value) || is_real_param(value); if (!is_valid) { - parse_error(lineno_, ".param", "Incorrect parameter value specification"); + std::string msg = "Incorrect parameter '" + name + "' value specification. Value '" + value + "' is not recognized as string, binary word or real number. Possible causes:\n\t* lack or inconsistency in quotes (string)\n\t* no dot '.' to separate integer and fractional part (real number)\n\t* use of characters other than '1' and '0' (binary word)"; + parse_error(lineno_, ".param", msg); } curr_model().set_block_param(curr_block(), name, value); From 1cbc9b90cc75b9b641e109fd75819401f5332b42 Mon Sep 17 00:00:00 2001 From: Pawel Czarnecki Date: Fri, 21 Jan 2022 14:44:35 +0100 Subject: [PATCH 8/8] docs: vpr: file formats: blif: explain no support for escaping chars in string params Signed-off-by: Pawel Czarnecki --- doc/src/vpr/file_formats.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/vpr/file_formats.rst b/doc/src/vpr/file_formats.rst index 24075a842e7..789667f2bbe 100644 --- a/doc/src/vpr/file_formats.rst +++ b/doc/src/vpr/file_formats.rst @@ -394,7 +394,7 @@ The ``.param`` statement allows parameters (e.g. primitive modes) to be tagged o Parameters can have one of the three available types. Type is inferred from the format in which a parameter is provided. * **string** - Whenever a parameter value is quoted it is considered to be a string. + Whenever a parameter value is quoted it is considered to be a string. BLIF parser does not allow escaped characters hence those are illegal and will cause syntax errors. * **binary word** Binary words are specified using strings of characters ``0`` and ``1``. No other characters are allowed. Number of characters denotes the word length.