Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving concat #278

Open
wants to merge 3 commits into
base: pymtl4.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pymtl3/datatypes/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Date : Nov 3, 2017
"""
import math
import types

from .bits_import import *

Expand All @@ -18,6 +19,12 @@
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:
xnb = x.nbits
nbits += xnb
Expand Down
11 changes: 11 additions & 0 deletions pymtl3/datatypes/test/helpers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down