memory accesses

A

Adi

Hi,

I am writing a code which mimicks the memory accesses of an
application. Lets assume that array a[] contains all the addresses
accessed in sequence, check the for loop in the code given below. Now,
i want to mimick these accesses(not absolutely but atleast
relatively). I could see only one solution to that - writing a for
loop(see the code). But it gives extra memory accesses, accesing
address of index i and a along with the to b mimicked accesses.

main()
{
int a[300]; //stores the addresses
char x[5000]; //character array to mimick the memory accesses
int i;

a[0] = 0;
for(i=1;i<300;i++)
a = a[i-1]+16; //storing the addresses in the
array

x[0] = 0;
for(i=1;i<300;i++)
{
x[a]='0'; //mimick the realtive memory
accesses.
}
}

Is there any other solution to bypass these unwanted accesses like
storing value of i in registers etc... ?

Thanks.
 
M

Mike Wahler

Adi said:
Hi,

I am writing a code which mimicks the memory accesses of an
application. Lets assume that array a[] contains all the addresses
accessed in sequence, check the for loop in the code given below. Now,
i want to mimick these accesses(not absolutely but atleast
relatively). I could see only one solution to that - writing a for
loop(see the code). But it gives extra memory accesses, accesing
address of index i and a along with the to b mimicked accesses.

main()
{
int a[300]; //stores the addresses
char x[5000]; //character array to mimick the memory accesses
int i;

a[0] = 0;
for(i=1;i<300;i++)
a = a[i-1]+16; //storing the addresses in the
array

x[0] = 0;
for(i=1;i<300;i++)
{
x[a]='0'; //mimick the realtive memory
accesses.
}
}

Is there any other solution to bypass these unwanted accesses like
storing value of i in registers etc... ?


How do you know that 'i' isn't already being stored in a register?

Profile your code before trying to second-guess your compiler.

-Mike
 
A

Adi

main()
{
int a[300]; //stores the addresses
char x[5000]; //character array to mimick the memory accesses
int i;

a[0] = 0;
for(i=1;i<300;i++)
a = a[i-1]+16; //storing the addresses in the
array

x[0] = 0;
for(i=1;i<300;i++)
{
x[a]='0'; //mimick the realtive memory
accesses.
}
}

Is there any other solution to bypass these unwanted accesses like
storing value of i in registers etc... ?


How do you know that 'i' isn't already being stored in a register?

Profile your code before trying to second-guess your compiler.


I have profiled the code and i see 4 memory accesses(3 for i and 1 for
array a)between each access for x.
 
M

Mike Wahler

Adi said:
main()
{
int a[300]; //stores the addresses
char x[5000]; //character array to mimick the memory accesses
int i;

a[0] = 0;
for(i=1;i<300;i++)
a = a[i-1]+16; //storing the addresses in the
array

x[0] = 0;
for(i=1;i<300;i++)
{
x[a]='0'; //mimick the realtive memory
accesses.
}
}

Is there any other solution to bypass these unwanted accesses like
storing value of i in registers etc... ?


How do you know that 'i' isn't already being stored in a register?

Profile your code before trying to second-guess your compiler.


I have profiled the code and i see 4 memory accesses(3 for i and 1 for
array a)between each access for x.


And have you researched all the optimization switches of
your implementation? Have you proven that your code's
performance is somehow unacceptable? If so, perhaps you
need to drop down a level, and do this part with assembly
language, where you *can* have such low-level control.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top