In my previous post, I reviewed a new fast random number generator called wyhash. I commented that I expected it to do well on x64 processors (Intel and AMD), but not so well on ARM processors.

Let us review again wyhash:

uint64_t wyhash64_x ; uint64_t wyhash64() { wyhash64_x + = 0 x 60bee2bee120fc15 ; __uint128_t tmp ; tmp = ( __uint128_t ) wyhash64_x * 0 x a3b195354a39b70d ; uint64_t m1 = ( tmp > > 64 ) ^ tmp ; tmp = ( __uint128_t ) m1 * 0 x 1b03738712fad5c9 ; uint64_t m2 = ( tmp > > 64 ) ^ tmp ; return m2 ; }

(Source code)

It is only two multiplications (plus a few cheap operations like add and XOR), but these are full multiplications producing a 128-bit output.

Let us compared with a similar but conventional generator (splitmix) developed by Steele et al. and part of the Java library:

uint64_t splitmix64(void) { splitmix64_x + = 0 x 9E3779B97F4A7C15 ; uint64_t z = splitmix64_x ; z = ( z ^ ( z > > 30 ) ) * 0 x BF58476D1CE4E5B9 ; z = ( z ^ ( z > > 27 ) ) * 0 x 94D049BB133111EB ; return z ^ ( z > > 31 ) ; }

We still have two multiplications, but many more operation. So you would expect splitmix to be slower. And it is, on my typical x64 processor.

Let me reuse my benchmark where I simply sum up 524288 random integers are record how long it takes…

Skylake x64 Skylark ARM wyhash 0.5 ms 1.4 ms splitmix 0.6 ms 0.9 ms

According to my tests, on the x64 processor, wyhash is faster than splitmix. When I switch to my ARM server, wyhash becomes slower.

The difference is that the computation of the most significant bits of a 64-bit product on an ARM processor requires a separate and potentially expensive instruction.

Of course, your results will vary depending on your exact processor and exact compiler.

Note: I have about half a million integers, so if you double my numbers, you will get a rough estimate of the number of nanoseconds per 64-bit integer generated.

Update 1: W. Dijkstra correctly pointed out that wyhash could not, possibly, be several times faster than splitmix in a fair competition. I initially reported bad results with splitmix, but after disabling autovectorization (-fno-tree-vectorize), the results are closer. He also points out that results are vastly different on other ARM processors like Falkor and ThunderX2.

Update 2: One reading of this blog post is that I am pretending to compare Intel vs. ARM and to qualify one as being better than the other one. That was never my intention. My main message is that the underlying hardware matters a great deal when trying to determine which code is fastest.

Update 3. My initial results made the ARM processor look bad. Switching to a more recent compiler (GNU GCC 8.3) resolved the issue.