diff options
author | jjsuperpower <jjs29356@gmail.com> | 2022-09-06 22:03:09 -0500 |
---|---|---|
committer | jjsuperpower <jjs29356@gmail.com> | 2022-09-06 22:03:09 -0500 |
commit | ef50be8fd11f04deb192a22eb996f16aac47002d (patch) | |
tree | f782b1bbd43de18b2e0b8c85852d2bdd836ab654 /hdl | |
parent | 6dd3e93f876fa9f8c8bcf5ca96a4e03df9848aeb (diff) |
consolidated aluflags
Diffstat (limited to 'hdl')
-rw-r--r-- | hdl/core/alu.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/hdl/core/alu.py b/hdl/core/alu.py index d9858b1..b4261bd 100644 --- a/hdl/core/alu.py +++ b/hdl/core/alu.py @@ -23,6 +23,13 @@ class AluOpCodes(Enum): # udiv = 13 # sdiv = 14 +@unique +class ALUFlags(Enum): + zero = 0 + carry = 1 + overflow = 2 + negative = 3 + class ALU(Elaboratable): def __init__(self, **kargs): self.in1 = Signal(32, reset_less=True) @@ -37,12 +44,13 @@ class ALU(Elaboratable): self.zero = Signal(1, reset_less=True) self.neg = Signal(1, reset_less=True) + self.alu_flags = Signal(4, reset_less=True) self.out = Signal(32, reset_less=True) self.sim = kargs["sim"] if "sim" in kargs else None ports_in = [self.in1, self.in2, self.op, self.c_in] - ports_out = [self.c_in, self.out, self.c_out, self.overflow, self.zero, self.neg] + ports_out = [self.c_in, self.out, self.alu_flags] self.ports = {'in': ports_in, 'out': ports_out} def elaborate(self, platform=None): @@ -111,9 +119,14 @@ class ALU(Elaboratable): m.d.comb += self.c_out.eq(self.tmp[32]) m.d.comb += self.overflow.eq(self.tmp[32] ^ self.tmp[31]) - m.d.comb += self.out.eq(self.tmp[0:32]) m.d.comb += self.neg.eq(self.out[31]) m.d.comb += self.zero.eq(self.out == 0) + + m.d.comb += self.alu_flags[ALUFlags.zero.value].eq(self.zero) + m.d.comb += self.alu_flags[ALUFlags.carry.value].eq(self.c_out) + m.d.comb += self.alu_flags[ALUFlags.overflow.value].eq(self.overflow) + m.d.comb += self.alu_flags[ALUFlags.negative.value].eq(self.neg) + m.d.comb += self.out.eq(self.tmp[0:32]) return m |