-
Notifications
You must be signed in to change notification settings - Fork 0
/
mips3_arithm.h
157 lines (124 loc) · 2.31 KB
/
mips3_arithm.h
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifndef MIPS3_ARITHM
#define MIPS3_ARITHM
#include "mips3.h"
#include "mipsdef.h"
#include "memory.h"
namespace mips
{
// TODO: Overflow exception
void mips3::ADD(uint32_t opcode)
{
if (RDNUM)
RD = (int32_t)(RS_u32 + RT_u32);
}
void mips3::ADDU(uint32_t opcode)
{
if (RDNUM)
RD = (int32_t)(RS_u32 + RT_u32);
}
// TODO: Overflow exception
void mips3::ADDI(uint32_t opcode)
{
if (RTNUM)
RT = (int32_t)(RS_u32 + SIMM);
}
void mips3::ADDIU(uint32_t opcode)
{
if (RTNUM)
RT = (int32_t)(RS_u32 + SIMM);
}
void mips3::DADDI(uint32_t opcode)
{
if (RTNUM)
RT = RS + IMM_s64;
}
void mips3::DADDIU(uint32_t opcode)
{
if (RTNUM)
RT = RS + (uint64_t) SIMM;
}
// TODO: Overflow exception
void mips3::DADD(uint32_t opcode)
{
if (RDNUM)
RD = RS + RT;
}
void mips3::DADDU(uint32_t opcode)
{
if (RDNUM)
RD = RS + RT;
}
// TODO: Overflow exception
void mips3::SUB(uint32_t opcode)
{
if (RDNUM)
RD = (int32_t)(RS_u32 - RT_u32);
}
void mips3::SUBU(uint32_t opcode)
{
if (RDNUM)
RD = (int32_t)(RS_u32 - RT_u32);
}
// TODO: Overflow exception
void mips3::DSUB(uint32_t opcode)
{
if (RDNUM)
RD = RS - RT;
}
void mips3::DSUBU(uint32_t opcode)
{
if (RDNUM)
RD = RS - RT;
}
void mips3::MULT(uint32_t opcode)
{
int64_t value = (int64_t)RS_s32 * (int64_t)RT_s32;
LO = (int32_t) value;
HI = (int32_t) (value >> 32);
}
void mips3::MULTU(uint32_t opcode)
{
uint64_t value = (uint64_t) RS_u32 * (uint64_t) RT_u32;
LO = (int32_t) value;
HI = (int32_t) (value >> 32);
}
void mips3::DIV(uint32_t opcode)
{
if (RT) {
LO = (int32_t)(RS_s32 / RT_s32);
HI = (int32_t)(RS_s32 % RT_s32);
}
}
void mips3::DIVU(uint32_t opcode)
{
if (RT) {
LO = (int32_t)(RS_u32 / RT_u32);
HI = (int32_t)(RS_u32 % RT_u32);
}
}
// TODO: 128bit multiplication
void mips3::DMULT(uint32_t opcode)
{
uint64_t value = ((uint64_t) RS) * ((uint64_t) RT);
LO = value;
HI = (int64_t) (value >> 63);
}
void mips3::DDIV(uint32_t opcode)
{
if (RT) {
LO = RS / RT;
HI = RS % RT;
}
}
void mips3::DMULTU(uint32_t opcode)
{
}
void mips3::DDIVU(uint32_t opcode)
{
if (RTNUM) {
LO = RS / RT;
HI = RS % RT;
}
}
}
#endif // MIPS3_ARITHM