Jump to content

Checking ports for power estimations


sHeshmat

Recommended Posts

Hi

1- i am facing a problem , many developers on working on power estimation they count the transitions from 0 to 1.

if i am sending a packet of data that is user defined via sc_signal to communicate between two sc_port who also have user defined data types.

how it is possible to see the data transmitted and received in a binary manner.

2- how to know in systemc if a certain line or link switched from high to low and vice versa

thanks a lot.

Link to comment
Share on other sites

I'm not sure if I get your first question right. Essentially this is a C++ question. But what you could do is a type erase of your (POD) data, use it as a byte array and count the changed bits using XOR (be carefull to you plain data, no classes). Something like:

struct my_data {
  int x;
  long y;
};

my_data old_val, new_val;

uint8_t* old_data = reinterpret_cast<uint8_t*>(&old_val);
uint8_t* new_data = reinterpret_cast<uint8_t*>(&new_val);

unsigned toggles=0;
for(size_t i=0; i<sizeof(my_data); ++i){
  uint8_t diff = *(old_data+i)^*(new_data+i);
  uint8_t mask=1;
  for(size_t j=0; j<8; ++j, mask<<=1)
    if(mask&diff) ++toggles;
}

Regarding your second question: you transport the data via a signal which implements the signal_in_if. This interface has a value_changed_event()  getter which returns an event firing when the value of the signal changes. Just wait for this event.

Link to comment
Share on other sites

i have uploaded a print screen , concerning my first question.

i tried to make your example with value x= 2 , and y = 8 for the struct ,

but after making the reinterpret_cast the values appearing in the debug mode are very strange and i can not understand how i can use them in binary manner.

NB : i made red squares around the points in need

thanks a lot

systemc.png

Link to comment
Share on other sites

Well this a little bit about data representation. old_data is a pointer to a uint8_t and this is what you see in the variables view. It has the value of 0x7ff..fdb10. The memory at this address is 2 which is the lowest byte of the first element in your struct (x of type int).

Actually using the struct the compiler orders the 2 elements in a row. Depending on the platform and the compiler the members might be  32 or 64 bit long. Lets assume the int is 32bit and the long is 64 (gcc on 64bit Linux). The layout is as follows (the suffix denote the byte number):

old_data ->  	x.0
  		x.1
  		x.2
  		x.3
  		y.0
  		y.1
  		y.2
  		y.3
  		y.4
  		y.5
  		y.6
  		y.7
  

So the value 2 is the lowest byte of the old_val.x variable having the value of 2 (or 258,...)

Well, the struct shown above is not entirely correct. The compiler might choose to put padding bytes inbetweeen the members for performance reasons. In this case above there will be 4 byte of padding between x and y so that y is at an aligned address (a multiple of 8). So you would declare it as

struct __attribute__ ((__packed__)) my_data {
	int x;
	long y;
};

to avoid the paddng. See also https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes

Back to your question: you use the pointer like in an array. the notion

*(old_data+i)

is equivalent to

old_data[i]

So in the for loop you iterate over every byte belonging to the struct.

BR

Link to comment
Share on other sites

value_changed_event() returns a constant reference to an sc_core::sc_event. A SystemC method or thread can be made sensitive to that event to get activated each time the corresponding sc_event gets notified. Easiest would be to connect your sc_signals to matching sc_in port of a dedicated module, which sets up the method or thread responsible for counting your bit changes. I recommend that you read a good introduction to the basic concepts of SystemC, e.g., David C. Black et al. "SystemC from the Ground Up", 2nd ed. The SystemC elaboration and simulation semantics are also described in clause 4 of the freely available IEEE Std 1666-2011. If you are not yet much familiar with C++ itself, it might be a good idea to get first familiar with the fundamental concepts of C++ first.

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.

Guest
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...