move ashift out to common area
[soc.git] / src / soc / minerva / units / compare.py
1 from nmigen import Elaboratable, Module, Signal
2
3 from ..isa import Funct3
4
5
6 __all__ = ["CompareUnit"]
7
8
9 class CompareUnit(Elaboratable):
10 def __init__(self):
11 self.op = Signal(3)
12 self.zero = Signal()
13 self.negative = Signal()
14 self.overflow = Signal()
15 self.carry = Signal()
16
17 self.condition_met = Signal()
18
19 def elaborate(self, platform):
20 m = Module()
21
22 with m.Switch(self.op):
23 with m.Case(Funct3.BEQ):
24 m.d.comb += self.condition_met.eq(self.zero)
25 with m.Case(Funct3.BNE):
26 m.d.comb += self.condition_met.eq(~self.zero)
27 with m.Case(Funct3.BLT):
28 m.d.comb += self.condition_met.eq(~self.zero & (self.negative != self.overflow))
29 with m.Case(Funct3.BGE):
30 m.d.comb += self.condition_met.eq(self.negative == self.overflow)
31 with m.Case(Funct3.BLTU):
32 m.d.comb += self.condition_met.eq(~self.zero & self.carry)
33 with m.Case(Funct3.BGEU):
34 m.d.comb += self.condition_met.eq(~self.carry)
35
36 return m