20 #if !defined(__MITSUBA_CORE_QMC_H_)
21 #define __MITSUBA_CORE_QMC_H_
23 #include <mitsuba/mitsuba.h>
38 static const size_t primeTableSize = 1024;
45 #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))) || defined(__clang__)
46 n = __builtin_bswap32(n);
48 n = (n << 16) | (n >> 16);
49 n = ((n & 0x00ff00ff) << 8) | ((n & 0xff00ff00) >> 8);
51 n = ((n & 0x0f0f0f0f) << 4) | ((n & 0xf0f0f0f0) >> 4);
52 n = ((n & 0x33333333) << 2) | ((n & 0xcccccccc) >> 2);
53 n = ((n & 0x55555555) << 1) | ((n & 0xaaaaaaaa) >> 1);
56 n = (n >> (32 - 24)) ^ (scramble & ~-(1 << 24));
58 return (
float) n / (float) (1U << 24);
64 #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))) || defined(__clang__)
65 n = __builtin_bswap64(n);
67 n = (n << 32) | (n >> 32);
68 n = ((n & 0x0000ffff0000ffffULL) << 16) | ((n & 0xffff0000ffff0000ULL) >> 16);
69 n = ((n & 0x00ff00ff00ff00ffULL) << 8) | ((n & 0xff00ff00ff00ff00ULL) >> 8);
71 n = ((n & 0x0f0f0f0f0f0f0f0fULL) << 4) | ((n & 0xf0f0f0f0f0f0f0f0ULL) >> 4);
72 n = ((n & 0x3333333333333333ULL) << 2) | ((n & 0xccccccccccccccccULL) >> 2);
73 n = ((n & 0x5555555555555555ULL) << 1) | ((n & 0xaaaaaaaaaaaaaaaaULL) >> 1);
76 n = (n >> (64 - 53)) ^ (scramble & ~-(1LL << 53));
78 return (
double) n / (double) (1ULL << 53);
83 for (
uint32_t v = 1U << 31; n != 0; n >>= 1, v ^= v >> 1)
86 return (
float) scramble / (float) (1ULL << 32);
91 scramble &= ~-(1LL << 53);
92 for (uint64_t v = 1ULL << 52; n != 0; n >>= 1, v ^= v >> 1)
95 return (
double) scramble / (double) (1ULL << 53);
116 #if defined(SINGLE_PRECISION)
149 for (
int i=0; i<rounds; ++i) {
151 v0 += ((v1 << 4) + 0xA341316C) ^ (v1 + sum) ^ ((v1 >> 5) + 0xC8013EA4);
152 v1 += ((v0 << 4) + 0xAD90777D) ^ (v0 + sum) ^ ((v0 >> 5) + 0x7E95761E);
155 return ((uint64_t) v1 << 32) + v0;
182 x.u = ((
sampleTEA(v0, v1, rounds) & 0xFFFFFFFF) >> 9) | 0x3f800000UL;
210 x.u = (
sampleTEA(v0, v1, rounds) >> 12) | 0x3ff0000000000000ULL;
214 #if defined(SINGLE_PRECISION)
248 uint64_t index, uint16_t *perm);
285 uint64_t index, uint16_t *perm);
Point2d sample02Double(uint64_t n, uint64_t scramble[2])
Generate an element from a (0, 2) sequence, double precision version.
Definition: qmc.h:107
float radicalInverse2Single(uint32_t n, uint32_t scramble=0U)
Van der Corput radical inverse in base 2 with single precision.
Definition: qmc.h:43
float sobol2Single(uint32_t n, uint32_t scramble=0U)
Sobol' radical inverse in base 2 with single precision.
Definition: qmc.h:82
Float radicalInverseFast(uint16_t baseIndex, uint64_t index)
Calculate a radical inverse function (fast version)
float sampleTEASingle(uint32_t v0, uint32_t v1, int rounds=4)
Generate fast and reasonably good pseudorandom numbers using the Tiny Encryption Algorithm (TEA) by D...
Definition: qmc.h:175
TPoint2< float > Point2f
Definition: fwd.h:133
#define MTS_EXPORT_CORE
Definition: getopt.h:29
double sobol2Double(uint64_t n, uint64_t scramble=0ULL)
Sobol' radical inverse in base 2 with double precision.
Definition: qmc.h:90
Float scrambledRadicalInverse(int base, uint64_t index, uint16_t *perm)
Calculate a scrambled radical inverse function.
TPoint2< double > Point2d
Definition: fwd.h:134
TPoint2< Float > Point2
Definition: fwd.h:129
double sampleTEADouble(uint32_t v0, uint32_t v1, int rounds=4)
Generate fast and reasonably good pseudorandom numbers using the Tiny Encryption Algorithm (TEA) by D...
Definition: qmc.h:203
Float radicalInverseIncremental(int base, Float x)
Incrementally calculate the next Van Der Corput sequence value starting from a current entry x (wrt...
uint64_t sampleTEA(uint32_t v0, uint32_t v1, int rounds=4)
Generate fast and reasonably good pseudorandom numbers using the Tiny Encryption Algorithm (TEA) by D...
Definition: qmc.h:146
Float scrambledRadicalInverseFast(uint16_t baseIndex, uint64_t index, uint16_t *perm)
Calculate a scrambled radical inverse function (fast version)
double radicalInverse2Double(uint64_t n, uint64_t scramble=0ULL)
Van der Corput radical inverse in base 2 with double precision.
Definition: qmc.h:62
Point2 sample02(size_t n)
Generate an element from a (0, 2) sequence (without scrambling)
Definition: qmc.h:115
const int primeTable[primeTableSize]
Table of the first 1024 prime numbers.
Point2f sample02Single(uint32_t n, uint32_t scramble[2])
Generate an element from a (0, 2) sequence, single precision.
Definition: qmc.h:99
Float sampleTEAFloat(uint32_t v0, uint32_t v1, int rounds=4)
Alias to sampleTEASingle or sampleTEADouble based on compilation flags.
Definition: qmc.h:221
Float radicalInverse(int base, uint64_t index)
Calculate the radical inverse function.