[cfe-users] Clang and __gnu_cxx::simd_fast_mersenne_twister_engine. SSE2 bug?
John Steele Scott
toojays at toojays.net
Mon Mar 31 23:32:32 PDT 2014
GCC 4.8 added an SSE2 optimized simd_fast_mersenne_twister_engine in the
__gnu_cxx namespace. I've been able to use this successfully with both GCC and
ICC, but when I use it with Clang, it doesn't give consistent results.
Here's a simple example:
jscott at saaz:/tmp$ cat sfmt.cpp
#include <stdio.h>
#include <random>
#include <ext/random>
int main (void)
{
/* Construct an engine, and print the first word of output. */
__gnu_cxx::sfmt19937 engine;
uint32_t first_word = engine();
printf("%08x\n", first_word);
/* Reset the engine, and print the first word again. */
engine.seed();
uint32_t first_word_again = engine();
printf("%08x\n", first_word_again);
if (first_word != first_word_again)
{
printf("FAIL: values should match!\n");
return 1;
}
return 0;
}
jscott at saaz:/tmp$ clang++ -std=c++11 sfmt.cpp -o sfmt
jscott at saaz:/tmp$ ./sfmt
02fafdb7
74994db7
FAIL: values should match!
With GCC it looks fine:
jscott at saaz:/tmp$ g++-4.8 -std=c++11 sfmt.cpp -o sfmt
jscott at saaz:/tmp$ ./sfmt
02ef8db7
02ef8db7
I also notice that if I disable SSE2, clang works fine:
jscott at saaz:/tmp$ clang++ -std=c++11 sfmt.cpp -o sfmt -mno-sse2
jscott at saaz:/tmp$ ./sfmt
02ef8db7
02ef8db7
Can a Clang expert tell me whether this is a bug in Clang? Or something else?
I'm using Clang 3.4 on x86_64.
Thanks,
John
More information about the cfe-users
mailing list