Jump to content

TLM2 endianness conversion functions

Recommended Posts

Hi ,

I am looking at endianness conversion functions in 1666-2011.pdf @492.

I have couple of related questions

1. What is the template parameter DATAWORD signifies in these functions. Why it is needed when we pass the socket size explicitly

2. There are following functions for to_hostendian_

inline void tlm_to_hostendian_generic(tlm_generic_payload *, unsigned int );

inline void tlm_to_hostendian_word(tlm_generic_payload *, unsigned int);

inline void tlm_to_hostendian_aligned(tlm_generic_payload *, unsigned int);

inline void tlm_to_hostendian_single(tlm_generic_payload *, unsigned int);

Which function we should use ? What is the meaning of _generic, _word, _aligned and _single in these functions

Same for _from_hostendian functions.

Thanks in advance for your kind help



Link to comment
Share on other sites

Hi Khushi,

the best is to look up the definition in the IEEE 1666-2011 standard, section 14.20(.3).

The different conversion functions have different constraints associated with them, allowing for more performant implementations for the _word, _aligned, and _single specializations.  The _generic one covers arbitrary cases.  The DATAWORD template parameter allows for optimizations as well (and endianness is always specific to the notion of a word).

Hope that helps,

Link to comment
Share on other sites

Thanks Philip

Can you tell me for a scenario when payload data length is 16 bytes the n what value of DATAWORD I should use when using _generic endianness conversion function.

For my specific case, I do not have the byte enable constraints. Can I use my function to convert the payload data from BE to LE on bus width boundary before calling b_transport and use the opposite one when b_transport call returns.

For example, If I have the following data (16 bytes)

char *data = "ABCDEFGHIJKLMNOP", then my function convert it to "DCBAHGFELKJIPONM" for a socket of 32bit.

Can we do it ?



Link to comment
Share on other sites

The full data length is independent of the word length. The rules for DATAWORD are defined by the standard as follows (see 14.20.3):


e) The template argument to a hostendian function should be a type representing the internal initiator data word for the endianness conversion. The expression sizeof(DATAWORD) is used to determine the width of the data word in bytes, and the assignment operator of type DATAWORD is used during copying. sizeof(DATAWORD) shall be a power of 2.

From your example below, you seem to be using four byte word, so "unsigned" (or uint32_t) could be a used as a DATAWORD parameter.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...