UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Observer usam95
Observer
2,943 Views
Registered: ‎10-06-2016

Performance difference between single or double pointer dereferencing (MicroBlaze)

Jump to solution

Hello everyone,
I wounder if there is any difference while accessing data pointed to by single and double pointer (without virtual MMU)?

As I understood, it depends on underlying machine architecture and compiler's possibility to optimize the code. But I have no idea how the MB architecture and gcc compiler used by Xilinx SDK promote or have effect on code optimizing.

 

For example, I have a MB accessing the folllowing data structures in DDR3 pointed to by pointers *sub_component_ptr  and *component_ptr;

 

typedef struct

{

   int  value;
   u8  symbol;

   int  values_array[10];
   ....
} sub_component;

typedef struct
{

   sub_component  *aPart;
   .....

} component;

 

Which access will be faster for a MB: 

int aValue = sub_component_ptr->value;
or
int aValue = component_ptr->sub_component->value;

 

Does the multiple dereferencing decrease the code execution time in such a way that I necessarily need to consider it for my programm code?

Thanks!

Best regards
Usam

0 Kudos
1 Solution

Accepted Solutions
Moderator
Moderator
5,500 Views
Registered: ‎07-31-2012

Re: Performance difference between single or double pointer dereferencing (MicroBlaze)

Jump to solution

Hi,

 

As you know Pointer does not contain the ordinary value, contain the address of variable.

Single pointer is use to keep the address of variable,But Double pointer is use to keep the address of Single pointer.

 

The concept of pointer can easily be explained with the help of an example:

Value of x=50 adress of x= 120

Adress of y= 130

Adress of z= 140

Now let y= &x and z=&y

Then to print the value of x we can write :

printf(“%d”,x); or printf(“%d”,*y) both of these Will print the value 50

Now since y=&x thus y will store the adress of x

Printf(“%d”,y)=120

And z will store the address of y

z=&y thus printf(“%d',z)=130

Now if you use single pointer

Printf(“%d”,*z)= 120

When you use double pointer than

printf(“%d”,**z)=50

Therefore you could easily see the difference here , variable having single pointer points to the value of another variable whose address it stores whereas variable having double pointer points to the value of another variable whose address is already being stored in some other variable.

 

Regards

Praveen


-------------------------------------------------------------------------
Don’t forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
0 Kudos
2 Replies
Moderator
Moderator
5,501 Views
Registered: ‎07-31-2012

Re: Performance difference between single or double pointer dereferencing (MicroBlaze)

Jump to solution

Hi,

 

As you know Pointer does not contain the ordinary value, contain the address of variable.

Single pointer is use to keep the address of variable,But Double pointer is use to keep the address of Single pointer.

 

The concept of pointer can easily be explained with the help of an example:

Value of x=50 adress of x= 120

Adress of y= 130

Adress of z= 140

Now let y= &x and z=&y

Then to print the value of x we can write :

printf(“%d”,x); or printf(“%d”,*y) both of these Will print the value 50

Now since y=&x thus y will store the adress of x

Printf(“%d”,y)=120

And z will store the address of y

z=&y thus printf(“%d',z)=130

Now if you use single pointer

Printf(“%d”,*z)= 120

When you use double pointer than

printf(“%d”,**z)=50

Therefore you could easily see the difference here , variable having single pointer points to the value of another variable whose address it stores whereas variable having double pointer points to the value of another variable whose address is already being stored in some other variable.

 

Regards

Praveen


-------------------------------------------------------------------------
Don’t forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
0 Kudos
Highlighted
Observer usam95
Observer
2,837 Views
Registered: ‎10-06-2016

Re: Performance difference between single or double pointer dereferencing (MicroBlaze)

Jump to solution

Thanks for your reply. I also undestood it so. It's easy or faster to find the needed value if you just have to ask the right address by one pointer (single dereferencing) compared to asking the right address of needed value two times by two pointers (double dereferencing). But do you know, whether a double pointer dereferencing heavy influences the duration of programm execution time in contrast to a single dereferencing. I mean, if I'm doing a design of my software to run on MicroBlaze, do I necessarily need to consider this aspect? Do you know an approximate difference in memory access time by single or double dereferencing on MicroBlaze using DDR3 as memory?

 

Regards
Usam

 

0 Kudos