From: sandmann AT clio DOT rice DOT edu (Charles Sandmann) Message-Id: <10302130355.AA21095@clio.rice.edu> Subject: _rdtsc proposal To: djgpp-workers AT delorie DOT com (DJGPP developers) Date: Wed, 12 Feb 2003 21:55:10 -0600 (CST) X-Mailer: ELM [version 2.5 PL2] Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com Given the FAQ nature of rdtsc; given the potential to use this in libc; for your amusement and comments. Patterned after farptr.h. When used inline for timing generates the single assembly instruction with no additional overhead (cool for timing small C sections). If OK, also will add makefile entry and docs. Yes I know it can kill some CPUs - that will be in the docs with an example how to work around it. (For those that don't know, the construct below will inline with appropriate optimization, and will call libc module if compiled with no optimization). --- time.bak Tue Feb 4 20:46:08 2003 +++ time.h Wed Feb 12 21:43:38 2003 @@ -100,6 +100,16 @@ int settimeofday(struct timeval *_tp, . void tzsetwall(void); uclock_t uclock(void); +unsigned long long _rdtsc(void); + +extern __inline__ unsigned long long +_rdtsc(void) +{ + unsigned long long result; + __asm__ __volatile__ ("rdtsc" : "=A"(result) ); + return result; +} + #endif /* !_POSIX_SOURCE */ #endif /* !__STRICT_ANSI__ */ #endif /* !__dj_ENFORCE_ANSI_FREESTANDING */ --- src/libc/pc_hw/timer/rdtsc.c /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */ #define extern #define __inline__ #include