-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.cpp
37 lines (36 loc) · 1.37 KB
/
mem.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
#include "parameters.hpp"
r_type mem(r_type addr, func3_type func3, r_type waddr, bit_type we) {
//#pragma HLS PIPELINE II=4
static data_type data_mem[DATAMEMSIZE];
bit_type error = 0;
data_type current_data = data_mem[waddr.range(31,2)];
if (we) {
switch(func3) {
case SB:
switch(waddr.range(1,0)) {
case 0: data_mem[waddr.range(31,2)]=(current_data.range(31, 8) << 8) & addr.range(7,0);break;
case 1: data_mem[waddr.range(31,2)]=(current_data.range(31, 16) << 16) & (addr.range(7,0)<<8) & (current_data.range(7, 0));break;
case 2: data_mem[waddr.range(31,2)]=(current_data.range(31, 24) << 24) & (addr.range(7,0)<<16) & (current_data.range(15, 0));break;
case 3: data_mem[waddr.range(31,2)]= (addr.range(7,0)<<24) & (current_data.range(23, 0));break;
}
break;
case SH:
switch(waddr.range(1,0)) {
case 0: data_mem[waddr.range(31,2)]=(current_data.range(31, 16) << 16) & addr.range(15,0);break;
case 2: data_mem[waddr.range(31,2)]=(addr.range(15,0)<<16) & (current_data.range(15, 0));break;
default: data_mem[waddr.range(31,2)]=0xFFFFFFFF; error=1;break;
}
break;
case SW:
switch(waddr.range(1,0)) {
case 0: data_mem[waddr.range(31,2)]=addr.range(31,0);break;
default: data_mem[waddr.range(31,2)]=0xFFFFFFFF;error = 1;break;
}
break;
default: error = 1; break;
}
return error;
} else {
return data_mem[addr.range(31,2)];
}
}