void readHexDigitsInBinaryFormat(FILE *fp) { int i, done, num_0s, num_1s, bitsRead; BYTE buffer[4]; if ( (epsilon = (BitSequence *) calloc(tp.n,sizeof(BitSequence))) == NULL ) { printf("BITSTREAM DEFINITION: Insufficient memory available.\n"); return; } printf(" Statistical Testing In Progress.........\n\n"); for ( i=0; i<tp.numOfBitStreams; i++ ) { num_0s = 0; num_1s = 0; bitsRead = 0; done = 0; do { if ( fread(buffer, sizeof(unsigned char), 4, fp) != 4 ) { printf("READ ERROR: Insufficient data in file.\n"); free(epsilon); return; } done = convertToBits(buffer, 32, tp.n, &num_0s, &num_1s, &bitsRead); } while ( !done ); fprintf(freqfp, "\t\tBITSREAD = %d 0s = %d 1s = %d\n", bitsRead, num_0s, num_1s); nist_test_suite(); } free(epsilon); }
void PTPSoCTestJigInterface2::customEvent(QEvent *eve) { unsigned int l_nRegisterValue; unsigned int reads; if (eve->type() == GpioEvent) { l_nRegisterValue = IBackPlane->readBackPlaneRegister(0x001E); IBackPlane->writeBackPlaneRegister(0x0900, 0x001E); qDebug() << "data read at 1E is" << hex << l_nRegisterValue; IPsoc->writeSerial(0x01); usleep(1000); reads = IPsoc->readSerial(); convertToBits((unsigned char) reads, 5); qDebug() << "Inside GPIO EMBEDDED PROBE" << hex << m_nGPIOCode; IBackPlane->writeBackPlaneRegister(0x0001, 0x0024); } QEvent(eve->type()); }
int main () { int n = 3; printf("convert %d to bits: %d\n", n, convertToBits(n)); printf("7 & 3 = %d\n", n&convertToBits(n)); }
//In this function, we access the cache with a particular address. //If the address results in a hit, return 1. If it is a miss, return 0. int accessCache(void *cache, int address) { //my currently myCache cache Cache* myCache = (Cache*)cache; //type of cache myCache switch(myCache->type) { case 0: { //values probablyb not needed int blocksize = myCache->blocksize; int cachesize = myCache->cachesize; //total offset only used for shifting in this case int total_offset = myCache->total_offset; //index_size used for shifting int index_size = myCache->index_size; //index_mask used for masking int index_mask = convertToBits(index_size); //tag size used for shifting int tag_size = myCache->tag_size; //tag_mask used for masking int tag_mask = convertToBits(tag_size); //shifting and masking the index int index = (address >> total_offset) & index_mask; index %= myCache->nblocks; //shifting and masking the address int tag = address >> (total_offset+index_size); //accesses myCache->accesses++; //determining hit or miss increase the count if (myCache->direct_tags[index] == tag) { return 1; } else { //sets the tag for the array myCache->direct_tags[index] = tag; //increment miss myCache->misses++; return 0; } break; } case 1: { //values probablyb not needed int blocksize = myCache->blocksize; int cachesize = myCache->cachesize; //total offset only used for shifting in this case int total_offset = myCache->total_offset; //index_size used for shifting int index_size = myCache->index_size; //index_mask used for masking int index_mask = convertToBits(index_size); //tag size used for shifting int tag_size = myCache->tag_size; //tag_mask used for masking int tag_mask = convertToBits(tag_size); //shifting and masking the index int index = (address >> total_offset) & index_mask; index %= myCache->nblocks; //shifting and masking the address int tag = address >> (total_offset+index_size); //accesses myCache->accesses++; //determining hit or miss increase the count if (myCache->pseudo_tags1[index] == tag) { // myCache->accesses++; //updates which of the arrays were last updated return 1; } else if (myCache->pseudo_tags2[index] == tag) { //updates which of the arrays were last updated int temp = myCache->pseudo_tags1[index]; myCache->pseudo_tags1[index] = myCache->pseudo_tags2[index]; myCache->pseudo_tags2[index] = temp; // myCache->accesses+=2; return 1; } else { // myCache->accesses+=2; //evaluates which pseudo-set to store the tag in if (myCache->pseudo_tags1[index] == -1) { //sets the tag for the array myCache->pseudo_tags1[index] = tag; } else if (myCache->pseudo_tags2[index] == -1) { myCache->pseudo_tags2[index] = tag; } else { myCache->pseudo_tags2[index] = myCache->pseudo_tags1[index]; myCache->pseudo_tags1[index] = tag; } //increment miss myCache->misses++; return 0; } break; } case 2: { break; } } }