2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2021 Marcelina KoĆcielnicka <mwk@0x04.net>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include "kernel/qcsat.h"
24 std::vector
<int> QuickConeSat::importSig(SigSpec sig
)
26 sig
= modwalker
.sigmap(sig
);
28 bits_queue
.insert(bit
);
29 return satgen
.importSigSpec(sig
);
32 int QuickConeSat::importSigBit(SigBit bit
)
34 bit
= modwalker
.sigmap(bit
);
35 bits_queue
.insert(bit
);
36 return satgen
.importSigBit(bit
);
39 void QuickConeSat::prepare()
41 while (!bits_queue
.empty())
43 pool
<ModWalker::PortBit
> portbits
;
44 modwalker
.get_drivers(portbits
, bits_queue
);
46 for (auto bit
: bits_queue
)
47 if (bit
.wire
&& bit
.wire
->get_bool_attribute(ID::onehot
) && !imported_onehot
.count(bit
.wire
))
49 std::vector
<int> bits
= satgen
.importSigSpec(bit
.wire
);
53 ez
->assume(ez
->NOT(i
), j
);
54 imported_onehot
.insert(bit
.wire
);
59 for (auto &pbit
: portbits
)
61 if (imported_cells
.count(pbit
.cell
))
63 if (cell_complexity(pbit
.cell
) > max_cell_complexity
)
65 if (max_cell_outs
&& GetSize(modwalker
.cell_outputs
[pbit
.cell
]) > max_cell_outs
)
67 auto &inputs
= modwalker
.cell_inputs
[pbit
.cell
];
68 bits_queue
.insert(inputs
.begin(), inputs
.end());
69 satgen
.importCell(pbit
.cell
);
70 imported_cells
.insert(pbit
.cell
);
73 if (max_cell_count
&& GetSize(imported_cells
) > max_cell_count
)
78 int QuickConeSat::cell_complexity(RTLIL::Cell
*cell
)
80 if (cell
->type
.in(ID($concat
), ID($slice
), ID($pos
), ID($_BUF_
)))
82 if (cell
->type
.in(ID($
not), ID($
and), ID($
or), ID($
xor), ID($xnor
),
83 ID($reduce_and
), ID($reduce_or
), ID($reduce_xor
),
84 ID($reduce_xnor
), ID($reduce_bool
),
85 ID($logic_not
), ID($logic_and
), ID($logic_or
),
86 ID($eq
), ID($ne
), ID($eqx
), ID($nex
), ID($fa
),
87 ID($mux
), ID($pmux
), ID($lut
), ID($sop
),
88 ID($_NOT_
), ID($_AND_
), ID($_NAND_
), ID($_OR_
), ID($_NOR_
),
89 ID($_XOR_
), ID($_XNOR_
), ID($_ANDNOT_
), ID($_ORNOT_
),
90 ID($_MUX_
), ID($_NMUX_
), ID($_MUX4_
), ID($_MUX8_
), ID($_MUX16_
),
91 ID($_AOI3_
), ID($_OAI3_
), ID($_AOI4_
), ID($_OAI4_
)))
93 if (cell
->type
.in(ID($neg
), ID($add
), ID($sub
), ID($alu
), ID($lcu
),
94 ID($lt
), ID($le
), ID($gt
), ID($ge
)))
96 if (cell
->type
.in(ID($shl
), ID($shr
), ID($sshl
), ID($sshr
), ID($shift
), ID($shiftx
)))
98 if (cell
->type
.in(ID($mul
), ID($macc
), ID($div
), ID($mod
), ID($divfloor
), ID($modfloor
), ID($pow
)))