33 #define __MIXMAX_C // do NOT define it in your own program, just include mixmax.h
48 inline uint64_t
MULWU (uint64_t k){ (
void)k;
return 0;}
50 #error SPECIALMUL not undefined
60 Y[0] = ( tempV = sumtotOld);
61 myuint sumtot = Y[0], ovflow = 0;
66 tempP =
modadd(tempP,Y[i]);
69 tempP =
modadd(tempP , Y[i]);
70 tempV =
modadd(tempV , tempP);
73 sumtot += tempV;
if (sumtot < tempV) {ovflow++;}
77 Y[2] =
modadd( Y[2] , temp2 );
78 sumtot += temp2;
if (sumtot < temp2) {ovflow++;}
103 #if defined(__SSE__) && defined(USE_INLINE_ASM)
105 __asm__ (
"pxor %0, %0; "
122 for (i=0; i<(n/M); i++){
125 unsigned int rem=(n % M);
128 for (j=0; j< (rem); j++){
146 myuint sumtot = 0, ovflow = 0;
149 tempP =
modadd(tempP,Y[i]);
150 Y[i] = ( tempV =
modadd(tempV,tempP) );
151 sumtot += tempV;
if (sumtot < tempV) {ovflow++;}
156 Y[2] =
modadd( Y[2] , temp2 );
157 sumtot += temp2;
if (sumtot < temp2) {ovflow++;}
163 #if defined(__x86_64__) && defined(USE_INLINE_ASM)
166 __asm__ (
"addq %2, %0; "
203 for ( i=0; i <
N; i++){
205 sumtot += X->
V[(i)];
if (sumtot < X->V[(i)]) {ovflow++;}
216 for (i=0; i <
N; i++){
231 const myuint MULT64=6364136223846793005ULL;
235 fprintf(stderr,
" try seeding with nonzero seed next time!\n");
243 for (i=0; i <
N; i++){
244 l*=MULT64; l = (l << 32) ^ (l>>32);
246 sumtot += X->
V[(i)];
if (sumtot < X->V[(i)]) {ovflow++;}
256 for (i=0; i <
N; i++){
276 #if defined(__x86_64__)
277 inline myuint mod128(__uint128_t s){
285 temp = (__uint128_t)a*(__uint128_t)b + cum;
289 #else // on all other platforms, including 32-bit linux, PPC and PPC64 and all Windows
290 #define MASK32 0xFFFFFFFFULL
300 o = (o &
M61) + ((ph*ah)<<3) + ((ah*pl+al*ph + ((al*pl)>>32))>>29) ;
302 o = (o &
M61) + ((o>>61));
309 fprintf(X->
fh,
"mixmax state, file version 1.0\n" );
312 fprintf(X->
fh,
"%llu, ", X->
V[j] );
315 fprintf(X->
fh,
"}; " );
316 fprintf(X->
fh,
"counter=%u; ", X->
counter );
317 fprintf(X->
fh,
"sumtot=%llu;\n", X->
sumtot );
323 if( ( fin = fopen(filename,
"r") ) ){
330 fprintf(stderr,
"mixmax -> read_state: error reading file %s\n", filename);
336 if (!fscanf(fin,
"%llu", &X->
V[0]) ) {fprintf(stderr,
"mixmax -> read_state: error reading file %s\n", filename); exit(
ERROR_READING_STATE_FILE);}
340 if (!fscanf(fin,
", %llu", &vecVal) ) {fprintf(stderr,
"mixmax -> read_state: error reading vector component i=%d from file %s\n", i, filename); exit(
ERROR_READING_STATE_FILE);}
345 fprintf(stderr,
"mixmax -> read_state: Invalid state vector value= %llu"
346 " ( must be less than %llu ) "
347 " obtained from reading file %s\n"
353 unsigned int counter;
354 if (!fscanf( fin,
"}; counter=%u; ", &counter)){fprintf(stderr,
"mixmax -> read_state: error reading counter from file %s\n", filename); exit(
ERROR_READING_STATE_FILE);}
358 fprintf(stderr,
"mixmax -> read_state: Invalid counter = %d"
359 " Must be 0 <= counter < %u\n" , counter,
N);
365 if (!fscanf( fin,
"sumtot=%llu\n", &sumtot)){fprintf(stderr,
"mixmax -> read_state: error reading checksum from file %s\n", filename); exit(
ERROR_READING_STATE_FILE);}
367 if (X->
sumtot != sumtot) {
368 fprintf(stderr,
"mixmax -> checksum error while reading state from file %s - corrupted?\n", filename);
376 #define FUSEDMODMULVEC \
377 { for (i =0; i<N; i++){ \
378 cum[i] = fmodmulM61( cum[i], coeff , Y[i] ) ; \
384 #if ( ( (N==88)||(N==256) ||(N==1000) || (N==3150) ) && BITS==61 && SKIPISON!=0)
420 #include "mixmax_skip_N88.icc"
424 #include "mixmax_skip_N1000.icc"
426 #include "mixmax_skip_N3150.icc"
430 myID_t IDvec[4] = {streamID, runID, machineID, clusterID};
439 for (i=0; i<
N; i++) { Y[i] = Vin[i]; sumtot =
modadd( sumtot, Vin[i]); } ;
440 for (IDindex=0; IDindex<4; IDindex++) {
446 rowPtr = (
myuint*)skipMat[r + IDindex*8*
sizeof(
myID_t)];
448 for (i=0; i<
N; i++){ cum[i] = 0; }
456 for (i=0; i<
N; i++){ Y[i] = cum[i]; sumtot =
modadd( sumtot, cum[i]); } ;
462 for (i=0; i<
N; i++){ Vout[i] = Y[i]; sumtot =
modadd( sumtot, Y[i]); } ;
466 #warning For this N, we dont have the skipping coefficients yet, using alternative method to seed
473 Xin->
V[4] = (
myuint)clusterID << 5;
474 Xin->
V[5] = (
myuint)machineID << 7;
475 Xin->
V[6] = (
myuint)runID << 11;
476 Xin->
V[7] = (
myuint)streamID << 13;
rng_state_t * rng_copy(myuint *Y)
#define ERROR_READING_STATE_FILE
void branch_inplace(rng_state_t *Xin, myID_t *IDvec)
static const char * filename()
int rng_free(rng_state_t *X)
rng_state_t * rng_alloc()
double get_next_float(rng_state_t *X)
#define ARRAY_INDEX_OUT_OF_BOUNDS
myuint get_next(rng_state_t *X)
void seed_uniquestream(rng_state_t *Xin, myID_t clusterID, myID_t machineID, myID_t runID, myID_t streamID)
void seed_vielbein(rng_state_t *X, unsigned int index)
myuint fmodmulM61(myuint cum, myuint s, myuint a)
void read_state(rng_state_t *X, const char filename[])
#define ERROR_READING_STATE_CHECKSUM
void seed_spbox(rng_state_t *X, myuint seed)
void print_state(rng_state_t *X)
myuint apply_bigskip(myuint *Vout, myuint *Vin, myID_t clusterID, myID_t machineID, myID_t runID, myID_t streamID)
uint64_t MULWU(uint64_t k)
void iterate_and_fill_array(rng_state_t *X, double *array)
myuint precalc(rng_state_t *X)
myuint iterate_raw_vec(myuint *Y, myuint sumtotOld)
typedef void((*Func_t)())
int iterate(rng_state_t *X)
std::complex< float_v > Z
#define ERROR_READING_STATE_COUNTER
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
void fill_array(rng_state_t *X, unsigned int n, double *array)
myuint modadd(myuint foo, myuint bar)