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
|
/* -*- mode: C; tab-width: 2; indent-tabs-mode: nil; -*-
*
* This file provides utility functions for the RandomAccess benchmark suite.
*/
#include <hpcc.h>
#include "RandomAccess.h"
/* Utility routine to start random number generator at Nth step */
u64Int
HPCC_starts(s64Int n)
{
int i, j;
u64Int m2[64];
u64Int temp, ran;
while (n < 0) n += PERIOD;
while (n > PERIOD) n -= PERIOD;
if (n == 0) return 0x1;
temp = 0x1;
for (i=0; i<64; i++) {
m2[i] = temp;
temp = (temp << 1) ^ ((s64Int) temp < 0 ? POLY : 0);
temp = (temp << 1) ^ ((s64Int) temp < 0 ? POLY : 0);
}
for (i=62; i>=0; i--)
if ((n >> i) & 1)
break;
ran = 0x2;
while (i > 0) {
temp = 0;
for (j=0; j<64; j++)
if ((ran >> j) & 1)
temp ^= m2[j];
ran = temp;
i -= 1;
if ((n >> i) & 1)
ran = (ran << 1) ^ ((s64Int) ran < 0 ? POLY : 0);
}
return ran;
}
/* Utility routine to start LCG random number generator at Nth step */
u64Int
HPCC_starts_LCG(s64Int n)
{
u64Int mul_k, add_k, ran, un;
mul_k = LCG_MUL64;
add_k = LCG_ADD64;
ran = 1;
for (un = (u64Int)n; un; un >>= 1) {
if (un & 1)
ran = mul_k * ran + add_k;
add_k *= (mul_k + 1);
mul_k *= mul_k;
}
return ran;
}
|