Skip to content

Commit

Permalink
Fix PowerPC read_time()
Browse files Browse the repository at this point in the history
The inline assembly used for the PowerPC version of read_time() is
broken:

$ ./src/csmith |grep Seed
 * Seed:      276270
$ ./src/csmith |grep Seed
 * Seed:      276270
$ ./src/csmith |grep Seed
 * Seed:      276270

Since platform_gen_seed() only returns a long we can simplify things
and just use mftb. With the patch applied we see correct behaviour:

$ ./src/csmith |grep Seed
 * Seed:      1186590549319330
$ ./src/csmith |grep Seed
 * Seed:      1186590989534520
$ ./src/csmith |grep Seed
 * Seed:      1186591288978819
  • Loading branch information
antonblanchard committed Nov 19, 2015
1 parent 33641e3 commit 798b7da
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/platform.cpp
Expand Up @@ -45,20 +45,13 @@
#include "platform.h"

#if (TARGET_CPU_powerpc == 1 || TARGET_CPU_powerpc64 == 1)
/*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;
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));
return retval;
static inline unsigned long read_time(void)
{
unsigned long a;

asm volatile("mftb %0" : "=r" (a));

return a;
}
#else
#ifdef WIN32
Expand Down

0 comments on commit 798b7da

Please sign in to comment.