0% found this document useful (0 votes)
5 views

ACA compre cheat

advance architecture
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

ACA compre cheat

advance architecture
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Inst.

opcode ALUOp I operation Funct field ALU action ALUCtrl


100010 (LW) 00 load word xxxxxx add 0010
100011 (SW) 00 store word xxxxxx add 0010
000100 (BEQ) 01 branch equal xxxxxx subtract 0110
000000 (R-typ) 10 add 100000 add 0010
R-type 10 Subtract 100010 subtract 0110
R-type 10 AND 100100 AND 0000
R-type 10 OR 100101 OR 0001
R-type 10 slt 101010 slt 0111
001000 (addi) 00 Immediate xxxxxx add xxxx
000010 (j) xx jump xxxxxx jump xxxx
cycles cycleshit cyclesmiss
CPI = = +
inst inst inst
cycleshit cycles miss
= + 
inst miss inst
cycleshit
= + Miss _ penalty  Miss _ rate
inst
######zerone ########fibbb######## prompt: .asciiz "Enter the prediction = 1; } for (int i = 0; i < if (outcome) { return 0; }} &address) != EOF) {
`include .data n: " return prediction;} N_ROWS_BTB; i++) { predictStat[indxBTB][1]++; if (branchPredictor[pc] int calculateCacheHitRate() accessCache(address); }
"system_under_test.v" Entervalue:.asciiz "Enter a element_prompt:.asciiz void predictStat[i] = (int } < (1 << N_BITS) - 1) { int hits = 0; fclose(traceFile); return 0; }
`timescale 1ns / 1ps number (N): " "Enter ele" updateNbitPredictor(int n, *)malloc(2 * sizeof(int)); branchPredictor[pc]++; int totalAccesses = 1000; void initializeCache(int
module testbench(); isFibMsg:.asciiz " Given newline: .asciiz "\n" int *currState, int predictStat[i][0] = 0; predictStat[indxBTB][0]++; } else { if for (int i = 0; i < cacheSize, int blockSize) {
reg clk; number is a Fibonacci array: .space 100 actualOutcome) { predictStat[i][1] = 0; } } (branchPredictor[pc] > 0) totalAccesses; i++) { int numBlocks = cacheSize /
reg [1:0] in_data; number " .text int maxState, pivotState; fp = #######branchless c#### branchPredictor[pc]--; hits += blockSize; for (int i = 0; i <
wire out; notFibMsg:.asciiz " Given main: maxState = pow(2, n) - 1; fopen(BOUTCOME_FILE, #include <stdio.h> }} getCacheEntryStatus(); } numBlocks; i++) {
system_under_test dut ( number is not a Fibonacci li $v0, 4 pivotState = maxState / 2; "r"); int main() { int hitRate = (hits * 100) cache[i].valid = 0;
.clk(clk), number." la $a0, prompt if (actualOutcome == 1) { predictStat = (int void countAndPrint(int initPredictor(); / totalAccesses; cache[i].tag = -1;
.in_data(in_data), positionInd:.asciiz " and its syscall if (*currState < **)malloc(pow(2, *sets, int size, int item) { FILE *fp; return hitRate;} cache[i].sctr = 0; } }
.out(out) Position Index in Fibonacci li $v0, 5 maxState) { *currState = N_BITS_PC_2LEVEL) * int countLarger = 0; fp = fopen("btrace.txt", int main() { void accessCache(int
); sequence is : " syscall *currState + 1; } sizeof(int *)); int countSmaller = 0; "r"); if (fp == NULL) { printf("Cache entry address) { int tag = address
always #5 clk = ~clk; .text move $t1, $v0 } else { for (int i = 0; i < pow(2, printf("Error opening status: %s\n", / blockSize; int index = tag
initial begin main: li $t0, 0 if (*currState > 0) { N_BITS_PC_2LEVEL); i++) { for (int i = 0; i < size; i++) file.\n"); getCacheEntryStatus() ? % (cacheSize / blockSize); if
clk = 1; li $v0, 4 la $t2, array *currState = *currState predictStat[i] = (int { return 1; } "Hit" : "Miss"); (cache[index].valid &&
in_data = 2'b00; la $a0, Entervalue read_loop: - 1;}}} *)malloc(2 * sizeof(int)); int diff = sets[i] - item; int pc, outcome; printf("Cache hit rate: cache[index].tag == tag) {
#10 in_data = 2'b01; syscall beq $t0, $t1, print_array //2bitpredictor predictStat[i][0] = 0; countLarger += (diff >> while (fscanf(fp, "B %d%%\n", updateSctr(tag, 1); } else {
#10 in_data = 2'b10; li $v0, 5 addi $t3, $t0, 1 int **LHT_2Level = NULL; predictStat[i][1] = 0; } 31) & 1; %d\t%d", &pc, &outcome) calculateCacheHitRate()); replaceBlock(address); } }
#10 in_data = 2'b11; syscall li $v0, 4 void initLHT2Level(void) { initBTB(); countSmaller += (~diff != EOF) { return 0;} void updateSctr(int tag, int
#10 $finish; move $t0, $v0 la $a0, element_prompt int noEntry = pow(2, initLHT2Level(); >> 31) & 1; } int prediction = #######hybridcache2bsctr hit) { int index = tag %
end li $t1, 0 syscall N_BITS_PC_2LEVEL); BTBLastIndx = -1; printf("Number of getPrediction(pc); #include <stdio.h> (cacheSize / blockSize); int
always @(posedge clk) li $t2, 1 li $v0, 5 int noInfo = 2; //[0] for while (1) { elements larger than %d: updatePred(pc, #include <stdlib.h> sctr = cache[index].sctr; if
begin li $t3, 1 syscall histroy and [1] for BPs fscanf(fp, "%x", &pc); %d\n", item, countLarger); outcome); } #define MAX_CACHE_SIZE (hit) { if (sctr < 3) {
$display("Time: %0t, li $t4, 2 sw $v0, 0($t2) LHT_2Level = new int fscanf(fp, "%s", printf("Number of fclose(fp); 1024 cache[index].sctr++; } } else
Output: %b", $time, out); check_fibonacci: addi $t2, $t2, 4 *[noEntry]; outcome); elements smaller than %d: return 0; } #define MAX_BLOCK_SIZE { if (sctr > 0) {
end beq $t0, $t3, addi $t0, $t0, 1 for (int i = 0; i < noEntry; if (fgetc(fp) == EOF) %d\n", item, ########### percOfhits## 64 cache[index].sctr--; } } }
endmodule found_fibonacci j read_loop i++) { break; countSmaller);} #include <stdio.h> typedef struct { int valid; int selectBlockToReplace() {
system: bgt $t3, $t0, not_fibonacci print_array: LHT_2Level[i] = new indxBTB = int main() { #define CACHE_SIZE 256 int tag; int sctr; } int minSctr = 4; int
module system_under_test add $t1, $t2, $t3 li $t0, 0 int[noInfo]; searchIndxBTB(pc); int sets[] = {3, 5, 8, 2, 10, #define BLOCK_SIZE 4 CacheEntry; indexToReplace = -1; for
( move $t2, $t3 la $t2, array LHT_2Level[i][0] = 0; indxLHT = 6}; #define MEMORY_SIZE CacheEntry (int i = 0; i < cacheSize /
input wire clk, move $t3, $t1 print_loop: // assigning the history as getTableIndx(pc); int size = sizeof(sets) / 65536 cache[MAX_CACHE_SIZE / blockSize; i++) { if
input wire [1:0] in_data, addi $t4, $t4, 1 bge $t0, $t1, exit 0s if (indxBTB == -1) { sizeof(sets[0]); #define ADDRESS_WIDTH MAX_BLOCK_SIZE]; (!cache[i].valid) { return i; }
output wire out j check_fibonacci lw $a0, 0($t2) LHT_2Level[i][1] = BTBLastIndx = int item = 5; 16 int cacheSize, blockSize; if (cache[i].sctr < minSctr) {
); found_fibonacci: li $v0, 1 initStateLBP; // assigning (BTBLastIndx + 1) % countAndPrint(sets, size, typedef struct { void initializeCache(int minSctr = cache[i].sctr;
reg [1:0] counter; li $v0, 4 syscall the initial value, N_ROWS_BTB; item); int tag; cacheSize, int blockSize); indexToReplace = i; } }
always @(posedge clk) la $a0, isFibMsg li $v0, 4 initStateLBP, to each BTB[BTBLastIndx][0] = return 0;} char block[BLOCK_SIZE]; void accessCache(int return indexToReplace; }
begin syscall la $a0, newline predictors. }} pc; #####c code get_pred # int valid; address); void replaceBlock(int
if (in_data[0] == 1'b1) li $v0, 4 syscall void updateLHT2Level(int indxBTB = BTBLastIndx; #include <stdio.h> } CacheLine; void updateSctr(int tag, int address) { int tag = address
begin la $a0, positionInd addi $t2, $t2, 4 indx, int outcome) { } #include <stdlib.h> CacheLine hit); / blockSize; int
counter <= counter + 1; syscall addi $t0, $t0, 1 int temp; intOutcome = #define MAX_SIZE 1000 cache[CACHE_SIZE]; int selectBlockToReplace(); indexToReplace =
end li $v0, 1 j print_loop LHT_2Level[indx][0] = outcome[0] == 'T' ? 1 : 0; #define N_BITS 2 char void replaceBlock(int selectBlockToReplace();
if (in_data[1] == 1'b1) move $a0, $t4 exit: (LHT_2Level[indx][0] >> 1) predictOutcome = int memory[MEMORY_SIZE]; address); cache[indexToReplace].vali
begin syscall li $v0, 10 + (outcome << 2);} getPrediction(2, branchPredictor[MAX_SIZE unsigned int int main() { cacheSize = d = 1;
counter <= counter + 1; li $v0, 10 syscall void LHT_2Level[LHT_2Level[ind ];void initPredictor() { getCacheEntryStatus(void) 512; blockSize = 32; cache[indexToReplace].tag
end syscall ################pred twoLevelBranchPredictor() xLHT][0]][1]); for (int i = 0; i < { unsigned int address; initializeCache(cacheSize, = tag;
not_fibonacci: int getPrediction(int n, int { char outcome[4]; updateNbitPredictor(2, MAX_SIZE; i++) { address = 0x1234; blockSize); FILE *traceFile; cache[indexToReplace].sctr
if (in_data == 2'b00) li $v0, 4 currState) { int pc, indxBTB, indxLHT, &LHT_2Level[LHT_2Level[i branchPredictor[i] = 0; unsigned int index = char filename[] = = 0; }
begin la $a0, notFibMsg int maxState, pivotState, getCurState, intOutcome, ndxLHT][0]][1], }} address % CACHE_SIZE; "cache_trace.bxt";
counter <= 0; syscall prediction; predictOutcome; intOutcome); int getPrediction(int pc) { unsigned int tag = traceFile = fopen(filename,
end li $v0, 10 maxState = pow(2, n) - 1; int **predictStat = NULL; return address / CACHE_SIZE; "r"); if (traceFile == NULL) {
end syscall pivotState = maxState / 2; predictStat = (int updateLHT2Level(indxLHT, branchPredictor[pc] >= (1 if (cache[index].valid && printf("Error opening trace
assign out = (counter % 2 #########array# if (currState <= pivotState) **)malloc(N_ROWS_BTB * intOutcome); << (N_BITS - 1)); cache[index].tag == tag) { file.\n"); return 1; } int
== 0) ? 1'b1 : 1'b0; .data { prediction = 0; sizeof(int *)); if (predictOutcome == }void updatePred(int pc, int return 1; address; while
endmodule } else { intOutcome) { outcome) { } else { (fscanf(traceFile, "%d",

You might also like