Skip to content

Updating test_cell #5024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,40 @@ jobs:
run: |
find tests/**/*.err -print -exec cat {} \;

test-cells:
name: Run test_cell
runs-on: ubuntu-latest
needs: [build-yosys, pre_job]
if: needs.pre_job.outputs.should_skip != 'true'
env:
CC: clang
steps:
- name: Checkout Yosys
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup environment
uses: ./.github/actions/setup-build-env

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build-ubuntu-latest

- name: Uncompress build
shell: bash
run:
tar -xvf build.tar

- name: test_cell
shell: bash
run: |
./yosys -p 'test_cell all'
./yosys -p 'test_cell -nosat -aigmap $pow $pmux'
./yosys -p 'test_cell -nosat -aigmap $eqx $nex $bweqx'
./yosys -p 'test_cell -aigmap $buf'

test-docs:
name: Run docs tests
runs-on: ${{ matrix.os }}
Expand Down
6 changes: 6 additions & 0 deletions kernel/celltypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ struct CellTypes
return v;
}

// Consider using the ConstEval struct instead if you need named ports and/or multiple outputs
static RTLIL::Const eval(RTLIL::IdString type, const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len, bool *errp = nullptr)
{
if (type == ID($sshr) && !signed1)
Expand Down Expand Up @@ -416,6 +417,7 @@ struct CellTypes
log_abort();
}

// Consider using the ConstEval struct instead if you need named ports and/or multiple outputs
static RTLIL::Const eval(RTLIL::Cell *cell, const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool *errp = nullptr)
{
if (cell->type == ID($slice)) {
Expand Down Expand Up @@ -503,10 +505,13 @@ struct CellTypes
return eval(cell->type, arg1, arg2, signed_a, signed_b, result_len, errp);
}

// Consider using the ConstEval struct instead if you need named ports and/or multiple outputs
static RTLIL::Const eval(RTLIL::Cell *cell, const RTLIL::Const &arg1, const RTLIL::Const &arg2, const RTLIL::Const &arg3, bool *errp = nullptr)
{
if (cell->type.in(ID($mux), ID($_MUX_)))
return const_mux(arg1, arg2, arg3);
if (cell->type == ID($_NMUX_))
return eval_not(const_mux(arg1, arg2, arg3));
if (cell->type == ID($bwmux))
return const_bwmux(arg1, arg2, arg3);
if (cell->type == ID($pmux))
Expand All @@ -520,6 +525,7 @@ struct CellTypes
return eval(cell, arg1, arg2, errp);
}

// Consider using the ConstEval struct instead if you need named ports and/or multiple outputs
static RTLIL::Const eval(RTLIL::Cell *cell, const RTLIL::Const &arg1, const RTLIL::Const &arg2, const RTLIL::Const &arg3, const RTLIL::Const &arg4, bool *errp = nullptr)
{
if (cell->type == ID($_AOI4_))
Expand Down
6 changes: 5 additions & 1 deletion kernel/consteval.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ struct ConstEval
return false;

bool eval_err = false;
RTLIL::Const eval_ret = CellTypes::eval(cell, sig_a.as_const(), sig_b.as_const(), sig_c.as_const(), sig_d.as_const(), &eval_err);
RTLIL::Const eval_ret;
if (sig_s.size() > 0 && eval(sig_s, undef, cell)) {
eval_ret = CellTypes::eval(cell, sig_a.as_const(), sig_b.as_const(), sig_s.as_const(), &eval_err);
} else
eval_ret = CellTypes::eval(cell, sig_a.as_const(), sig_b.as_const(), sig_c.as_const(), sig_d.as_const(), &eval_err);

if (eval_err)
return false;
Expand Down
6 changes: 3 additions & 3 deletions kernel/rtlil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2377,7 +2377,7 @@
// assertion check below to make sure that there are no
// cases where a cell has a blackbox attribute since
// that is deprecated
log_assert(!it.second->get_blackbox_attribute());

Check warning on line 2380 in kernel/rtlil.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc-10)

‘bool Yosys::RTLIL::AttrObject::get_blackbox_attribute(bool) const’ is deprecated: Use Module::get_blackbox_attribute() instead. [-Wdeprecated-declarations]

Check warning on line 2380 in kernel/rtlil.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, clang-10)

'get_blackbox_attribute' is deprecated: Use Module::get_blackbox_attribute() instead. [-Wdeprecated-declarations]

Check warning on line 2380 in kernel/rtlil.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc-13)

‘bool Yosys::RTLIL::AttrObject::get_blackbox_attribute(bool) const’ is deprecated: Use Module::get_blackbox_attribute() instead. [-Wdeprecated-declarations]

Check warning on line 2380 in kernel/rtlil.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc-13)

‘bool Yosys::RTLIL::AttrObject::get_blackbox_attribute(bool) const’ is deprecated: Use Module::get_blackbox_attribute() instead. [-Wdeprecated-declarations]

Check warning on line 2380 in kernel/rtlil.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, clang-19)

'get_blackbox_attribute' is deprecated: Use Module::get_blackbox_attribute() instead. [-Wdeprecated-declarations]

Check warning on line 2380 in kernel/rtlil.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, clang-19)

'get_blackbox_attribute' is deprecated: Use Module::get_blackbox_attribute() instead. [-Wdeprecated-declarations]

Check warning on line 2380 in kernel/rtlil.cc

View workflow job for this annotation

GitHub Actions / test-compile (macos-13, clang)

'get_blackbox_attribute' is deprecated: Use Module::get_blackbox_attribute() instead. [-Wdeprecated-declarations]
}
}

Expand Down Expand Up @@ -4242,9 +4242,9 @@
type.begins_with("$verific$") || type.begins_with("$array:") || type.begins_with("$extern:"))
return;

if (type == ID($buf) || type == ID($mux) || type == ID($pmux) || type == ID($bmux)) {
if (type == ID($buf) || type == ID($mux) || type == ID($pmux) || type == ID($bmux) || type == ID($bwmux) || type == ID($bweqx)) {
parameters[ID::WIDTH] = GetSize(connections_[ID::Y]);
if (type != ID($buf) && type != ID($mux))
if (type.in(ID($pmux), ID($bmux)))
parameters[ID::S_WIDTH] = GetSize(connections_[ID::S]);
check();
return;
Expand Down Expand Up @@ -4299,7 +4299,7 @@
parameters[ID::B_WIDTH] = GetSize(connections_[ID::B]);
}

if (connections_.count(ID::Y))
if (connections_.count(ID::Y) && type != ID($concat))
parameters[ID::Y_WIDTH] = GetSize(connections_[ID::Y]);

if (connections_.count(ID::Q))
Expand Down
169 changes: 151 additions & 18 deletions passes/tests/test_cell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ static RTLIL::Cell* create_gold_module(RTLIL::Design *design, RTLIL::IdString ce
cell->setPort(ID::Y, wire);
}

if (cell_type.in(ID($_MUX_), ID($_NMUX_)))
{
wire = module->addWire(ID::A);
wire->width = 1;
wire->port_input = true;
cell->setPort(ID::A, wire);

wire = module->addWire(ID::B);
wire->width = 1;
wire->port_input = true;
cell->setPort(ID::B, wire);

wire = module->addWire(ID::S);
wire->width = 1;
wire->port_input = true;
cell->setPort(ID::S, wire);

wire = module->addWire(ID::Y);
wire->width = 1;
wire->port_output = true;
cell->setPort(ID::Y, wire);
}

if (cell_type == ID($bmux))
{
int width = 1 + xorshift32(8 * bloat_factor);
Expand Down Expand Up @@ -167,7 +190,7 @@ static RTLIL::Cell* create_gold_module(RTLIL::Design *design, RTLIL::IdString ce
cell->setPort(ID::CO, wire);
}

if (cell_type == ID($macc))
if (cell_type == ID($macc_v2))
{
Macc macc;
int width = 1 + xorshift32(8 * bloat_factor);
Expand Down Expand Up @@ -201,19 +224,14 @@ static RTLIL::Cell* create_gold_module(RTLIL::Design *design, RTLIL::IdString ce
this_term.do_subtract = xorshift32(2) == 1;
macc.terms.push_back(this_term);
}

// Macc::to_cell sets the input ports
macc.to_cell(cell);

wire = module->addWire(ID::Y);
wire->width = width;
wire->port_output = true;
cell->setPort(ID::Y, wire);

// override the B input (macc helpers always sets an empty vector)
wire = module->addWire(ID::B);
wire->width = xorshift32(mulbits_a ? xorshift32(4)+1 : xorshift32(16)+1);
wire->port_input = true;
cell->setPort(ID::B, wire);
}

if (cell_type == ID($lut))
Expand Down Expand Up @@ -273,21 +291,46 @@ static RTLIL::Cell* create_gold_module(RTLIL::Design *design, RTLIL::IdString ce

if (cell_type_flags.find('A') != std::string::npos) {
wire = module->addWire(ID::A);
wire->width = 1 + xorshift32(8 * bloat_factor);
if (cell_type_flags.find('b') != std::string::npos)
wire->width = 1;
else
wire->width = 1 + xorshift32(8 * bloat_factor);
wire->port_input = true;
cell->setPort(ID::A, wire);
}

if (cell_type_flags.find('B') != std::string::npos) {
wire = module->addWire(ID::B);
if (cell_type_flags.find('h') != std::string::npos)
if (cell_type_flags.find('b') != std::string::npos)
wire->width = 1;
else if (cell_type_flags.find('h') != std::string::npos)
wire->width = 1 + xorshift32(6 * bloat_factor);
else
wire->width = 1 + xorshift32(8 * bloat_factor);
wire->port_input = true;
cell->setPort(ID::B, wire);
}

if (cell_type_flags.find('C') != std::string::npos) {
wire = module->addWire(ID::C);
if (cell_type_flags.find('b') != std::string::npos)
wire->width = 1;
else
wire->width = 1 + xorshift32(8 * bloat_factor);
wire->port_input = true;
cell->setPort(ID::C, wire);
}

if (cell_type_flags.find('D') != std::string::npos) {
wire = module->addWire(ID::D);
if (cell_type_flags.find('b') != std::string::npos)
wire->width = 1;
else
wire->width = 1 + xorshift32(8 * bloat_factor);
wire->port_input = true;
cell->setPort(ID::D, wire);
}

if (cell_type_flags.find('S') != std::string::npos && xorshift32(2)) {
if (cell_type_flags.find('A') != std::string::npos)
cell->parameters[ID::A_SIGNED] = true;
Expand All @@ -304,7 +347,10 @@ static RTLIL::Cell* create_gold_module(RTLIL::Design *design, RTLIL::IdString ce

if (cell_type_flags.find('Y') != std::string::npos) {
wire = module->addWire(ID::Y);
wire->width = 1 + xorshift32(8 * bloat_factor);
if (cell_type_flags.find('b') != std::string::npos)
wire->width = 1;
else
wire->width = 1 + xorshift32(8 * bloat_factor);
wire->port_output = true;
cell->setPort(ID::Y, wire);
}
Expand Down Expand Up @@ -345,6 +391,58 @@ static RTLIL::Cell* create_gold_module(RTLIL::Design *design, RTLIL::IdString ce
cell->setPort(ID::CO, wire);
}

if (cell_type == ID($slice))
{
int a_size = GetSize(cell->getPort(ID::A));
int y_size = 1;
if (a_size > 1)
y_size += (xorshift32(8 * bloat_factor) % (a_size - 1));
wire = module->addWire(ID::Y);
wire->width = y_size;
wire->port_output = true;
cell->setPort(ID::Y, wire);
if (a_size > y_size)
cell->setParam(ID::OFFSET, (xorshift32(8 * bloat_factor) % (a_size - y_size)));
else
cell->setParam(ID::OFFSET, 0);
}

if (cell_type == ID($concat))
{
wire = module->addWire(ID::Y);
wire->width = GetSize(cell->getPort(ID::A)) + GetSize(cell->getPort(ID::B));
wire->port_output = true;
cell->setPort(ID::Y, wire);
}

if (cell_type == ID($buf))
{
wire = module->addWire(ID::Y);
wire->width = GetSize(cell->getPort(ID::A));
wire->port_output = true;
cell->setPort(ID::Y, wire);
}

if (cell_type.in(ID($bwmux), ID($bweqx)))
{
int a_size = GetSize(cell->getPort(ID::A));
wire = module->addWire(ID::B);
wire->width = a_size;
wire->port_input = true;
cell->setPort(ID::B, wire);
if (cell_type == ID($bwmux))
{
wire = module->addWire(ID::S);
wire->width = a_size;
wire->port_input = true;
cell->setPort(ID::S, wire);
}
wire = module->addWire(ID::Y);
wire->width = a_size;
wire->port_output = true;
cell->setPort(ID::Y, wire);
}

if (constmode)
{
auto conn_list = cell->connections();
Expand Down Expand Up @@ -882,6 +980,9 @@ struct TestCellPass : public Pass {
cell_types[ID($not)] = "ASY";
cell_types[ID($pos)] = "ASY";
cell_types[ID($neg)] = "ASY";
// $buf is unsupported with techmap -assert
if (techmap_cmd.compare("techmap -assert") != 0)
cell_types[ID($buf)] = "A";

cell_types[ID($and)] = "ABSY";
cell_types[ID($or)] = "ABSY";
Expand All @@ -905,8 +1006,14 @@ struct TestCellPass : public Pass {
cell_types[ID($le)] = "ABSY";
cell_types[ID($eq)] = "ABSY";
cell_types[ID($ne)] = "ABSY";
// cell_types[ID($eqx)] = "ABSY";
// cell_types[ID($nex)] = "ABSY";
// $eqx, $nex, and $bweqx don't work in sat, and are unsupported with
// 'techmap -assert'
if (nosat && techmap_cmd.compare("techmap -assert") != 0)
{
cell_types[ID($eqx)] = "ABSY";
cell_types[ID($nex)] = "ABSY";
cell_types[ID($bweqx)] = "A";
}
cell_types[ID($ge)] = "ABSY";
cell_types[ID($gt)] = "ABSY";

Expand All @@ -917,7 +1024,10 @@ struct TestCellPass : public Pass {
cell_types[ID($mod)] = "ABSY";
cell_types[ID($divfloor)] = "ABSY";
cell_types[ID($modfloor)] = "ABSY";
// cell_types[ID($pow)] = "ABsY";
// $pow doesnt work in sat, not supported with 'techmap -assert', and only
// only partially supported with '-simlib'
if (nosat && techmap_cmd.compare("aigmap") == 0)
cell_types[ID($pow)] = "ABsY";

cell_types[ID($logic_not)] = "ASY";
cell_types[ID($logic_and)] = "ABSY";
Expand All @@ -926,20 +1036,43 @@ struct TestCellPass : public Pass {
cell_types[ID($mux)] = "*";
cell_types[ID($bmux)] = "*";
cell_types[ID($demux)] = "*";
if (edges) {
// $pmux doesn't work in sat, and is not supported with 'techmap -assert' or
// '-simlib'
if (nosat && techmap_cmd.compare("aigmap") == 0)
cell_types[ID($pmux)] = "*";
}
cell_types[ID($bwmux)] = "A";

// cell_types[ID($slice)] = "A";
// cell_types[ID($concat)] = "A";
cell_types[ID($slice)] = "A";
cell_types[ID($concat)] = "AB";

cell_types[ID($lut)] = "*";
cell_types[ID($sop)] = "*";
cell_types[ID($alu)] = "ABSY";
cell_types[ID($lcu)] = "*";
cell_types[ID($macc)] = "*";
cell_types[ID($macc_v2)] = "*";
cell_types[ID($fa)] = "*";

cell_types[ID($_BUF_)] = "AYb";
cell_types[ID($_NOT_)] = "AYb";
cell_types[ID($_AND_)] = "ABYb";
cell_types[ID($_NAND_)] = "ABYb";
cell_types[ID($_OR_)] = "ABYb";
cell_types[ID($_NOR_)] = "ABYb";
cell_types[ID($_XOR_)] = "ABYb";
cell_types[ID($_XNOR_)] = "ABYb";
cell_types[ID($_ANDNOT_)] = "ABYb";
cell_types[ID($_ORNOT_)] = "ABYb";
cell_types[ID($_MUX_)] = "*";
cell_types[ID($_NMUX_)] = "*";
// wide $_MUX_ cells are not yet implemented
// cell_types[ID($_MUX4_)] = "*";
// cell_types[ID($_MUX8_)] = "*";
// cell_types[ID($_MUX16_)] = "*";
cell_types[ID($_AOI3_)] = "ABCYb";
cell_types[ID($_OAI3_)] = "ABCYb";
cell_types[ID($_AOI4_)] = "ABCDYb";
cell_types[ID($_OAI4_)] = "ABCDYb";

for (; argidx < GetSize(args); argidx++)
{
if (args[argidx].rfind("-", 0) == 0)
Expand Down
Loading