Blender  V3.3
RandGen.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 #include "RandGen.h"
9 
10 namespace Freestyle {
11 
12 //
13 // Macro definitions
14 //
16 
17 #define N 16
18 #define MASK ((unsigned)(1 << (N - 1)) + (1 << (N - 1)) - 1)
19 #define X0 0x330E
20 #define X1 0xABCD
21 #define X2 0x1234
22 #define A0 0xE66D
23 #define A1 0xDEEC
24 #define A2 0x5
25 #define C 0xB
26 #if 0 // XXX Unused
27 # define HI_BIT (1L << (2 * N - 1))
28 #endif
29 
30 #define LOW(x) ((unsigned)(x)&MASK)
31 #define HIGH(x) LOW((x) >> N)
32 
33 #define MUL(x, y, z) \
34  { \
35  long l = (long)(x) * (long)(y); \
36  (z)[0] = LOW(l); \
37  (z)[1] = HIGH(l); \
38  } \
39  ((void)0)
40 
41 #define CARRY(x, y) ((unsigned long)((long)(x) + (long)(y)) > MASK)
42 #define ADDEQU(x, y, z) (z = CARRY(x, (y)), x = LOW(x + (y)))
43 #define SET3(x, x0, x1, x2) ((x)[0] = (x0), (x)[1] = (x1), (x)[2] = (x2))
44 #if 0 // XXX, unused
45 # define SETLOW(x, y, n) SET3(x, LOW((y)[n]), LOW((y)[(n) + 1]), LOW((y)[(n) + 2]))
46 #endif
47 #define SEED(x0, x1, x2) (SET3(x, x0, x1, x2), SET3(a, A0, A1, A2), c = C)
48 
49 #if 0 // XXX, unused
50 # define REST(v) \
51  for (i = 0; i < 3; i++) { \
52  xsubi[i] = x[i]; \
53  x[i] = temp[i]; \
54  } \
55  return (v); \
56  (void)0
57 
58 # define NEST(TYPE, f, F) \
59  TYPE f(unsigned short *xsubi) \
60  { \
61  int i; \
62  TYPE v; \
63  unsigned temp[3]; \
64  for (i = 0; i < 3; i++) { \
65  temp[i] = x[i]; \
66  x[i] = LOW(xsubi[i]); \
67  } \
68  v = F(); \
69  REST(v); \
70  }
71 #endif
72 
73 static unsigned x[3] = {
74  X0,
75  X1,
76  X2,
77 };
78 static unsigned a[3] = {
79  A0,
80  A1,
81  A2,
82 };
83 static unsigned c = C;
84 
85 //
86 // Methods implementation
87 //
89 
91 {
92  static real two16m = 1.0 / (1L << N);
93  next();
94  return (two16m * (two16m * (two16m * x[0] + x[1]) + x[2]));
95 }
96 
97 void RandGen::srand48(long seedval)
98 {
99  SEED(X0, LOW(seedval), HIGH(seedval));
100 }
101 
102 void RandGen::next()
103 {
104  unsigned p[2], q[2], r[2], carry0, carry1;
105 
106  MUL(a[0], x[0], p);
107  ADDEQU(p[0], c, carry0);
108  ADDEQU(p[1], carry0, carry1);
109  MUL(a[0], x[1], q);
110  ADDEQU(p[1], q[0], carry0);
111  MUL(a[1], x[0], r);
112  x[2] = LOW(carry0 + carry1 + CARRY(p[1], r[0]) + q[1] + r[1] + a[0] * x[2] + a[1] * x[1] +
113  a[2] * x[0]);
114  x[1] = LOW(p[1] + r[0]);
115  x[0] = LOW(p[0]);
116 }
117 
118 } /* namespace Freestyle */
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
#define N
Definition: RandGen.cpp:17
#define A0
Definition: RandGen.cpp:22
#define X1
Definition: RandGen.cpp:20
#define A2
Definition: RandGen.cpp:24
#define LOW(x)
Definition: RandGen.cpp:30
#define X2
Definition: RandGen.cpp:21
#define X0
Definition: RandGen.cpp:19
#define ADDEQU(x, y, z)
Definition: RandGen.cpp:42
#define MUL(x, y, z)
Definition: RandGen.cpp:33
#define HIGH(x)
Definition: RandGen.cpp:31
#define C
Definition: RandGen.cpp:25
#define A1
Definition: RandGen.cpp:23
#define CARRY(x, y)
Definition: RandGen.cpp:41
#define SEED(x0, x1, x2)
Definition: RandGen.cpp:47
Pseudo-random number generator.
static void srand48(long seedval)
Definition: RandGen.cpp:97
static real drand48()
Definition: RandGen.cpp:90
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned c
Definition: RandGen.cpp:83
static unsigned x[3]
Definition: RandGen.cpp:73
static unsigned a[3]
Definition: RandGen.cpp:78
double real
Definition: Precision.h:12