1 from nmigen
import Elaboratable
, Module
, Signal
3 from ..isa
import Funct3
6 __all__
= ["CompareUnit"]
9 class CompareUnit(Elaboratable
):
13 self
.negative
= Signal()
14 self
.overflow
= Signal()
17 self
.condition_met
= Signal()
19 def elaborate(self
, platform
):
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
)