From 4f212bc77fda3406b51f5e7c9aa12206b5474a9b Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 27 Jan 2020 13:26:21 +0000 Subject: [PATCH] add (untested) partitioned xor/or/and operators these all work regardless of partitioning --- src/ieee754/part/partsig.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/ieee754/part/partsig.py b/src/ieee754/part/partsig.py index 25e90583..a4565c20 100644 --- a/src/ieee754/part/partsig.py +++ b/src/ieee754/part/partsig.py @@ -19,9 +19,17 @@ http://bugs.libre-riscv.org/show_bug.cgi?id=132 from ieee754.part_mul_add.adder import PartitionedAdder from ieee754.part_cmp.equal import PartitionedEq from ieee754.part_mul_add.partpoints import make_partition +from operator import or_, xor, and_, not_ from nmigen import (Signal, ) +def applyop(op1, op2, op): + if isinstance(op1, PartitionedSignal): + op1 = op1.sig + if isinstance(op2, PartitionedSignal): + op2 = op2.sig + return op(op1, op2) + class PartitionedSignal: def __init__(self, mask, *args, **kwargs): @@ -42,10 +50,23 @@ class PartitionedSignal: def eq(self, val): return self.sig.eq(val) + def __and__(self, other): + return applyop(self, other, and_) + + def __rand__(self, other): + return applyop(other, self, and_) + + def __or__(self, other): + return applyop(self, other, or_) + + def __ror__(self, other): + return applyop(other, self, or_) + def __xor__(self, other): - if isinstance(other, PartitionedSignal): - return self.sig ^ other.sig - return self.sig ^ other + return applyop(self, other, xor) + + def __rxor__(self, other): + return applyop(other, self, xor) def __add__(self, other): shape = self.sig.shape() -- 2.30.2