public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/15516] New: assembly snippets for nano second resolution wall clock time
@ 2004-05-18 23:30 avle at ii dot uib dot no
  2004-05-18 23:43 ` [Bug libfortran/15516] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: avle at ii dot uib dot no @ 2004-05-18 23:30 UTC (permalink / raw)
  To: gcc-bugs

if someone feels for making gfortran's system_clock into a nano second
resolution wall clock timer see this page for some assembly snippets(ia32,64):

http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IA32LinuxCluster/Doc/timing.html

(relevant lines pasted below if the page disappears)


1.5 Linux Assembly code
The highest resolution but least portable timers are the Linux ASM timers. These
routines provide wall clock time .
IA64
In order to use the Linux ASM timer on the IA64 platform (titan), you will need
to compile the routine using the GNU C compiler. The routine is:

unsigned long long int nanotime_ia64(void)
{
    unsigned long long int val;
    __asm__ __volatile__("mov %0=ar.itc" : "=r"(val) :: "memory");
    return(val);
}
IA32
On the IA32 platform (platinum) you can use either the Intel or GNU compiler.
The routine is:

unsigned long long int nanotime_ia32(void)
{
     unsigned long long int val;
    __asm__ __volatile__("rdtsc" : "=A" (val) : );
     return(val);
}

You can link to the resulting object file with either Intel or GNU compiler from
C or Fortran with the appropriate wrapper if needed. If you extract the object
file get_clockfreq.o from /usr/lib/librt.a then you can call the function
__get_clockfreq() to determine clock frequency. To extract the routine, try:

    ar xv /usr/lib/librt.a get_clockfreq.o

To use the routines as timers, you can use the following routine. Call it before
and after the section of code you want to time and the difference will be the
elapsed time. Be sure to include the appropriate routine from above.


static long int CPS;
static double iCPS;
static unsigned start=0;

/* CPU Clock Freq. in Hz from routine in /usr/lib/librt.a */  
/* extern unsigned long long int __get_clockfreq(void); */ 

double second(void) /* Include an '_' if you will be calling from Fortan */
{
  double foo;
  if (!start)
  {
     /* CPU Clock Freq. in Hz from routine in /usr/lib/librt.a */
     /* CPS=__get_clockfreq(); */
     /* CPU Clock Freq. in Hz taken from /proc/cpuinfo */
     CPS=800134992;  
     iCPS=1.0/(double)CPS;
     start=1;
  }

    /* Uncomment one of the following */
  /* foo=iCPS*nanotime_ia32(); */  /* If running on IA32 machine */
  /* foo=iCPS*nanotime_ia64(); */   /* If running on IA64 machine */

  return(foo);
}

-- 
           Summary: assembly snippets for nano second resolution wall clock
                    time
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: avle at ii dot uib dot no
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15516


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug libfortran/15516] assembly snippets for nano second resolution wall clock time
  2004-05-18 23:30 [Bug libfortran/15516] New: assembly snippets for nano second resolution wall clock time avle at ii dot uib dot no
@ 2004-05-18 23:43 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-18 23:43 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-18 14:02 -------
Confirmed, and here is the PPC32 one too (but I do not know how to get the timebase frequency):
Note (long needs to be really a 32bit value and I also wrote this from memory):

unsigned long long GetTimebase(void)
{
  unsigned long low;
  unsigned long high;
  unsinged long high1;
  do
  {
    asm volatile ("mftbu %0":"=r"(high));
    asm volatile ("mftb %0":"=r"(low));
    asm volatile ("mftbu %0":"=r"(high1));
  } while (high != high1);
  return ((unsigned long long)high)<<32ULL|(unsigned long long) low;
}

PPC64 (easier as mftb gives the full timebase register for 64bit processors):

unsigned long long GetTimebase(void)
{
  unsigned long long timebase;
  asm volatile ("mftb %0":"=r"(timebase));
  return timebase;
}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-05-18 14:02:39
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15516


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-05-18 14:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-18 23:30 [Bug libfortran/15516] New: assembly snippets for nano second resolution wall clock time avle at ii dot uib dot no
2004-05-18 23:43 ` [Bug libfortran/15516] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).