1
#ifndef _RANDOMDGEN__SFC64_H_
2
#define _RANDOMDGEN__SFC64_H_
3

4
#include "numpy/npy_common.h"
5
#include <inttypes.h>
6
#ifdef _WIN32
7
#include <stdlib.h>
8
#endif
9

10
typedef struct s_sfc64_state {
11
  uint64_t s[4];
12
  int has_uint32;
13
  uint32_t uinteger;
14
} sfc64_state;
15

16

17
static NPY_INLINE uint64_t rotl(const uint64_t value, unsigned int rot) {
18
#ifdef _WIN32
19
  return _rotl64(value, rot);
20
#else
21 1
  return (value << rot) | (value >> ((-rot) & 63));
22
#endif
23
}
24

25
static NPY_INLINE uint64_t sfc64_next(uint64_t *s) {
26 1
  const uint64_t tmp = s[0] + s[1] + s[3]++;
27

28 1
  s[0] = s[1] ^ (s[1] >> 11);
29 1
  s[1] = s[2] + (s[2] << 3);
30 1
  s[2] = rotl(s[2], 24) + tmp;
31

32
  return tmp;
33
}
34

35

36
static NPY_INLINE uint64_t sfc64_next64(sfc64_state *state) {
37 1
  return sfc64_next(&state->s[0]);
38
}
39

40 1
static NPY_INLINE uint32_t sfc64_next32(sfc64_state *state) {
41
  uint64_t next;
42 1
  if (state->has_uint32) {
43 1
    state->has_uint32 = 0;
44 1
    return state->uinteger;
45
  }
46 1
  next = sfc64_next(&state->s[0]);
47 1
  state->has_uint32 = 1;
48 1
  state->uinteger = (uint32_t)(next >> 32);
49 1
  return (uint32_t)(next & 0xffffffff);
50
}
51

52
void sfc64_set_seed(sfc64_state *state, uint64_t *seed);
53

54
void sfc64_get_state(sfc64_state *state, uint64_t *state_arr, int *has_uint32,
55
                     uint32_t *uinteger);
56

57
void sfc64_set_state(sfc64_state *state, uint64_t *state_arr, int has_uint32,
58
                     uint32_t uinteger);
59

60
#endif

Read our documentation on viewing source code .

Loading