• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision6633 (tree)
Time2017-03-16 12:31:48
Authordoda

Log Message

lib/SFMT を使うように変更 [Ttssh2-devel 3214]

VS2005 以外は未チェック

Change Summary

Incremental Difference

--- trunk/teraterm/ttpmacro/SFMT-common.h (revision 6632)
+++ trunk/teraterm/ttpmacro/SFMT-common.h (nonexistent)
@@ -1,164 +0,0 @@
1-#pragma once
2-/**
3- * @file SFMT-common.h
4- *
5- * @brief SIMD oriented Fast Mersenne Twister(SFMT) pseudorandom
6- * number generator with jump function. This file includes common functions
7- * used in random number generation and jump.
8- *
9- * @author Mutsuo Saito (Hiroshima University)
10- * @author Makoto Matsumoto (The University of Tokyo)
11- *
12- * Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
13- * University.
14- * Copyright (C) 2012 Mutsuo Saito, Makoto Matsumoto, Hiroshima
15- * University and The University of Tokyo.
16- * All rights reserved.
17- *
18- * The 3-clause BSD License is applied to this software, see
19- * LICENSE.txt
20- */
21-#ifndef SFMT_COMMON_H
22-#define SFMT_COMMON_H
23-
24-#if defined(__cplusplus)
25-extern "C" {
26-#endif
27-
28-#include "SFMT.h"
29-
30-inline static void do_recursion(w128_t * r, w128_t * a, w128_t * b,
31- w128_t * c, w128_t * d);
32-
33-inline static void rshift128(w128_t *out, w128_t const *in, int shift);
34-inline static void lshift128(w128_t *out, w128_t const *in, int shift);
35-
36-/**
37- * This function simulates SIMD 128-bit right shift by the standard C.
38- * The 128-bit integer given in in is shifted by (shift * 8) bits.
39- * This function simulates the LITTLE ENDIAN SIMD.
40- * @param out the output of this function
41- * @param in the 128-bit data to be shifted
42- * @param shift the shift value
43- */
44-#ifdef ONLY64
45-inline static void rshift128(w128_t *out, w128_t const *in, int shift) {
46- uint64_t th, tl, oh, ol;
47-
48- th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
49- tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
50-
51- oh = th >> (shift * 8);
52- ol = tl >> (shift * 8);
53- ol |= th << (64 - shift * 8);
54- out->u[0] = (uint32_t)(ol >> 32);
55- out->u[1] = (uint32_t)ol;
56- out->u[2] = (uint32_t)(oh >> 32);
57- out->u[3] = (uint32_t)oh;
58-}
59-#else
60-inline static void rshift128(w128_t *out, w128_t const *in, int shift)
61-{
62- uint64_t th, tl, oh, ol;
63-
64- th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
65- tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
66-
67- oh = th >> (shift * 8);
68- ol = tl >> (shift * 8);
69- ol |= th << (64 - shift * 8);
70- out->u[1] = (uint32_t)(ol >> 32);
71- out->u[0] = (uint32_t)ol;
72- out->u[3] = (uint32_t)(oh >> 32);
73- out->u[2] = (uint32_t)oh;
74-}
75-#endif
76-/**
77- * This function simulates SIMD 128-bit left shift by the standard C.
78- * The 128-bit integer given in in is shifted by (shift * 8) bits.
79- * This function simulates the LITTLE ENDIAN SIMD.
80- * @param out the output of this function
81- * @param in the 128-bit data to be shifted
82- * @param shift the shift value
83- */
84-#ifdef ONLY64
85-inline static void lshift128(w128_t *out, w128_t const *in, int shift) {
86- uint64_t th, tl, oh, ol;
87-
88- th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
89- tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
90-
91- oh = th << (shift * 8);
92- ol = tl << (shift * 8);
93- oh |= tl >> (64 - shift * 8);
94- out->u[0] = (uint32_t)(ol >> 32);
95- out->u[1] = (uint32_t)ol;
96- out->u[2] = (uint32_t)(oh >> 32);
97- out->u[3] = (uint32_t)oh;
98-}
99-#else
100-inline static void lshift128(w128_t *out, w128_t const *in, int shift)
101-{
102- uint64_t th, tl, oh, ol;
103-
104- th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
105- tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
106-
107- oh = th << (shift * 8);
108- ol = tl << (shift * 8);
109- oh |= tl >> (64 - shift * 8);
110- out->u[1] = (uint32_t)(ol >> 32);
111- out->u[0] = (uint32_t)ol;
112- out->u[3] = (uint32_t)(oh >> 32);
113- out->u[2] = (uint32_t)oh;
114-}
115-#endif
116-/**
117- * This function represents the recursion formula.
118- * @param r output
119- * @param a a 128-bit part of the internal state array
120- * @param b a 128-bit part of the internal state array
121- * @param c a 128-bit part of the internal state array
122- * @param d a 128-bit part of the internal state array
123- */
124-#ifdef ONLY64
125-inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
126- w128_t *d) {
127- w128_t x;
128- w128_t y;
129-
130- lshift128(&x, a, SFMT_SL2);
131- rshift128(&y, c, SFMT_SR2);
132- r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SFMT_SR1) & SFMT_MSK2) ^ y.u[0]
133- ^ (d->u[0] << SFMT_SL1);
134- r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SFMT_SR1) & SFMT_MSK1) ^ y.u[1]
135- ^ (d->u[1] << SFMT_SL1);
136- r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SFMT_SR1) & SFMT_MSK4) ^ y.u[2]
137- ^ (d->u[2] << SFMT_SL1);
138- r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SFMT_SR1) & SFMT_MSK3) ^ y.u[3]
139- ^ (d->u[3] << SFMT_SL1);
140-}
141-#else
142-inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b,
143- w128_t *c, w128_t *d)
144-{
145- w128_t x;
146- w128_t y;
147-
148- lshift128(&x, a, SFMT_SL2);
149- rshift128(&y, c, SFMT_SR2);
150- r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SFMT_SR1) & SFMT_MSK1)
151- ^ y.u[0] ^ (d->u[0] << SFMT_SL1);
152- r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SFMT_SR1) & SFMT_MSK2)
153- ^ y.u[1] ^ (d->u[1] << SFMT_SL1);
154- r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SFMT_SR1) & SFMT_MSK3)
155- ^ y.u[2] ^ (d->u[2] << SFMT_SL1);
156- r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SFMT_SR1) & SFMT_MSK4)
157- ^ y.u[3] ^ (d->u[3] << SFMT_SL1);
158-}
159-#endif
160-#endif
161-
162-#if defined(__cplusplus)
163-}
164-#endif
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
--- trunk/teraterm/ttpmacro/SFMT.c (revision 6632)
+++ trunk/teraterm/ttpmacro/SFMT.c (nonexistent)
@@ -1,435 +0,0 @@
1-/**
2- * @file SFMT.c
3- * @brief SIMD oriented Fast Mersenne Twister(SFMT)
4- *
5- * @author Mutsuo Saito (Hiroshima University)
6- * @author Makoto Matsumoto (Hiroshima University)
7- *
8- * Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
9- * University.
10- * Copyright (C) 2012 Mutsuo Saito, Makoto Matsumoto, Hiroshima
11- * University and The University of Tokyo.
12- * Copyright (C) 2013 Mutsuo Saito, Makoto Matsumoto and Hiroshima
13- * University.
14- * All rights reserved.
15- *
16- * The 3-clause BSD License is applied to this software, see
17- * LICENSE.txt
18- */
19-
20-#if defined(__cplusplus)
21-extern "C" {
22-#endif
23-
24-#include <string.h>
25-#include <assert.h>
26-#include "SFMT.h"
27-#include "SFMT-params.h"
28-#include "SFMT-common.h"
29-
30-#if defined(__BIG_ENDIAN__) && !defined(__amd64) && !defined(BIG_ENDIAN64)
31-#define BIG_ENDIAN64 1
32-#endif
33-#if defined(HAVE_ALTIVEC) && !defined(BIG_ENDIAN64)
34-#define BIG_ENDIAN64 1
35-#endif
36-#if defined(ONLY64) && !defined(BIG_ENDIAN64)
37- #if defined(__GNUC__)
38- #error "-DONLY64 must be specified with -DBIG_ENDIAN64"
39- #endif
40-#undef ONLY64
41-#endif
42-
43-/*----------------
44- STATIC FUNCTIONS
45- ----------------*/
46-inline static int idxof(int i);
47-inline static void gen_rand_array(sfmt_t * sfmt, w128_t *array, int size);
48-inline static uint32_t func1(uint32_t x);
49-inline static uint32_t func2(uint32_t x);
50-static void period_certification(sfmt_t * sfmt);
51-#if defined(BIG_ENDIAN64) && !defined(ONLY64)
52-inline static void swap(w128_t *array, int size);
53-#endif
54-
55-#if defined(HAVE_ALTIVEC)
56- #include "SFMT-alti.h"
57-#elif defined(HAVE_SSE2)
58-/**
59- * parameters used by sse2.
60- */
61- static const w128_t sse2_param_mask = {{SFMT_MSK1, SFMT_MSK2,
62- SFMT_MSK3, SFMT_MSK4}};
63- #if defined(_MSC_VER)
64- #include "SFMT-sse2-msc.h"
65- #else
66- #include "SFMT-sse2.h"
67- #endif
68-#elif defined(HAVE_NEON)
69- #include "SFMT-neon.h"
70-#endif
71-
72-/**
73- * This function simulate a 64-bit index of LITTLE ENDIAN
74- * in BIG ENDIAN machine.
75- */
76-#ifdef ONLY64
77-inline static int idxof(int i) {
78- return i ^ 1;
79-}
80-#else
81-inline static int idxof(int i) {
82- return i;
83-}
84-#endif
85-
86-#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2)) && (!defined(HAVE_NEON))
87-/**
88- * This function fills the user-specified array with pseudorandom
89- * integers.
90- *
91- * @param sfmt SFMT internal state
92- * @param array an 128-bit array to be filled by pseudorandom numbers.
93- * @param size number of 128-bit pseudorandom numbers to be generated.
94- */
95-inline static void gen_rand_array(sfmt_t * sfmt, w128_t *array, int size) {
96- int i, j;
97- w128_t *r1, *r2;
98-
99- r1 = &sfmt->state[SFMT_N - 2];
100- r2 = &sfmt->state[SFMT_N - 1];
101- for (i = 0; i < SFMT_N - SFMT_POS1; i++) {
102- do_recursion(&array[i], &sfmt->state[i], &sfmt->state[i + SFMT_POS1], r1, r2);
103- r1 = r2;
104- r2 = &array[i];
105- }
106- for (; i < SFMT_N; i++) {
107- do_recursion(&array[i], &sfmt->state[i],
108- &array[i + SFMT_POS1 - SFMT_N], r1, r2);
109- r1 = r2;
110- r2 = &array[i];
111- }
112- for (; i < size - SFMT_N; i++) {
113- do_recursion(&array[i], &array[i - SFMT_N],
114- &array[i + SFMT_POS1 - SFMT_N], r1, r2);
115- r1 = r2;
116- r2 = &array[i];
117- }
118- for (j = 0; j < 2 * SFMT_N - size; j++) {
119- sfmt->state[j] = array[j + size - SFMT_N];
120- }
121- for (; i < size; i++, j++) {
122- do_recursion(&array[i], &array[i - SFMT_N],
123- &array[i + SFMT_POS1 - SFMT_N], r1, r2);
124- r1 = r2;
125- r2 = &array[i];
126- sfmt->state[j] = array[i];
127- }
128-}
129-#endif
130-
131-#if defined(BIG_ENDIAN64) && !defined(ONLY64) && !defined(HAVE_ALTIVEC)
132-inline static void swap(w128_t *array, int size) {
133- int i;
134- uint32_t x, y;
135-
136- for (i = 0; i < size; i++) {
137- x = array[i].u[0];
138- y = array[i].u[2];
139- array[i].u[0] = array[i].u[1];
140- array[i].u[2] = array[i].u[3];
141- array[i].u[1] = x;
142- array[i].u[3] = y;
143- }
144-}
145-#endif
146-/**
147- * This function represents a function used in the initialization
148- * by init_by_array
149- * @param x 32-bit integer
150- * @return 32-bit integer
151- */
152-static uint32_t func1(uint32_t x) {
153- return (x ^ (x >> 27)) * (uint32_t)1664525UL;
154-}
155-
156-/**
157- * This function represents a function used in the initialization
158- * by init_by_array
159- * @param x 32-bit integer
160- * @return 32-bit integer
161- */
162-static uint32_t func2(uint32_t x) {
163- return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
164-}
165-
166-/**
167- * This function certificate the period of 2^{MEXP}
168- * @param sfmt SFMT internal state
169- */
170-static void period_certification(sfmt_t * sfmt) {
171- int inner = 0;
172- int i, j;
173- uint32_t work;
174- uint32_t *psfmt32 = &sfmt->state[0].u[0];
175- const uint32_t parity[4] = {SFMT_PARITY1, SFMT_PARITY2,
176- SFMT_PARITY3, SFMT_PARITY4};
177-
178- for (i = 0; i < 4; i++)
179- inner ^= psfmt32[idxof(i)] & parity[i];
180- for (i = 16; i > 0; i >>= 1)
181- inner ^= inner >> i;
182- inner &= 1;
183- /* check OK */
184- if (inner == 1) {
185- return;
186- }
187- /* check NG, and modification */
188- for (i = 0; i < 4; i++) {
189- work = 1;
190- for (j = 0; j < 32; j++) {
191- if ((work & parity[i]) != 0) {
192- psfmt32[idxof(i)] ^= work;
193- return;
194- }
195- work = work << 1;
196- }
197- }
198-}
199-
200-/*----------------
201- PUBLIC FUNCTIONS
202- ----------------*/
203-#define UNUSED_VARIABLE(x) (void)(x)
204-/**
205- * This function returns the identification string.
206- * The string shows the word size, the Mersenne exponent,
207- * and all parameters of this generator.
208- * @param sfmt SFMT internal state
209- */
210-const char *sfmt_get_idstring(sfmt_t * sfmt) {
211- UNUSED_VARIABLE(sfmt);
212- return SFMT_IDSTR;
213-}
214-
215-/**
216- * This function returns the minimum size of array used for \b
217- * fill_array32() function.
218- * @param sfmt SFMT internal state
219- * @return minimum size of array used for fill_array32() function.
220- */
221-int sfmt_get_min_array_size32(sfmt_t * sfmt) {
222- UNUSED_VARIABLE(sfmt);
223- return SFMT_N32;
224-}
225-
226-/**
227- * This function returns the minimum size of array used for \b
228- * fill_array64() function.
229- * @param sfmt SFMT internal state
230- * @return minimum size of array used for fill_array64() function.
231- */
232-int sfmt_get_min_array_size64(sfmt_t * sfmt) {
233- UNUSED_VARIABLE(sfmt);
234- return SFMT_N64;
235-}
236-
237-#if !defined(HAVE_SSE2) && !defined(HAVE_ALTIVEC) && !defined(HAVE_NEON)
238-/**
239- * This function fills the internal state array with pseudorandom
240- * integers.
241- * @param sfmt SFMT internal state
242- */
243-void sfmt_gen_rand_all(sfmt_t * sfmt) {
244- int i;
245- w128_t *r1, *r2;
246-
247- r1 = &sfmt->state[SFMT_N - 2];
248- r2 = &sfmt->state[SFMT_N - 1];
249- for (i = 0; i < SFMT_N - SFMT_POS1; i++) {
250- do_recursion(&sfmt->state[i], &sfmt->state[i],
251- &sfmt->state[i + SFMT_POS1], r1, r2);
252- r1 = r2;
253- r2 = &sfmt->state[i];
254- }
255- for (; i < SFMT_N; i++) {
256- do_recursion(&sfmt->state[i], &sfmt->state[i],
257- &sfmt->state[i + SFMT_POS1 - SFMT_N], r1, r2);
258- r1 = r2;
259- r2 = &sfmt->state[i];
260- }
261-}
262-#endif
263-
264-#ifndef ONLY64
265-/**
266- * This function generates pseudorandom 32-bit integers in the
267- * specified array[] by one call. The number of pseudorandom integers
268- * is specified by the argument size, which must be at least 624 and a
269- * multiple of four. The generation by this function is much faster
270- * than the following gen_rand function.
271- *
272- * For initialization, init_gen_rand or init_by_array must be called
273- * before the first call of this function. This function can not be
274- * used after calling gen_rand function, without initialization.
275- *
276- * @param sfmt SFMT internal state
277- * @param array an array where pseudorandom 32-bit integers are filled
278- * by this function. The pointer to the array must be \b "aligned"
279- * (namely, must be a multiple of 16) in the SIMD version, since it
280- * refers to the address of a 128-bit integer. In the standard C
281- * version, the pointer is arbitrary.
282- *
283- * @param size the number of 32-bit pseudorandom integers to be
284- * generated. size must be a multiple of 4, and greater than or equal
285- * to (MEXP / 128 + 1) * 4.
286- *
287- * @note \b memalign or \b posix_memalign is available to get aligned
288- * memory. Mac OSX doesn't have these functions, but \b malloc of OSX
289- * returns the pointer to the aligned memory block.
290- */
291-void sfmt_fill_array32(sfmt_t * sfmt, uint32_t *array, int size) {
292- assert(sfmt->idx == SFMT_N32);
293- assert(size % 4 == 0);
294- assert(size >= SFMT_N32);
295-
296- gen_rand_array(sfmt, (w128_t *)array, size / 4);
297- sfmt->idx = SFMT_N32;
298-}
299-#endif
300-
301-/**
302- * This function generates pseudorandom 64-bit integers in the
303- * specified array[] by one call. The number of pseudorandom integers
304- * is specified by the argument size, which must be at least 312 and a
305- * multiple of two. The generation by this function is much faster
306- * than the following gen_rand function.
307- *
308- * @param sfmt SFMT internal state
309- * For initialization, init_gen_rand or init_by_array must be called
310- * before the first call of this function. This function can not be
311- * used after calling gen_rand function, without initialization.
312- *
313- * @param array an array where pseudorandom 64-bit integers are filled
314- * by this function. The pointer to the array must be "aligned"
315- * (namely, must be a multiple of 16) in the SIMD version, since it
316- * refers to the address of a 128-bit integer. In the standard C
317- * version, the pointer is arbitrary.
318- *
319- * @param size the number of 64-bit pseudorandom integers to be
320- * generated. size must be a multiple of 2, and greater than or equal
321- * to (MEXP / 128 + 1) * 2
322- *
323- * @note \b memalign or \b posix_memalign is available to get aligned
324- * memory. Mac OSX doesn't have these functions, but \b malloc of OSX
325- * returns the pointer to the aligned memory block.
326- */
327-void sfmt_fill_array64(sfmt_t * sfmt, uint64_t *array, int size) {
328- assert(sfmt->idx == SFMT_N32);
329- assert(size % 2 == 0);
330- assert(size >= SFMT_N64);
331-
332- gen_rand_array(sfmt, (w128_t *)array, size / 2);
333- sfmt->idx = SFMT_N32;
334-
335-#if defined(BIG_ENDIAN64) && !defined(ONLY64)
336- swap((w128_t *)array, size /2);
337-#endif
338-}
339-
340-/**
341- * This function initializes the internal state array with a 32-bit
342- * integer seed.
343- *
344- * @param sfmt SFMT internal state
345- * @param seed a 32-bit integer used as the seed.
346- */
347-void sfmt_init_gen_rand(sfmt_t * sfmt, uint32_t seed) {
348- int i;
349-
350- uint32_t *psfmt32 = &sfmt->state[0].u[0];
351-
352- psfmt32[idxof(0)] = seed;
353- for (i = 1; i < SFMT_N32; i++) {
354- psfmt32[idxof(i)] = 1812433253UL * (psfmt32[idxof(i - 1)]
355- ^ (psfmt32[idxof(i - 1)] >> 30))
356- + i;
357- }
358- sfmt->idx = SFMT_N32;
359- period_certification(sfmt);
360-}
361-
362-/**
363- * This function initializes the internal state array,
364- * with an array of 32-bit integers used as the seeds
365- * @param sfmt SFMT internal state
366- * @param init_key the array of 32-bit integers, used as a seed.
367- * @param key_length the length of init_key.
368- */
369-void sfmt_init_by_array(sfmt_t * sfmt, uint32_t *init_key, int key_length) {
370- int i, j, count;
371- uint32_t r;
372- int lag;
373- int mid;
374- int size = SFMT_N * 4;
375- uint32_t *psfmt32 = &sfmt->state[0].u[0];
376-
377- if (size >= 623) {
378- lag = 11;
379- } else if (size >= 68) {
380- lag = 7;
381- } else if (size >= 39) {
382- lag = 5;
383- } else {
384- lag = 3;
385- }
386- mid = (size - lag) / 2;
387-
388- memset(sfmt, 0x8b, sizeof(sfmt_t));
389- if (key_length + 1 > SFMT_N32) {
390- count = key_length + 1;
391- } else {
392- count = SFMT_N32;
393- }
394- r = func1(psfmt32[idxof(0)] ^ psfmt32[idxof(mid)]
395- ^ psfmt32[idxof(SFMT_N32 - 1)]);
396- psfmt32[idxof(mid)] += r;
397- r += key_length;
398- psfmt32[idxof(mid + lag)] += r;
399- psfmt32[idxof(0)] = r;
400-
401- count--;
402- for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
403- r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % SFMT_N32)]
404- ^ psfmt32[idxof((i + SFMT_N32 - 1) % SFMT_N32)]);
405- psfmt32[idxof((i + mid) % SFMT_N32)] += r;
406- r += init_key[j] + i;
407- psfmt32[idxof((i + mid + lag) % SFMT_N32)] += r;
408- psfmt32[idxof(i)] = r;
409- i = (i + 1) % SFMT_N32;
410- }
411- for (; j < count; j++) {
412- r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % SFMT_N32)]
413- ^ psfmt32[idxof((i + SFMT_N32 - 1) % SFMT_N32)]);
414- psfmt32[idxof((i + mid) % SFMT_N32)] += r;
415- r += i;
416- psfmt32[idxof((i + mid + lag) % SFMT_N32)] += r;
417- psfmt32[idxof(i)] = r;
418- i = (i + 1) % SFMT_N32;
419- }
420- for (j = 0; j < SFMT_N32; j++) {
421- r = func2(psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % SFMT_N32)]
422- + psfmt32[idxof((i + SFMT_N32 - 1) % SFMT_N32)]);
423- psfmt32[idxof((i + mid) % SFMT_N32)] ^= r;
424- r -= i;
425- psfmt32[idxof((i + mid + lag) % SFMT_N32)] ^= r;
426- psfmt32[idxof(i)] = r;
427- i = (i + 1) % SFMT_N32;
428- }
429-
430- sfmt->idx = SFMT_N32;
431- period_certification(sfmt);
432-}
433-#if defined(__cplusplus)
434-}
435-#endif
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
--- trunk/teraterm/ttpmacro/SFMT.h (revision 6632)
+++ trunk/teraterm/ttpmacro/SFMT.h (nonexistent)
@@ -1,304 +0,0 @@
1-#pragma once
2-/**
3- * @file SFMT.h
4- *
5- * @brief SIMD oriented Fast Mersenne Twister(SFMT) pseudorandom
6- * number generator using C structure.
7- *
8- * @author Mutsuo Saito (Hiroshima University)
9- * @author Makoto Matsumoto (The University of Tokyo)
10- *
11- * Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima
12- * University.
13- * Copyright (C) 2012 Mutsuo Saito, Makoto Matsumoto, Hiroshima
14- * University and The University of Tokyo.
15- * All rights reserved.
16- *
17- * The 3-clause BSD License is applied to this software, see
18- * LICENSE.txt
19- *
20- * @note We assume that your system has inttypes.h. If your system
21- * doesn't have inttypes.h, you have to typedef uint32_t and uint64_t,
22- * and you have to define PRIu64 and PRIx64 in this file as follows:
23- * @verbatim
24- typedef unsigned int uint32_t
25- typedef unsigned long long uint64_t
26- #define PRIu64 "llu"
27- #define PRIx64 "llx"
28-@endverbatim
29- * uint32_t must be exactly 32-bit unsigned integer type (no more, no
30- * less), and uint64_t must be exactly 64-bit unsigned integer type.
31- * PRIu64 and PRIx64 are used for printf function to print 64-bit
32- * unsigned int and 64-bit unsigned int in hexadecimal format.
33- */
34-
35-#ifndef SFMTST_H
36-#define SFMTST_H
37-#if defined(__cplusplus)
38-extern "C" {
39-#endif
40-
41-#include <stdio.h>
42-#include <assert.h>
43-
44-#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
45- #include <inttypes.h>
46-#elif defined(_MSC_VER) || defined(__BORLANDC__)
47- typedef unsigned int uint32_t;
48- typedef unsigned __int64 uint64_t;
49- #define inline __inline
50-#else
51- #include <inttypes.h>
52- #if defined(__GNUC__)
53- #define inline __inline__
54- #endif
55-#endif
56-
57-#ifndef PRIu64
58- #if defined(_MSC_VER) || defined(__BORLANDC__)
59- #define PRIu64 "I64u"
60- #define PRIx64 "I64x"
61- #else
62- #define PRIu64 "llu"
63- #define PRIx64 "llx"
64- #endif
65-#endif
66-
67-#include "SFMT-params.h"
68-
69-/*------------------------------------------
70- 128-bit SIMD like data type for standard C
71- ------------------------------------------*/
72-#if defined(HAVE_ALTIVEC)
73- #if !defined(__APPLE__)
74- #include <altivec.h>
75- #endif
76-/** 128-bit data structure */
77-union W128_T {
78- vector unsigned int s;
79- uint32_t u[4];
80- uint64_t u64[2];
81-};
82-#elif defined(HAVE_NEON)
83- #include <arm_neon.h>
84-
85-/** 128-bit data structure */
86-union W128_T {
87- uint32_t u[4];
88- uint64_t u64[2];
89- uint32x4_t si;
90-};
91-#elif defined(HAVE_SSE2)
92- #include <emmintrin.h>
93-
94-/** 128-bit data structure */
95-union W128_T {
96- uint32_t u[4];
97- uint64_t u64[2];
98- __m128i si;
99-};
100-#else
101-/** 128-bit data structure */
102-union W128_T {
103- uint32_t u[4];
104- uint64_t u64[2];
105-};
106-#endif
107-
108-/** 128-bit data type */
109-typedef union W128_T w128_t;
110-
111-/**
112- * SFMT internal state
113- */
114-struct SFMT_T {
115- /** the 128-bit internal state array */
116- w128_t state[SFMT_N];
117- /** index counter to the 32-bit internal state array */
118- int idx;
119-};
120-
121-typedef struct SFMT_T sfmt_t;
122-
123-void sfmt_fill_array32(sfmt_t * sfmt, uint32_t * array, int size);
124-void sfmt_fill_array64(sfmt_t * sfmt, uint64_t * array, int size);
125-void sfmt_init_gen_rand(sfmt_t * sfmt, uint32_t seed);
126-void sfmt_init_by_array(sfmt_t * sfmt, uint32_t * init_key, int key_length);
127-const char * sfmt_get_idstring(sfmt_t * sfmt);
128-int sfmt_get_min_array_size32(sfmt_t * sfmt);
129-int sfmt_get_min_array_size64(sfmt_t * sfmt);
130-void sfmt_gen_rand_all(sfmt_t * sfmt);
131-
132-#ifndef ONLY64
133-/**
134- * This function generates and returns 32-bit pseudorandom number.
135- * init_gen_rand or init_by_array must be called before this function.
136- * @param sfmt SFMT internal state
137- * @return 32-bit pseudorandom number
138- */
139-inline static uint32_t sfmt_genrand_uint32(sfmt_t * sfmt) {
140- uint32_t r;
141- uint32_t * psfmt32 = &sfmt->state[0].u[0];
142-
143- if (sfmt->idx >= SFMT_N32) {
144- sfmt_gen_rand_all(sfmt);
145- sfmt->idx = 0;
146- }
147- r = psfmt32[sfmt->idx++];
148- return r;
149-}
150-#endif
151-/**
152- * This function generates and returns 64-bit pseudorandom number.
153- * init_gen_rand or init_by_array must be called before this function.
154- * The function gen_rand64 should not be called after gen_rand32,
155- * unless an initialization is again executed.
156- * @param sfmt SFMT internal state
157- * @return 64-bit pseudorandom number
158- */
159-inline static uint64_t sfmt_genrand_uint64(sfmt_t * sfmt) {
160-#if defined(BIG_ENDIAN64) && !defined(ONLY64)
161- uint32_t * psfmt32 = &sfmt->state[0].u[0];
162- uint32_t r1, r2;
163-#else
164- uint64_t r;
165-#endif
166- uint64_t * psfmt64 = &sfmt->state[0].u64[0];
167- assert(sfmt->idx % 2 == 0);
168-
169- if (sfmt->idx >= SFMT_N32) {
170- sfmt_gen_rand_all(sfmt);
171- sfmt->idx = 0;
172- }
173-#if defined(BIG_ENDIAN64) && !defined(ONLY64)
174- r1 = psfmt32[sfmt->idx];
175- r2 = psfmt32[sfmt->idx + 1];
176- sfmt->idx += 2;
177- return ((uint64_t)r2 << 32) | r1;
178-#else
179- r = psfmt64[sfmt->idx / 2];
180- sfmt->idx += 2;
181- return r;
182-#endif
183-}
184-
185-/* =================================================
186- The following real versions are due to Isaku Wada
187- ================================================= */
188-/**
189- * converts an unsigned 32-bit number to a double on [0,1]-real-interval.
190- * @param v 32-bit unsigned integer
191- * @return double on [0,1]-real-interval
192- */
193-inline static double sfmt_to_real1(uint32_t v)
194-{
195- return v * (1.0/4294967295.0);
196- /* divided by 2^32-1 */
197-}
198-
199-/**
200- * generates a random number on [0,1]-real-interval
201- * @param sfmt SFMT internal state
202- * @return double on [0,1]-real-interval
203- */
204-inline static double sfmt_genrand_real1(sfmt_t * sfmt)
205-{
206- return sfmt_to_real1(sfmt_genrand_uint32(sfmt));
207-}
208-
209-/**
210- * converts an unsigned 32-bit integer to a double on [0,1)-real-interval.
211- * @param v 32-bit unsigned integer
212- * @return double on [0,1)-real-interval
213- */
214-inline static double sfmt_to_real2(uint32_t v)
215-{
216- return v * (1.0/4294967296.0);
217- /* divided by 2^32 */
218-}
219-
220-/**
221- * generates a random number on [0,1)-real-interval
222- * @param sfmt SFMT internal state
223- * @return double on [0,1)-real-interval
224- */
225-inline static double sfmt_genrand_real2(sfmt_t * sfmt)
226-{
227- return sfmt_to_real2(sfmt_genrand_uint32(sfmt));
228-}
229-
230-/**
231- * converts an unsigned 32-bit integer to a double on (0,1)-real-interval.
232- * @param v 32-bit unsigned integer
233- * @return double on (0,1)-real-interval
234- */
235-inline static double sfmt_to_real3(uint32_t v)
236-{
237- return (((double)v) + 0.5)*(1.0/4294967296.0);
238- /* divided by 2^32 */
239-}
240-
241-/**
242- * generates a random number on (0,1)-real-interval
243- * @param sfmt SFMT internal state
244- * @return double on (0,1)-real-interval
245- */
246-inline static double sfmt_genrand_real3(sfmt_t * sfmt)
247-{
248- return sfmt_to_real3(sfmt_genrand_uint32(sfmt));
249-}
250-
251-/**
252- * converts an unsigned 32-bit integer to double on [0,1)
253- * with 53-bit resolution.
254- * @param v 32-bit unsigned integer
255- * @return double on [0,1)-real-interval with 53-bit resolution.
256- */
257-inline static double sfmt_to_res53(uint64_t v)
258-{
259- return (v >> 11) * (1.0/9007199254740992.0);
260-}
261-
262-/**
263- * generates a random number on [0,1) with 53-bit resolution
264- * @param sfmt SFMT internal state
265- * @return double on [0,1) with 53-bit resolution
266- */
267-inline static double sfmt_genrand_res53(sfmt_t * sfmt)
268-{
269- return sfmt_to_res53(sfmt_genrand_uint64(sfmt));
270-}
271-
272-
273-/* =================================================
274- The following function are added by Saito.
275- ================================================= */
276-/**
277- * generates a random number on [0,1) with 53-bit resolution from two
278- * 32 bit integers
279- */
280-inline static double sfmt_to_res53_mix(uint32_t x, uint32_t y)
281-{
282- return sfmt_to_res53(x | ((uint64_t)y << 32));
283-}
284-
285-/**
286- * generates a random number on [0,1) with 53-bit resolution
287- * using two 32bit integers.
288- * @param sfmt SFMT internal state
289- * @return double on [0,1) with 53-bit resolution
290- */
291-inline static double sfmt_genrand_res53_mix(sfmt_t * sfmt)
292-{
293- uint32_t x, y;
294-
295- x = sfmt_genrand_uint32(sfmt);
296- y = sfmt_genrand_uint32(sfmt);
297- return sfmt_to_res53_mix(x, y);
298-}
299-
300-#if defined(__cplusplus)
301-}
302-#endif
303-
304-#endif
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
--- trunk/teraterm/ttpmacro/SFMT-params.h (revision 6632)
+++ trunk/teraterm/ttpmacro/SFMT-params.h (nonexistent)
@@ -1,98 +0,0 @@
1-#pragma once
2-#ifndef SFMT_PARAMS_H
3-#define SFMT_PARAMS_H
4-
5-#if !defined(SFMT_MEXP)
6-#if defined(__GNUC__) && !defined(__ICC)
7- #warning "SFMT_MEXP is not defined. I assume MEXP is 19937."
8-#endif
9- #define SFMT_MEXP 19937
10-#endif
11-/*-----------------
12- BASIC DEFINITIONS
13- -----------------*/
14-/** Mersenne Exponent. The period of the sequence
15- * is a multiple of 2^MEXP-1.
16- * #define SFMT_MEXP 19937 */
17-/** SFMT generator has an internal state array of 128-bit integers,
18- * and N is its size. */
19-#define SFMT_N (SFMT_MEXP / 128 + 1)
20-/** N32 is the size of internal state array when regarded as an array
21- * of 32-bit integers.*/
22-#define SFMT_N32 (SFMT_N * 4)
23-/** N64 is the size of internal state array when regarded as an array
24- * of 64-bit integers.*/
25-#define SFMT_N64 (SFMT_N * 2)
26-
27-/*----------------------
28- the parameters of SFMT
29- following definitions are in paramsXXXX.h file.
30- ----------------------*/
31-/** the pick up position of the array.
32-#define SFMT_POS1 122
33-*/
34-
35-/** the parameter of shift left as four 32-bit registers.
36-#define SFMT_SL1 18
37- */
38-
39-/** the parameter of shift left as one 128-bit register.
40- * The 128-bit integer is shifted by (SFMT_SL2 * 8) bits.
41-#define SFMT_SL2 1
42-*/
43-
44-/** the parameter of shift right as four 32-bit registers.
45-#define SFMT_SR1 11
46-*/
47-
48-/** the parameter of shift right as one 128-bit register.
49- * The 128-bit integer is shifted by (SFMT_SL2 * 8) bits.
50-#define SFMT_SR21 1
51-*/
52-
53-/** A bitmask, used in the recursion. These parameters are introduced
54- * to break symmetry of SIMD.
55-#define SFMT_MSK1 0xdfffffefU
56-#define SFMT_MSK2 0xddfecb7fU
57-#define SFMT_MSK3 0xbffaffffU
58-#define SFMT_MSK4 0xbffffff6U
59-*/
60-
61-/** These definitions are part of a 128-bit period certification vector.
62-#define SFMT_PARITY1 0x00000001U
63-#define SFMT_PARITY2 0x00000000U
64-#define SFMT_PARITY3 0x00000000U
65-#define SFMT_PARITY4 0xc98e126aU
66-*/
67-
68-#if SFMT_MEXP == 607
69- #include "SFMT-params607.h"
70-#elif SFMT_MEXP == 1279
71- #include "SFMT-params1279.h"
72-#elif SFMT_MEXP == 2281
73- #include "SFMT-params2281.h"
74-#elif SFMT_MEXP == 4253
75- #include "SFMT-params4253.h"
76-#elif SFMT_MEXP == 11213
77- #include "SFMT-params11213.h"
78-#elif SFMT_MEXP == 19937
79- #include "SFMT-params19937.h"
80-#elif SFMT_MEXP == 44497
81- #include "SFMT-params44497.h"
82-#elif SFMT_MEXP == 86243
83- #include "SFMT-params86243.h"
84-#elif SFMT_MEXP == 132049
85- #include "SFMT-params132049.h"
86-#elif SFMT_MEXP == 216091
87- #include "SFMT-params216091.h"
88-#else
89-#if defined(__GNUC__) && !defined(__ICC)
90- #error "SFMT_MEXP is not valid."
91- #undef SFMT_MEXP
92-#else
93- #undef SFMT_MEXP
94-#endif
95-
96-#endif
97-
98-#endif /* SFMT_PARAMS_H */
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
--- trunk/teraterm/ttpmacro/SFMT-params19937.h (revision 6632)
+++ trunk/teraterm/ttpmacro/SFMT-params19937.h (nonexistent)
@@ -1,50 +0,0 @@
1-#pragma once
2-#ifndef SFMT_PARAMS19937_H
3-#define SFMT_PARAMS19937_H
4-
5-#define SFMT_POS1 122
6-#define SFMT_SL1 18
7-#define SFMT_SL2 1
8-#define SFMT_SR1 11
9-#define SFMT_SR2 1
10-#define SFMT_MSK1 0xdfffffefU
11-#define SFMT_MSK2 0xddfecb7fU
12-#define SFMT_MSK3 0xbffaffffU
13-#define SFMT_MSK4 0xbffffff6U
14-#define SFMT_PARITY1 0x00000001U
15-#define SFMT_PARITY2 0x00000000U
16-#define SFMT_PARITY3 0x00000000U
17-#define SFMT_PARITY4 0x13c9e684U
18-
19-
20-/* PARAMETERS FOR ALTIVEC */
21-#if defined(__APPLE__) /* For OSX */
22- #define SFMT_ALTI_SL1 \
23- (vector unsigned int)(SFMT_SL1, SFMT_SL1, SFMT_SL1, SFMT_SL1)
24- #define SFMT_ALTI_SR1 \
25- (vector unsigned int)(SFMT_SR1, SFMT_SR1, SFMT_SR1, SFMT_SR1)
26- #define SFMT_ALTI_MSK \
27- (vector unsigned int)(SFMT_MSK1, SFMT_MSK2, SFMT_MSK3, SFMT_MSK4)
28- #define SFMT_ALTI_MSK64 \
29- (vector unsigned int)(SFMT_MSK2, SFMT_MSK1, SFMT_MSK4, SFMT_MSK3)
30- #define SFMT_ALTI_SL2_PERM \
31- (vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
32- #define SFMT_ALTI_SL2_PERM64 \
33- (vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
34- #define SFMT_ALTI_SR2_PERM \
35- (vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
36- #define SFMT_ALTI_SR2_PERM64 \
37- (vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
38-#else /* For OTHER OSs(Linux?) */
39- #define SFMT_ALTI_SL1 {SFMT_SL1, SFMT_SL1, SFMT_SL1, SFMT_SL1}
40- #define SFMT_ALTI_SR1 {SFMT_SR1, SFMT_SR1, SFMT_SR1, SFMT_SR1}
41- #define SFMT_ALTI_MSK {SFMT_MSK1, SFMT_MSK2, SFMT_MSK3, SFMT_MSK4}
42- #define SFMT_ALTI_MSK64 {SFMT_MSK2, SFMT_MSK1, SFMT_MSK4, SFMT_MSK3}
43- #define SFMT_ALTI_SL2_PERM {1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
44- #define SFMT_ALTI_SL2_PERM64 {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
45- #define SFMT_ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
46- #define SFMT_ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
47-#endif /* For OSX */
48-#define SFMT_IDSTR "SFMT-19937:122-18-1-11-1:dfffffef-ddfecb7f-bffaffff-bffffff6"
49-
50-#endif /* SFMT_PARAMS19937_H */
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
Show on old repository browser