Skip to content

Commit e558f00

Browse files
committedSep 14, 2017
Minor changes to opt_demorgan requested during code review
1 parent 7d42afd commit e558f00

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed
 

Diff for: ‎passes/opt/Makefile.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ OBJS += passes/opt/opt_reduce.o
66
OBJS += passes/opt/opt_rmdff.o
77
OBJS += passes/opt/opt_clean.o
88
OBJS += passes/opt/opt_expr.o
9-
OBJS += passes/opt/opt_demorgan.o
10-
OBJS += passes/opt/rmports.o
119

1210
ifneq ($(SMALL),1)
1311
OBJS += passes/opt/share.o
1412
OBJS += passes/opt/wreduce.o
13+
OBJS += passes/opt/opt_demorgan.o
14+
OBJS += passes/opt/rmports.o
1515
endif
1616

Diff for: ‎passes/opt/opt_demorgan.cc

+16-16
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ void demorgan_worker(
3939
return;
4040

4141
auto insig = sigmap(cell->getPort("\\A"));
42-
log("Inspecting %s cell %s (%d inputs)\n", log_id(cell->type), log_id(cell->name), insig.size());
42+
log("Inspecting %s cell %s (%d inputs)\n", log_id(cell->type), log_id(cell->name), GetSize(insig));
4343
int num_inverted = 0;
44-
for(int i=0; i<insig.size(); i++)
44+
for(int i=0; i<GetSize(insig); i++)
4545
{
4646
auto b = insig[i];
4747

@@ -63,19 +63,19 @@ void demorgan_worker(
6363
}
6464

6565
//Stop if less than half of the inputs are inverted
66-
if(num_inverted*2 < insig.size())
66+
if(num_inverted*2 < GetSize(insig))
6767
{
68-
log(" %d / %d inputs are inverted, not pushing\n", num_inverted, insig.size());
68+
log(" %d / %d inputs are inverted, not pushing\n", num_inverted, GetSize(insig));
6969
return;
7070
}
7171

7272
//More than half of the inputs are inverted! Push through
7373
cells_changed ++;
74-
log(" %d / %d inputs are inverted, pushing inverter through reduction\n", num_inverted, insig.size());
74+
log(" %d / %d inputs are inverted, pushing inverter through reduction\n", num_inverted, GetSize(insig));
7575

7676
//For each input, either add or remove the inverter as needed
7777
//TODO: this duplicates the loop up above, can we refactor it?
78-
for(int i=0; i<insig.size(); i++)
78+
for(int i=0; i<GetSize(insig); i++)
7979
{
8080
auto b = insig[i];
8181

@@ -110,10 +110,10 @@ void demorgan_worker(
110110
//Reductions are all commutative, so there's no point in having them in a weird order
111111
bool same_signal = true;
112112
RTLIL::Wire* srcwire = insig[0].wire;
113-
std::map<int, int> seen_bits;
114-
for(int i=0; i<insig.size(); i++)
113+
dict<int, int> seen_bits;
114+
for(int i=0; i<GetSize(insig); i++)
115115
seen_bits[i] = 0;
116-
for(int i=0; i<insig.size(); i++)
116+
for(int i=0; i<GetSize(insig); i++)
117117
{
118118
seen_bits[insig[i].offset] ++;
119119
if(insig[i].wire != srcwire)
@@ -126,7 +126,7 @@ void demorgan_worker(
126126
{
127127
//Make sure we've seen every bit exactly once
128128
bool every_bit_once = true;
129-
for(int i=0; i<insig.size(); i++)
129+
for(int i=0; i<GetSize(insig); i++)
130130
{
131131
if(seen_bits[i] != 1)
132132
{
@@ -139,12 +139,12 @@ void demorgan_worker(
139139
//We do have to swap MSB to LSB b/c that's the way the reduction cells seem to work?
140140
//Unclear on why this isn't sorting properly
141141
//TODO: can we do SigChunks instead of single bits if we have subsets of a bus?
142-
if(every_bit_once && (insig.size() == srcwire->width) )
142+
if(every_bit_once && (GetSize(insig) == srcwire->width) )
143143
{
144144
log("Rearranging bits\n");
145145
RTLIL::SigSpec newsig;
146-
for(int i=0; i<insig.size(); i++)
147-
newsig.append(RTLIL::SigBit(srcwire, insig.size() - i - 1));
146+
for(int i=0; i<GetSize(insig); i++)
147+
newsig.append(RTLIL::SigBit(srcwire, GetSize(insig) - i - 1));
148148
insig = newsig;
149149
insig.sort();
150150
}
@@ -179,12 +179,12 @@ struct OptDemorganPass : public Pass {
179179
log("overall gate count of the circuit\n");
180180
log("\n");
181181
}
182-
virtual void execute(std::vector<std::string> /*args*/, RTLIL::Design *design)
182+
virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
183183
{
184184
log_header(design, "Executing OPT_DEMORGAN pass (push inverters through $reduce_* cells).\n");
185185

186-
//int argidx = 0;
187-
//extra_args(args, argidx, design);
186+
int argidx = 0;
187+
extra_args(args, argidx, design);
188188

189189
unsigned int cells_changed = 0;
190190
for (auto module : design->selected_modules())

0 commit comments

Comments
 (0)
Please sign in to comment.