21#ifndef __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_ENDIAN_CONV_HH__
22#define __SYSTEMC_EXT_TLM_CORE_2_GENERIC_PAYLOAD_ENDIAN_CONV_HH__
147class tlm_endian_context;
285 unsigned char *tmp = (
unsigned char *)(&d);
286 for (ptrdiff_t i = 0; i !=
sizeof(D); i++)
294 operator bool()
const {
return b; }
308 unsigned char *dest1,
unsigned char *dest2)
316 unsigned char *dest1,
unsigned char *dest2)
324 unsigned char * ,
unsigned char *dest2)
331 unsigned char * ,
unsigned char *dest2)
338 unsigned char *dest1,
unsigned char *dest2)
346 void COPY(
unsigned char *he_d,
unsigned char *he_b,
347 unsigned char *ie_d,
unsigned char *ie_b)>
352 unsigned char *ie_data,
unsigned char *ie_be,
353 unsigned char *he_data,
unsigned char *he_be)
355 for (
int orig_sword = 0, new_sword = 0; new_sword < new_len;
356 new_sword += new_stream_width, orig_sword += orig_stream_width) {
358 for (
int orig_dword = orig_sword;
359 orig_dword < orig_sword + orig_stream_width;
360 orig_dword +=
sizeof(D)) {
361 for (
int curr_byte = orig_dword +
sizeof(D) - 1;
362 curr_byte >= orig_dword; curr_byte--) {
363 ptrdiff_t he_index = ((ie_addr++) ^ (sizeof_databus - 1)) -
364 new_start_address + new_sword;
365 COPY(ie_data + curr_byte,
367 ie_be + (curr_byte % be_length),
368 he_data + he_index, he_be + he_index);
379template <
class DATAWORD>
382 unsigned int sizeof_databus)
386 txn->template get_extension<tlm_endian_context>();
398template <
class DATAWORD>
401 unsigned int sizeof_databus)
411 if (s_width >= length)
413 int nr_stream_words = length / s_width;
418 ~(sizeof_databus - 1));
420 int new_stream_width = end_address - new_address + sizeof_databus;
421 int new_length = new_stream_width * nr_stream_words;
446 new_length, new_stream_width, s_width, sizeof_databus,
451 s_width, sizeof_databus, tc->
address, new_address,
452 orig_be_length, tc->
data_ptr, orig_be,
459 new_stream_width, s_width, sizeof_databus, tc->
address,
460 new_address, new_length, tc->
data_ptr, 0,
464 s_width, sizeof_databus, tc->
address, new_address,
465 orig_be_length, tc->
data_ptr, orig_be,
478copy_d1(
unsigned char *src1,
unsigned char *src2,
479 unsigned char *dest1,
unsigned char *dest2)
481 *((D *)dest1) = *((D *)src1);
488 unsigned char *dest1,
unsigned char *dest2)
490 *((D *)dest1) = *((D *)src1);
491 *((D *)dest2) = *((D *)src2);
496true_b1(
unsigned char *src1,
unsigned char *src2,
497 unsigned char *dest1,
unsigned char *dest2)
504copy_b1(
unsigned char *src1,
unsigned char *src2,
505 unsigned char *dest1,
unsigned char *dest2)
507 *((D *)dest2) = *((D *)src2);
513 unsigned char *dest1,
unsigned char *dest2)
516 *((D *)src1) = *((D *)dest1);
522 unsigned char *dest1,
unsigned char *dest2)
524 *((D *)src1) = *((D *)dest1);
540 void COPY(
unsigned char *src1,
unsigned char *src2,
541 unsigned char *dest1,
unsigned char *dest2),
542 void COPYuchar(
unsigned char *src1,
unsigned char *src2,
543 unsigned char *dest1,
unsigned char *dest2),
544 void FILLFALSE(
unsigned char *dest1),
545 void FILLFALSEuchar(
unsigned char *dest1)>
547loop_word1(
int bytes_left,
int len0,
int lenN,
int sizeof_databus,
548 unsigned char *start,
unsigned char *end,
549 unsigned char *src,
unsigned char *bsrc,
550 unsigned char *dest,
unsigned char *bdest)
552 ptrdiff_t d2b_src = bsrc - src;
553 ptrdiff_t d2b_dest = bdest - dest;
554 unsigned char *original_dest = dest;
558 if ((src >= start) && (src < end)) {
559 for (
int i = 0; i < len0; i++) {
560 COPYuchar(src, src + d2b_src, dest, dest + d2b_dest);
566 return int(dest - original_dest);
568 for (
int i = 0; i < len0; i++) {
569 FILLFALSEuchar(dest + d2b_dest);
574 src -= 2 *
sizeof(D);
577 for (
unsigned int i = 1; i < sizeof_databus /
sizeof(D); i++) {
578 if ((src >= start) && (src < end)) {
579 COPY(src, src + d2b_src, dest, dest + d2b_dest);
580 bytes_left -=
sizeof(D);
582 FILLFALSE(dest + d2b_dest);
586 return int(dest - original_dest);
591 if ((src >= start) && (src < end)) {
592 for (
int i = 0; i < lenN; i++) {
593 COPYuchar(src, src + d2b_src, dest, dest + d2b_dest);
599 return int(dest - original_dest);
601 for (
int i = 0; i < lenN; i++) {
602 FILLFALSEuchar(dest + d2b_dest);
607 src += 2 * sizeof_databus;
616template <
class DATAWORD>
622 txn->template get_extension<tlm_endian_context>();
624 int d_mask =
sizeof(DATAWORD) - 1;
625 int a_offset =
static_cast<int>(tc->
address & b_mask);
626 int len0 = (sizeof_databus - a_offset) & d_mask;
627 int lenN =
sizeof(DATAWORD) - len0;
628 unsigned char *d_start = tc->
data_ptr;
629 unsigned char *d_end =
630 ptrdiff_t(tc->
length) + d_start;
632 ptrdiff_t(((sizeof_databus - a_offset) & ~d_mask) + lenN) +
640 tc->
length, len0, lenN, sizeof_databus,
646 tc->
length, len0, lenN, sizeof_databus,
659template <
class DATAWORD>
668 int d_mask =
sizeof(DATAWORD) - 1;
670 int a_offset =
static_cast<int>(txn->
get_address() & b_mask);
671 int len0 = (sizeof_databus - a_offset) & d_mask;
672 int lenN =
sizeof(DATAWORD) - len0;
674 unsigned char *d_end =
678 ptrdiff_t(((sizeof_databus - a_offset) & ~d_mask) + lenN) + d_start;
684 unsigned char *new_data = tc->
new_dbuf;
700 sizeof_databus, d_start, d_end, d, 0,
709 sizeof_databus, d_start, d_end, d,
723 sizeof_databus, d_start, d_end, d, 0,
732 sizeof_databus, d_start, d_end, d,
751inline void copy_d2(D *src1, D *src2, D *dest1, D *dest2) { *dest1 = *src1; }
769template <
class D,
void COPY(D *src1, D *src2, D *dest1, D *dest2)>
775 ptrdiff_t src1to2 = (
char *)src2 - (
char *)src1;
777 ptrdiff_t dest1to2 = (
char *)dest2 - (
char *)dest1;
779 D *done = src1 + ptrdiff_t(words);
781 src1 += ptrdiff_t(words_per_bus - 1);
784 COPY(src1, (D *)(src1to2 + (
char *)src1), dest1,
785 (D *)(dest1to2 + (
char *)dest1));
787 if ((--src1) < bus_start) {
788 bus_start += ptrdiff_t(words_per_bus);
789 if (bus_start == done)
791 src1 = bus_start + ptrdiff_t(words_per_bus - 1);
801template <
class DATAWORD>
806 int words_per_bus = sizeof_databus /
sizeof(DATAWORD);
807 if (words_per_bus == 1)
818 (DATAWORD *)(tc->
data_ptr), 0, words, words_per_bus);
827 (DATAWORD *)(tc->
data_ptr), 0, words, words_per_bus);
837template <
class DATAWORD>
846 int words_per_bus = sizeof_databus /
sizeof(DATAWORD);
847 if (words_per_bus == 1)
852 DATAWORD *original_data = (DATAWORD *)(txn->
get_data_ptr());
858 if (original_be == 0) {
864 words, words_per_bus);
867 tc->
data_ptr = (
unsigned char *)original_data;
879 original_data, original_be,
882 words, words_per_bus);
885 tc->
data_ptr = (
unsigned char *)original_data;
889 0, words, words_per_bus);
900template <
class DATAWORD>
911template <
class DATAWORD>
923 (sizeof_databus - (
a & mask) -
sizeof(DATAWORD)));
std::vector< Fiber * > next
static D make_uchar_array(unsigned char c)
tlm_endian_context_pool()
tlm_endian_context * first
void push(tlm_endian_context *c)
tlm_endian_context * pop()
~tlm_endian_context_pool()
void copy_from(tlm_extension_base const &)
sc_dt::uint64 new_address
tlm_endian_context * next
unsigned char * byte_enable
void(* from_f)(tlm_generic_payload *txn, unsigned int sizeof_databus)
tlm_extension_base * clone() const
void establish_bebuf(int len)
void establish_dbuf(int len)
unsigned char * new_bebuf
void set_data_ptr(unsigned char *data)
unsigned char * get_data_ptr() const
void set_byte_enable_length(const unsigned int byte_enable_length)
void set_address(const sc_dt::uint64 address)
unsigned char * get_byte_enable_ptr() const
sc_dt::uint64 get_address() const
unsigned int get_byte_enable_length() const
void set_data_length(const unsigned int length)
void get_extension(T *&ext) const
unsigned int get_streaming_width() const
unsigned int get_data_length() const
void set_streaming_width(const unsigned int streaming_width)
T * set_extension(T *ext)
void set_byte_enable_ptr(unsigned char *byte_enable)
#define TLM_BYTE_DISABLED
void copy_db1(unsigned char *src1, unsigned char *src2, unsigned char *dest1, unsigned char *dest2)
void loop_aligned2(D *src1, D *src2, D *dest1, D *dest2, int words, int words_per_bus)
void tlm_to_hostendian_single(tlm_generic_payload *txn, unsigned int sizeof_databus)
void tlm_to_hostendian_word(tlm_generic_payload *txn, unsigned int sizeof_databus)
void copy_dbyb0(unsigned char *src1, unsigned char *, unsigned char *dest1, unsigned char *dest2)
void copy_btrue0(unsigned char *, unsigned char *, unsigned char *, unsigned char *dest2)
tlm_endian_context * establish_context(tlm_generic_payload *txn)
void loop_generic0(int new_len, int new_stream_width, int orig_stream_width, int sizeof_databus, sc_dt::uint64 orig_start_address, sc_dt::uint64 new_start_address, int be_length, unsigned char *ie_data, unsigned char *ie_be, unsigned char *he_data, unsigned char *he_be)
void copy_dbyb1(unsigned char *src1, unsigned char *src2, unsigned char *dest1, unsigned char *dest2)
void copy_db2(D *src1, D *src2, D *dest1, D *dest2)
void copy_db0(unsigned char *src1, unsigned char *src2, unsigned char *dest1, unsigned char *dest2)
static tlm_endian_context_pool global_tlm_endian_context_pool
void tlm_to_hostendian_generic(tlm_generic_payload *txn, unsigned int sizeof_databus)
void tlm_from_hostendian(tlm_generic_payload *txn)
void copy_b1(unsigned char *src1, unsigned char *src2, unsigned char *dest1, unsigned char *dest2)
void copy_b0(unsigned char *, unsigned char *src2, unsigned char *, unsigned char *dest2)
void copy_dbyb2(D *src1, D *src2, D *dest1, D *dest2)
void no_b1(unsigned char *dest1)
void tlm_from_hostendian_word(tlm_generic_payload *txn, unsigned int sizeof_databus)
void tlm_to_hostendian_aligned(tlm_generic_payload *txn, unsigned int sizeof_databus)
void true_b1(unsigned char *src1, unsigned char *src2, unsigned char *dest1, unsigned char *dest2)
void copy_d1(unsigned char *src1, unsigned char *src2, unsigned char *dest1, unsigned char *dest2)
void tlm_from_hostendian_single(tlm_generic_payload *txn, unsigned int sizeof_databus)
void tlm_from_hostendian_generic(tlm_generic_payload *txn, unsigned int sizeof_databus)
int loop_word1(int bytes_left, int len0, int lenN, int sizeof_databus, unsigned char *start, unsigned char *end, unsigned char *src, unsigned char *bsrc, unsigned char *dest, unsigned char *bdest)
void copy_d2(D *src1, D *src2, D *dest1, D *dest2)
void copy_dbtrue0(unsigned char *src1, unsigned char *, unsigned char *dest1, unsigned char *dest2)
void false_b1(unsigned char *dest1)
void tlm_from_hostendian_aligned(tlm_generic_payload *txn, unsigned int sizeof_databus)
void copy_dbytrue1(unsigned char *src1, unsigned char *src2, unsigned char *dest1, unsigned char *dest2)