36 #include <cugar/basic/types.h> 77 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
82 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
91 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
92 float next(uint32 scramble, uint32* state)
const;
116 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
118 m_matrix(matrix), m_state(state ? state : 0xFFFFFFFF), m_scramble(scramble) {}
120 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
128 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
129 LFSRGeneratorMatrix::LFSRGeneratorMatrix(
const uint32 m,
const LFSRGeneratorMatrix::Offset_type offset_type)
135 const uint32 primitive_polynomials[32 - 3 + 1] =
142 (1 << 4) | (1 << 3) | (1 << 2) | 1,
146 (1 << 6) | (1 << 4) | (1 << 1) | 1,
147 (1 << 4) | (1 << 3) | (1 << 1) | 1,
148 (1 << 5) | (1 << 3) | (1 << 1) | 1,
150 (1 << 5) | (1 << 3) | (1 << 2) | 1,
153 (1 << 5) | (1 << 2) | (1 << 1) | 1,
158 (1 << 4) | (1 << 3) | (1 << 1) | 1,
160 (1 << 6) | (1 << 2) | (1 << 1) | 1,
161 (1 << 5) | (1 << 2) | (1 << 1) | 1,
164 (1 << 6) | (1 << 4) | (1 << 1) | 1,
166 (1 << 7) | (1 << 6) | (1 << 2) | 1
175 const uint32 offsets[32 - 3 + 1][2] =
213 for (uint32 i = 1, pp = primitive_polynomials[m - 3]; i < m; ++i, pp >>= 1)
215 matrix[m - 1] |= (pp & 1) << (m - i);
216 matrix[i - 1] = 1 << (m - i - 1);
220 uint32 result0[32], result1[32];
221 for (
unsigned i = 0; i < m; ++i)
222 result0[i] = matrix[i];
223 uint32* in = result0;
224 uint32* out = result1;
225 const uint32 offset = offsets[m - 3][
static_cast<int>(offset_type)];
226 for (
unsigned i = 1; i < offset; ++i)
229 for (uint32 y = 0; y < m; ++y)
232 for (uint32 x = 0; x < m; ++x)
233 for (uint32 i = 0; i < m; ++i)
234 out[y] ^= (((in[y] >> i) & (matrix[m - i - 1] >> x)) & 1) << x;
244 for (uint32 y = 0; y < m; ++y)
247 for (uint32 x = 0; x < m; ++x)
248 m_f[y] |= ((in[x] >> y) & 1) << (m - x - 1);
252 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
253 float LFSRGeneratorMatrix::next(
const uint32 scramble, uint32*
const state)
const 259 for (uint32 i = 0, s = *state; s; ++i, s >>= 1)
265 #if !defined(FLT_EPSILON) 266 const float FLT_EPSILON = 1.0e-10f;
271 result = (result << (32 - m_m)) ^ scramble;
272 const float fresult = result * (1.f / float(uint64(1ULL) << 32));
273 return fresult <= 1.0f - FLT_EPSILON ?
274 fresult : 1.0f - FLT_EPSILON;
277 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
278 float LFSRRandomStream::next()
280 return m_matrix->next(m_scramble, &m_state);
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38