6 #define DSFMT_DO_NOT_USE_OLD_NAMES
9 #define NUM_RANDS 50000
11 #define TIC_COUNT 2000
13 w128_t dummy
[NUM_RANDS
/ 2 + 1];
15 typedef double (*genrand_t
)(void);
16 typedef double (*st_genrand_t
)(dsfmt_t
*dsfmt
);
17 typedef void (*fill_array_t
)(double array
[], int size
);
18 typedef void (*st_fill_array_t
)(dsfmt_t
*dsfmt
, double array
[], int size
);
21 static void test_co(void) __attribute__((noinline
));
22 static void test_oc(void) __attribute__((noinline
));
23 static void test_oo(void) __attribute__((noinline
));
24 static void test_12(void) __attribute__((noinline
));
25 static void test_seq_co(void) __attribute__((noinline
));
26 static void test_seq_oc(void) __attribute__((noinline
));
27 static void test_seq_oo(void) __attribute__((noinline
));
28 static void test_seq_12(void) __attribute__((noinline
));
30 static void test_co(void);
31 static void test_oc(void);
32 static void test_oo(void);
33 static void test_12(void);
34 static void test_seq_co(void);
35 static void test_seq_oc(void);
36 static void test_seq_oo(void);
37 static void test_seq_12(void);
39 static void check(char *start_mess
, genrand_t genrand
, fill_array_t fill_array
,
40 st_genrand_t st_genrand
, st_fill_array_t st_fill_array
,
41 uint32_t seed
, int n
);
42 static void check_ar(char *start_mess
, genrand_t genrand
,
43 fill_array_t fill_array
,
44 st_genrand_t st_genrand
,
45 st_fill_array_t st_fill_array
,
48 /* not inline wrapper functions for check() */
49 static double s_genrand_close_open(void) {
50 return dsfmt_gv_genrand_close_open();
52 static double s_genrand_open_close(void) {
53 return dsfmt_gv_genrand_open_close();
55 static double s_genrand_open_open(void) {
56 return dsfmt_gv_genrand_open_open();
58 static double s_genrand_close1_open2(void) {
59 return dsfmt_gv_genrand_close1_open2();
61 static double sst_genrand_close_open(dsfmt_t
*dsfmt
) {
62 return dsfmt_genrand_close_open(dsfmt
);
64 static double sst_genrand_open_close(dsfmt_t
*dsfmt
) {
65 return dsfmt_genrand_open_close(dsfmt
);
67 static double sst_genrand_open_open(dsfmt_t
*dsfmt
) {
68 return dsfmt_genrand_open_open(dsfmt
);
70 static double sst_genrand_close1_open2(dsfmt_t
*dsfmt
) {
71 return dsfmt_genrand_close1_open2(dsfmt
);
73 static void s_fill_array_close_open(double array
[], int size
) {
74 dsfmt_gv_fill_array_close_open(array
, size
);
76 static void s_fill_array_open_close(double array
[], int size
) {
77 dsfmt_gv_fill_array_open_close(array
, size
);
79 static void s_fill_array_open_open(double array
[], int size
) {
80 dsfmt_gv_fill_array_open_open(array
, size
);
82 static void s_fill_array_close1_open2(double array
[], int size
) {
83 dsfmt_gv_fill_array_close1_open2(array
, size
);
85 static void sst_fill_array_close_open(dsfmt_t
*dsfmt
, double array
[],
87 dsfmt_fill_array_close_open(dsfmt
, array
, size
);
89 static void sst_fill_array_open_close(dsfmt_t
*dsfmt
, double array
[],
91 dsfmt_fill_array_open_close(dsfmt
, array
, size
);
93 static void sst_fill_array_open_open(dsfmt_t
*dsfmt
, double array
[],
95 dsfmt_fill_array_open_open(dsfmt
, array
, size
);
97 static void sst_fill_array_close1_open2(dsfmt_t
*dsfmt
, double array
[],
99 dsfmt_fill_array_close1_open2(dsfmt
, array
, size
);
102 static void check(char *range_str
, genrand_t genrand
, fill_array_t fill_array
,
103 st_genrand_t st_genrand
, st_fill_array_t st_fill_array
,
104 uint32_t seed
, int print_size
) {
110 w128_t little
[DSFMT_N
+1];
111 union W64_T
*array
= (union W64_T
*)dummy
;
112 union W64_T
*plittle
= (union W64_T
*)little
;
114 int lsize
= DSFMT_N
* 2 + 2;
117 printf("generated randoms %s\n", range_str
);
118 dsfmt_gv_init_gen_rand(seed
);
119 fill_array(&plittle
[0].d
, lsize
);
120 fill_array(&array
[0].d
, 5000);
121 dsfmt_gv_init_gen_rand(seed
);
122 dsfmt_init_gen_rand(&dsfmt
, seed
);
123 for (i
= 0; i
< lsize
; i
++) {
125 r_st
.d
= st_genrand(&dsfmt
);
126 if (r
.u
!= r_st
.u
|| r
.u
!= plittle
[i
].u
) {
127 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64
"), "
128 "st = %1.15f(%08"PRIx64
")"
129 "array = %1.15f(%08"PRIx64
")\n",
130 range_str
, i
, r
.d
, r
.u
,
132 plittle
[i
].d
, plittle
[i
].u
);
135 if (i
< print_size
) {
136 printf("%1.15f ", plittle
[i
].d
);
142 for (i
= 0; i
< 5000; i
++) {
144 if (r
.u
!= array
[i
].u
) {
145 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64
"), "
146 "array = %1.15f(%08"PRIx64
")\n",
147 range_str
, i
+ lsize
, r
.d
, r
.u
,
148 array
[i
].d
, array
[i
].u
);
151 if (i
+ lsize
< print_size
) {
152 printf("%1.15f ", array
[i
].d
);
153 if ((i
+ lsize
) % 4 == 3) {
159 dsfmt_init_gen_rand(&dsfmt
, seed
);
160 st_fill_array(&dsfmt
, &plittle
[0].d
, lsize
);
161 st_fill_array(&dsfmt
, &array
[0].d
, 5000);
162 dsfmt_init_gen_rand(&dsfmt
, seed
);
163 for (i
= 0; i
< lsize
; i
++) {
164 r_st
.d
= st_genrand(&dsfmt
);
165 if (r_st
.u
!= plittle
[i
].u
) {
166 printf("\n%s mismatch i = %d: st = %1.15f(%08"PRIx64
"), "
167 "array = %1.15f(%08"PRIx64
")\n",
168 range_str
, i
, r_st
.d
, r_st
.u
,
169 plittle
[i
].d
, plittle
[i
].u
);
173 for (i
= 0; i
< 5000; i
++) {
174 r_st
.d
= st_genrand(&dsfmt
);
175 if (r_st
.u
!= array
[i
].u
) {
176 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64
"), "
177 "array = %1.15f(%08"PRIx64
")\n",
178 range_str
, i
+ lsize
, r_st
.d
, r_st
.u
,
179 array
[i
].d
, array
[i
].u
);
185 static void check_ar(char *range_str
, genrand_t genrand
,
186 fill_array_t fill_array
,
187 st_genrand_t st_genrand
,
188 st_fill_array_t st_fill_array
,
195 w128_t little
[DSFMT_N
+1];
196 union W64_T
*array
= (union W64_T
*)dummy
;
197 union W64_T
*plittle
= (union W64_T
*)little
;
199 int lsize
= DSFMT_N
* 2 + 2;
201 uint32_t ar
[4] = {1, 2, 3, 4};
203 printf("generated randoms %s\n", range_str
);
204 dsfmt_gv_init_by_array(ar
, 4);
205 fill_array(&plittle
[0].d
, lsize
);
206 fill_array(&array
[0].d
, 5000);
207 dsfmt_gv_init_by_array(ar
, 4);
208 dsfmt_init_by_array(&dsfmt
, ar
, 4);
209 for (i
= 0; i
< lsize
; i
++) {
211 r_st
.d
= st_genrand(&dsfmt
);
212 if (r
.u
!= r_st
.u
|| r
.u
!= plittle
[i
].u
) {
213 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64
"), "
214 "st = %1.15f(%08"PRIx64
")"
215 "array = %1.15f(%08"PRIx64
")\n",
216 range_str
, i
, r
.d
, r
.u
,
218 plittle
[i
].d
, plittle
[i
].u
);
221 if (i
< print_size
) {
222 printf("%1.15f ", plittle
[i
].d
);
228 for (i
= 0; i
< 5000; i
++) {
230 if (r
.u
!= array
[i
].u
) {
231 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64
"), "
232 "array = %1.15f(%08"PRIx64
")\n",
233 range_str
, i
+ lsize
, r
.d
, r
.u
,
234 array
[i
].d
, array
[i
].u
);
237 if (i
+ lsize
< print_size
) {
238 printf("%1.15f ", array
[i
].d
);
239 if ((i
+ lsize
) % 4 == 3) {
245 dsfmt_init_by_array(&dsfmt
, ar
, 4);
246 st_fill_array(&dsfmt
, &plittle
[0].d
, lsize
);
247 st_fill_array(&dsfmt
, &array
[0].d
, 5000);
248 dsfmt_init_by_array(&dsfmt
, ar
, 4);
249 for (i
= 0; i
< lsize
; i
++) {
250 r_st
.d
= st_genrand(&dsfmt
);
251 if (r_st
.u
!= plittle
[i
].u
) {
252 printf("\n%s mismatch i = %d: st = %1.15f(%08"PRIx64
"), "
253 "array = %1.15f(%08"PRIx64
")\n",
254 range_str
, i
, r_st
.d
, r_st
.u
,
255 plittle
[i
].d
, plittle
[i
].u
);
259 for (i
= 0; i
< 5000; i
++) {
260 r_st
.d
= st_genrand(&dsfmt
);
261 if (r_st
.u
!= array
[i
].u
) {
262 printf("\n%s mismatch i = %d: r = %1.15f(%08"PRIx64
"), "
263 "array = %1.15f(%08"PRIx64
")\n",
264 range_str
, i
+ lsize
, r_st
.d
, r_st
.u
,
265 array
[i
].d
, array
[i
].u
);
271 static void test_co(void) {
275 double *array
= (double *)dummy
;
279 dsfmt_gv_init_gen_rand(1234);
281 for (i
= 0; i
< 10; i
++) {
283 for (j
= 0; j
< TIC_COUNT
; j
++) {
284 dsfmt_gv_fill_array_close_open(array
, NUM_RANDS
);
289 printf("GL BLOCK [0, 1) AVE:%4"PRIu64
"ms.\n",
290 (sum
* 100) / CLOCKS_PER_SEC
);
292 dsfmt_init_gen_rand(&dsfmt
, 1234);
294 for (i
= 0; i
< 10; i
++) {
296 for (j
= 0; j
< TIC_COUNT
; j
++) {
297 dsfmt_fill_array_close_open(&dsfmt
, array
, NUM_RANDS
);
302 printf("ST BLOCK [0, 1) AVE:%4"PRIu64
"ms.\n",
303 (sum
* 100) / CLOCKS_PER_SEC
);
306 static void test_oc(void) {
310 double *array
= (double *)dummy
;
313 dsfmt_gv_init_gen_rand(1234);
315 for (i
= 0; i
< 10; i
++) {
317 for (j
= 0; j
< TIC_COUNT
; j
++) {
318 dsfmt_gv_fill_array_open_close(array
, NUM_RANDS
);
323 printf("GL BLOCK (0, 1] AVE:%4"PRIu64
"ms.\n",
324 (sum
* 100) / CLOCKS_PER_SEC
);
326 dsfmt_init_gen_rand(&dsfmt
, 1234);
328 for (i
= 0; i
< 10; i
++) {
330 for (j
= 0; j
< TIC_COUNT
; j
++) {
331 dsfmt_fill_array_open_close(&dsfmt
, array
, NUM_RANDS
);
336 printf("ST BLOCK (0, 1] AVE:%4"PRIu64
"ms.\n",
337 (sum
* 100) / CLOCKS_PER_SEC
);
340 static void test_oo(void) {
344 double *array
= (double *)dummy
;
347 dsfmt_gv_init_gen_rand(1234);
349 for (i
= 0; i
< 10; i
++) {
351 for (j
= 0; j
< TIC_COUNT
; j
++) {
352 dsfmt_gv_fill_array_open_open(array
, NUM_RANDS
);
357 printf("GL BLOCK (0, 1) AVE:%4"PRIu64
"ms.\n",
358 (sum
* 100) / CLOCKS_PER_SEC
);
360 dsfmt_init_gen_rand(&dsfmt
, 1234);
362 for (i
= 0; i
< 10; i
++) {
364 for (j
= 0; j
< TIC_COUNT
; j
++) {
365 dsfmt_fill_array_open_open(&dsfmt
, array
, NUM_RANDS
);
370 printf("ST BLOCK (0, 1) AVE:%4"PRIu64
"ms.\n",
371 (sum
* 100) / CLOCKS_PER_SEC
);
374 static void test_12(void) {
378 double *array
= (double *)dummy
;
381 dsfmt_gv_init_gen_rand(1234);
383 for (i
= 0; i
< 10; i
++) {
385 for (j
= 0; j
< TIC_COUNT
; j
++) {
386 dsfmt_gv_fill_array_close1_open2(array
, NUM_RANDS
);
391 printf("GL BLOCK [1, 2) AVE:%4"PRIu64
"ms.\n",
392 (sum
* 100) / CLOCKS_PER_SEC
);
394 dsfmt_init_gen_rand(&dsfmt
, 1234);
396 for (i
= 0; i
< 10; i
++) {
398 for (j
= 0; j
< TIC_COUNT
; j
++) {
399 dsfmt_fill_array_close1_open2(&dsfmt
, array
, NUM_RANDS
);
404 printf("ST BLOCK [1, 2) AVE:%4"PRIu64
"ms.\n",
405 (sum
* 100) / CLOCKS_PER_SEC
);
408 static void test_seq_co(void) {
412 double *array
= (double *)dummy
;
417 dsfmt_gv_init_gen_rand(1234);
420 for (i
= 0; i
< 10; i
++) {
422 for (j
= 0; j
< TIC_COUNT
; j
++) {
423 for (k
= 0; k
< NUM_RANDS
; k
++) {
424 r
+= dsfmt_gv_genrand_close_open();
431 printf("GL SEQ [0, 1) 1 AVE:%4"PRIu64
"ms.\n",
432 (sum
* 100) / CLOCKS_PER_SEC
);
435 for (i
= 0; i
< 10; i
++) {
437 for (j
= 0; j
< TIC_COUNT
; j
++) {
438 for (k
= 0; k
< NUM_RANDS
; k
++) {
439 array
[k
] = dsfmt_gv_genrand_close_open();
445 for (k
= 0; k
< NUM_RANDS
; k
++) {
448 printf("GL SEQ [0, 1) 2 AVE:%4"PRIu64
"ms.\n",
449 (sum
* 100) / CLOCKS_PER_SEC
);
451 dsfmt_init_gen_rand(&dsfmt
, 1234);
454 for (i
= 0; i
< 10; i
++) {
456 for (j
= 0; j
< TIC_COUNT
; j
++) {
457 for (k
= 0; k
< NUM_RANDS
; k
++) {
458 r
+= dsfmt_genrand_close_open(&dsfmt
);
465 printf("ST SEQ [0, 1) 1 AVE:%4"PRIu64
"ms.\n",
466 (sum
* 100) / CLOCKS_PER_SEC
);
469 for (i
= 0; i
< 10; i
++) {
471 for (j
= 0; j
< TIC_COUNT
; j
++) {
472 for (k
= 0; k
< NUM_RANDS
; k
++) {
473 array
[k
] = dsfmt_genrand_close_open(&dsfmt
);
479 for (k
= 0; k
< NUM_RANDS
; k
++) {
482 printf("ST SEQ [0, 1) 2 AVE:%4"PRIu64
"ms.\n",
483 (sum
* 100) / CLOCKS_PER_SEC
);
485 printf("total = %f\n", total
);
488 static void test_seq_oc(void) {
492 double *array
= (double *)dummy
;
497 dsfmt_gv_init_gen_rand(1234);
500 for (i
= 0; i
< 10; i
++) {
502 for (j
= 0; j
< TIC_COUNT
; j
++) {
503 for (k
= 0; k
< NUM_RANDS
; k
++) {
504 r
+= dsfmt_gv_genrand_open_close();
511 printf("GL SEQ (0, 1] 1 AVE:%4"PRIu64
"ms.\n",
512 (sum
* 100) / CLOCKS_PER_SEC
);
514 for (i
= 0; i
< 10; i
++) {
516 for (j
= 0; j
< TIC_COUNT
; j
++) {
517 for (k
= 0; k
< NUM_RANDS
; k
++) {
518 array
[k
] = dsfmt_gv_genrand_open_close();
524 for (k
= 0; k
< NUM_RANDS
; k
++) {
527 printf("GL SEQ (0, 1] 2 AVE:%4"PRIu64
"ms.\n",
528 (sum
* 100) / CLOCKS_PER_SEC
);
530 dsfmt_init_gen_rand(&dsfmt
, 1234);
533 for (i
= 0; i
< 10; i
++) {
535 for (j
= 0; j
< TIC_COUNT
; j
++) {
536 for (k
= 0; k
< NUM_RANDS
; k
++) {
537 r
+= dsfmt_genrand_open_close(&dsfmt
);
544 printf("ST SEQ (0, 1] 1 AVE:%4"PRIu64
"ms.\n",
545 (sum
* 100) / CLOCKS_PER_SEC
);
547 for (i
= 0; i
< 10; i
++) {
549 for (j
= 0; j
< TIC_COUNT
; j
++) {
550 for (k
= 0; k
< NUM_RANDS
; k
++) {
551 array
[k
] = dsfmt_genrand_open_close(&dsfmt
);
557 for (k
= 0; k
< NUM_RANDS
; k
++) {
560 printf("ST SEQ (0, 1] 2 AVE:%4"PRIu64
"ms.\n",
561 (sum
* 100) / CLOCKS_PER_SEC
);
562 printf("total = %f\n", total
);
565 static void test_seq_oo(void) {
569 double *array
= (double *)dummy
;
574 dsfmt_gv_init_gen_rand(1234);
577 for (i
= 0; i
< 10; i
++) {
579 for (j
= 0; j
< TIC_COUNT
; j
++) {
580 for (k
= 0; k
< NUM_RANDS
; k
++) {
581 r
+= dsfmt_gv_genrand_open_open();
588 printf("GL SEQ (0, 1) 1 AVE:%4"PRIu64
"ms.\n",
589 (sum
* 100) / CLOCKS_PER_SEC
);
591 for (i
= 0; i
< 10; i
++) {
593 for (j
= 0; j
< TIC_COUNT
; j
++) {
594 for (k
= 0; k
< NUM_RANDS
; k
++) {
595 array
[k
] = dsfmt_gv_genrand_open_open();
601 for (k
= 0; k
< NUM_RANDS
; k
++) {
604 printf("GL SEQ (0, 1) 2 AVE:%4"PRIu64
"ms.\n",
605 (sum
* 100) / CLOCKS_PER_SEC
);
607 dsfmt_init_gen_rand(&dsfmt
, 1234);
610 for (i
= 0; i
< 10; i
++) {
612 for (j
= 0; j
< TIC_COUNT
; j
++) {
613 for (k
= 0; k
< NUM_RANDS
; k
++) {
614 r
+= dsfmt_genrand_open_open(&dsfmt
);
621 printf("ST SEQ (0, 1) 1 AVE:%4"PRIu64
"ms.\n",
622 (sum
* 100) / CLOCKS_PER_SEC
);
624 for (i
= 0; i
< 10; i
++) {
626 for (j
= 0; j
< TIC_COUNT
; j
++) {
627 for (k
= 0; k
< NUM_RANDS
; k
++) {
628 array
[k
] = dsfmt_genrand_open_open(&dsfmt
);
634 for (k
= 0; k
< NUM_RANDS
; k
++) {
637 printf("ST SEQ (0, 1) 2 AVE:%4"PRIu64
"ms.\n",
638 (sum
* 100) / CLOCKS_PER_SEC
);
639 printf("total = %f\n", total
);
642 static void test_seq_12(void) {
646 double *array
= (double *)dummy
;
651 dsfmt_gv_init_gen_rand(1234);
654 for (i
= 0; i
< 10; i
++) {
656 for (j
= 0; j
< TIC_COUNT
; j
++) {
657 for (k
= 0; k
< NUM_RANDS
; k
++) {
658 r
+= dsfmt_gv_genrand_close1_open2();
665 printf("GL SEQ [1, 2) 1 AVE:%4"PRIu64
"ms.\n",
666 (sum
* 100) / CLOCKS_PER_SEC
);
668 for (i
= 0; i
< 10; i
++) {
670 for (j
= 0; j
< TIC_COUNT
; j
++) {
671 for (k
= 0; k
< NUM_RANDS
; k
++) {
672 array
[k
] = dsfmt_gv_genrand_close1_open2();
678 for (k
= 0; k
< NUM_RANDS
; k
++) {
681 printf("GL SEQ [1, 2) 2 AVE:%4"PRIu64
"ms.\n",
682 (sum
* 100) / CLOCKS_PER_SEC
);
684 dsfmt_init_gen_rand(&dsfmt
, 1234);
687 for (i
= 0; i
< 10; i
++) {
689 for (j
= 0; j
< TIC_COUNT
; j
++) {
690 for (k
= 0; k
< NUM_RANDS
; k
++) {
691 r
+= dsfmt_genrand_close1_open2(&dsfmt
);
698 printf("ST SEQ [1, 2) 1 AVE:%4"PRIu64
"ms.\n",
699 (sum
* 100) / CLOCKS_PER_SEC
);
701 for (i
= 0; i
< 10; i
++) {
703 for (j
= 0; j
< TIC_COUNT
; j
++) {
704 for (k
= 0; k
< NUM_RANDS
; k
++) {
705 array
[k
] = dsfmt_genrand_close1_open2(&dsfmt
);
711 for (k
= 0; k
< NUM_RANDS
; k
++) {
714 printf("ST SEQ [1, 2) 2 AVE:%4"PRIu64
"ms.\n",
715 (sum
* 100) / CLOCKS_PER_SEC
);
716 printf("total = %f\n", total
);
719 int main(int argc
, char *argv
[]) {
722 if ((argc
>= 2) && (strncmp(argv
[1],"-s",2) == 0)) {
723 printf("consumed time for generating %d randoms.\n",
724 NUM_RANDS
* TIC_COUNT
);
734 printf("%s\n", dsfmt_get_idstring());
735 printf("init_gen_rand(0) ");
736 check("[1, 2)", s_genrand_close1_open2
, s_fill_array_close1_open2
,
737 sst_genrand_close1_open2
, sst_fill_array_close1_open2
, 0, 1000);
738 for (i
= 0; i
< 20; i
++) {
739 printf("init_gen_rand(%d) ", i
);
742 check("[0, 1)", s_genrand_close_open
, s_fill_array_close_open
,
743 sst_genrand_close_open
, sst_fill_array_close_open
, i
, 12);
746 check("(0, 1]", s_genrand_open_close
, s_fill_array_open_close
,
747 sst_genrand_open_close
, sst_fill_array_open_close
, i
, 12);
750 check("(0, 1)", s_genrand_open_open
, s_fill_array_open_open
,
751 sst_genrand_open_open
, sst_fill_array_open_open
, i
, 12);
755 check("[1, 2)", s_genrand_close1_open2
,
756 s_fill_array_close1_open2
,
757 sst_genrand_close1_open2
,
758 sst_fill_array_close1_open2
, i
, 12);
761 printf("init_by_array {1, 2, 3, 4} ");
762 check_ar("[1, 2)", s_genrand_close1_open2
,
763 s_fill_array_close1_open2
,
764 sst_genrand_close1_open2
,
765 sst_fill_array_close1_open2
,