From a10b1fd1e62bb1bbeee11ba3b4f136f83fe9f65f Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 28 Oct 2022 19:13:27 +0200 Subject: [PATCH] gen/common/Reduce: Add ADD support. --- litex/gen/common.py | 3 ++- test/test_reduce.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/litex/gen/common.py b/litex/gen/common.py index c1cfebaf3..3ce0696d1 100644 --- a/litex/gen/common.py +++ b/litex/gen/common.py @@ -26,7 +26,7 @@ def reverse_bytes(s): # Reduction ---------------------------------------------------------------------------------------- from functools import reduce -from operator import and_, or_, not_, xor +from operator import and_, or_, not_, xor, add def Reduce(operator, value): # List of supported Operators. @@ -35,6 +35,7 @@ def Reduce(operator, value): "OR" : or_, "NOR" : not_, "XOR" : xor, + "ADD" : add, } # Switch to upper-case. diff --git a/test/test_reduce.py b/test/test_reduce.py index ebecfcdad..9865a611f 100644 --- a/test/test_reduce.py +++ b/test/test_reduce.py @@ -50,3 +50,12 @@ class TestReduce(unittest.TestCase): self.reduce_test(operator="XOR", value=Constant(0b01, 2), reduced=0b1) self.reduce_test(operator="XOR", value=Constant(0b10, 2), reduced=0b1) self.reduce_test(operator="XOR", value=Constant(0b11, 2), reduced=0b0) + + def test_reduced_add(self): + self.reduce_test(operator="ADD", value=Constant(0b000, 3), reduced=0) + self.reduce_test(operator="ADD", value=Constant(0b001, 3), reduced=1) + self.reduce_test(operator="ADD", value=Constant(0b010, 3), reduced=1) + self.reduce_test(operator="ADD", value=Constant(0b100, 3), reduced=1) + self.reduce_test(operator="ADD", value=Constant(0b011, 3), reduced=2) + self.reduce_test(operator="ADD", value=Constant(0b110, 3), reduced=2) + self.reduce_test(operator="ADD", value=Constant(0b111, 3), reduced=3)