-
Notifications
You must be signed in to change notification settings - Fork 3
/
ALU.cpp
96 lines (83 loc) · 2.21 KB
/
ALU.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* @ASCK
*/
#include <systemc.h>
SC_MODULE (ALU) {
sc_in <sc_int<8>> in1; // A
sc_in <sc_int<8>> in2; // B
sc_in <bool> c; // Carry Out // in this project, this signal is always 1
// ALUOP // has 5 bits by merging: opselect (4bits) and first LSB bit of opcode (1bit)
sc_in <sc_uint<5>> aluop;
sc_in <sc_uint<3>> sa; // Shift Amount
sc_out <sc_int<8>> out; // Output
/*
** module global variables
*/
//
SC_CTOR (ALU){
SC_METHOD (process);
sensitive << in1 << in2 << aluop;
}
void process () {
sc_int<8> a = in1.read();
sc_int<8> b = in2.read();
bool cin = c.read();
sc_uint<5> op = aluop.read();
sc_uint<3> sh = sa.read();
switch (op){
case 0b00000 :
out.write(a);
break;
case 0b00001 :
out.write(++a);
break;
case 0b00010 :
out.write(a+b);
break;
case 0b00011 :
out.write(a+b+cin);
break;
case 0b00100 :
out.write(a-b);
break;
case 0b00101 :
out.write(a-b-cin);
break;
case 0b00110 :
out.write(--a);
break;
case 0b00111 :
out.write(b);
break;
case 0b01000 :
case 0b01001 :
out.write(a&b);
break;
case 0b01010 :
case 0b01011 :
out.write(a|b);
break;
case 0b01100 :
case 0b01101 :
out.write(a^b);
break;
case 0b01110 :
case 0b01111 :
out.write(~a);
break;
case 0b10000 :
case 0b10001 :
case 0b10010 :
case 0b10011 :
case 0b10100 :
case 0b10101 :
case 0b10110 :
case 0b10111 :
out.write(a>>sh);
break;
default:
out.write(a<<sh);
break;
}
}
};