Can I send a value of a variable of type std::array<sc_fixed<16, 9>, 64> using the void set_data_ptr( unsigned char* ) member function of the tlm_generic_payload class through the void b_transport( tlm::tlm_generic_payload& trans, sc_time& delay ) member function of the tlm_blocking_transport_if class in TLM?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
set_data_ptr expects a pointer to a contiguous block of memory (unsigned char*).
std::array<sc_fixed<16, 9>, 64> is a fixed-size array of 64 sc_fixed<16,9> elements.
sc_fixed<16, 9> is a SystemC fixed-point data type, which is a class, not a plain old data (POD) type.
Can you directly pass the address of std::array<sc_fixed<16, 9>, 64> as unsigned char*?
The set_data_ptr function expects a pointer to raw bytes (unsigned char*), typically pointing to a buffer of bytes representing the data to be transferred.
std::array stores its elements contiguously, so &my_array[0] points to the first sc_fixed<16,9> element.
However, sc_fixed<16,9> is not a simple POD type; it has internal members and methods, and its in-memory representation is not guaranteed to be a simple contiguous block of bytes representing the fixed-point value in a standard way.
Simply casting &my_array[0] to unsigned char* and passing it to set_data_ptr will pass the raw memory of the sc_fixed objects, including any internal bookkeeping data, not just the fixed-point value bits.
What are the implications?
If the receiver expects raw bytes representing the fixed-point values in a specific format (e.g., 16-bit integers), sending the raw sc_fixed objects will not work correctly.
The receiver will not be able to interpret the data correctly unless it knows the exact internal layout of sc_fixed, which is not portable or recommended.
Recommended approach
Serialize the fixed-point values into a raw buffer of bytes before sending.
For example, convert each sc_fixed<16,9> to a 16-bit integer or a known binary format, store these in a std::vector<uint16_t> or std::array<uint16_t, 64>, then pass the pointer to that buffer to set_data_ptr.
Example:
cpp
std::array<sc_fixed<16,9>, 64> fixed_array = /* your data */;
std::array<uint16_t, 64> raw_data;
for (size_t i = 0; i < 64; ++i) {
raw_data[i] = fixed_array[i].to_uint(); // or to_int(), depending on signedness
}
tlm::tlm_generic_payload trans;
trans.set_data_ptr(reinterpret_cast<unsigned char*>(raw_data.data()));
trans.set_data_length(sizeof(raw_data));
On the receiving side, reconstruct the sc_fixed values from the raw 16-bit integers.
Summary
No, you should not directly pass the address of std::array<sc_fixed<16,9>, 64> to set_data_ptr.
You must serialize the fixed-point values into a raw byte buffer first.
This ensures correct and portable data transfer through TLM transactions.
If you want, I can help you write a full example of serialization and deserialization for this case!
User
Could you refine my original question for improved clarity?
Assistant
Certainly! Here’s a refined version of your original question for improved clarity and precision:
Original: Can I send a value of a variable of type std::array<sc_fixed<16, 9>, 64> using the void set_data_ptr( unsigned char* ) member function of the tlm_generic_payload class through the void b_transport( tlm::tlm_generic_payload& trans, sc_time& delay ) member function of the tlm_blocking_transport_if class in TLM?
Refined:
Is it possible to directly send a variable of type std::array<sc_fixed<16, 9>, 64> by passing its data pointer (cast to unsigned char*) to the set_data_ptr() method of a tlm_generic_payload object, and then transmit it through the b_transport(tlm::tlm_generic_payload& trans, sc_time& delay) method of the tlm_blocking_transport_if interface in TLM? If not, what is the recommended way to transfer such fixed-point data using TLM?
Would you like me to help you further improve or expand this question?