m.d.comb += ab_equal.eq(a1.v == b1.v)
contains_nan = Signal()
m.d.comb += contains_nan.eq(a1.is_nan | b1.is_nan)
+ a_lt_b = Signal()
+ with m.If(a1.s != b1.s):
+ comb += a_lt_b.eq(a1.s > b1.s)
+ with m.Elif(a1.s == 0):
+ comb += a_lt_b.eq(a1.v[0:31] < b1.v[0:31])
+ with m.Else():
+ comb += a_lt_b.eq(a1.v[0:31] > b1.v[0:31])
+
+
with m.If(contains_nan):
m.d.comb += z1.eq(0)
with m.Switch(opcode):
with m.Case(0b10):
comb += z1.eq(ab_equal)
+ with m.Case(0b00):
+ comb += z1.eq(a_lt_b)
+ with m.Case(0b01):
+ comb += z1.eq(a_lt_b | ab_equal)
# copy the context (muxid, operator)
comb += self.o.ctx.eq(self.i.ctx)
def fpcmp_lt(a, b):
return Float32(a.lt(b))
+def fpcmp_le(a, b):
+ return Float32(a.le(b))
def test_fpcmp_eq():
dut = FPCMPMuxInOut(32, 4)
runfp(dut, 32, "test_fpcmp_lt", Float32, fpcmp_lt,
n_vals=100, opcode=0b00)
+def test_fpcmp_le():
+ dut = FPCMPMuxInOut(32, 4)
+ runfp(dut, 32, "test_fpcmp_le", Float32, fpcmp_le,
+ n_vals=100, opcode=0b01)
+
if __name__ == '__main__':
for i in range(50):
test_fpcmp_lt()
test_fpcmp_eq()
+ test_fpcmp_le()