PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Inlining asm in C source

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
Manuel



Joined: 30 Jul 2004
Posts: 4

PostPosted: Fri Jul 30, 2004 6:53 am    Post subject: Inlining asm in C source Reply with quote

Hello,

Some one here can help me ?

In a C program I try to use the assembly instruction RDTSC which ReaDs the CPU Time Stamp Counter and returns the result in EDX:EAX.

The problem is that I dont know how to transfer the values stored in the
registers EDX and EAX to C variables with inlined asm for PGCC.

I managed to develop an high precision timer for with GCC compiler
and i want to do the PGCC version :

double get_timesc()
{
unsigned long int edx, eax;
double x;

__asm__ volatile ("RDTSC" : "=a"(eax) : "=d"(edx) );

x = edx*4294967296 + eax;
return (x);
}

How to initialise C variables from registers ?

Many thanks for your help

Manuel.
Back to top
View user's profile
mwolfe



Joined: 13 Jul 2004
Posts: 20

PostPosted: Fri Jul 30, 2004 8:22 am    Post subject: asm("rdtsc") Reply with quote

I got the following to work:

unsigned long long
get_rdtsc()
{
asm ("rdtsc");
}

double get_timesc()
{
unsigned long long s;
s = get_rdtsc();
return s;
}

compiled with pgcc -Masmkeyword

Ignore the pgcc warning
PGC-W-0118-Function get_rdtsc does not contain a return statement (a.c: 13)
'rdtsc' returns its value in %eax/%edx pair, which just happens to be the register pair used for returning long long function return values, so this works, though it's not very pretty.
You can accumulate the result in long long unsigned integers, or in doubles, as you have been, though the long long->double conversion is another runtime function call
Back to top
View user's profile
Manuel



Joined: 30 Jul 2004
Posts: 4

PostPosted: Mon Aug 02, 2004 2:04 am    Post subject: Any other solution ? Reply with quote

Thanks for your help,

I tried your solution but it does not work.

The values returned by the double function
get_timesc are not good and some times they are
also negatives.

There is any no meaning to read a register and
send its value in a C variable.

regards.
Back to top
View user's profile
mwolfe



Joined: 13 Jul 2004
Posts: 20

PostPosted: Mon Aug 02, 2004 12:59 pm    Post subject: Reply with quote

There is no way to read a register and return its value in a C register using pgcc.

I've not found your problems (negative return values) unless get_timesc isn't declared extern double in the caller. I don't have any other ideas, sorry.
Back to top
View user's profile
Manuel



Joined: 30 Jul 2004
Posts: 4

PostPosted: Wed Aug 04, 2004 3:36 am    Post subject: Reply with quote

Hello mwolfe,

I found a solution. In fact we can define long integer
global variables (hi_reg and lo_reg) in the C source
and then move the registers into them using the two
following asm instructions:

Code:
    mov %eax, lo_reg
    mov %edx, hi_reg

Now my timer tool has a very good precision depending
of the CPU frequence and works on AMD/Operon which was
the target machine.

Best regards.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group