5 ms·
What's the advantage compared to this: static uint128_t state = 1; // can be seeded to any odd number static inline uint64_t next(){ return
by pps43 7y ago
What's the advantage compared to this:
static uint128_t state = 1; // can be seeded to any odd number
static inline uint64_t next(){
return (state *= 0xda942042e4dd58b5ULL) >> 64;
}
from http://www.pcg-random.org/posts/on-vignas-pcg-critique.html http://www.pcg-random.org/posts/on-vignas-pcg-critique.html?
- dependenttypes 7y agoI am not aware of any architecture which allows for 128-bit multiplication.
- pps43 7y agoBoth CLang and GCC do it just fine. CLang even optimizes away unnecessary steps when upper half of one multiplicand is all zeroes like in this example.
- dfox 7y ago15 years ago I have observed that gcc on i386 would optimize away unnecessary steps of 64bit multiplication so one would assume that it is capable of doing the same for 128bit multiplication on 64bit platform and that thus it is not exclusively llvm/clang feature.
- shakna 7y agoSSE2 introduced native 128-bit types (__m128i), and GCC and Clang both have their own implementations that may be emulated in software or SSE instructions, depending on support.
- deleted 7y ago[deleted]
- wahern 7y agoAre you sure? AFAIU, __m128i isn't for 128-bit arithmetic, it's simply a convenience type for packing 8-bit, 32-bit, or 64-bit values for SIMD operations. GCC and clang do have a 128-bit integral type, __int128, but arithmetic operations are synthesized inline, and judging by the generated assembly don't even make use of SIMD at all. Note that an unintended consequence of C99's uintmax_t made the introduction of a standard 128-bit integral type impossible on platforms that cared about ABI compatibility, an effect somewhat contradictory to the original intention of improving portability and code integration. A future C standard will loosen some language and introduce some new facilities to help promote the introduction of larger integral types. At that point Unix platforms may begin typedef'ing __int128 to int128_t.
- edflsafoiewq 7y agoRomuDuo (same state size) appears to be slightly faster.