diff options
author | Robert Kern <robert.kern@gmail.com> | 2019-06-27 22:27:55 -0700 |
---|---|---|
committer | Robert Kern <robert.kern@gmail.com> | 2019-06-27 22:27:55 -0700 |
commit | 6e7f42efe7a2e3c9a8222429de94c4fbed98769b (patch) | |
tree | b816c8e2a613d1081216c26c37dd84c01eec6bee /numpy/random/src/pcg64 | |
parent | 588310c7bdf75715955e7eefce4151c0569dc730 (diff) | |
download | numpy-6e7f42efe7a2e3c9a8222429de94c4fbed98769b.tar.gz |
BUG: do not force emulation of 128-bit arithmetic.
Diffstat (limited to 'numpy/random/src/pcg64')
-rw-r--r-- | numpy/random/src/pcg64/pcg64.c | 12 | ||||
-rw-r--r-- | numpy/random/src/pcg64/pcg64.h | 17 |
2 files changed, 20 insertions, 9 deletions
diff --git a/numpy/random/src/pcg64/pcg64.c b/numpy/random/src/pcg64/pcg64.c index 45c11a010..b15973aef 100644 --- a/numpy/random/src/pcg64/pcg64.c +++ b/numpy/random/src/pcg64/pcg64.c @@ -32,7 +32,9 @@ * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. @@ -117,7 +119,7 @@ extern inline uint32_t pcg64_next32(pcg64_state *state); extern void pcg64_advance(pcg64_state *state, uint64_t *step) { pcg128_t delta; -#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH) +#ifndef PCG_EMULATED_128BIT_MATH delta = (((pcg128_t)step[0]) << 64) | step[1]; #else delta.high = step[0]; @@ -128,7 +130,7 @@ extern void pcg64_advance(pcg64_state *state, uint64_t *step) { extern void pcg64_set_seed(pcg64_state *state, uint64_t *seed, uint64_t *inc) { pcg128_t s, i; -#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH) +#ifndef PCG_EMULATED_128BIT_MATH s = (((pcg128_t)seed[0]) << 64) | seed[1]; i = (((pcg128_t)inc[0]) << 64) | inc[1]; #else @@ -148,7 +150,7 @@ extern void pcg64_get_state(pcg64_state *state, uint64_t *state_arr, * 64 bits of a uint128_t variable * */ -#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH) +#ifndef PCG_EMULATED_128BIT_MATH state_arr[0] = (uint64_t)(state->pcg_state->state >> 64); state_arr[1] = (uint64_t)(state->pcg_state->state & 0xFFFFFFFFFFFFFFFFULL); state_arr[2] = (uint64_t)(state->pcg_state->inc >> 64); @@ -171,7 +173,7 @@ extern void pcg64_set_state(pcg64_state *state, uint64_t *state_arr, * 64 bits of a uint128_t variable * */ -#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH) +#ifndef PCG_EMULATED_128BIT_MATH state->pcg_state->state = (((pcg128_t)state_arr[0]) << 64) | state_arr[1]; state->pcg_state->inc = (((pcg128_t)state_arr[2]) << 64) | state_arr[3]; #else diff --git a/numpy/random/src/pcg64/pcg64.h b/numpy/random/src/pcg64/pcg64.h index 67695d002..2a7217dd9 100644 --- a/numpy/random/src/pcg64/pcg64.h +++ b/numpy/random/src/pcg64/pcg64.h @@ -32,7 +32,9 @@ * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. @@ -72,9 +74,6 @@ typedef struct { uint64_t low; } pcg128_t; -#define PCG_DEFAULT_MULTIPLIER_HIGH 2549297995355413924ULL -#define PCG_DEFAULT_MULTIPLIER_LOW 4865540595714422341ULL - static inline pcg128_t PCG_128BIT_CONSTANT(uint64_t high, uint64_t low) { pcg128_t result; result.high = high; @@ -92,6 +91,9 @@ typedef struct { pcg128_t inc; } pcg_state_setseq_128; +#define PCG_DEFAULT_MULTIPLIER_HIGH 2549297995355413924ULL +#define PCG_DEFAULT_MULTIPLIER_LOW 4865540595714422341ULL + #define PCG_DEFAULT_MULTIPLIER_128 \ PCG_128BIT_CONSTANT(PCG_DEFAULT_MULTIPLIER_HIGH, PCG_DEFAULT_MULTIPLIER_LOW) #define PCG_DEFAULT_INCREMENT_128 \ @@ -207,6 +209,13 @@ static inline uint64_t pcg_output_xsl_rr_128_64(pcg128_t state) { state >> 122u); } +static inline uint64_t +pcg_setseq_128_xsl_rr_64_random_r(pcg_state_setseq_128* rng) +{ + pcg_setseq_128_step_r(rng); + return pcg_output_xsl_rr_128_64(rng->state); +} + static inline void pcg_setseq_128_srandom_r(pcg_state_setseq_128 *rng, pcg128_t initstate, pcg128_t initseq) { |