Skip to content

stream: make use of reverse parameter for changing byte endianness - #2346

Open
ozel wants to merge 2 commits into
enjoy-digital:masterfrom
ozel:stream-convert-endianess
Open

stream: make use of reverse parameter for changing byte endianness#2346
ozel wants to merge 2 commits into
enjoy-digital:masterfrom
ozel:stream-convert-endianess

Conversation

@ozel

@ozel ozel commented Oct 8, 2025

Copy link
Copy Markdown

When stream.Convert() operates on equal data widths (nbits_from = nbits_to) the reverse parameter wasn't used so far in _IdentityConverter(). Only in case of up/down conversion, e.g. from 8 to 32 bit width and vice versa, reverse could be used to swap byte endianness.

With this PR, Convert(...,reverse=True) can be used to reverse byte order of equally-sized LiteX streams. I have not seen an alternative LiteX stream module that could do this. This is handy for dealing with UDP streams as the etherbone/UDP core of LiteEth converts Ethernet payloads to little endian already on reception and independently of downstream processing in a CPU core (see enjoy-digital/liteeth#82).

There should be a built-in LiteX feature to convert a streams' byte order like this commit. Please let me know if there is a more canonical way that I've missed.

Comment on lines +475 to +479
if reverse:
# reverse order/endianness of bytes
if nbits_from % 8:
raise ValueError("When reversing ratio=1 streams, data width must be a multiple of 8 bits")
self.comb += source.data.eq(reverse_bytes(sink.data)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could put this after sink.connect(source)
that way it overwrites the source.data.eq(sink.data) of sink.connect(source), just like in verilog

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sure, yes of course! Do you think enabling reversal of byte order in streams this way is generally acceptable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants