diff options
author | Clifford Wolf <clifford@clifford.at> | 2015-10-26 14:33:57 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2015-10-26 14:33:57 +0100 |
commit | ff83127bdac18f1fe1088a8355353300ef8b7563 (patch) | |
tree | 4d09060bb0afd3abe07871f8188e5723ee41b55e | |
parent | e4ed27a3ab81284d556be3dde77a64caab895397 (diff) | |
parent | 8447080d628d11a5571e715bfc5a6f5ba3d46e25 (diff) | |
download | icestorm-ff83127bdac18f1fe1088a8355353300ef8b7563.tar.gz icestorm-ff83127bdac18f1fe1088a8355353300ef8b7563.tar.bz2 icestorm-ff83127bdac18f1fe1088a8355353300ef8b7563.zip |
Merge pull request #14 from ylm/master
Added heuristics to further reduce LUT equations.
-rwxr-xr-x | icebox/icebox_vlog.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/icebox/icebox_vlog.py b/icebox/icebox_vlog.py index 4a79cd4..4d1a772 100755 --- a/icebox/icebox_vlog.py +++ b/icebox/icebox_vlog.py @@ -810,17 +810,24 @@ for lut in luts_queue: elif not "0" in lut_bits: const_assigns.append([net_out, "1'b1"]) else: + def equals_1(expr): + return (expr == "1") or (expr == "1'b1") + def equals_0(expr): + return (expr == "0") or (expr == "1'b0") def make_lut_expr(bits, sigs): if not sigs: return "1'b%s" % bits[0] l_expr = make_lut_expr(bits[0:len(bits)//2], sigs[1:]) h_expr = make_lut_expr(bits[len(bits)//2:len(bits)], sigs[1:]) if h_expr == l_expr: return h_expr - if sigs[0] == "0": return l_expr - if sigs[0] == "1": return h_expr - if h_expr == "1" and l_expr == "0": return sigs[0] - if h_expr == "0" and l_expr == "1": return "!" + sigs[0] - return "%s ? %s : %s" % (sigs[0], h_expr, l_expr) + if equals_0(sigs[0]): return l_expr + if equals_1(sigs[0]): return h_expr + if equals_1(h_expr) and equals_0(l_expr): return sigs[0] + if equals_0(h_expr) and equals_1(l_expr): return "!" + sigs[0] + if h_expr == "!" + l_expr: return "(%s ^ %s)" % (sigs[0], l_expr) + if equals_0(h_expr): return "(%s & !%s)" % (sigs[0], l_expr) + if equals_0(l_expr): return "(%s & %s)" % (sigs[0], h_expr) + return "(%s ? %s : %s)" % (sigs[0], h_expr, l_expr) lut_expr = make_lut_expr(lut_bits, [net_in3, net_in2, net_in1, net_in0]) lut_assigns.append([net_out, "/* LUT %2d %2d %2d */ %s" % (lut[0], lut[1], lut[2], lut_expr)]) max_net_len = max(max_net_len, len(net_out)) |