summaryrefslogtreecommitdiff
path: root/numpy/random/src
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2019-05-20 23:06:48 +0300
committermattip <matti.picus@gmail.com>2019-05-20 23:23:36 +0300
commit3d19ae92ac3dc4fad7018112a3e293a5e4b283b1 (patch)
tree9e2846f113d3b4dff7504d980a3f4cb803cacc1e /numpy/random/src
parente058ae46f534f675bb39e521eacc5874c0149c11 (diff)
downloadnumpy-3d19ae92ac3dc4fad7018112a3e293a5e4b283b1.tar.gz
MAINT: remove threefry32, xoroshiro128, xorshift1024 BitGenerators
Diffstat (limited to 'numpy/random/src')
-rw-r--r--numpy/random/src/threefry32/LICENSE.md31
-rw-r--r--numpy/random/src/threefry32/threefry32-test-data-gen.c88
-rw-r--r--numpy/random/src/threefry32/threefry32.c29
-rw-r--r--numpy/random/src/threefry32/threefry32.h832
4 files changed, 0 insertions, 980 deletions
diff --git a/numpy/random/src/threefry32/LICENSE.md b/numpy/random/src/threefry32/LICENSE.md
deleted file mode 100644
index 591cd75f4..000000000
--- a/numpy/random/src/threefry32/LICENSE.md
+++ /dev/null
@@ -1,31 +0,0 @@
-# THREEFRY32
-
-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/threefry32/threefry32-test-data-gen.c b/numpy/random/src/threefry32/threefry32-test-data-gen.c
deleted file mode 100644
index 0e6229995..000000000
--- a/numpy/random/src/threefry32/threefry32-test-data-gen.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Generate testing csv files
- *
- * cl threefry32-test-data-gen.c /Ox ../splitmix64/splitmix64.c /Ox
- * threefry32-test-data-gen.exe
- *
- * gcc threefry32-test-data-gen.c ../splitmix64/splitmix64.c /Ox -o
- * threefry32-test-data-gen
- * ./threefry32-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() {
- threefry4x32_key_t ctr = {{0, 0, 0, 0}};
- uint64_t state, seed = 0xDEADBEAF;
- state = seed;
- threefry4x32_ctr_t key = {{0}};
- threefry4x32_ctr_t out;
- uint64_t store[N];
- uint64_t seed_val;
- int i, j;
- for (i = 0; i < 4; i++) {
- seed_val = splitmix64_next(&state);
- key.v[2*i] = (uint32_t)seed_val;
- key.v[2*i+1] = (uint32_t)(seed_val >> 32);
- }
- for (i = 0; i < N / 4UL; i++) {
- ctr.v[0]++;
- out = threefry4x32_R(threefry4x32_rounds, ctr, key);
- for (j = 0; j < 4; j++) {
- store[i * 4 + j] = out.v[j];
- }
- }
-
- FILE *fp;
- fp = fopen("threefry32-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++) {
- seed_val = splitmix64_next(&state);
- key.v[2*i] = (uint32_t)seed_val;
- key.v[2*i+1] = (uint32_t)(seed_val >> 32);
- }
- for (i = 0; i < N / 4; i++) {
- ctr.v[0]++;
- out = threefry4x32_R(threefry4x32_rounds, ctr, key);
- for (j = 0; j < 4; j++) {
- store[i * 4 + j] = out.v[j];
- }
- }
-
- fp = fopen("threefry32-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/threefry32/threefry32.c b/numpy/random/src/threefry32/threefry32.c
deleted file mode 100644
index cc6890f2e..000000000
--- a/numpy/random/src/threefry32/threefry32.c
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "threefry32.h"
-
-extern NPY_INLINE uint64_t threefry32_next64(threefry32_state *state);
-
-extern NPY_INLINE uint32_t threefry32_next32(threefry32_state *state);
-
-extern void threefry32_jump(threefry32_state *state) {
- /* Advances state as-if 2^64 draws were made */
- state->ctr->v[2]++;
- if (state->ctr->v[2] == 0) {
- state->ctr->v[3]++;
- }
-}
-
-extern void threefry32_advance(uint32_t *step, threefry32_state *state) {
- int i, carry = 0;
- uint32_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/threefry32/threefry32.h b/numpy/random/src/threefry32/threefry32.h
deleted file mode 100644
index ebedee804..000000000
--- a/numpy/random/src/threefry32/threefry32.h
+++ /dev/null
@@ -1,832 +0,0 @@
-/*
-Adapted from random123's threefry.h
-*/
-#ifndef _RANDOMDGEN__THREEFRY32_H_
-#define _RANDOMDGEN__THREEFRY32_H_
-
-#include <inttypes.h>
-#include "numpy/npy_common.h"
-
-#define THREEFRY_BUFFER_SIZE 4L
-
-static NPY_INLINE uint32_t RotL_32(uint32_t x, unsigned int N);
-static NPY_INLINE uint32_t RotL_32(uint32_t x, unsigned int N) {
- return (x << (N & 31)) | (x >> ((32 - N) & 31));
-}
-
-struct r123array4x32 {
- uint32_t v[4];
-};
-
-enum r123_enum_threefry32x4 {
-
- R_32x4_0_0 = 10,
- R_32x4_0_1 = 26,
- R_32x4_1_0 = 11,
- R_32x4_1_1 = 21,
- R_32x4_2_0 = 13,
- R_32x4_2_1 = 27,
- R_32x4_3_0 = 23,
- R_32x4_3_1 = 5,
- R_32x4_4_0 = 6,
- R_32x4_4_1 = 20,
- R_32x4_5_0 = 17,
- R_32x4_5_1 = 11,
- R_32x4_6_0 = 25,
- R_32x4_6_1 = 10,
- R_32x4_7_0 = 18,
- R_32x4_7_1 = 20
-
-};
-
-typedef struct r123array4x32 threefry4x32_ctr_t;
-typedef struct r123array4x32 threefry4x32_key_t;
-typedef struct r123array4x32 threefry4x32_ukey_t;
-static NPY_INLINE threefry4x32_key_t threefry4x32keyinit(threefry4x32_ukey_t uk) {
- return uk;
-};
-static NPY_INLINE threefry4x32_ctr_t threefry4x32_R(unsigned int Nrounds,
- threefry4x32_ctr_t in,
- threefry4x32_key_t k);
-static NPY_INLINE threefry4x32_ctr_t threefry4x32_R(unsigned int Nrounds,
- threefry4x32_ctr_t in,
- threefry4x32_key_t k) {
- threefry4x32_ctr_t X;
- uint32_t ks[4 + 1];
- int i;
- ks[4] = 0x1BD11BDA;
- 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_32(X.v[1], R_32x4_0_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_0_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 1) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_1_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_1_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 2) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_2_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_2_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 3) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_3_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_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_32(X.v[1], R_32x4_4_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_4_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 5) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_5_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_5_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 6) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_6_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_6_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 7) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_7_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_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_32(X.v[1], R_32x4_0_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_0_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 9) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_1_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_1_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 10) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_2_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_2_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 11) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_3_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_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_32(X.v[1], R_32x4_4_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_4_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 13) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_5_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_5_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 14) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_6_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_6_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 15) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_7_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_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_32(X.v[1], R_32x4_0_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_0_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 17) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_1_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_1_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 18) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_2_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_2_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 19) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_3_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_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;
- }
- if (Nrounds > 20) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_4_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_4_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 21) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_5_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_5_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 22) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_6_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_6_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 23) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_7_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_7_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 23) {
- X.v[0] += ks[1];
- X.v[1] += ks[2];
- X.v[2] += ks[3];
- X.v[3] += ks[4];
- X.v[4 - 1] += 6;
- }
- if (Nrounds > 24) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_0_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_0_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 25) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_1_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_1_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 26) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_2_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_2_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 27) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_3_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_3_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 27) {
- X.v[0] += ks[2];
- X.v[1] += ks[3];
- X.v[2] += ks[4];
- X.v[3] += ks[0];
- X.v[4 - 1] += 7;
- }
- if (Nrounds > 28) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_4_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_4_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 29) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_5_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_5_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 30) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_6_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_6_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 31) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_7_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_7_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 31) {
- X.v[0] += ks[3];
- X.v[1] += ks[4];
- X.v[2] += ks[0];
- X.v[3] += ks[1];
- X.v[4 - 1] += 8;
- }
- if (Nrounds > 32) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_0_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_0_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 33) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_1_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_1_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 34) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_2_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_2_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 35) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_3_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_3_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 35) {
- X.v[0] += ks[4];
- X.v[1] += ks[0];
- X.v[2] += ks[1];
- X.v[3] += ks[2];
- X.v[4 - 1] += 9;
- }
- if (Nrounds > 36) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_4_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_4_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 37) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_5_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_5_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 38) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_6_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_6_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 39) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_7_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_7_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 39) {
- X.v[0] += ks[0];
- X.v[1] += ks[1];
- X.v[2] += ks[2];
- X.v[3] += ks[3];
- X.v[4 - 1] += 10;
- }
- if (Nrounds > 40) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_0_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_0_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 41) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_1_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_1_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 42) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_2_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_2_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 43) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_3_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_3_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 43) {
- X.v[0] += ks[1];
- X.v[1] += ks[2];
- X.v[2] += ks[3];
- X.v[3] += ks[4];
- X.v[4 - 1] += 11;
- }
- if (Nrounds > 44) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_4_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_4_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 45) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_5_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_5_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 46) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_6_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_6_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 47) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_7_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_7_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 47) {
- X.v[0] += ks[2];
- X.v[1] += ks[3];
- X.v[2] += ks[4];
- X.v[3] += ks[0];
- X.v[4 - 1] += 12;
- }
- if (Nrounds > 48) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_0_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_0_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 49) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_1_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_1_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 50) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_2_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_2_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 51) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_3_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_3_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 51) {
- X.v[0] += ks[3];
- X.v[1] += ks[4];
- X.v[2] += ks[0];
- X.v[3] += ks[1];
- X.v[4 - 1] += 13;
- }
- if (Nrounds > 52) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_4_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_4_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 53) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_5_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_5_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 54) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_6_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_6_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 55) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_7_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_7_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 55) {
- X.v[0] += ks[4];
- X.v[1] += ks[0];
- X.v[2] += ks[1];
- X.v[3] += ks[2];
- X.v[4 - 1] += 14;
- }
- if (Nrounds > 56) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_0_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_0_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 57) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_1_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_1_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 58) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_2_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_2_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 59) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_3_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_3_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 59) {
- X.v[0] += ks[0];
- X.v[1] += ks[1];
- X.v[2] += ks[2];
- X.v[3] += ks[3];
- X.v[4 - 1] += 15;
- }
- if (Nrounds > 60) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_4_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_4_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 61) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_5_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_5_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 62) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_6_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_6_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 63) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_7_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_7_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 63) {
- X.v[0] += ks[1];
- X.v[1] += ks[2];
- X.v[2] += ks[3];
- X.v[3] += ks[4];
- X.v[4 - 1] += 16;
- }
- if (Nrounds > 64) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_0_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_0_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 65) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_1_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_1_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 66) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_2_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_2_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 67) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_3_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_3_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 67) {
- X.v[0] += ks[2];
- X.v[1] += ks[3];
- X.v[2] += ks[4];
- X.v[3] += ks[0];
- X.v[4 - 1] += 17;
- }
- if (Nrounds > 68) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_4_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_4_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 69) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_5_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_5_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 70) {
- X.v[0] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_6_0);
- X.v[1] ^= X.v[0];
- X.v[2] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_6_1);
- X.v[3] ^= X.v[2];
- }
- if (Nrounds > 71) {
- X.v[0] += X.v[3];
- X.v[3] = RotL_32(X.v[3], R_32x4_7_0);
- X.v[3] ^= X.v[0];
- X.v[2] += X.v[1];
- X.v[1] = RotL_32(X.v[1], R_32x4_7_1);
- X.v[1] ^= X.v[2];
- }
- if (Nrounds > 71) {
- X.v[0] += ks[3];
- X.v[1] += ks[4];
- X.v[2] += ks[0];
- X.v[3] += ks[1];
- X.v[4 - 1] += 18;
- }
- return X;
-}
-enum r123_enum_threefry4x32 { threefry4x32_rounds = 20 };
-static NPY_INLINE threefry4x32_ctr_t threefry4x32(threefry4x32_ctr_t in,
- threefry4x32_key_t k);
-static NPY_INLINE threefry4x32_ctr_t threefry4x32(threefry4x32_ctr_t in,
- threefry4x32_key_t k) {
- return threefry4x32_R(threefry4x32_rounds, in, k);
-}
-
-typedef struct s_threefry32_state {
- threefry4x32_key_t *ctr;
- threefry4x32_ctr_t *key;
- int buffer_pos;
- uint32_t buffer[THREEFRY_BUFFER_SIZE];
-} threefry32_state;
-
-static NPY_INLINE uint32_t threefry32_next(threefry32_state *state) {
- int i;
- threefry4x32_ctr_t ct;
- uint32_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 = threefry4x32_R(threefry4x32_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 threefry32_next64(threefry32_state *state) {
- return ((uint64_t)threefry32_next(state) << 32) | threefry32_next(state);
-}
-
-static NPY_INLINE uint32_t threefry32_next32(threefry32_state *state) {
- return threefry32_next(state);
-}
-
-static NPY_INLINE double threefry32_next_double(threefry32_state *state) {
- int32_t a = threefry32_next(state) >> 5, b = threefry32_next(state) >> 6;
- return (a * 67108864.0 + b) / 9007199254740992.0;
-}
-
-extern void threefry32_jump(threefry32_state *state);
-
-extern void threefry32_advance(uint32_t *step, threefry32_state *state);
-
-#endif