From 631ed32c6ba9a7966d52b1de1c3e59283e1f8312 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 11 Aug 2020 23:08:45 +0200 Subject: Added visual studio _umul128() declaration in crandom.h --- stc/crandom.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/stc/crandom.h b/stc/crandom.h index 1e3b2107..a3d0b77c 100644 --- a/stc/crandom.h +++ b/stc/crandom.h @@ -94,15 +94,16 @@ STC_INLINE double crandom_f64(crandom_eng64_t* rng) { STC_INLINE crandom_distrib_i64_t crandom_uniform_i64_init(int64_t low, int64_t high) { crandom_distrib_i64_t dist = {low, high - low + 1}; return dist; } -STC_INLINE int64_t crandom_uniform_i64(crandom_eng64_t* rng, crandom_distrib_i64_t dist) { -#if defined(__SIZEOF_INT128__) - return dist.offset + (int64_t) (((__uint128_t) crandom_i64(rng) * dist.range) >> 64); -#elif defined(_MSC_VER) && defined(_WIN64) - int64_t hi; _umul128(crandom_i64(rng), dist.range, &hi); return dist.offset + hi; -#else - return dist.offset + crandom_i64(rng) % dist.range; // slower -#endif +STC_INLINE int64_t crandom_uniform_i64(crandom_eng64_t* rng, crandom_distrib_i64_t dist) { + #if defined(__SIZEOF_INT128__) + return dist.offset + (int64_t) (((__uint128_t) crandom_i64(rng) * dist.range) >> 64); + #elif defined(_MSC_VER) && defined(_WIN64) + uint64_t _umul128(uint64_t x, uint64_t y, uint64_t *hi); + uint64_t hi; _umul128(crandom_i64(rng), dist.range, &hi); return dist.offset + hi; + #else + return dist.offset + crandom_i64(rng) % dist.range; // slower + #endif } STC_INLINE crandom_distrib_f64_t crandom_uniform_f64_init(double low, double high) { -- cgit v1.2.3