From 99417d6499b006a172d5b8cba413fd6181737374 Mon Sep 17 00:00:00 2001 From: Charlotte Date: Sat, 24 Jun 2023 13:22:56 +1000 Subject: [PATCH] sim._pyrtl: mask bitwise binary operands. Boolean negation produces negative integers, which when unmasked drastically affects the result of these operations. --- amaranth/sim/_pyrtl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/amaranth/sim/_pyrtl.py b/amaranth/sim/_pyrtl.py index 1545686..d9787ff 100644 --- a/amaranth/sim/_pyrtl.py +++ b/amaranth/sim/_pyrtl.py @@ -166,11 +166,11 @@ class _RHSValueCompiler(_ValueCompiler): if value.operator == "%": return f"zmod({sign(lhs)}, {sign(rhs)})" if value.operator == "&": - return f"({self(lhs)} & {self(rhs)})" + return f"({mask(lhs)} & {mask(rhs)})" if value.operator == "|": - return f"({self(lhs)} | {self(rhs)})" + return f"({mask(lhs)} | {mask(rhs)})" if value.operator == "^": - return f"({self(lhs)} ^ {self(rhs)})" + return f"({mask(lhs)} ^ {mask(rhs)})" if value.operator == "<<": return f"({sign(lhs)} << {sign(rhs)})" if value.operator == ">>":