45 #if __GNUC__ > 3 && __GNUC_MINOR__ > 8
46 #pragma GCC diagnostic push
47 #pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"
64 halfBuff(0), numFlats(0)
66 int numEngines = numberOfEngines++;
69 buffer[i] = (
unsigned int)((numEngines+19780503
L*(i+1))& 0xffffffff);
75 for( i = 0; i < 10000; ++i)
flat();
80 halfBuff(0), numFlats(0)
87 halfBuff(0), numFlats(0)
89 for (
int i = 0; i <
numBuff; ++i) {
90 buffer[i] = (
unsigned int)seed&0xffffffff;
95 for (j = 0; j < numBuff*20; ++j) {
102 halfBuff(0), numFlats(0)
106 buffer[i] = (
unsigned int)((rowIndex + (i+1)*(colIndex+8))&0xffffffff);
110 redSpin = colIndex & 0xffffffff;
111 for( i = 0; i < 100; ++i)
flat();
118 unsigned int blkSpin =
buffer[redAngle] & 0xffffffff;
119 unsigned int boostResult = blkSpin ^
redSpin;
121 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
123 redSpin = (blkSpin +
numFlats++) & 0xffffffff;
132 for (
int i = 0; i < size; ++i) {
144 while (seeds[i] && i <
numBuff) {
159 std::ofstream outFile(filename, std::ios::out);
160 if (!outFile.bad()) {
162 std::vector<unsigned long>
v =
put();
163 for (
unsigned int i=0; i<v.size(); ++i) {
164 outFile << v[i] <<
"\n";
172 std::cerr <<
" -- Engine state remains unchanged\n";
176 std::vector<unsigned long>
v;
181 inFile.clear(std::ios::badbit | inFile.rdstate());
182 std::cerr <<
"\nRanshiEngine state (vector) description improper."
183 <<
"\nrestoreStatus has failed."
184 <<
"\nInput stream is probably mispositioned now." << std::endl;
195 for (
int i = 0; i <
numBuff; ++i) {
203 std::cout << std::setprecision(20) << std::endl;
204 std::cout <<
"----------- Ranshi engine status ----------" << std::endl;
205 std::cout <<
"Initial seed = " <<
theSeed << std::endl;
206 std::cout <<
"Current red spin = " <<
redSpin << std::endl;
207 std::cout <<
"Values produced = " <<
numFlats << std::endl;
208 std::cout <<
"Side of buffer = " << (
halfBuff ?
"upper" :
"lower")
210 std::cout <<
"Current buffer = " << std::endl;
211 for (
int i = 0; i <
numBuff; i+=4) {
213 <<
buffer[i] << std::setw(11) <<
buffer[i+1] << std::setw(11)
214 <<
buffer[i+2] << std::setw(11) <<
buffer[i+3] << std::endl;
216 std::cout <<
"-------------------------------------------" << std::endl;
219 RanshiEngine::operator double() {
223 RanshiEngine::operator float() {
224 unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
225 unsigned int blkSpin =
buffer[redAngle] & 0xffffffff;
227 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
229 redSpin = (blkSpin + numFlats++) & 0xffffffff;
230 halfBuff = numBuff/2 - halfBuff;
232 return float(blkSpin * twoToMinus_32());
235 RanshiEngine::operator
unsigned int() {
236 unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
237 unsigned int blkSpin =
buffer[redAngle] & 0xffffffff;
239 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
241 redSpin = (blkSpin + numFlats++) & 0xffffffff;
242 halfBuff = numBuff/2 - halfBuff;
248 char beginMarker[] =
"RanshiEngine-begin";
249 os << beginMarker <<
"\nUvec\n";
250 std::vector<unsigned long>
v =
put();
251 for (
unsigned int i=0; i<v.size(); ++i) {
258 std::vector<unsigned long>
v;
259 v.push_back (engineIDulong<RanshiEngine>());
260 for (
int i = 0; i <
numBuff; ++i) {
261 v.push_back(static_cast<unsigned long>(
buffer[i]));
263 v.push_back(static_cast<unsigned long>(
redSpin));
264 v.push_back(static_cast<unsigned long>(
numFlats));
265 v.push_back(static_cast<unsigned long>(
halfBuff));
276 if (strcmp(beginMarker,
"RanshiEngine-begin")) {
277 is.clear(std::ios::badbit | is.rdstate());
278 std::cerr <<
"\nInput mispositioned or"
279 <<
"\nRanshiEngine state description missing or"
280 <<
"\nwrong engine type found." << std::endl;
287 return "RanshiEngine-begin";
292 std::vector<unsigned long>
v;
297 is.clear(std::ios::badbit | is.rdstate());
298 std::cerr <<
"\nRanshiEngine state (vector) description improper."
299 <<
"\ngetState() has failed."
300 <<
"\nInput stream is probably mispositioned now." << std::endl;
312 for (
int i = 0; i <
numBuff; ++i) {
319 if (strcmp(endMarker,
"RanshiEngine-end")) {
320 is.clear(std::ios::badbit | is.rdstate());
321 std::cerr <<
"\nRanshiEngine state description incomplete."
322 <<
"\nInput stream is probably mispositioned now." << std::endl;
329 if ((v[0] & 0xffffffffUL) != engineIDulong<RanshiEngine>()) {
331 "\nRanshiEngine get:state vector has wrong ID word - state unchanged\n";
340 "\nRanshiEngine get:state vector has wrong length - state unchanged\n";
343 for (
int i = 0; i <
numBuff; ++i) {
355 #if __GNUC__ > 3 && __GNUC_MINOR__ > 8
356 #pragma GCC diagnostic pop