litex/migen/flow/ala.py

71 lines
2.1 KiB
Python
Raw Normal View History

2011-12-22 18:35:53 -05:00
from migen.fhdl.structure import *
2012-01-08 07:56:11 -05:00
from migen.fhdl.structure import _Operator
2011-12-22 18:35:53 -05:00
from migen.flow.actor import *
2012-01-06 08:32:00 -05:00
from migen.corelogic.record import *
2011-12-22 18:35:53 -05:00
from migen.corelogic import divider
2012-01-08 07:56:11 -05:00
class _SimpleBinary(Actor):
def __init__(self, op, bv_op, bv_r):
self.op = op
2011-12-22 18:35:53 -05:00
Actor.__init__(self,
SchedulingModel(SchedulingModel.COMBINATORIAL),
2012-01-15 09:09:44 -05:00
("operands", Sink, [('a', bv_op), ('b', bv_op)]),
("result", Source, [('r', bv_r)]))
2012-01-06 08:32:00 -05:00
2011-12-22 18:35:53 -05:00
def get_process_fragment(self):
2012-01-08 07:56:11 -05:00
return Fragment([
2012-01-15 09:09:44 -05:00
self.token("result").r.eq(_Operator(self.op,
[self.token("operands").a, self.token("operands").b]))
2012-01-08 07:56:11 -05:00
])
class Add(_SimpleBinary):
def __init__(self, bv):
_SimpleBinary.__init__(self, '+', bv, BV(bv.width+1, bv.signed))
class Sub(_SimpleBinary):
def __init__(self, bv):
_SimpleBinary.__init__(self, '-', bv, BV(bv.width+1, bv.signed))
class Mul(_SimpleBinary):
def __init__(self, bv):
_SimpleBinary.__init__(self, '*', bv, BV(2*bv.width, bv.signed))
class And(_SimpleBinary):
def __init__(self, bv):
_SimpleBinary.__init__(self, '*', bv, bv)
class Xor(_SimpleBinary):
def __init__(self, bv):
_SimpleBinary.__init__(self, '^', bv, bv)
class Or(_SimpleBinary):
def __init__(self, bv):
_SimpleBinary.__init__(self, '|', bv, bv)
class LT(_SimpleBinary):
def __init__(self, bv):
_SimpleBinary.__init__(self, '<', bv, BV(1))
class LE(_SimpleBinary):
def __init__(self, bv):
_SimpleBinary.__init__(self, '<=', bv, BV(1))
class EQ(_SimpleBinary):
def __init__(self, bv):
_SimpleBinary.__init__(self, '==', bv, BV(1))
class NE(_SimpleBinary):
def __init__(self, bv):
_SimpleBinary.__init__(self, '!=', bv, BV(1))
2011-12-22 18:35:53 -05:00
2012-01-08 07:56:11 -05:00
class DivMod(Actor):
2011-12-22 18:35:53 -05:00
def __init__(self, width):
self.div = divider.Inst(width)
Actor.__init__(self,
SchedulingModel(SchedulingModel.SEQUENTIAL, width),
2012-01-15 09:09:44 -05:00
("operands", Sink, [("dividend", self.div.dividend_i), ("divisor", self.div.divisor_i)]),
("result", Source, [("quotient", self.div.quotient_o), ("remainder", self.div.remainder_o)]))
2012-01-06 08:32:00 -05:00
2011-12-22 18:35:53 -05:00
def get_process_fragment(self):
return self.div.get_fragment() + Fragment([self.div.start_i.eq(self.trigger)])