Blender  V2.93
RandGen.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 #include "RandGen.h"
23 
24 namespace Freestyle {
25 
26 //
27 // Macro definitions
28 //
30 
31 #define N 16
32 #define MASK ((unsigned)(1 << (N - 1)) + (1 << (N - 1)) - 1)
33 #define X0 0x330E
34 #define X1 0xABCD
35 #define X2 0x1234
36 #define A0 0xE66D
37 #define A1 0xDEEC
38 #define A2 0x5
39 #define C 0xB
40 #if 0 // XXX Unused
41 # define HI_BIT (1L << (2 * N - 1))
42 #endif
43 
44 #define LOW(x) ((unsigned)(x)&MASK)
45 #define HIGH(x) LOW((x) >> N)
46 
47 #define MUL(x, y, z) \
48  { \
49  long l = (long)(x) * (long)(y); \
50  (z)[0] = LOW(l); \
51  (z)[1] = HIGH(l); \
52  } \
53  ((void)0)
54 
55 #define CARRY(x, y) ((unsigned long)((long)(x) + (long)(y)) > MASK)
56 #define ADDEQU(x, y, z) (z = CARRY(x, (y)), x = LOW(x + (y)))
57 #define SET3(x, x0, x1, x2) ((x)[0] = (x0), (x)[1] = (x1), (x)[2] = (x2))
58 #if 0 // XXX, unused
59 # define SETLOW(x, y, n) SET3(x, LOW((y)[n]), LOW((y)[(n) + 1]), LOW((y)[(n) + 2]))
60 #endif
61 #define SEED(x0, x1, x2) (SET3(x, x0, x1, x2), SET3(a, A0, A1, A2), c = C)
62 
63 #if 0 // XXX, unused
64 # define REST(v) \
65  for (i = 0; i < 3; i++) { \
66  xsubi[i] = x[i]; \
67  x[i] = temp[i]; \
68  } \
69  return (v); \
70  (void)0
71 
72 # define NEST(TYPE, f, F) \
73  TYPE f(unsigned short *xsubi) \
74  { \
75  int i; \
76  TYPE v; \
77  unsigned temp[3]; \
78  for (i = 0; i < 3; i++) { \
79  temp[i] = x[i]; \
80  x[i] = LOW(xsubi[i]); \
81  } \
82  v = F(); \
83  REST(v); \
84  }
85 #endif
86 
87 static unsigned x[3] = {
88  X0,
89  X1,
90  X2,
91 };
92 static unsigned a[3] = {
93  A0,
94  A1,
95  A2,
96 };
97 static unsigned c = C;
98 
99 //
100 // Methods implementation
101 //
103 
105 {
106  static real two16m = 1.0 / (1L << N);
107  next();
108  return (two16m * (two16m * (two16m * x[0] + x[1]) + x[2]));
109 }
110 
111 void RandGen::srand48(long seedval)
112 {
113  SEED(X0, LOW(seedval), HIGH(seedval));
114 }
115 
116 void RandGen::next()
117 {
118  unsigned p[2], q[2], r[2], carry0, carry1;
119 
120  MUL(a[0], x[0], p);
121  ADDEQU(p[0], c, carry0);
122  ADDEQU(p[1], carry0, carry1);
123  MUL(a[0], x[1], q);
124  ADDEQU(p[1], q[0], carry0);
125  MUL(a[1], x[0], r);
126  x[2] = LOW(carry0 + carry1 + CARRY(p[1], r[0]) + q[1] + r[1] + a[0] * x[2] + a[1] * x[1] +
127  a[2] * x[0]);
128  x[1] = LOW(p[1] + r[0]);
129  x[0] = LOW(p[0]);
130 }
131 
132 } /* 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:31
#define A0
Definition: RandGen.cpp:36
#define X1
Definition: RandGen.cpp:34
#define A2
Definition: RandGen.cpp:38
#define LOW(x)
Definition: RandGen.cpp:44
#define X2
Definition: RandGen.cpp:35
#define X0
Definition: RandGen.cpp:33
#define ADDEQU(x, y, z)
Definition: RandGen.cpp:56
#define MUL(x, y, z)
Definition: RandGen.cpp:47
#define HIGH(x)
Definition: RandGen.cpp:45
#define C
Definition: RandGen.cpp:39
#define A1
Definition: RandGen.cpp:37
#define CARRY(x, y)
Definition: RandGen.cpp:55
#define SEED(x0, x1, x2)
Definition: RandGen.cpp:61
Pseudo-random number generator.
static void srand48(long seedval)
Definition: RandGen.cpp:111
static real drand48()
Definition: RandGen.cpp:104
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned c
Definition: RandGen.cpp:97
static unsigned x[3]
Definition: RandGen.cpp:87
static unsigned a[3]
Definition: RandGen.cpp:92
double real
Definition: Precision.h:26