Jump to content
Khushi

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

--

Khushi

Share this post


Link to post
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,
  Philipp 

Share this post


Link to post
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 ?

Thanks

 

Share this post


Link to post
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):

Quote

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×