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

Bit-replicate operator support #280

Closed
Aegithalos-caudatus opened this issue Jun 3, 2024 · 2 comments
Closed

Bit-replicate operator support #280

Aegithalos-caudatus opened this issue Jun 3, 2024 · 2 comments

Comments

@Aegithalos-caudatus
Copy link

Aegithalos-caudatus commented Jun 3, 2024

Hi! Is there any direct support or equivalence for the bit-replicate operator in PyMTL? I am trying to implement some logic like this:

// Verilog
logic [2:0] A;
logic [NBITS-1 : 0] B;

B = { NBITS{ A[1] }};

I searched for several related keywords in the repository but did not find useful information.

Also, I have tried the updates in Improving concat #278. However, such generator expression is still rejected inside the update/update_ff block.

# PyMTL
#     - invalid operation: generator expression

# code-1
s.B //= lambda: concat( s.A[1] for _ in range(NBITS) )

# code-2
@update
def bit_replicate():
    s.B @= concat( s.A[1] for _ in range(NBITS) )

Update: Okay I think the sext() is a workaround for 1 bit :) Then what if there are multiple bits to be replicated?

@cbatten
Copy link
Contributor

cbatten commented Jun 4, 2024

right ... we have the sext and zext operators ... if there are multiple bits to be replicated I think you would need to write a for loop in an update block?

@Aegithalos-caudatus
Copy link
Author

Thanks. I think a modern synthesizer should be able to yield the same result for these approaches. Though the for-loop version might be a bit harder to read ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants