Mail Archives: djgpp-workers/2003/02/12/22:52:57
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 <time.h>
- Raw text -