All Projects → lemire → SIMDxorshift

lemire / SIMDxorshift

Licence: Apache-2.0 License
Fast random number generators: Vectorized (SIMD) version of xorshift128+

Programming Languages

c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to SIMDxorshift

sliceslice-rs
A fast implementation of single-pattern substring search using SIMD acceleration.
Stars: ✭ 66 (-21.43%)
Mutual labels:  simd, simd-instructions
positional-popcount
Fast C functions for the computing the positional popcount (pospopcnt).
Stars: ✭ 47 (-44.05%)
Mutual labels:  simd, simd-instructions
std find simd
std::find simd version
Stars: ✭ 19 (-77.38%)
Mutual labels:  simd, simd-instructions
lsp-dsp-lib
DSP library for signal processing
Stars: ✭ 37 (-55.95%)
Mutual labels:  simd, simd-instructions
ultra-sort
DSL for SIMD Sorting on AVX2 & AVX512
Stars: ✭ 29 (-65.48%)
Mutual labels:  simd, simd-instructions
RNG
A simple state-of-the-art C++ random number generator
Stars: ✭ 19 (-77.38%)
Mutual labels:  prng
shredos.x86 64
Shredos Disk Eraser 64 bit for all Intel 64 bit processors as well as processors from AMD and other vendors which make compatible 64 bit chips. ShredOS - Secure disk erasure/wipe
Stars: ✭ 383 (+355.95%)
Mutual labels:  prng
wasm
fast wasm modules
Stars: ✭ 37 (-55.95%)
Mutual labels:  simd
glm
OpenGL Mathematics (GLM)
Stars: ✭ 6,667 (+7836.9%)
Mutual labels:  simd
hlml
vectorized high-level math library
Stars: ✭ 42 (-50%)
Mutual labels:  simd
optimath
A #[no_std] LinAlg library
Stars: ✭ 47 (-44.05%)
Mutual labels:  simd
Intriman
Intriman is a documentation generator that retargets the Intel Intrinsics Guide to other documentation formats
Stars: ✭ 25 (-70.24%)
Mutual labels:  simd
random
The most random module on npm
Stars: ✭ 106 (+26.19%)
Mutual labels:  prng
nes-runner
An infinite runner NES game!
Stars: ✭ 28 (-66.67%)
Mutual labels:  prng
dcurl
Hardware-accelerated Multi-threaded IOTA PoW, drop-in replacement for ccurl
Stars: ✭ 39 (-53.57%)
Mutual labels:  simd
generic-simd
Generic SIMD abstractions for Rust.
Stars: ✭ 45 (-46.43%)
Mutual labels:  simd
zig-gamedev
Building game development ecosystem for @ziglang!
Stars: ✭ 1,059 (+1160.71%)
Mutual labels:  simd
frp
FRP: Fast Random Projections
Stars: ✭ 40 (-52.38%)
Mutual labels:  simd
komihash
Very fast, high-quality hash function (non-cryptographic, C) + PRNG
Stars: ✭ 68 (-19.05%)
Mutual labels:  prng
simdjson-rs
Rust version of lemire's SimdJson
Stars: ✭ 18 (-78.57%)
Mutual labels:  simd

SIMDxorshift

Xorshift are a family of pseudo-random number generators (RNG) invented by Marsaglia.

https://en.wikipedia.org/wiki/Xorshift

We present a vectorized version of xorshift128+, a popular random-number generator part of this family. It is written in C. The implementation uses Intel's SIMD instructions and is based on Vigna's original (pure C) implementation.

As a random number generator, xorshift128+ is not very strong. It fails statistical tests such as BigCrush. It should never be used alone in applications where the quality of the random numbers matters a great deal. However, when you just want fast and "good enough" random numbers, it should do well.

Since speed is the primary benefit of xorshift128+, then it is tempting to accelerate it further using vector instructions.

This library is used by the Yandex ClickHouse high-performance data engine.

Prerequisite

You should have a recent Intel processor (Haswell or better). If you bought your PC before everyone on Earth had a smartphone, it is probably too old a PC. Please upgrade.

Your compiler supports C99, right? C99 stands for 1999. That was almost 20 years ago.

Code sample

#include "simdxorshift128plus.h"

// create a new key
avx_xorshift128plus_key_t mykey;
avx_xorshift128plus_init(324,4444,&mykey); // values 324, 4444 are arbitrary, must be non-zero

// generate 32 random bytes, do this as many times as you want
__m256i randomstuff =  avx_xorshift128plus(&mykey);

Usage

$ make
$ ./fillarray
Generating 5000 32-bit random numbers
Time reported in number of cycles per array element.
We store values to an array of size = 19 kB.

We just generate the random numbers:
populateRandom_xorshift128plus(prec, size):  3.63 cycles per operation
populateRandom_avx_xorshift128plus(prec, size):  2.21 cycles per operation
populateRandom_avx_xorshift128plus_two(prec, size):  1.88 cycles per operation
populateRandom_avx512_xorshift128plus_two(prec, size):  1.47 cycles per operation

(Tests on a Skylake-X processor.)

Shallow analysis

SIMD random-number generation is something like twice as fast as plain C random number generation. However on algorithms such as random shuffling, the benefits of faster random number generation are lesser because other bottlenecks arise.

For the most part however, the application of SIMD instructions for random number generation is "free" if the CPU supports it.

Related work

Reference

Vigna's xorshift128+ implementation http://xorshift.di.unimi.it/xorshift128plus.c

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].