github.com/keysonZZZ/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgRand/LcgCalculateConstants/c/rand-primegen.h (about)

     1  #ifndef PRIMEGEN_H
     2  #define PRIMEGEN_H
     3  
     4  #include <stdint.h>
     5  
     6  /**
     7   * This is B/32: the number of 32-bit words of space used in the primegen
     8   * inner loop. This should fit into the CPU's level-1 cache.
     9   *
    10   * 2048 works well on a Pentium-100.
    11   * 3600 works well on a Pentium II-350
    12   * 4004 works well on an UltraSPARC-I/167
    13   *
    14   * 2012-nov (Rob): This code was written 15 years ago. Processor caches
    15   * haven't really gotten any larger. A number like 8008 works slightly
    16   * better on an Ivy Bridge CPU, but works noticeably worse on an Atom
    17   * or ARM processor. The value 4004 seems to be a good compromise for
    18   * all these processors. In any case, modern CPUs will automatically
    19   * prefetch the buffers anyway, significantly lessoning the impact of
    20   * having a poor number defined here. I tried 16016, but it crashed, and
    21   * I don't know why, but I don't care because I'm not oing to use such a
    22   * large size.
    23   */
    24  #define PRIMEGEN_WORDS 4004
    25  
    26  typedef struct {
    27    uint32_t buf[16][PRIMEGEN_WORDS];
    28    uint64_t p[512]; /* p[num-1] ... p[0], in that order */
    29    int num;
    30    int pos; /* next entry to use in buf; WORDS to restart */
    31    uint64_t base;
    32    uint64_t L;
    33  } primegen;
    34  
    35  extern void primegen_sieve(primegen *);
    36  extern void primegen_fill(primegen *);
    37  
    38  extern void primegen_init(primegen *);
    39  extern uint64_t primegen_next(primegen *);
    40  extern uint64_t primegen_peek(primegen *);
    41  extern uint64_t primegen_count(primegen *,uint64_t to);
    42  extern void primegen_skipto(primegen *,uint64_t to);
    43  
    44  #endif