PCFOP * read_instr(struct PCFState * st, const char * line, uint32_t iptr) { char buf[LINE_MAX], *bitr; buf[0] = '\0'; bitr = buf; assert(line[0] == '('); line++; while((line[0] != ' ') && (line[0] != ')')) { bitr[0] = line[0]; line++; bitr++; } bitr[0] = '\0'; if(strcmp(buf, "LABEL") == 0) return read_label(line, st, iptr); else if(strcmp(buf, "INITBASE") == 0) return read_initbase(line); else if(strcmp(buf, "CONST") == 0) return read_const(line); else if(strcmp(buf, "GATE") == 0) return read_gate(line); else if(strcmp(buf, "BITS") == 0) return read_bits(line); else if(strcmp(buf, "MKPTR") == 0) return read_mkptr(line); else if(strcmp(buf, "COPY") == 0) return read_copy(line); else if(strcmp(buf, "COPY-INDIR") == 0) return read_copy_indir(line); else if(strcmp(buf, "INDIR-COPY") == 0) return read_indir_copy(line); else if(strcmp(buf, "CALL") == 0) return read_call(line); else if(strcmp(buf, "RET") == 0) return read_ret(line); else if(strcmp(buf, "BRANCH") == 0) return read_branch(line); else if(strcmp(buf, "CLEAR") == 0) return read_clear(line); else if(strcmp(buf, "JOIN") == 0) return read_join(line); else if(strcmp(buf, "ADD") == 0) return read_add(line); else if(strcmp(buf, "MUL") == 0) return read_mul(line); assert(0); }
int main (int argc, char * argv[]) { long mis_preds = 0; long num_branches = 0; uint32_t pc = 0; bool outcome = false; // Initialize the predictor init_predictor (); if (argc == 2) setup_trace (argv[1]); else setup_trace (NULL); // Read the number of instructions from the trace uint32_t stat_num_insts = 0; if (fread (&stat_num_insts, sizeof (uint32_t), 1, stream) != 1) { printf ("Could not read intput file\n"); return 1; } stat_num_insts = ntohl (stat_num_insts); // Read each branch from the trace while (read_branch (&pc, &outcome)) { pc = ntohl (pc); num_branches ++; // Make a prediction and compare with actual outcome if (make_prediction (pc) != outcome) mis_preds ++; // Train the predictor train_predictor (pc, outcome); } // Print out the mispredict statistics printf ("Branches\t\t%10d\n", num_branches); printf ("Incorrect\t\t%10d\n", mis_preds); float mis_pred_rate = 100*(float)mis_preds / float(num_branches); printf ("100*wrong_predicts/total branches is %8d / %8d = %7.3f\n", mis_preds, num_branches, mis_pred_rate); if (argc == 2) close_trace (); return 0; }
void init_predictor (){ int i=0; int num_of_unique_branches=0; int list_of_PC[MAX_NUM_OF_BRANCHES]; int curr_index=0; while (read_branch (&pc, &outcome)) { pc = ntohl (pc); if(!is_PC_exist(pc, &list_of_PC)){ list_of_PC[curr_index++] = pc; num_of_unique_branches++;} } printf("\n The num of unique branches is %d\n", num_of_unique_branches); int pht_size=28672/num_of_unique_branches; for }