G4 assembly question

palott

Registered
Hi,

I'm hoping someone out there does some assembly programming on the G4 and could give me a pointer on how to compute the number of clock cycles for a given computation. I have a C code that works okay for pentiums, but I'm trying to do some optimization comparisons between pentiums and the G4.

I found this bit of code on someones webpage, but I'm pretty certain that this isn't correct given the results
asm("li %0,64;mtspr MMCR0,%0;mfspr %0,PMC1" : "=r" (t) : );
I'm hoping the mimic the access_counter function below with the G4 assembly language.

Thanks!

-Aaron



On an intel chip I use the following code
with a simple call to start_counter();
before the computation, and
count=get_counter(); after the computation.



void start_counter()
{

access_counter(&cyc_hi,&cyc_lo);

}

void access_counter(unsigned *hi,unsigned *lo)
{
asm("rdtsc; movl %%edx,%0; movl %%eax,%1"
:"=r" (*hi), "=r" (*lo)
:
:"%edx", "%eax");
}

double get_counter()
{

unsigned ncyc_hi,ncyc_lo;
unsigned hi,lo,borrow;
double result;

access_counter(&ncyc_hi,&ncyc_lo);
lo=ncyc_lo-cyc_lo;
borrow=lo>ncyc_lo;
hi=ncyc_hi-cyc_hi-borrow;
result=(double)hi*(1<<30)*4+lo;
if(result<0){
printf("error: counter returned negative value");
}

return result;

}
 
Back
Top