from migen.fhdl.std import *
from migen.fhdl import verilog
-from migen.genlib.misc import optree
+
+from functools import reduce
+from operator import or_
def gen_list(n):
for lst in [a, b, c]:
for obj in lst:
allsigs.extend(obj.sigs)
- self.comb += output.eq(optree("|", allsigs))
+ self.comb += output.eq(reduce(or_, allsigs))
print(verilog.convert(Example()))
from migen.fhdl.std import *
from migen.fhdl import verilog
-from migen.genlib.misc import optree
from migen.sim.generic import run_simulation
+from functools import reduce
+from operator import add
# A synthesizable FIR filter.
class FIR(Module):
c_fp = int(c*2**(self.wsize - 1))
muls.append(c_fp*sreg)
sum_full = Signal((2*self.wsize-1, True))
- self.sync += sum_full.eq(optree("+", muls))
+ self.sync += sum_full.eq(reduce(add, muls))
self.comb += self.o.eq(sum_full[self.wsize-1:])
from migen.fhdl.std import *
-from migen.fhdl.structure import _Operator
-
-
-def optree(op, operands, lb=None, ub=None, default=None):
- if lb is None:
- lb = 0
- if ub is None:
- ub = len(operands)
- l = ub - lb
- if l == 0:
- if default is None:
- raise AttributeError
- else:
- return default
- elif l == 1:
- return operands[lb]
- else:
- s = lb + l//2
- return _Operator(op,
- [optree(op, operands, lb, s, default),
- optree(op, operands, s, ub, default)])
def split(v, *counts):
from migen.fhdl.std import *
from migen.fhdl.tracer import get_obj_var_name
-from migen.genlib.misc import optree
+
+from functools import reduce
+from operator import or_
+
(DIR_NONE, DIR_S_TO_M, DIR_M_TO_S) = range(3)
if direction == DIR_M_TO_S:
r += [getattr(slave, field).eq(self_e) for slave in slaves]
elif direction == DIR_S_TO_M:
- r.append(self_e.eq(optree("|", [getattr(slave, field) for slave in slaves])))
+ r.append(self_e.eq(reduce(or_, [getattr(slave, field) for slave in slaves])))
else:
raise TypeError
else:
s_signal, s_direction = next(iter_slave)
assert(s_direction == DIR_S_TO_M)
s_signals.append(s_signal)
- r.append(m_signal.eq(optree("|", s_signals)))
+ r.append(m_signal.eq(reduce(or_, s_signals)))
else:
raise TypeError
return r