Skip to content

Commit 0e2bb13

Browse files
committed
make format
1 parent b3c1cef commit 0e2bb13

File tree

1 file changed

+103
-104
lines changed

1 file changed

+103
-104
lines changed

libs/libvtrutil/src/specrand.cpp

Lines changed: 103 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,86 @@
11
/*
22
* * For inclusion in the SPEC cpu benchmarks
3-
* This file implements the random number generation necessary for the SPEC cpu benchmarks. The functions
4-
* defined here are used in vtr_random.h/cpp
5-
6-
7-
A C-program for MT19937, with initialization improved 2002/1/26.
8-
Coded by Takuji Nishimura and Makoto Matsumoto.
9-
10-
Before using, initialize the state by using init_genrand(seed)
11-
or init_by_array(init_key, key_length).
12-
13-
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
14-
All rights reserved.
15-
Copyright (C) 2005, Mutsuo Saito,
16-
All rights reserved.
17-
18-
Redistribution and use in source and binary forms, with or without
19-
modification, are permitted provided that the following conditions
20-
are met:
21-
22-
1. Redistributions of source code must retain the above copyright
23-
notice, this list of conditions and the following disclaimer.
24-
25-
2. Redistributions in binary form must reproduce the above copyright
26-
notice, this list of conditions and the following disclaimer in the
27-
documentation and/or other materials provided with the distribution.
28-
29-
3. The names of its contributors may not be used to endorse or promote
30-
products derived from this software without specific prior written
31-
permission.
32-
33-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44-
45-
46-
Any feedback is very welcome.
47-
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
48-
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
49-
*/
3+
* This file implements the random number generation necessary for the SPEC cpu benchmarks. The functions
4+
* defined here are used in vtr_random.h/cpp
5+
*
6+
*
7+
* A C-program for MT19937, with initialization improved 2002/1/26.
8+
* Coded by Takuji Nishimura and Makoto Matsumoto.
9+
*
10+
* Before using, initialize the state by using init_genrand(seed)
11+
* or init_by_array(init_key, key_length).
12+
*
13+
* Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
14+
* All rights reserved.
15+
* Copyright (C) 2005, Mutsuo Saito,
16+
* All rights reserved.
17+
*
18+
* Redistribution and use in source and binary forms, with or without
19+
* modification, are permitted provided that the following conditions
20+
* are met:
21+
*
22+
* 1. Redistributions of source code must retain the above copyright
23+
* notice, this list of conditions and the following disclaimer.
24+
*
25+
* 2. Redistributions in binary form must reproduce the above copyright
26+
* notice, this list of conditions and the following disclaimer in the
27+
* documentation and/or other materials provided with the distribution.
28+
*
29+
* 3. The names of its contributors may not be used to endorse or promote
30+
* products derived from this software without specific prior written
31+
* permission.
32+
*
33+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44+
*
45+
*
46+
* Any feedback is very welcome.
47+
* http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
48+
* email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
49+
*/
5050
/* Slightly modified for use in SPEC CPU by Cloyce D. Spradling (5 Nov 2009)
5151
*/
5252

5353
#include "specrand.h"
5454

55-
/* Period parameters */
55+
/* Period parameters */
5656
#define N 624
5757
#define M 397
5858
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
5959
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
6060
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
6161

6262
static unsigned long mt[N]; /* the array for the state vector */
63-
static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
63+
static int mti = N + 1; /* mti==N+1 means mt[N] is not initialized */
6464

6565
void spec_srand(int seed) {
66-
spec_init_genrand((unsigned long) seed);
66+
spec_init_genrand((unsigned long)seed);
6767
}
6868

6969
/* Just a copy of spec_genrand_real2() */
7070
double spec_rand() {
71-
return spec_genrand_int32()*(1.0/4294967296.0);
71+
return spec_genrand_int32() * (1.0 / 4294967296.0);
7272
}
7373

7474
/* Just a copy of spec_genrand_int31() */
7575
long spec_lrand48() {
76-
return (long)(spec_genrand_int32()>>1);
76+
return (long)(spec_genrand_int32() >> 1);
7777
}
7878

7979
/* initializes mt[N] with a seed */
80-
void spec_init_genrand(unsigned long s)
81-
{
82-
mt[0]= s & 0xffffffffUL;
83-
for (mti=1; mti<N; mti++) {
84-
mt[mti] =
85-
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
80+
void spec_init_genrand(unsigned long s) {
81+
mt[0] = s & 0xffffffffUL;
82+
for (mti = 1; mti < N; mti++) {
83+
mt[mti] = (1812433253UL * (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + mti);
8684
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
8785
/* In the previous versions, MSBs of the seed affect */
8886
/* only MSBs of the array mt[]. */
@@ -96,58 +94,64 @@ void spec_init_genrand(unsigned long s)
9694
/* init_key is the array for initializing keys */
9795
/* key_length is its length */
9896
/* slight change for C++, 2004/2/26 */
99-
void spec_init_by_array(unsigned long init_key[], int key_length)
100-
{
97+
void spec_init_by_array(unsigned long init_key[], int key_length) {
10198
int i, j, k;
10299
spec_init_genrand(19650218UL);
103-
i=1; j=0;
104-
k = (N>key_length ? N : key_length);
100+
i = 1;
101+
j = 0;
102+
k = (N > key_length ? N : key_length);
105103
for (; k; k--) {
106-
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
107-
+ init_key[j] + j; /* non linear */
108-
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
109-
i++; j++;
110-
if (i>=N) { mt[0] = mt[N-1]; i=1; }
111-
if (j>=key_length) j=0;
104+
mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1664525UL))
105+
+ init_key[j] + j; /* non linear */
106+
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
107+
i++;
108+
j++;
109+
if (i >= N) {
110+
mt[0] = mt[N - 1];
111+
i = 1;
112+
}
113+
if (j >= key_length) j = 0;
112114
}
113-
for (k=N-1; k; k--) {
114-
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
115-
- i; /* non linear */
115+
for (k = N - 1; k; k--) {
116+
mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1566083941UL))
117+
- i; /* non linear */
116118
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
117119
i++;
118-
if (i>=N) { mt[0] = mt[N-1]; i=1; }
120+
if (i >= N) {
121+
mt[0] = mt[N - 1];
122+
i = 1;
123+
}
119124
}
120125

121-
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
126+
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
122127
}
123128

124129
/* generates a random number on [0,0xffffffff]-interval */
125-
unsigned long spec_genrand_int32()
126-
{
130+
unsigned long spec_genrand_int32() {
127131
unsigned long y;
128-
static unsigned long mag01[2]={0x0UL, MATRIX_A};
132+
static unsigned long mag01[2] = {0x0UL, MATRIX_A};
129133
/* mag01[x] = x * MATRIX_A for x=0,1 */
130134

131135
if (mti >= N) { /* generate N words at one time */
132136
int kk;
133137

134-
if (mti == N+1) /* if init_genrand() has not been called, */
138+
if (mti == N + 1) /* if init_genrand() has not been called, */
135139
spec_init_genrand(5489UL); /* a default initial seed is used */
136140

137-
for (kk=0;kk<N-M;kk++) {
138-
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
139-
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
141+
for (kk = 0; kk < N - M; kk++) {
142+
y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
143+
mt[kk] = mt[kk + M] ^ (y >> 1) ^ mag01[y & 0x1UL];
140144
}
141-
for (;kk<N-1;kk++) {
142-
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
143-
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
145+
for (; kk < N - 1; kk++) {
146+
y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
147+
mt[kk] = mt[kk + (M - N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
144148
}
145-
y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
146-
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
149+
y = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
150+
mt[N - 1] = mt[M - 1] ^ (y >> 1) ^ mag01[y & 0x1UL];
147151

148152
mti = 0;
149153
}
150-
154+
151155
y = mt[mti++];
152156

153157
/* Tempering */
@@ -160,36 +164,31 @@ unsigned long spec_genrand_int32()
160164
}
161165

162166
/* generates a random number on [0,0x7fffffff]-interval */
163-
long spec_genrand_int31()
164-
{
165-
return (long)(spec_genrand_int32()>>1);
167+
long spec_genrand_int31() {
168+
return (long)(spec_genrand_int32() >> 1);
166169
}
167170

168171
/* generates a random number on [0,1]-real-interval */
169-
double spec_genrand_real1()
170-
{
171-
return spec_genrand_int32()*(1.0/4294967295.0);
172-
/* divided by 2^32-1 */
172+
double spec_genrand_real1() {
173+
return spec_genrand_int32() * (1.0 / 4294967295.0);
174+
/* divided by 2^32-1 */
173175
}
174176

175177
/* generates a random number on [0,1)-real-interval */
176-
double spec_genrand_real2()
177-
{
178-
return spec_genrand_int32()*(1.0/4294967296.0);
178+
double spec_genrand_real2() {
179+
return spec_genrand_int32() * (1.0 / 4294967296.0);
179180
/* divided by 2^32 */
180181
}
181182

182183
/* generates a random number on (0,1)-real-interval */
183-
double spec_genrand_real3()
184-
{
185-
return (((double)spec_genrand_int32()) + 0.5)*(1.0/4294967296.0);
184+
double spec_genrand_real3() {
185+
return (((double)spec_genrand_int32()) + 0.5) * (1.0 / 4294967296.0);
186186
/* divided by 2^32 */
187187
}
188188

189189
/* generates a random number on [0,1) with 53-bit resolution*/
190-
double spec_genrand_res53()
191-
{
192-
unsigned long a=spec_genrand_int32()>>5, b=spec_genrand_int32()>>6;
193-
return(a*67108864.0+b)*(1.0/9007199254740992.0);
194-
}
190+
double spec_genrand_res53() {
191+
unsigned long a = spec_genrand_int32() >> 5, b = spec_genrand_int32() >> 6;
192+
return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0);
193+
}
195194
/* These real versions are due to Isaku Wada, 2002/01/09 added */

0 commit comments

Comments
 (0)