Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: src/mips/constants-mips.h

Issue 6709022: Re-establish mips basic infrastructure. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Updated per comments, and rebased on r7312. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_MIPS_CONSTANTS_H_ 28 #ifndef V8_MIPS_CONSTANTS_H_
29 #define V8_MIPS_CONSTANTS_H_ 29 #define V8_MIPS_CONSTANTS_H_
30 30
31 #include "checks.h"
32
33 // UNIMPLEMENTED_ macro for MIPS. 31 // UNIMPLEMENTED_ macro for MIPS.
32 #ifdef DEBUG
34 #define UNIMPLEMENTED_MIPS() \ 33 #define UNIMPLEMENTED_MIPS() \
35 v8::internal::PrintF("%s, \tline %d: \tfunction %s not implemented. \n", \ 34 v8::internal::PrintF("%s, \tline %d: \tfunction %s not implemented. \n", \
36 __FILE__, __LINE__, __func__) 35 __FILE__, __LINE__, __func__)
36 #else
37 #define UNIMPLEMENTED_MIPS()
38 #endif
39
37 #define UNSUPPORTED_MIPS() v8::internal::PrintF("Unsupported instruction.\n") 40 #define UNSUPPORTED_MIPS() v8::internal::PrintF("Unsupported instruction.\n")
38 41
39 42
43 #ifdef _MIPS_ARCH_MIPS32R2
44 #define mips32r2 1
45 #else
46 #define mips32r2 0
47 #endif
48
49
40 // Defines constants and accessor classes to assemble, disassemble and 50 // Defines constants and accessor classes to assemble, disassemble and
41 // simulate MIPS32 instructions. 51 // simulate MIPS32 instructions.
42 // 52 //
43 // See: MIPS32 Architecture For Programmers 53 // See: MIPS32 Architecture For Programmers
44 // Volume II: The MIPS32 Instruction Set 54 // Volume II: The MIPS32 Instruction Set
45 // Try www.cs.cornell.edu/courses/cs3410/2008fa/MIPS_Vol2.pdf. 55 // Try www.cs.cornell.edu/courses/cs3410/2008fa/MIPS_Vol2.pdf.
46 56
47 namespace assembler { 57 namespace v8 {
48 namespace mips { 58 namespace internal {
49 59
50 // ----------------------------------------------------------------------------- 60 // -----------------------------------------------------------------------------
51 // Registers and FPURegister. 61 // Registers and FPURegister.
52 62
53 // Number of general purpose registers. 63 // Number of general purpose registers.
54 static const int kNumRegisters = 32; 64 static const int kNumRegisters = 32;
55 static const int kInvalidRegister = -1; 65 static const int kInvalidRegister = -1;
56 66
57 // Number of registers with HI, LO, and pc. 67 // Number of registers with HI, LO, and pc.
58 static const int kNumSimuRegisters = 35; 68 static const int kNumSimuRegisters = 35;
59 69
60 // In the simulator, the PC register is simulated as the 34th register. 70 // In the simulator, the PC register is simulated as the 34th register.
61 static const int kPCRegister = 34; 71 static const int kPCRegister = 34;
62 72
63 // Number coprocessor registers. 73 // Number coprocessor registers.
64 static const int kNumFPURegister = 32; 74 static const int kNumFPURegisters = 32;
65 static const int kInvalidFPURegister = -1; 75 static const int kInvalidFPURegister = -1;
66 76
77 // FPU (coprocessor 1) control registers. Currently only FCSR is implemented.
78 static const int kFCSRRegister = 31;
79 static const int kInvalidFPUControlRegister = -1;
80 static const uint32_t kFPUInvalidResult = (uint32_t) (1 << 31) - 1;
81
82 // FCSR constants.
83 static const uint32_t kFCSRFlagMask = (1 << 6) - 1;
84 static const uint32_t kFCSRFlagShift = 2;
85
67 // Helper functions for converting between register numbers and names. 86 // Helper functions for converting between register numbers and names.
68 class Registers { 87 class Registers {
69 public: 88 public:
70 // Return the name of the register. 89 // Return the name of the register.
71 static const char* Name(int reg); 90 static const char* Name(int reg);
72 91
73 // Lookup the register number for the name provided. 92 // Lookup the register number for the name provided.
74 static int Number(const char* name); 93 static int Number(const char* name);
75 94
76 struct RegisterAlias { 95 struct RegisterAlias {
77 int reg; 96 int reg;
78 const char *name; 97 const char *name;
79 }; 98 };
80 99
81 static const int32_t kMaxValue = 0x7fffffff; 100 static const int32_t kMaxValue = 0x7fffffff;
82 static const int32_t kMinValue = 0x80000000; 101 static const int32_t kMinValue = 0x80000000;
83 102
84 private: 103 private:
85 104
86 static const char* names_[kNumSimuRegisters]; 105 static const char* names_[kNumSimuRegisters];
87 static const RegisterAlias aliases_[]; 106 static const RegisterAlias aliases_[];
88 }; 107 };
89 108
90 // Helper functions for converting between register numbers and names. 109 // Helper functions for converting between register numbers and names.
91 class FPURegister { 110 class FPURegisters {
92 public: 111 public:
93 // Return the name of the register. 112 // Return the name of the register.
94 static const char* Name(int reg); 113 static const char* Name(int reg);
95 114
96 // Lookup the register number for the name provided. 115 // Lookup the register number for the name provided.
97 static int Number(const char* name); 116 static int Number(const char* name);
98 117
99 struct RegisterAlias { 118 struct RegisterAlias {
100 int creg; 119 int creg;
101 const char *name; 120 const char *name;
102 }; 121 };
103 122
104 private: 123 private:
105 124
106 static const char* names_[kNumFPURegister]; 125 static const char* names_[kNumFPURegisters];
107 static const RegisterAlias aliases_[]; 126 static const RegisterAlias aliases_[];
108 }; 127 };
109 128
110 129
111 // ----------------------------------------------------------------------------- 130 // -----------------------------------------------------------------------------
112 // Instructions encoding constants. 131 // Instructions encoding constants.
113 132
114 // On MIPS all instructions are 32 bits. 133 // On MIPS all instructions are 32 bits.
115 typedef int32_t Instr; 134 typedef int32_t Instr;
116 135
(...skipping 22 matching lines...) Expand all
139 158
140 static const int kImm16Shift = 0; 159 static const int kImm16Shift = 0;
141 static const int kImm16Bits = 16; 160 static const int kImm16Bits = 16;
142 static const int kImm26Shift = 0; 161 static const int kImm26Shift = 0;
143 static const int kImm26Bits = 26; 162 static const int kImm26Bits = 26;
144 163
145 static const int kFsShift = 11; 164 static const int kFsShift = 11;
146 static const int kFsBits = 5; 165 static const int kFsBits = 5;
147 static const int kFtShift = 16; 166 static const int kFtShift = 16;
148 static const int kFtBits = 5; 167 static const int kFtBits = 5;
168 static const int kFdShift = 6;
169 static const int kFdBits = 5;
170 static const int kFCccShift = 8;
171 static const int kFCccBits = 3;
172 static const int kFBccShift = 18;
173 static const int kFBccBits = 3;
174 static const int kFBtrueShift = 16;
175 static const int kFBtrueBits = 1;
149 176
150 // ----- Miscellianous useful masks. 177 // ----- Miscellianous useful masks.
151 // Instruction bit masks. 178 // Instruction bit masks.
152 static const int kOpcodeMask = ((1 << kOpcodeBits) - 1) << kOpcodeShift; 179 static const int kOpcodeMask = ((1 << kOpcodeBits) - 1) << kOpcodeShift;
153 static const int kImm16Mask = ((1 << kImm16Bits) - 1) << kImm16Shift; 180 static const int kImm16Mask = ((1 << kImm16Bits) - 1) << kImm16Shift;
154 static const int kImm26Mask = ((1 << kImm26Bits) - 1) << kImm26Shift; 181 static const int kImm26Mask = ((1 << kImm26Bits) - 1) << kImm26Shift;
155 static const int kRsFieldMask = ((1 << kRsBits) - 1) << kRsShift; 182 static const int kRsFieldMask = ((1 << kRsBits) - 1) << kRsShift;
156 static const int kRtFieldMask = ((1 << kRtBits) - 1) << kRtShift; 183 static const int kRtFieldMask = ((1 << kRtBits) - 1) << kRtShift;
157 static const int kRdFieldMask = ((1 << kRdBits) - 1) << kRdShift; 184 static const int kRdFieldMask = ((1 << kRdBits) - 1) << kRdShift;
158 static const int kSaFieldMask = ((1 << kSaBits) - 1) << kSaShift; 185 static const int kSaFieldMask = ((1 << kSaBits) - 1) << kSaShift;
(...skipping 28 matching lines...) Expand all
187 XORI = ((1 << 3) + 6) << kOpcodeShift, 214 XORI = ((1 << 3) + 6) << kOpcodeShift,
188 LUI = ((1 << 3) + 7) << kOpcodeShift, 215 LUI = ((1 << 3) + 7) << kOpcodeShift,
189 216
190 COP1 = ((2 << 3) + 1) << kOpcodeShift, // Coprocessor 1 class 217 COP1 = ((2 << 3) + 1) << kOpcodeShift, // Coprocessor 1 class
191 BEQL = ((2 << 3) + 4) << kOpcodeShift, 218 BEQL = ((2 << 3) + 4) << kOpcodeShift,
192 BNEL = ((2 << 3) + 5) << kOpcodeShift, 219 BNEL = ((2 << 3) + 5) << kOpcodeShift,
193 BLEZL = ((2 << 3) + 6) << kOpcodeShift, 220 BLEZL = ((2 << 3) + 6) << kOpcodeShift,
194 BGTZL = ((2 << 3) + 7) << kOpcodeShift, 221 BGTZL = ((2 << 3) + 7) << kOpcodeShift,
195 222
196 SPECIAL2 = ((3 << 3) + 4) << kOpcodeShift, 223 SPECIAL2 = ((3 << 3) + 4) << kOpcodeShift,
224 SPECIAL3 = ((3 << 3) + 7) << kOpcodeShift,
197 225
198 LB = ((4 << 3) + 0) << kOpcodeShift, 226 LB = ((4 << 3) + 0) << kOpcodeShift,
227 LH = ((4 << 3) + 1) << kOpcodeShift,
228 LWL = ((4 << 3) + 2) << kOpcodeShift,
199 LW = ((4 << 3) + 3) << kOpcodeShift, 229 LW = ((4 << 3) + 3) << kOpcodeShift,
200 LBU = ((4 << 3) + 4) << kOpcodeShift, 230 LBU = ((4 << 3) + 4) << kOpcodeShift,
231 LHU = ((4 << 3) + 5) << kOpcodeShift,
232 LWR = ((4 << 3) + 6) << kOpcodeShift,
201 SB = ((5 << 3) + 0) << kOpcodeShift, 233 SB = ((5 << 3) + 0) << kOpcodeShift,
234 SH = ((5 << 3) + 1) << kOpcodeShift,
235 SWL = ((5 << 3) + 2) << kOpcodeShift,
202 SW = ((5 << 3) + 3) << kOpcodeShift, 236 SW = ((5 << 3) + 3) << kOpcodeShift,
237 SWR = ((5 << 3) + 6) << kOpcodeShift,
203 238
204 LWC1 = ((6 << 3) + 1) << kOpcodeShift, 239 LWC1 = ((6 << 3) + 1) << kOpcodeShift,
205 LDC1 = ((6 << 3) + 5) << kOpcodeShift, 240 LDC1 = ((6 << 3) + 5) << kOpcodeShift,
206 241
207 SWC1 = ((7 << 3) + 1) << kOpcodeShift, 242 SWC1 = ((7 << 3) + 1) << kOpcodeShift,
208 SDC1 = ((7 << 3) + 5) << kOpcodeShift 243 SDC1 = ((7 << 3) + 5) << kOpcodeShift
209 }; 244 };
210 245
211 enum SecondaryField { 246 enum SecondaryField {
212 // SPECIAL Encoding of Function Field. 247 // SPECIAL Encoding of Function Field.
213 SLL = ((0 << 3) + 0), 248 SLL = ((0 << 3) + 0),
214 SRL = ((0 << 3) + 2), 249 SRL = ((0 << 3) + 2),
215 SRA = ((0 << 3) + 3), 250 SRA = ((0 << 3) + 3),
216 SLLV = ((0 << 3) + 4), 251 SLLV = ((0 << 3) + 4),
217 SRLV = ((0 << 3) + 6), 252 SRLV = ((0 << 3) + 6),
218 SRAV = ((0 << 3) + 7), 253 SRAV = ((0 << 3) + 7),
254 MOVCI = ((0 << 3) + 1),
219 255
220 JR = ((1 << 3) + 0), 256 JR = ((1 << 3) + 0),
221 JALR = ((1 << 3) + 1), 257 JALR = ((1 << 3) + 1),
258 MOVZ = ((1 << 3) + 2),
259 MOVN = ((1 << 3) + 3),
222 BREAK = ((1 << 3) + 5), 260 BREAK = ((1 << 3) + 5),
223 261
224 MFHI = ((2 << 3) + 0), 262 MFHI = ((2 << 3) + 0),
225 MFLO = ((2 << 3) + 2), 263 MFLO = ((2 << 3) + 2),
226 264
227 MULT = ((3 << 3) + 0), 265 MULT = ((3 << 3) + 0),
228 MULTU = ((3 << 3) + 1), 266 MULTU = ((3 << 3) + 1),
229 DIV = ((3 << 3) + 2), 267 DIV = ((3 << 3) + 2),
230 DIVU = ((3 << 3) + 3), 268 DIVU = ((3 << 3) + 3),
231 269
(...skipping 11 matching lines...) Expand all
243 281
244 TGE = ((6 << 3) + 0), 282 TGE = ((6 << 3) + 0),
245 TGEU = ((6 << 3) + 1), 283 TGEU = ((6 << 3) + 1),
246 TLT = ((6 << 3) + 2), 284 TLT = ((6 << 3) + 2),
247 TLTU = ((6 << 3) + 3), 285 TLTU = ((6 << 3) + 3),
248 TEQ = ((6 << 3) + 4), 286 TEQ = ((6 << 3) + 4),
249 TNE = ((6 << 3) + 6), 287 TNE = ((6 << 3) + 6),
250 288
251 // SPECIAL2 Encoding of Function Field. 289 // SPECIAL2 Encoding of Function Field.
252 MUL = ((0 << 3) + 2), 290 MUL = ((0 << 3) + 2),
291 CLZ = ((4 << 3) + 0),
292 CLO = ((4 << 3) + 1),
293
294 // SPECIAL3 Encoding of Function Field.
295 EXT = ((0 << 3) + 0),
296 INS = ((0 << 3) + 4),
253 297
254 // REGIMM encoding of rt Field. 298 // REGIMM encoding of rt Field.
255 BLTZ = ((0 << 3) + 0) << 16, 299 BLTZ = ((0 << 3) + 0) << 16,
256 BGEZ = ((0 << 3) + 1) << 16, 300 BGEZ = ((0 << 3) + 1) << 16,
257 BLTZAL = ((2 << 3) + 0) << 16, 301 BLTZAL = ((2 << 3) + 0) << 16,
258 BGEZAL = ((2 << 3) + 1) << 16, 302 BGEZAL = ((2 << 3) + 1) << 16,
259 303
260 // COP1 Encoding of rs Field. 304 // COP1 Encoding of rs Field.
261 MFC1 = ((0 << 3) + 0) << 21, 305 MFC1 = ((0 << 3) + 0) << 21,
306 CFC1 = ((0 << 3) + 2) << 21,
262 MFHC1 = ((0 << 3) + 3) << 21, 307 MFHC1 = ((0 << 3) + 3) << 21,
263 MTC1 = ((0 << 3) + 4) << 21, 308 MTC1 = ((0 << 3) + 4) << 21,
309 CTC1 = ((0 << 3) + 6) << 21,
264 MTHC1 = ((0 << 3) + 7) << 21, 310 MTHC1 = ((0 << 3) + 7) << 21,
265 BC1 = ((1 << 3) + 0) << 21, 311 BC1 = ((1 << 3) + 0) << 21,
266 S = ((2 << 3) + 0) << 21, 312 S = ((2 << 3) + 0) << 21,
267 D = ((2 << 3) + 1) << 21, 313 D = ((2 << 3) + 1) << 21,
268 W = ((2 << 3) + 4) << 21, 314 W = ((2 << 3) + 4) << 21,
269 L = ((2 << 3) + 5) << 21, 315 L = ((2 << 3) + 5) << 21,
270 PS = ((2 << 3) + 6) << 21, 316 PS = ((2 << 3) + 6) << 21,
271 // COP1 Encoding of Function Field When rs=S. 317 // COP1 Encoding of Function Field When rs=S.
318 ROUND_L_S = ((1 << 3) + 0),
319 TRUNC_L_S = ((1 << 3) + 1),
320 CEIL_L_S = ((1 << 3) + 2),
321 FLOOR_L_S = ((1 << 3) + 3),
322 ROUND_W_S = ((1 << 3) + 4),
323 TRUNC_W_S = ((1 << 3) + 5),
324 CEIL_W_S = ((1 << 3) + 6),
325 FLOOR_W_S = ((1 << 3) + 7),
272 CVT_D_S = ((4 << 3) + 1), 326 CVT_D_S = ((4 << 3) + 1),
273 CVT_W_S = ((4 << 3) + 4), 327 CVT_W_S = ((4 << 3) + 4),
274 CVT_L_S = ((4 << 3) + 5), 328 CVT_L_S = ((4 << 3) + 5),
275 CVT_PS_S = ((4 << 3) + 6), 329 CVT_PS_S = ((4 << 3) + 6),
276 // COP1 Encoding of Function Field When rs=D. 330 // COP1 Encoding of Function Field When rs=D.
331 ADD_D = ((0 << 3) + 0),
332 SUB_D = ((0 << 3) + 1),
333 MUL_D = ((0 << 3) + 2),
334 DIV_D = ((0 << 3) + 3),
335 SQRT_D = ((0 << 3) + 4),
336 ABS_D = ((0 << 3) + 5),
337 MOV_D = ((0 << 3) + 6),
338 NEG_D = ((0 << 3) + 7),
339 ROUND_L_D = ((1 << 3) + 0),
340 TRUNC_L_D = ((1 << 3) + 1),
341 CEIL_L_D = ((1 << 3) + 2),
342 FLOOR_L_D = ((1 << 3) + 3),
343 ROUND_W_D = ((1 << 3) + 4),
344 TRUNC_W_D = ((1 << 3) + 5),
345 CEIL_W_D = ((1 << 3) + 6),
346 FLOOR_W_D = ((1 << 3) + 7),
277 CVT_S_D = ((4 << 3) + 0), 347 CVT_S_D = ((4 << 3) + 0),
278 CVT_W_D = ((4 << 3) + 4), 348 CVT_W_D = ((4 << 3) + 4),
279 CVT_L_D = ((4 << 3) + 5), 349 CVT_L_D = ((4 << 3) + 5),
350 C_F_D = ((6 << 3) + 0),
351 C_UN_D = ((6 << 3) + 1),
352 C_EQ_D = ((6 << 3) + 2),
353 C_UEQ_D = ((6 << 3) + 3),
354 C_OLT_D = ((6 << 3) + 4),
355 C_ULT_D = ((6 << 3) + 5),
356 C_OLE_D = ((6 << 3) + 6),
357 C_ULE_D = ((6 << 3) + 7),
280 // COP1 Encoding of Function Field When rs=W or L. 358 // COP1 Encoding of Function Field When rs=W or L.
281 CVT_S_W = ((4 << 3) + 0), 359 CVT_S_W = ((4 << 3) + 0),
282 CVT_D_W = ((4 << 3) + 1), 360 CVT_D_W = ((4 << 3) + 1),
283 CVT_S_L = ((4 << 3) + 0), 361 CVT_S_L = ((4 << 3) + 0),
284 CVT_D_L = ((4 << 3) + 1), 362 CVT_D_L = ((4 << 3) + 1),
285 // COP1 Encoding of Function Field When rs=PS. 363 // COP1 Encoding of Function Field When rs=PS.
286 364
287 NULLSF = 0 365 NULLSF = 0
288 }; 366 };
289 367
290 368
291 // ----- Emulated conditions. 369 // ----- Emulated conditions.
292 // On MIPS we use this enum to abstract from conditionnal branch instructions. 370 // On MIPS we use this enum to abstract from conditionnal branch instructions.
293 // the 'U' prefix is used to specify unsigned comparisons. 371 // the 'U' prefix is used to specify unsigned comparisons.
294 enum Condition { 372 enum Condition {
295 // Any value < 0 is considered no_condition. 373 // Any value < 0 is considered no_condition.
296 no_condition = -1, 374 kNoCondition = -1,
297 375
298 overflow = 0, 376 overflow = 0,
299 no_overflow = 1, 377 no_overflow = 1,
300 Uless = 2, 378 Uless = 2,
301 Ugreater_equal= 3, 379 Ugreater_equal= 3,
302 equal = 4, 380 equal = 4,
303 not_equal = 5, 381 not_equal = 5,
304 Uless_equal = 6, 382 Uless_equal = 6,
305 Ugreater = 7, 383 Ugreater = 7,
306 negative = 8, 384 negative = 8,
307 positive = 9, 385 positive = 9,
308 parity_even = 10, 386 parity_even = 10,
309 parity_odd = 11, 387 parity_odd = 11,
310 less = 12, 388 less = 12,
311 greater_equal = 13, 389 greater_equal = 13,
312 less_equal = 14, 390 less_equal = 14,
313 greater = 15, 391 greater = 15,
314 392
315 cc_always = 16, 393 cc_always = 16,
316 394
317 // aliases 395 // aliases
318 carry = Uless, 396 carry = Uless,
319 not_carry = Ugreater_equal, 397 not_carry = Ugreater_equal,
320 zero = equal, 398 zero = equal,
321 eq = equal, 399 eq = equal,
322 not_zero = not_equal, 400 not_zero = not_equal,
323 ne = not_equal, 401 ne = not_equal,
402 nz = not_equal,
324 sign = negative, 403 sign = negative,
325 not_sign = positive, 404 not_sign = positive,
405 mi = negative,
406 pl = positive,
407 hi = Ugreater,
408 ls = Uless_equal,
409 ge = greater_equal,
410 lt = less,
411 gt = greater,
412 le = less_equal,
413 hs = Ugreater_equal,
414 lo = Uless,
415 al = cc_always,
326 416
327 cc_default = no_condition 417 cc_default = kNoCondition
328 }; 418 };
329 419
420
421 // Returns the equivalent of !cc.
422 // Negation of the default kNoCondition (-1) results in a non-default
423 // no_condition value (-2). As long as tests for no_condition check
424 // for condition < 0, this will work as expected.
425 inline Condition NegateCondition(Condition cc) {
426 ASSERT(cc != cc_always);
427 return static_cast<Condition>(cc ^ 1);
428 }
429
430
431 inline Condition ReverseCondition(Condition cc) {
432 switch (cc) {
433 case Uless:
434 return Ugreater;
435 case Ugreater:
436 return Uless;
437 case Ugreater_equal:
438 return Uless_equal;
439 case Uless_equal:
440 return Ugreater_equal;
441 case less:
442 return greater;
443 case greater:
444 return less;
445 case greater_equal:
446 return less_equal;
447 case less_equal:
448 return greater_equal;
449 default:
450 return cc;
451 };
452 }
453
454
330 // ----- Coprocessor conditions. 455 // ----- Coprocessor conditions.
331 enum FPUCondition { 456 enum FPUCondition {
332 F, // False 457 F, // False
333 UN, // Unordered 458 UN, // Unordered
334 EQ, // Equal 459 EQ, // Equal
335 UEQ, // Unordered or Equal 460 UEQ, // Unordered or Equal
336 OLT, // Ordered or Less Than 461 OLT, // Ordered or Less Than
337 ULT, // Unordered or Less Than 462 ULT, // Unordered or Less Than
338 OLE, // Ordered or Less Than or Equal 463 OLE, // Ordered or Less Than or Equal
339 ULE // Unordered or Less Than or Equal 464 ULE // Unordered or Less Than or Equal
340 }; 465 };
341 466
342 467
468 // -----------------------------------------------------------------------------
469 // Hints.
470
471 // Branch hints are not used on the MIPS. They are defined so that they can
472 // appear in shared function signatures, but will be ignored in MIPS
473 // implementations.
474 enum Hint {
475 no_hint = 0
476 };
477
478
479 inline Hint NegateHint(Hint hint) {
480 return no_hint;
481 }
482
483
484 // -----------------------------------------------------------------------------
485 // Specific instructions, constants, and masks.
486 // These constants are declared in assembler-mips.cc, as they use named
487 // registers and other constants.
488
489 // addiu(sp, sp, 4) aka Pop() operation or part of Pop(r)
490 // operations as post-increment of sp.
491 extern const Instr kPopInstruction;
492 // addiu(sp, sp, -4) part of Push(r) operation as pre-decrement of sp.
493 extern const Instr kPushInstruction;
494 // sw(r, MemOperand(sp, 0))
495 extern const Instr kPushRegPattern;
496 // lw(r, MemOperand(sp, 0))
497 extern const Instr kPopRegPattern;
498 extern const Instr kLwRegFpOffsetPattern;
499 extern const Instr kSwRegFpOffsetPattern;
500 extern const Instr kLwRegFpNegOffsetPattern;
501 extern const Instr kSwRegFpNegOffsetPattern;
502 // A mask for the Rt register for push, pop, lw, sw instructions.
503 extern const Instr kRtMask;
504 extern const Instr kLwSwInstrTypeMask;
505 extern const Instr kLwSwInstrArgumentMask;
506 extern const Instr kLwSwOffsetMask;
507
343 // Break 0xfffff, reserved for redirected real time call. 508 // Break 0xfffff, reserved for redirected real time call.
344 const Instr rtCallRedirInstr = SPECIAL | BREAK | call_rt_redirected << 6; 509 const Instr rtCallRedirInstr = SPECIAL | BREAK | call_rt_redirected << 6;
345 // A nop instruction. (Encoding of sll 0 0 0). 510 // A nop instruction. (Encoding of sll 0 0 0).
346 const Instr nopInstr = 0; 511 const Instr nopInstr = 0;
347 512
348 class Instruction { 513 class Instruction {
349 public: 514 public:
350 enum { 515 enum {
351 kInstructionSize = 4, 516 kInstrSize = 4,
352 kInstructionSizeLog2 = 2, 517 kInstrSizeLog2 = 2,
353 // On MIPS PC cannot actually be directly accessed. We behave as if PC was 518 // On MIPS PC cannot actually be directly accessed. We behave as if PC was
354 // always the value of the current instruction being exectued. 519 // always the value of the current instruction being executed.
355 kPCReadOffset = 0 520 kPCReadOffset = 0
356 }; 521 };
357 522
358 // Get the raw instruction bits. 523 // Get the raw instruction bits.
359 inline Instr InstructionBits() const { 524 inline Instr InstructionBits() const {
360 return *reinterpret_cast<const Instr*>(this); 525 return *reinterpret_cast<const Instr*>(this);
361 } 526 }
362 527
363 // Set the raw instruction bits to value. 528 // Set the raw instruction bits to value.
364 inline void SetInstructionBits(Instr value) { 529 inline void SetInstructionBits(Instr value) {
(...skipping 16 matching lines...) Expand all
381 kImmediateType, 546 kImmediateType,
382 kJumpType, 547 kJumpType,
383 kUnsupported = -1 548 kUnsupported = -1
384 }; 549 };
385 550
386 // Get the encoding type of the instruction. 551 // Get the encoding type of the instruction.
387 Type InstructionType() const; 552 Type InstructionType() const;
388 553
389 554
390 // Accessors for the different named fields used in the MIPS encoding. 555 // Accessors for the different named fields used in the MIPS encoding.
391 inline Opcode OpcodeField() const { 556 inline Opcode OpcodeValue() const {
392 return static_cast<Opcode>( 557 return static_cast<Opcode>(
393 Bits(kOpcodeShift + kOpcodeBits - 1, kOpcodeShift)); 558 Bits(kOpcodeShift + kOpcodeBits - 1, kOpcodeShift));
394 } 559 }
395 560
396 inline int RsField() const { 561 inline int RsValue() const {
397 ASSERT(InstructionType() == kRegisterType || 562 ASSERT(InstructionType() == kRegisterType ||
398 InstructionType() == kImmediateType); 563 InstructionType() == kImmediateType);
399 return Bits(kRsShift + kRsBits - 1, kRsShift); 564 return Bits(kRsShift + kRsBits - 1, kRsShift);
400 } 565 }
401 566
402 inline int RtField() const { 567 inline int RtValue() const {
403 ASSERT(InstructionType() == kRegisterType || 568 ASSERT(InstructionType() == kRegisterType ||
404 InstructionType() == kImmediateType); 569 InstructionType() == kImmediateType);
405 return Bits(kRtShift + kRtBits - 1, kRtShift); 570 return Bits(kRtShift + kRtBits - 1, kRtShift);
406 } 571 }
407 572
408 inline int RdField() const { 573 inline int RdValue() const {
409 ASSERT(InstructionType() == kRegisterType); 574 ASSERT(InstructionType() == kRegisterType);
410 return Bits(kRdShift + kRdBits - 1, kRdShift); 575 return Bits(kRdShift + kRdBits - 1, kRdShift);
411 } 576 }
412 577
413 inline int SaField() const { 578 inline int SaValue() const {
414 ASSERT(InstructionType() == kRegisterType); 579 ASSERT(InstructionType() == kRegisterType);
415 return Bits(kSaShift + kSaBits - 1, kSaShift); 580 return Bits(kSaShift + kSaBits - 1, kSaShift);
416 } 581 }
417 582
418 inline int FunctionField() const { 583 inline int FunctionValue() const {
419 ASSERT(InstructionType() == kRegisterType || 584 ASSERT(InstructionType() == kRegisterType ||
420 InstructionType() == kImmediateType); 585 InstructionType() == kImmediateType);
421 return Bits(kFunctionShift + kFunctionBits - 1, kFunctionShift); 586 return Bits(kFunctionShift + kFunctionBits - 1, kFunctionShift);
422 } 587 }
423 588
424 inline int FsField() const { 589 inline int FdValue() const {
425 return Bits(kFsShift + kRsBits - 1, kFsShift); 590 return Bits(kFdShift + kFdBits - 1, kFdShift);
426 } 591 }
427 592
428 inline int FtField() const { 593 inline int FsValue() const {
429 return Bits(kFtShift + kRsBits - 1, kFtShift); 594 return Bits(kFsShift + kFsBits - 1, kFsShift);
595 }
596
597 inline int FtValue() const {
598 return Bits(kFtShift + kFtBits - 1, kFtShift);
599 }
600
601 // Float Compare condition code instruction bits.
602 inline int FCccValue() const {
603 return Bits(kFCccShift + kFCccBits - 1, kFCccShift);
604 }
605
606 // Float Branch condition code instruction bits.
607 inline int FBccValue() const {
608 return Bits(kFBccShift + kFBccBits - 1, kFBccShift);
609 }
610
611 // Float Branch true/false instruction bit.
612 inline int FBtrueValue() const {
613 return Bits(kFBtrueShift + kFBtrueBits - 1, kFBtrueShift);
430 } 614 }
431 615
432 // Return the fields at their original place in the instruction encoding. 616 // Return the fields at their original place in the instruction encoding.
433 inline Opcode OpcodeFieldRaw() const { 617 inline Opcode OpcodeFieldRaw() const {
434 return static_cast<Opcode>(InstructionBits() & kOpcodeMask); 618 return static_cast<Opcode>(InstructionBits() & kOpcodeMask);
435 } 619 }
436 620
437 inline int RsFieldRaw() const { 621 inline int RsFieldRaw() const {
438 ASSERT(InstructionType() == kRegisterType || 622 ASSERT(InstructionType() == kRegisterType ||
439 InstructionType() == kImmediateType); 623 InstructionType() == kImmediateType);
440 return InstructionBits() & kRsFieldMask; 624 return InstructionBits() & kRsFieldMask;
441 } 625 }
442 626
627 // Same as above function, but safe to call within InstructionType().
628 inline int RsFieldRawNoAssert() const {
629 return InstructionBits() & kRsFieldMask;
630 }
631
443 inline int RtFieldRaw() const { 632 inline int RtFieldRaw() const {
444 ASSERT(InstructionType() == kRegisterType || 633 ASSERT(InstructionType() == kRegisterType ||
445 InstructionType() == kImmediateType); 634 InstructionType() == kImmediateType);
446 return InstructionBits() & kRtFieldMask; 635 return InstructionBits() & kRtFieldMask;
447 } 636 }
448 637
449 inline int RdFieldRaw() const { 638 inline int RdFieldRaw() const {
450 ASSERT(InstructionType() == kRegisterType); 639 ASSERT(InstructionType() == kRegisterType);
451 return InstructionBits() & kRdFieldMask; 640 return InstructionBits() & kRdFieldMask;
452 } 641 }
453 642
454 inline int SaFieldRaw() const { 643 inline int SaFieldRaw() const {
455 ASSERT(InstructionType() == kRegisterType); 644 ASSERT(InstructionType() == kRegisterType);
456 return InstructionBits() & kSaFieldMask; 645 return InstructionBits() & kSaFieldMask;
457 } 646 }
458 647
459 inline int FunctionFieldRaw() const { 648 inline int FunctionFieldRaw() const {
460 return InstructionBits() & kFunctionFieldMask; 649 return InstructionBits() & kFunctionFieldMask;
461 } 650 }
462 651
463 // Get the secondary field according to the opcode. 652 // Get the secondary field according to the opcode.
464 inline int SecondaryField() const { 653 inline int SecondaryValue() const {
465 Opcode op = OpcodeFieldRaw(); 654 Opcode op = OpcodeFieldRaw();
466 switch (op) { 655 switch (op) {
467 case SPECIAL: 656 case SPECIAL:
468 case SPECIAL2: 657 case SPECIAL2:
469 return FunctionField(); 658 return FunctionValue();
470 case COP1: 659 case COP1:
471 return RsField(); 660 return RsValue();
472 case REGIMM: 661 case REGIMM:
473 return RtField(); 662 return RtValue();
474 default: 663 default:
475 return NULLSF; 664 return NULLSF;
476 } 665 }
477 } 666 }
478 667
479 inline int32_t Imm16Field() const { 668 inline int32_t Imm16Value() const {
480 ASSERT(InstructionType() == kImmediateType); 669 ASSERT(InstructionType() == kImmediateType);
481 return Bits(kImm16Shift + kImm16Bits - 1, kImm16Shift); 670 return Bits(kImm16Shift + kImm16Bits - 1, kImm16Shift);
482 } 671 }
483 672
484 inline int32_t Imm26Field() const { 673 inline int32_t Imm26Value() const {
485 ASSERT(InstructionType() == kJumpType); 674 ASSERT(InstructionType() == kJumpType);
486 return Bits(kImm16Shift + kImm26Bits - 1, kImm26Shift); 675 return Bits(kImm16Shift + kImm26Bits - 1, kImm26Shift);
487 } 676 }
488 677
489 // Say if the instruction should not be used in a branch delay slot. 678 // Say if the instruction should not be used in a branch delay slot.
490 bool IsForbiddenInBranchDelay(); 679 bool IsForbiddenInBranchDelay() const;
491 // Say if the instruction 'links'. eg: jal, bal. 680 // Say if the instruction 'links'. eg: jal, bal.
492 bool IsLinkingInstruction(); 681 bool IsLinkingInstruction() const;
493 // Say if the instruction is a break or a trap. 682 // Say if the instruction is a break or a trap.
494 bool IsTrap(); 683 bool IsTrap() const;
495 684
496 // Instructions are read of out a code stream. The only way to get a 685 // Instructions are read of out a code stream. The only way to get a
497 // reference to an instruction is to convert a pointer. There is no way 686 // reference to an instruction is to convert a pointer. There is no way
498 // to allocate or create instances of class Instruction. 687 // to allocate or create instances of class Instruction.
499 // Use the At(pc) function to create references to Instruction. 688 // Use the At(pc) function to create references to Instruction.
500 static Instruction* At(byte_* pc) { 689 static Instruction* At(byte_* pc) {
501 return reinterpret_cast<Instruction*>(pc); 690 return reinterpret_cast<Instruction*>(pc);
502 } 691 }
503 692
504 private: 693 private:
505 // We need to prevent the creation of instances of class Instruction. 694 // We need to prevent the creation of instances of class Instruction.
506 DISALLOW_IMPLICIT_CONSTRUCTORS(Instruction); 695 DISALLOW_IMPLICIT_CONSTRUCTORS(Instruction);
507 }; 696 };
508 697
509 698
510 // ----------------------------------------------------------------------------- 699 // -----------------------------------------------------------------------------
511 // MIPS assembly various constants. 700 // MIPS assembly various constants.
512 701
513 static const int kArgsSlotsSize = 4 * Instruction::kInstructionSize; 702
703 static const int kArgsSlotsSize = 4 * Instruction::kInstrSize;
514 static const int kArgsSlotsNum = 4; 704 static const int kArgsSlotsNum = 4;
705 // C/C++ argument slots size.
706 static const int kCArgsSlotsSize = 4 * Instruction::kInstrSize;
707 // JS argument slots size.
708 static const int kJSArgsSlotsSize = 0 * Instruction::kInstrSize;
709 // Assembly builtins argument slots size.
710 static const int kBArgsSlotsSize = 0 * Instruction::kInstrSize;
515 711
516 static const int kBranchReturnOffset = 2 * Instruction::kInstructionSize; 712 static const int kBranchReturnOffset = 2 * Instruction::kInstrSize;
517 713
518 static const int kDoubleAlignment = 2 * 8; 714 static const int kDoubleAlignmentBits = 3;
519 static const int kDoubleAlignmentMask = kDoubleAlignmentMask - 1; 715 static const int kDoubleAlignment = (1 << kDoubleAlignmentBits);
716 static const int kDoubleAlignmentMask = kDoubleAlignment - 1;
520 717
521 718
522 } } // namespace assembler::mips 719 } } // namespace v8::internal
523 720
524 #endif // #ifndef V8_MIPS_CONSTANTS_H_ 721 #endif // #ifndef V8_MIPS_CONSTANTS_H_
525 722
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698