From b37fe09be198b98992f6c9b9e72105a598813b83 Mon Sep 17 00:00:00 2001 From: Kelvin Chung Date: Mon, 3 Jun 2024 10:30:05 +0100 Subject: [PATCH 1/3] allow concat to take generator or list as input --- pymtl3/datatypes/helpers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pymtl3/datatypes/helpers.py b/pymtl3/datatypes/helpers.py index 192f120dc..1e3d6fd8c 100644 --- a/pymtl3/datatypes/helpers.py +++ b/pymtl3/datatypes/helpers.py @@ -9,6 +9,7 @@ Date : Nov 3, 2017 """ import math +import types from .bits_import import * @@ -18,7 +19,14 @@ def concat( *args ): value = nbits = 0 + if len(args) == 1: + if isinstance(args[0], list): + args = args[0] + elif isinstance(args[0], types.GeneratorType): + args = args[0] + for x in args: + print(x) xnb = x.nbits nbits += xnb value = (value << xnb) | x.uint() From 4c9cbb6bf57980bcefb989ce6227ceb1e1600bf9 Mon Sep 17 00:00:00 2001 From: Kelvin Chung Date: Mon, 3 Jun 2024 10:33:02 +0100 Subject: [PATCH 2/3] add test --- pymtl3/datatypes/test/helpers_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pymtl3/datatypes/test/helpers_test.py b/pymtl3/datatypes/test/helpers_test.py index d01b7c174..278d7b516 100644 --- a/pymtl3/datatypes/test/helpers_test.py +++ b/pymtl3/datatypes/test/helpers_test.py @@ -17,6 +17,17 @@ def test_concat(): assert x.nbits == 380 assert x == mk_bits(380)(0x1234567890abcdef1234567890abcdeffffffffff22222222222222222444441234567890abcdef1234567890abcdef) +def test_concat_list(): + x = concat([Bits2(2) for _ in range(4)]) + assert x.nbits == 8 + assert x == Bits8(0b10101010) + + +def test_concat_generator(): + x = concat(Bits2(2) for _ in range(4)) + assert x.nbits == 8 + assert x == Bits8(0b10101010) + def test_zext(): assert zext( Bits8(0xe), 24 ) == Bits24(0xe) From a0236394f868e61c7344284c0ef043daa7974870 Mon Sep 17 00:00:00 2001 From: Kelvin Chung Date: Mon, 3 Jun 2024 10:35:37 +0100 Subject: [PATCH 3/3] remove not needed print --- pymtl3/datatypes/helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pymtl3/datatypes/helpers.py b/pymtl3/datatypes/helpers.py index 1e3d6fd8c..f548926f2 100644 --- a/pymtl3/datatypes/helpers.py +++ b/pymtl3/datatypes/helpers.py @@ -26,7 +26,6 @@ def concat( *args ): args = args[0] for x in args: - print(x) xnb = x.nbits nbits += xnb value = (value << xnb) | x.uint()