[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[csmith-bugs] [patch] read_time() on e500



As of bf42ffd, csmith contains PPC-specific code in src/platform.cpp for reading
time base register which doesn't work on e500 family cores. Specifically, mftb?
instructions are not implemented on these cores.

The code snippet in question is common between various open-source projects, and
qemu developers eventually came up w/ a correct fix suitable for all PPC CPUs.

--- a/csmith/src/platform.cpp	2014-03-17 16:16:02.029734524 +0800
+++ b/csmith/src/platform.cpp	2014-04-07 16:59:36.444156769 +0800
@@ -48,16 +48,16 @@
 /*For PPC, got from:
 http://lists.ozlabs.org/pipermail/linuxppc-dev/1999-October/003889.html
 */
-static unsigned long long read_time(void) {
-	unsigned long long retval;
+static inline int64_t read_time(void)
+{
+	int64_t retval;
 	unsigned long junk;
-	__asm__ __volatile__ ("\n\
-1:	mftbu %1\n\
-	mftb %L0\n\
-	mftbu %0\n\
-	cmpw %0,%1\n\
-	bne 1b"
-	: "=r" (retval), "=r" (junk));
+	__asm__ __volatile__ ("mfspr   %1,269\n\t"
+                          "mfspr   %L0,268\n\t"
+                          "mfspr   %0,269\n\t"
+                          "cmpw    %0,%1\n\t"
+                          "bne     $-16"
+                          : "=r" (retval), "=r" (junk));
 	return retval;
 }
 #else

W/ this trivial patch it is now possible to run csmith on e500-based CPUs,
specifically those made by Freescale.