bool isdupnonce(struct cgpu_info *cgpu, struct work *work, uint32_t nonce) { struct dupdata *dup = (struct dupdata *)(cgpu->dup_data); struct timeval now; bool unique = true; K_ITEM *item; if (!dup) return false; cgtime(&now); dup->checked++; K_WLOCK(dup->nfree_list); item = dup->nonce_list->tail; while (unique && item) { if (DATAN(item)->work_id == work->id && DATAN(item)->nonce == nonce) { unique = false; applog(LOG_WARNING, "%s%d: Duplicate nonce %08x", cgpu->drv->name, cgpu->device_id, nonce); } else item = item->prev; } if (unique) { item = k_unlink_head(dup->nfree_list); DATAN(item)->work_id = work->id; DATAN(item)->nonce = nonce; memcpy(&(DATAN(item)->when), &now, sizeof(now)); k_add_head(dup->nonce_list, item); } item = dup->nonce_list->tail; while (item && tdiff(&(DATAN(item)->when), &now) > dup->timelimit) { item = k_unlink_tail(dup->nonce_list); k_add_head(dup->nfree_list, item); item = dup->nonce_list->tail; } K_WUNLOCK(dup->nfree_list); if (!unique) dup->dup++; return !unique; }
int /* main(int argc, char *argv[]) */ whetstone_main() { /* used in the FORTRAN version */ long I; long N1, N2, N3, N4, N6, N7, N8, N9, N10, N11; double X1,X2,X3,X4,X,Y,Z; long LOOP; int II, JJ; /* added for this version */ long loopstart; long long startsec, finisec; float KIPS; int continuous; loopstart = 1000000; /* see the note about LOOP below */ loopstart = 250000; continuous = 0; II = 1; /* start at the first arg (temp use of II here) */ /* while (II < argc) { */ /* if (strncmp(argv[II], "-c", 2) == 0 || argv[II][0] == 'c') { */ /* continuous = 1; */ /* } else if (atol(argv[II]) > 0) { */ /* loopstart = atol(argv[II]); */ /* } else { */ /* fprintf(stderr, USAGE); */ /* return(1); */ /* } */ /* II++; */ /* } */ LCONT: /* C C Start benchmark timing at this point. C */ startsec = get_microsec();// time(0); /* C C The actual benchmark starts here. C */ T = .499975; T1 = 0.50025; T2 = 2.0; /* C C With loopcount LOOP=10, one million Whetstone instructions C will be executed in EACH MAJOR LOOP..A MAJOR LOOP IS EXECUTED C 'II' TIMES TO INCREASE WALL-CLOCK TIMING ACCURACY. C LOOP = 1000; */ LOOP = loopstart; II = 1; JJ = 1; IILOOP: N1 = 0; N2 = 12 * LOOP; N3 = 14 * LOOP; N4 = 345 * LOOP; N6 = 210 * LOOP; N7 = 32 * LOOP; N8 = 899 * LOOP; N9 = 616 * LOOP; N10 = 0; N11 = 93 * LOOP; /* C C Module 1: Simple identifiers C */ X1 = 1.0; X2 = -1.0; X3 = -1.0; X4 = -1.0; for (I = 1; I <= N1; I++) { X1 = (X1 + X2 + X3 - X4) * T; X2 = (X1 + X2 - X3 + X4) * T; X3 = (X1 - X2 + X3 + X4) * T; X4 = (-X1+ X2 + X3 + X4) * T; } #ifdef PRINTOUT IF (JJ==II)POUT(N1,N1,N1,X1,X2,X3,X4); #endif /* C C Module 2: Array elements C */ E1[1] = 1.0; E1[2] = -1.0; E1[3] = -1.0; E1[4] = -1.0; for (I = 1; I <= N2; I++) { E1[1] = ( E1[1] + E1[2] + E1[3] - E1[4]) * T; E1[2] = ( E1[1] + E1[2] - E1[3] + E1[4]) * T; E1[3] = ( E1[1] - E1[2] + E1[3] + E1[4]) * T; E1[4] = (-E1[1] + E1[2] + E1[3] + E1[4]) * T; } #ifdef PRINTOUT IF (JJ==II)POUT(N2,N3,N2,E1[1],E1[2],E1[3],E1[4]); #endif /* C C Module 3: Array as parameter C */ for (I = 1; I <= N3; I++) PA(E1); #ifdef PRINTOUT IF (JJ==II)POUT(N3,N2,N2,E1[1],E1[2],E1[3],E1[4]); #endif /* C C Module 4: Conditional jumps C */ J = 1; for (I = 1; I <= N4; I++) { if (J == 1) J = 2; else J = 3; if (J > 2) J = 0; else J = 1; if (J < 1) J = 1; else J = 0; } #ifdef PRINTOUT IF (JJ==II)POUT(N4,J,J,X1,X2,X3,X4); #endif /* C C Module 5: Omitted C Module 6: Integer arithmetic C */ J = 1; K = 2; L = 3; for (I = 1; I <= N6; I++) { J = J * (K-J) * (L-K); K = L * K - (L-J) * K; L = (L-K) * (K+J); E1[L-1] = J + K + L; E1[K-1] = J * K * L; } #ifdef PRINTOUT IF (JJ==II)POUT(N6,J,K,E1[1],E1[2],E1[3],E1[4]); #endif /* C C Module 7: Trigonometric functions C */ X = 0.5; Y = 0.5; for (I = 1; I <= N7; I++) { X = T * DATAN(T2*DSIN(X)*DCOS(X)/(DCOS(X+Y)+DCOS(X-Y)-1.0)); Y = T * DATAN(T2*DSIN(Y)*DCOS(Y)/(DCOS(X+Y)+DCOS(X-Y)-1.0)); } #ifdef PRINTOUT IF (JJ==II)POUT(N7,J,K,X,X,Y,Y); #endif /* C C Module 8: Procedure calls C */ X = 1.0; Y = 1.0; Z = 1.0; for (I = 1; I <= N8; I++) P3(X,Y,&Z); #ifdef PRINTOUT IF (JJ==II)POUT(N8,J,K,X,Y,Z,Z); #endif /* C C Module 9: Array references C */ J = 1; K = 2; L = 3; E1[1] = 1.0; E1[2] = 2.0; E1[3] = 3.0; for (I = 1; I <= N9; I++) P0(); #ifdef PRINTOUT IF (JJ==II)POUT(N9,J,K,E1[1],E1[2],E1[3],E1[4]); #endif /* C C Module 10: Integer arithmetic C */ J = 2; K = 3; for (I = 1; I <= N10; I++) { J = J + K; K = J + K; J = K - J; K = K - J - J; } #ifdef PRINTOUT IF (JJ==II)POUT(N10,J,K,X1,X2,X3,X4); #endif /* C C Module 11: Standard functions C */ X = 0.75; for (I = 1; I <= N11; I++) X = DSQRT(DEXP(DLOG(X)/T1)); #ifdef PRINTOUT IF (JJ==II)POUT(N11,J,K,X,X,X,X); #endif /* C C THIS IS THE END OF THE MAJOR LOOP. C */ if (++JJ <= II) goto IILOOP; /* C C Stop benchmark timing at this point. C */ finisec = get_microsec();// time(0); /* C---------------------------------------------------------------- C Performance in Whetstone KIP's per second is given by C C (100*LOOP*II)/TIME C C where TIME is in seconds. C-------------------------------------------------------------------- */ _printf("\n"); if (finisec-startsec <= 0) { _printf("Insufficient duration- Increase the LOOP count\n"); return(1); } _printf("Loops: %ld, Iterations: %d, Duration: %lld sec.\n", LOOP, II, (finisec-startsec)/1000000); KIPS = (100.0*LOOP*II)/((double)(finisec-startsec)/1000000.0); //(((double)(finisec-startsec)) / (double)CLOCKS_PER_SEC ); if (KIPS >= 1000.0){ _printf("C Converted Double Precision Whetstones: %.1f MIPS\n", KIPS/1000.0); } else{ _printf("C Converted Double Precision Whetstones: %.1f KIPS\n", KIPS); } if (continuous) goto LCONT; return(0); }
double XDATAN( double *arg ) { //============================ return( DATAN( *arg ) ); }
void FFT::fftStridedRadix2( Complex<T>* data, size_t n, size_t stride, bool backward ) { size_t i, k, l, klen, lstep; size_t mbit; float phi, tmp, dir = -1.0f; Complex<T> ctmp, ctmp2, cw, cwr; #define DATAN( x ) ( data[ ( x ) * stride ] ) if( n & ( n - 1 ) ) throw CVTException("data not power of 2!"); if( backward ) dir = 1.0f; /* do the bit reversal zero and n-1 hold their position */ mbit = n >> 1; /* highest bit occuring */ k = mbit; for( i = 1 ; i < n - 1; i++) { if ( i < k ) { ctmp = DATAN( i ); DATAN( i ) = DATAN( k ); DATAN( k ) = ctmp; } /* add 1, but from the left */ l = mbit; /* while highest bit set */ while ( k & l ) { /* unset: k &= ( l - 1 ); but we use k -= l; since there is no higher bit than l -> we save one op */ k -= l; l >>= 1; } /* set the highest bit not set*/ k |= l; } /* compute the butterfly */ for( klen = 1; klen < n; klen = lstep ) { lstep = klen << 1; phi = dir * ( Math::PI / ( float ) klen ); tmp = Math::sin( 0.5f * phi ); cwr.set( -2.0f * tmp * tmp, sin( phi ) ); cw.set( 1.0f, 0.0f ); for( k = 0; k < klen; k++ ) { /* We use a trigonometric recurrence outisde of the loop to calculate cw.re = cos( M_PI * ( float ) dir * ( float ) k / ( float ) klen ); cw.im = sin( M_PI * ( float ) dir * ( float ) k / ( float ) klen ); */ for( l = k; l < n; l += lstep ) { ctmp = DATAN( l ); ctmp2 = DATAN( l + klen ) * cw; DATAN( l ) += ctmp2; ctmp -= ctmp2; DATAN( l + klen ) = ctmp; } ctmp = cw; ctmp *= cwr; cw += ctmp; } } if( backward ) { tmp = 1.0f / ( float ) n; for( i = 0 ; i < n; i++) DATAN( i ) *= tmp; } #undef DATAN }