-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_api.cpp
76 lines (60 loc) · 1.34 KB
/
core_api.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* 046267 Computer Architecture - Spring 2020 - HW #4 */
#include "core_api.h"
#include "sim_api.h"
#include <stdio.h>
#include <iostream>
#include <list>
using namespace std;
class MT
{
private:
/* data */
public:
int instructions_counter;
int cycles_counter;
tcontext* th_regs;
MT(int threds_num);
~MT();
};
MT::MT(int threds_num)
{
instructions_counter = 0;
cycles_counter = 0;
th_regs = new tcontext[threds_num];
}
MT::~MT()
{
delete[] th_regs;
}
//Globals:
int threads_num = SIM_GetThreadsNum();
int load_latencey = SIM_GetLoadLat();
int store_latencey = SIM_GetStoreLat();
int switch_latencey = SIM_GetSwitchCycles();
MT blocked_mt(threads_num);
MT fine_mt(threads_num);
void CORE_BlockedMT() {
}
void CORE_FinegrainedMT() {
}
double CORE_BlockedMT_CPI(){
double cpi = blocked_mt.cycles_counter/blocked_mt.instructions_counter;
return cpi;
}
double CORE_FinegrainedMT_CPI(){
double cpi = fine_mt.cycles_counter/fine_mt.instructions_counter;
return cpi;
}
void CORE_BlockedMT_CTX(tcontext* context, int threadid) {
if(context==NULL) return;
for(int i=0; i<REGS_COUNT; i++){
context->reg[i] = blocked_mt.th_regs[threadid]->reg[i];
} return;
}
void CORE_FinegrainedMT_CTX(tcontext* context, int threadid) {
if(context==NULL) return;
for(int i=0; i<REGS_COUNT; i++){
context->reg[i] = fine_mt.th_regs[threadid]->reg[i];
}
return;
}