From b7d7b377fd8fbc414c01b3554f82ddf2db8deeac Mon Sep 17 00:00:00 2001 From: Mike Inouye Date: Tue, 22 Apr 2025 23:26:55 +0000 Subject: [PATCH 1/4] Detect FF functions that use parentheses. Signed-off-by: Mike Inouye --- passes/techmap/dfflibmap.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/passes/techmap/dfflibmap.cc b/passes/techmap/dfflibmap.cc index 84db7f157..ae13a6ddd 100644 --- a/passes/techmap/dfflibmap.cc +++ b/passes/techmap/dfflibmap.cc @@ -102,6 +102,9 @@ static bool parse_next_state(const LibertyAst *cell, const LibertyAst *attr, std } else if (expr[0] == '!') { data_name = expr.substr(1, expr.size()-1); data_not_inverted = false; + } else if (expr[0] == '(' && expr[expr.size() - 1] == ')') { + data_name = expr.substr(1, expr.size() - 2); + data_not_inverted = true; } else { data_name = expr; data_not_inverted = true; From bf8aece4e4ff5c5e34fe56f1d1575d1c5a9ad85f Mon Sep 17 00:00:00 2001 From: Mike Inouye Date: Wed, 23 Apr 2025 18:40:35 +0000 Subject: [PATCH 2/4] Add test to verify that the liberty format is properly parsed. --- tests/liberty/dff.lib | 22 ++++++++++++++++++++++ tests/liberty/dff.lib.filtered.ok | 19 +++++++++++++++++++ tests/liberty/dff.lib.verilogsim.ok | 12 ++++++++++++ tests/liberty/dff.log.ok | 29 +++++++++++++++++++++++++++++ tests/liberty/run-test.sh | 4 ++++ 5 files changed, 86 insertions(+) create mode 100644 tests/liberty/dff.lib create mode 100644 tests/liberty/dff.lib.filtered.ok create mode 100644 tests/liberty/dff.lib.verilogsim.ok create mode 100644 tests/liberty/dff.log.ok diff --git a/tests/liberty/dff.lib b/tests/liberty/dff.lib new file mode 100644 index 000000000..61f5966f5 --- /dev/null +++ b/tests/liberty/dff.lib @@ -0,0 +1,22 @@ +// Test library for different DFF function expressions + +library(dff) { + cell (dff) { + area : 1; + ff("IQ", "IQN") { + next_state : "(D)"; + clocked_on : "CLK"; + } + pin(D) { + direction : input; + } + pin(CLK) { + direction : input; + } + pin(Q) { + direction: output; + function : "IQ"; + } + } + +} /* end */ diff --git a/tests/liberty/dff.lib.filtered.ok b/tests/liberty/dff.lib.filtered.ok new file mode 100644 index 000000000..b7dcb96be --- /dev/null +++ b/tests/liberty/dff.lib.filtered.ok @@ -0,0 +1,19 @@ +library(dff) { + cell(dff) { + area : 1 ; + ff("IQ", "IQN") { + next_state : "(D)" ; + clocked_on : "CLK" ; + } + pin(D) { + direction : input ; + } + pin(CLK) { + direction : input ; + } + pin(Q) { + direction : output ; + function : "IQ" ; + } + } +} diff --git a/tests/liberty/dff.lib.verilogsim.ok b/tests/liberty/dff.lib.verilogsim.ok new file mode 100644 index 000000000..46441d0fc --- /dev/null +++ b/tests/liberty/dff.lib.verilogsim.ok @@ -0,0 +1,12 @@ +module dff (D, CLK, Q); + reg "IQ", "IQN"; + input D; + input CLK; + output Q; + assign Q = IQ; // "IQ" + always @(posedge CLK) begin + // "(D)" + "IQ" <= (D); + "IQN" <= ~((D)); + end +endmodule diff --git a/tests/liberty/dff.log.ok b/tests/liberty/dff.log.ok new file mode 100644 index 000000000..be187181d --- /dev/null +++ b/tests/liberty/dff.log.ok @@ -0,0 +1,29 @@ + +-- Running command `dfflibmap -info -liberty dff.lib' -- + +1. Executing DFFLIBMAP pass (mapping DFF cells to sequential cells from liberty file). + cell dff (noninv, pins=3, area=1.00) is a direct match for cell type $_DFF_P_. + final dff cell mappings: + unmapped dff cell: $_DFF_N_ + \dff _DFF_P_ (.CLK( C), .D( D), .Q( Q)); + unmapped dff cell: $_DFF_NN0_ + unmapped dff cell: $_DFF_NN1_ + unmapped dff cell: $_DFF_NP0_ + unmapped dff cell: $_DFF_NP1_ + unmapped dff cell: $_DFF_PN0_ + unmapped dff cell: $_DFF_PN1_ + unmapped dff cell: $_DFF_PP0_ + unmapped dff cell: $_DFF_PP1_ + unmapped dff cell: $_DFFE_NN_ + unmapped dff cell: $_DFFE_NP_ + unmapped dff cell: $_DFFE_PN_ + unmapped dff cell: $_DFFE_PP_ + unmapped dff cell: $_DFFSR_NNN_ + unmapped dff cell: $_DFFSR_NNP_ + unmapped dff cell: $_DFFSR_NPN_ + unmapped dff cell: $_DFFSR_NPP_ + unmapped dff cell: $_DFFSR_PNN_ + unmapped dff cell: $_DFFSR_PNP_ + unmapped dff cell: $_DFFSR_PPN_ + unmapped dff cell: $_DFFSR_PPP_ +dfflegalize command line: dfflegalize -cell $_DFF_P_ 01 t:$_DFF* t:$_SDFF* diff --git a/tests/liberty/run-test.sh b/tests/liberty/run-test.sh index 8fa99d419..f5cffdb18 100755 --- a/tests/liberty/run-test.sh +++ b/tests/liberty/run-test.sh @@ -7,6 +7,10 @@ for x in *.lib; do ../../yosys-filterlib - $x 2>/dev/null > $x.filtered ../../yosys-filterlib -verilogsim $x > $x.verilogsim diff $x.filtered $x.filtered.ok && diff $x.verilogsim $x.verilogsim.ok + if [[ -e ${x%.lib}.log.ok ]]; then + ../../yosys -p "dfflibmap -info -liberty ${x}" -TqqQl ${x%.lib}.log + diff ${x%.lib}.log ${x%.lib}.log.ok + fi done || exit 1 for x in *.ys; do From a0d865c2bf4646bda63309aad54fb4dbd6ca9a2b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 23 Apr 2025 00:23:08 +0000 Subject: [PATCH 3/4] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7076e949d..8b50fcb98 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,7 @@ ifeq ($(OS), Haiku) CXXFLAGS += -D_DEFAULT_SOURCE endif -YOSYS_VER := 0.52+75 +YOSYS_VER := 0.52+89 YOSYS_MAJOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f1) YOSYS_MINOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f2 | cut -d'+' -f1) YOSYS_COMMIT := $(shell echo $(YOSYS_VER) | cut -d'+' -f2) From 9631f6ece568ca8ceaeccb81107ea545f064b70a Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Wed, 16 Apr 2025 22:24:55 +0200 Subject: [PATCH 4/4] liberty: fix tests --- tests/liberty/run-test.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/liberty/run-test.sh b/tests/liberty/run-test.sh index f5cffdb18..5afdb727e 100755 --- a/tests/liberty/run-test.sh +++ b/tests/liberty/run-test.sh @@ -1,20 +1,21 @@ #!/usr/bin/env bash -set -e +set -eo pipefail for x in *.lib; do echo "Testing on $x.." ../../yosys -p "read_verilog small.v; synth -top small; dfflibmap -info -liberty ${x}" -ql ${x%.lib}.log ../../yosys-filterlib - $x 2>/dev/null > $x.filtered ../../yosys-filterlib -verilogsim $x > $x.verilogsim - diff $x.filtered $x.filtered.ok && diff $x.verilogsim $x.verilogsim.ok + diff $x.filtered $x.filtered.ok + diff $x.verilogsim $x.verilogsim.ok if [[ -e ${x%.lib}.log.ok ]]; then ../../yosys -p "dfflibmap -info -liberty ${x}" -TqqQl ${x%.lib}.log diff ${x%.lib}.log ${x%.lib}.log.ok fi -done || exit 1 +done for x in *.ys; do echo "Running $x.." ../../yosys -q -s $x -l ${x%.ys}.log -done || exit 1 +done