diff options
author | mattip <matti.picus@gmail.com> | 2019-06-25 18:46:30 +0300 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2019-06-25 22:02:01 +0300 |
commit | 578cf428470b6bcaaf5198b63acdabc251512612 (patch) | |
tree | 9cf8d4623be75cd7b2a467f430566df9b421f8a1 /numpy/random/src | |
parent | a1cd310ea6192945b7f4e452ad5794b291da77a5 (diff) | |
download | numpy-578cf428470b6bcaaf5198b63acdabc251512612.tar.gz |
MAINT: remove ThreeFry BitGenerator
Diffstat (limited to 'numpy/random/src')
-rw-r--r-- | numpy/random/src/philox/LICENSE.md | 2 | ||||
-rw-r--r-- | numpy/random/src/threefry/LICENSE.md | 31 | ||||
-rw-r--r-- | numpy/random/src/threefry/threefry-benchmark.c | 38 | ||||
-rw-r--r-- | numpy/random/src/threefry/threefry-orig.c | 83 | ||||
-rw-r--r-- | numpy/random/src/threefry/threefry-test-data-gen.c | 83 | ||||
-rw-r--r-- | numpy/random/src/threefry/threefry.c | 29 | ||||
-rw-r--r-- | numpy/random/src/threefry/threefry.h | 331 |
7 files changed, 1 insertions, 596 deletions
diff --git a/numpy/random/src/philox/LICENSE.md b/numpy/random/src/philox/LICENSE.md index 4a9f6bb29..9738e44de 100644 --- a/numpy/random/src/philox/LICENSE.md +++ b/numpy/random/src/philox/LICENSE.md @@ -1,4 +1,4 @@ -# THREEFRY +# PHILOX Copyright 2010-2012, D. E. Shaw Research. All rights reserved. diff --git a/numpy/random/src/threefry/LICENSE.md b/numpy/random/src/threefry/LICENSE.md deleted file mode 100644 index 4a9f6bb29..000000000 --- a/numpy/random/src/threefry/LICENSE.md +++ /dev/null @@ -1,31 +0,0 @@ -# THREEFRY - -Copyright 2010-2012, D. E. Shaw Research. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions, and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions, and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -* Neither the name of D. E. Shaw Research nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/numpy/random/src/threefry/threefry-benchmark.c b/numpy/random/src/threefry/threefry-benchmark.c deleted file mode 100644 index 5e2cfe844..000000000 --- a/numpy/random/src/threefry/threefry-benchmark.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Simple benchamrk command - * - * cl threefry-benchmark.c /Ox - * - * gcc threefry-benchmark.c -O3 -o threefry-benchmark - * - * Requires the Random123 directory containing header files to be located in the - * same directory (not included). - */ -#include "Random123/threefry.h" -#include <inttypes.h> -#include <stdio.h> -#include <time.h> - -#define N 1000000000 - -int main() { - threefry4x64_key_t ctr = {{0, 0, 0, 0}}; - threefry4x64_ctr_t key = {{0xDEADBEAF, 0, 0, 0}}; - threefry4x64_ctr_t out; - uint64_t count = 0, sum = 0; - int i, j; - clock_t begin = clock(); - for (i = 0; i < N / 4UL; i++) { - ctr.v[0]++; - out = threefry4x64_R(threefry4x64_rounds, ctr, key); - for (j = 0; j < 4; j++) { - sum += out.v[j]; - count++; - } - } - clock_t end = clock(); - double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; - printf("0x%" PRIx64 "\ncount: %" PRIu64 "\n", sum, count); - printf("%" PRIu64 " randoms per second\n", - (uint64_t)(N / time_spent) / 1000000 * 1000000); -} diff --git a/numpy/random/src/threefry/threefry-orig.c b/numpy/random/src/threefry/threefry-orig.c deleted file mode 100644 index d27cfd797..000000000 --- a/numpy/random/src/threefry/threefry-orig.c +++ /dev/null @@ -1,83 +0,0 @@ -/* -Copyright (c) 2017, Pierre de Buyl - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "threefry.h" -#include <stdint.h> - -#define N_WORDS 2 -#define KEY_LENGTH 3 -#define C240 0x1BD11BDAA9FC1A22 -#define N_ROUNDS 20 -#define MASK 0xffffffffffffffff -#define DOUBLE_MULT 5.421010862427522e-20 - -static const int ROTATION[] = {16, 42, 12, 31, 16, 32, 24, 21}; - -uint64_t rotl_64(uint64_t x, int d) { return ((x << d) | (x >> (64 - d))); } - -threefry_t mix(threefry_t x, int R) { - x.c0 += x.c1; - x.c1 = rotl_64(x.c1, R) ^ x.c0; - return x; -} - -threefry_t threefry(threefry_t p, threefry_t k) { - uint64_t K[] = {k.c0, k.c1, C240 ^ k.c0 ^ k.c1}; - int rmod4, rdiv4; - threefry_t x; - x = p; - for (int r = 0; r < N_ROUNDS; r++) { - rmod4 = r % 4; - if (rmod4 == 0) { - rdiv4 = r / 4; - x.c0 += K[rdiv4 % KEY_LENGTH]; - x.c1 += K[(rdiv4 + 1) % KEY_LENGTH] + rdiv4; - } - x = mix(x, ROTATION[r % 8]); - } - x.c0 += K[(N_ROUNDS / 4) % KEY_LENGTH]; - x.c1 += K[(N_ROUNDS / 4 + 1) % KEY_LENGTH] + N_ROUNDS / 4; - return x; -} - -uint64_t threefry_uint64(threefry_t *c, threefry_t *k) { - threefry_t x; - x = threefry(*c, *k); - c->c0++; - return x.c0; -} - -double threefry_double(threefry_t *c, threefry_t *k) { - threefry_t x; - x = threefry(*c, *k); - c->c0++; - return x.c0 * DOUBLE_MULT; -} diff --git a/numpy/random/src/threefry/threefry-test-data-gen.c b/numpy/random/src/threefry/threefry-test-data-gen.c deleted file mode 100644 index 8514a227e..000000000 --- a/numpy/random/src/threefry/threefry-test-data-gen.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Generate testing csv files - * - * cl threefry-test-data-gen.c /Ox ../splitmix64/splitmix64.c /Ox - * threefry-test-data-gen.exe - * - * gcc threefry-test-data-gen.c ../splitmix64/splitmix64.c /Ox -o - * threefry-test-data-gen - * ./threefry-test-data-gen - * - * Requires the Random123 directory containing header files to be located in the - * same directory (not included). - * - */ - -#include "../splitmix64/splitmix64.h" -#include "Random123/threefry.h" -#include <inttypes.h> -#include <stdio.h> - -#define N 1000 - -int main() { - threefry4x64_key_t ctr = {{0, 0, 0, 0}}; - uint64_t state, seed = 0xDEADBEAF; - state = seed; - threefry4x64_ctr_t key = {{0}}; - threefry4x64_ctr_t out; - uint64_t store[N]; - int i, j; - for (i = 0; i < 4; i++) { - key.v[i] = splitmix64_next(&state); - } - for (i = 0; i < N / 4UL; i++) { - ctr.v[0]++; - out = threefry4x64_R(threefry4x64_rounds, ctr, key); - for (j = 0; j < 4; j++) { - store[i * 4 + j] = out.v[j]; - } - } - - FILE *fp; - fp = fopen("threefry-testset-1.csv", "w"); - if (fp == NULL) { - printf("Couldn't open file\n"); - return -1; - } - fprintf(fp, "seed, 0x%" PRIx64 "\n", seed); - for (i = 0; i < N; i++) { - fprintf(fp, "%d, 0x%" PRIx64 "\n", i, store[i]); - if (i == 999) { - printf("%d, 0x%" PRIx64 "\n", i, store[i]); - } - } - fclose(fp); - - ctr.v[0] = 0; - state = seed = 0; - for (i = 0; i < 4; i++) { - key.v[i] = splitmix64_next(&state); - } - for (i = 0; i < N / 4; i++) { - ctr.v[0]++; - out = threefry4x64_R(threefry4x64_rounds, ctr, key); - for (j = 0; j < 4; j++) { - store[i * 4 + j] = out.v[j]; - } - } - - fp = fopen("threefry-testset-2.csv", "w"); - if (fp == NULL) { - printf("Couldn't open file\n"); - return -1; - } - fprintf(fp, "seed, 0x%" PRIx64 "\n", seed); - for (i = 0; i < N; i++) { - fprintf(fp, "%d, 0x%" PRIx64 "\n", i, store[i]); - if (i == 999) { - printf("%d, 0x%" PRIx64 "\n", i, store[i]); - } - } - fclose(fp); -} diff --git a/numpy/random/src/threefry/threefry.c b/numpy/random/src/threefry/threefry.c deleted file mode 100644 index 55d3c022a..000000000 --- a/numpy/random/src/threefry/threefry.c +++ /dev/null @@ -1,29 +0,0 @@ -#include "threefry.h" - -extern NPY_INLINE uint64_t threefry_next64(threefry_state *state); - -extern NPY_INLINE uint32_t threefry_next32(threefry_state *state); - -extern void threefry_jump(threefry_state *state) { - /* Advances state as-if 2^128 draws were made */ - state->ctr->v[2]++; - if (state->ctr->v[2] == 0) { - state->ctr->v[3]++; - } -} - -extern void threefry_advance(uint64_t *step, threefry_state *state) { - int i, carry = 0; - uint64_t v_orig; - for (i = 0; i < 4; i++) { - if (carry == 1) { - state->ctr->v[i]++; - carry = state->ctr->v[i] == 0 ? 1 : 0; - } - v_orig = state->ctr->v[i]; - state->ctr->v[i] += step[i]; - if (state->ctr->v[i] < v_orig && carry == 0) { - carry = 1; - } - } -} diff --git a/numpy/random/src/threefry/threefry.h b/numpy/random/src/threefry/threefry.h deleted file mode 100644 index 596b57e12..000000000 --- a/numpy/random/src/threefry/threefry.h +++ /dev/null @@ -1,331 +0,0 @@ -/* -Adapted from random123's threefry.h -*/ -#ifndef _RANDOMDGEN__THREEFRY_H_ -#define _RANDOMDGEN__THREEFRY_H_ - -#include <inttypes.h> -#include "numpy/npy_common.h" - -#define THREEFRY_BUFFER_SIZE 4L - -enum r123_enum_threefry64x4 { - /* These are the R_256 constants from the Threefish reference sources - with names changed to R_64x4... */ - R_64x4_0_0 = 14, - R_64x4_0_1 = 16, - R_64x4_1_0 = 52, - R_64x4_1_1 = 57, - R_64x4_2_0 = 23, - R_64x4_2_1 = 40, - R_64x4_3_0 = 5, - R_64x4_3_1 = 37, - R_64x4_4_0 = 25, - R_64x4_4_1 = 33, - R_64x4_5_0 = 46, - R_64x4_5_1 = 12, - R_64x4_6_0 = 58, - R_64x4_6_1 = 22, - R_64x4_7_0 = 32, - R_64x4_7_1 = 32 -}; - -struct r123array4x64 { - uint64_t v[4]; -}; /* r123array4x64 */ - -typedef struct r123array4x64 threefry4x64_key_t; -typedef struct r123array4x64 threefry4x64_ctr_t; - -static NPY_INLINE uint64_t RotL_64(uint64_t x, unsigned int N); -static NPY_INLINE uint64_t RotL_64(uint64_t x, unsigned int N) { - return (x << (N & 63)) | (x >> ((64 - N) & 63)); -} - -static NPY_INLINE threefry4x64_ctr_t threefry4x64_R(unsigned int Nrounds, - threefry4x64_ctr_t in, - threefry4x64_key_t k); -static NPY_INLINE threefry4x64_ctr_t threefry4x64_R(unsigned int Nrounds, - threefry4x64_ctr_t in, - threefry4x64_key_t k) { - threefry4x64_ctr_t X; - uint64_t ks[4 + 1]; - int i; - ks[4] = ((0xA9FC1A22) + (((uint64_t)(0x1BD11BDA)) << 32)); - for (i = 0; i < 4; i++) { - ks[i] = k.v[i]; - X.v[i] = in.v[i]; - ks[4] ^= k.v[i]; - } - X.v[0] += ks[0]; - X.v[1] += ks[1]; - X.v[2] += ks[2]; - X.v[3] += ks[3]; - if (Nrounds > 0) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_0_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_0_1); - X.v[3] ^= X.v[2]; - } - if (Nrounds > 1) { - X.v[0] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_1_0); - X.v[3] ^= X.v[0]; - X.v[2] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_1_1); - X.v[1] ^= X.v[2]; - } - if (Nrounds > 2) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_2_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_2_1); - X.v[3] ^= X.v[2]; - } - if (Nrounds > 3) { - X.v[0] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_3_0); - X.v[3] ^= X.v[0]; - X.v[2] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_3_1); - X.v[1] ^= X.v[2]; - } - if (Nrounds > 3) { - X.v[0] += ks[1]; - X.v[1] += ks[2]; - X.v[2] += ks[3]; - X.v[3] += ks[4]; - X.v[4 - 1] += 1; - } - if (Nrounds > 4) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_4_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_4_1); - X.v[3] ^= X.v[2]; - } - if (Nrounds > 5) { - X.v[0] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_5_0); - X.v[3] ^= X.v[0]; - X.v[2] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_5_1); - X.v[1] ^= X.v[2]; - } - if (Nrounds > 6) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_6_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_6_1); - X.v[3] ^= X.v[2]; - } - if (Nrounds > 7) { - X.v[0] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_7_0); - X.v[3] ^= X.v[0]; - X.v[2] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_7_1); - X.v[1] ^= X.v[2]; - } - if (Nrounds > 7) { - X.v[0] += ks[2]; - X.v[1] += ks[3]; - X.v[2] += ks[4]; - X.v[3] += ks[0]; - X.v[4 - 1] += 2; - } - if (Nrounds > 8) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_0_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_0_1); - X.v[3] ^= X.v[2]; - } - if (Nrounds > 9) { - X.v[0] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_1_0); - X.v[3] ^= X.v[0]; - X.v[2] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_1_1); - X.v[1] ^= X.v[2]; - } - if (Nrounds > 10) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_2_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_2_1); - X.v[3] ^= X.v[2]; - } - if (Nrounds > 11) { - X.v[0] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_3_0); - X.v[3] ^= X.v[0]; - X.v[2] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_3_1); - X.v[1] ^= X.v[2]; - } - if (Nrounds > 11) { - X.v[0] += ks[3]; - X.v[1] += ks[4]; - X.v[2] += ks[0]; - X.v[3] += ks[1]; - X.v[4 - 1] += 3; - } - if (Nrounds > 12) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_4_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_4_1); - X.v[3] ^= X.v[2]; - } - if (Nrounds > 13) { - X.v[0] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_5_0); - X.v[3] ^= X.v[0]; - X.v[2] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_5_1); - X.v[1] ^= X.v[2]; - } - if (Nrounds > 14) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_6_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_6_1); - X.v[3] ^= X.v[2]; - } - if (Nrounds > 15) { - X.v[0] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_7_0); - X.v[3] ^= X.v[0]; - X.v[2] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_7_1); - X.v[1] ^= X.v[2]; - } - if (Nrounds > 15) { - X.v[0] += ks[4]; - X.v[1] += ks[0]; - X.v[2] += ks[1]; - X.v[3] += ks[2]; - X.v[4 - 1] += 4; - } - if (Nrounds > 16) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_0_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_0_1); - X.v[3] ^= X.v[2]; - } - if (Nrounds > 17) { - X.v[0] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_1_0); - X.v[3] ^= X.v[0]; - X.v[2] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_1_1); - X.v[1] ^= X.v[2]; - } - if (Nrounds > 18) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_2_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_2_1); - X.v[3] ^= X.v[2]; - } - if (Nrounds > 19) { - X.v[0] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_3_0); - X.v[3] ^= X.v[0]; - X.v[2] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_3_1); - X.v[1] ^= X.v[2]; - } - if (Nrounds > 19) { - X.v[0] += ks[0]; - X.v[1] += ks[1]; - X.v[2] += ks[2]; - X.v[3] += ks[3]; - X.v[4 - 1] += 5; - } - /* Maximum of 20 rounds */ - if (Nrounds > 20) { - X.v[0] += X.v[1]; - X.v[1] = RotL_64(X.v[1], R_64x4_4_0); - X.v[1] ^= X.v[0]; - X.v[2] += X.v[3]; - X.v[3] = RotL_64(X.v[3], R_64x4_4_1); - X.v[3] ^= X.v[2]; - } - return X; -} -enum r123_enum_threefry4x64 { threefry4x64_rounds = 20 }; - -typedef struct s_threefry_state { - threefry4x64_key_t *ctr; - threefry4x64_ctr_t *key; - int buffer_pos; - uint64_t buffer[THREEFRY_BUFFER_SIZE]; - int has_uint32; - uint32_t uinteger; -} threefry_state; - -static NPY_INLINE uint64_t threefry_next(threefry_state *state) { - int i; - threefry4x64_ctr_t ct; - uint64_t out; - if (state->buffer_pos < THREEFRY_BUFFER_SIZE) { - out = state->buffer[state->buffer_pos]; - state->buffer_pos++; - return out; - } - /* generate 4 new uint64_t */ - state->ctr->v[0]++; - /* Handle carry */ - if (state->ctr->v[0] == 0) { - state->ctr->v[1]++; - if (state->ctr->v[1] == 0) { - state->ctr->v[2]++; - if (state->ctr->v[2] == 0) { - state->ctr->v[3]++; - } - } - } - ct = threefry4x64_R(threefry4x64_rounds, *state->ctr, *state->key); - for (i = 0; i < 4; i++) { - state->buffer[i] = ct.v[i]; - } - state->buffer_pos = 1; - return state->buffer[0]; -} - -static NPY_INLINE uint64_t threefry_next64(threefry_state *state) { - return threefry_next(state); -} - -static NPY_INLINE uint32_t threefry_next32(threefry_state *state) { - uint64_t next; - if (state->has_uint32) { - state->has_uint32 = 0; - return state->uinteger; - } - next = threefry_next(state); - - state->has_uint32 = 1; - state->uinteger = (uint32_t)(next >> 32); - return (uint32_t)(next & 0xffffffff); -} - -extern void threefry_jump(threefry_state *state); - -extern void threefry_advance(uint64_t *step, threefry_state *state); - -#endif |