migen icon indicating copy to clipboard operation
migen copied to clipboard

chained comparisons are not implemented correctly

Open whitequark opened this issue 6 years ago • 1 comments

These should be identical, and indeed they are in Python:

class OK(Module):
    def __init__(self):
        self.a = Signal(8)
        self.b = Signal(8)
        self.c = Signal()
        self.comb += \
            self.c.eq((self.a == 0) & (self.b == 0))

class NG(Module):
    def __init__(self):
        self.a = Signal(8)
        self.b = Signal(8)
        self.c = Signal()
        self.comb += \
            self.c.eq(self.a == self.b == 0)

print(verilog.convert(OK())) # assign c = ((a == 1'd0) & (b == 1'd0));
print(verilog.convert(NG())) # assign c = (a == b);

a = b = 0
print(a == b == 0) # True
a = b = 1
print(a == b == 0) # False

whitequark avatar May 13 '18 14:05 whitequark

Triage: fixed in nMigen, where a chained comparison is an error (throws TypeError: Attempted to convert nMigen value to boolean).

whitequark avatar Jul 05 '19 14:07 whitequark