-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcud_chen_naive.c
176 lines (157 loc) · 6.15 KB
/
cud_chen_naive.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// The existing Tausworthe generators using naive slow generation
// Implemented by Shin Harase
// S. Chen, M. Matsumoto, T. Nishimura, A. B. Owen,
// "New inputs and methods for Markov chain quasi-Monte Carlo",
// in: Monte Carloand quasi-Monte Carlo methods 2010, Vol. 23 of Springer Proc.
// Math. Stat., Springer, Heidelberg, 2012, pp. 313--327.
// doi:10.1007/978-3-642-27440-4_15.
#include <stdio.h>
#include <stdlib.h>
#define MAX_DEG 32
#define WORD_SIZE 32
unsigned int MSB[WORD_SIZE+1] = {
0x80000000, 0x40000000, 0x20000000, 0x10000000, 0x8000000, 0x4000000, 0x2000000, 0x1000000,
0x800000, 0x400000, 0x200000, 0x100000, 0x80000, 0x40000, 0x20000, 0x10000,
0x8000, 0x4000, 0x2000, 0x1000, 0x800, 0x400, 0x200, 0x100,
0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1};
unsigned int p_chen[MAX_DEG+1][MAX_DEG+1] = {
{}, //deg = 0
{}, //deg = 1
{}, //deg = 2
{}, //deg = 3
{}, //deg = 4
{}, //deg = 5
{}, //deg = 6,
{}, //deg = 7
{}, //deg = 8
{}, //deg = 9
{1, 0, 0, 1, 0,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // deg = 26
{1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // deg = 27
{1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // deg = 28
{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // deg = 29
{1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // deg = 30
{1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // deg = 31
{1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} // deg = 32
};
unsigned int q_chen[MAX_DEG+1][MAX_DEG+1] = {
{}, //deg = 0
{}, //deg = 1
{}, //deg = 2
{}, //deg = 3
{}, //deg = 4
{}, //deg = 5
{}, //deg = 6,
{}, //deg = 7
{}, //deg = 8
{}, //deg = 9
{1, 0, 1, 1, 1, 0, 0, 0, 1, 1}, // deg = 10, //deg = 10
{0, 1, 1, 1, 0, 0, 0, 1, 1}, // deg = 11, //deg = 11
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1}, //deg = 12
{0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1}, // deg = 13
{1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1}, // deg = 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1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1}, // deg = 29
{1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1}, // // deg = 30
{0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1}, // deg = 31
{1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1} // deg = 32
};
unsigned int tausworthe_full(unsigned int state, unsigned int *p, int m)
{
int i, j;
unsigned int x;
for(i = 0; i < WORD_SIZE - m; i++)
{
x = 0;
for(j = 0; j < m; j++)
if(p[j] != 0)
if((state & MSB[j+i]) != 0) x ^= MSB[m+i];
state = (state ^ x);
}
return state;
}
unsigned int tausworthe_next(unsigned int state, unsigned int *p, int m)
{
int i;
unsigned int x = 0;
for(i = 0; i < m; i++)
if(p[i] != 0)
if((state & MSB[i+WORD_SIZE-m]) != 0) x ^= MSB[WORD_SIZE-1]; //if((state & MSB[i]) != 0) x ^= MSB[m-1];
x ^= (state << 1);
return x;
}
unsigned int tausworthe_jump(unsigned int state, unsigned int * p, unsigned int *q, int m)
{
int i, j;
unsigned int x = 0;
unsigned int y = 0;
for(i = 0; i < m; i++)
{
if(q[i] != 0)
{
y = state;
for(j = 0; j < i; j++) y = tausworthe_next(y, p, m);
x ^= y;
}
}
return x;
}
unsigned int tausworthe_chen(int m)
{
static int i = 0, j;
static unsigned int state;
static unsigned int p[MAX_DEG+1];
static unsigned int q[MAX_DEG+1];
if(i == 0)
{
for(j = 0; j <= m; j++)
{
p[j] = p_chen[m][j];
q[j] = q_chen[m][j];
}
state = MSB[m-1];
state = tausworthe_full(state, p, m);
i = 1;
return state;
}
state = tausworthe_jump(state, p, q, m);
return state;
}
int main(int argc,char *argv[])
{
unsigned int i;
unsigned int m, N;
int w = 32; //WORD_SIZE
m = atoi(argv[1]);
N = (0xffffffff >> (w - m)); // N = 2^m-1
for(i = 0; i < N; i++) printf("%10.8f\n", tausworthe_chen(m)*(1.0/4294967296.0));
return 0;
}