OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 // Declares a Simulator for MIPS instructions if we are not generating a native | 6 // Declares a Simulator for MIPS instructions if we are not generating a native |
7 // MIPS binary. This Simulator allows us to run and debug MIPS code generation | 7 // MIPS binary. This Simulator allows us to run and debug MIPS code generation |
8 // on regular desktop machines. | 8 // on regular desktop machines. |
9 // V8 calls into generated code by "calling" the CALL_GENERATED_CODE macro, | 9 // V8 calls into generated code by "calling" the CALL_GENERATED_CODE macro, |
10 // which will start execution in the Simulator or forwards to the real entry | 10 // which will start execution in the Simulator or forwards to the real entry |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // Coprocessor registers. | 174 // Coprocessor registers. |
175 // Generated code will always use doubles. So we will only use even registers. | 175 // Generated code will always use doubles. So we will only use even registers. |
176 enum FPURegister { | 176 enum FPURegister { |
177 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, | 177 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, |
178 f12, f13, f14, f15, // f12 and f14 are arguments FPURegisters. | 178 f12, f13, f14, f15, // f12 and f14 are arguments FPURegisters. |
179 f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, | 179 f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, |
180 f26, f27, f28, f29, f30, f31, | 180 f26, f27, f28, f29, f30, f31, |
181 kNumFPURegisters | 181 kNumFPURegisters |
182 }; | 182 }; |
183 | 183 |
| 184 // MSA registers |
| 185 enum MSARegister { |
| 186 w0, |
| 187 w1, |
| 188 w2, |
| 189 w3, |
| 190 w4, |
| 191 w5, |
| 192 w6, |
| 193 w7, |
| 194 w8, |
| 195 w9, |
| 196 w10, |
| 197 w11, |
| 198 w12, |
| 199 w13, |
| 200 w14, |
| 201 w15, |
| 202 w16, |
| 203 w17, |
| 204 w18, |
| 205 w19, |
| 206 w20, |
| 207 w21, |
| 208 w22, |
| 209 w23, |
| 210 w24, |
| 211 w25, |
| 212 w26, |
| 213 w27, |
| 214 w28, |
| 215 w29, |
| 216 w30, |
| 217 w31, |
| 218 kNumMSARegisters |
| 219 }; |
| 220 |
184 explicit Simulator(Isolate* isolate); | 221 explicit Simulator(Isolate* isolate); |
185 ~Simulator(); | 222 ~Simulator(); |
186 | 223 |
187 // The currently executing Simulator instance. Potentially there can be one | 224 // The currently executing Simulator instance. Potentially there can be one |
188 // for each native thread. | 225 // for each native thread. |
189 static Simulator* current(v8::internal::Isolate* isolate); | 226 static Simulator* current(v8::internal::Isolate* isolate); |
190 | 227 |
191 // Accessors for register state. Reading the pc value adheres to the MIPS | 228 // Accessors for register state. Reading the pc value adheres to the MIPS |
192 // architecture specification and is off by a 8 from the currently executing | 229 // architecture specification and is off by a 8 from the currently executing |
193 // instruction. | 230 // instruction. |
(...skipping 12 matching lines...) Expand all Loading... |
206 void set_fpu_register_word_invalid_result(float original, float rounded); | 243 void set_fpu_register_word_invalid_result(float original, float rounded); |
207 void set_fpu_register_invalid_result64(double original, double rounded); | 244 void set_fpu_register_invalid_result64(double original, double rounded); |
208 void set_fpu_register_invalid_result(double original, double rounded); | 245 void set_fpu_register_invalid_result(double original, double rounded); |
209 void set_fpu_register_word_invalid_result(double original, double rounded); | 246 void set_fpu_register_word_invalid_result(double original, double rounded); |
210 int64_t get_fpu_register(int fpureg) const; | 247 int64_t get_fpu_register(int fpureg) const; |
211 int32_t get_fpu_register_word(int fpureg) const; | 248 int32_t get_fpu_register_word(int fpureg) const; |
212 int32_t get_fpu_register_signed_word(int fpureg) const; | 249 int32_t get_fpu_register_signed_word(int fpureg) const; |
213 int32_t get_fpu_register_hi_word(int fpureg) const; | 250 int32_t get_fpu_register_hi_word(int fpureg) const; |
214 float get_fpu_register_float(int fpureg) const; | 251 float get_fpu_register_float(int fpureg) const; |
215 double get_fpu_register_double(int fpureg) const; | 252 double get_fpu_register_double(int fpureg) const; |
| 253 template <typename T> |
| 254 void get_msa_register(int wreg, T* value); |
| 255 template <typename T> |
| 256 void set_msa_register(int wreg, const T* value); |
216 void set_fcsr_bit(uint32_t cc, bool value); | 257 void set_fcsr_bit(uint32_t cc, bool value); |
217 bool test_fcsr_bit(uint32_t cc); | 258 bool test_fcsr_bit(uint32_t cc); |
218 void set_fcsr_rounding_mode(FPURoundingMode mode); | 259 void set_fcsr_rounding_mode(FPURoundingMode mode); |
219 unsigned int get_fcsr_rounding_mode(); | 260 unsigned int get_fcsr_rounding_mode(); |
220 bool set_fcsr_round_error(double original, double rounded); | 261 bool set_fcsr_round_error(double original, double rounded); |
221 bool set_fcsr_round_error(float original, float rounded); | 262 bool set_fcsr_round_error(float original, float rounded); |
222 bool set_fcsr_round64_error(double original, double rounded); | 263 bool set_fcsr_round64_error(double original, double rounded); |
223 bool set_fcsr_round64_error(float original, float rounded); | 264 bool set_fcsr_round64_error(float original, float rounded); |
224 void round_according_to_fcsr(double toRound, double& rounded, | 265 void round_according_to_fcsr(double toRound, double& rounded, |
225 int32_t& rounded_int, double fs); | 266 int32_t& rounded_int, double fs); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 // Unpredictable value. | 327 // Unpredictable value. |
287 Unpredictable = 0xbadbeaf | 328 Unpredictable = 0xbadbeaf |
288 }; | 329 }; |
289 | 330 |
290 // Unsupported instructions use Format to print an error and stop execution. | 331 // Unsupported instructions use Format to print an error and stop execution. |
291 void Format(Instruction* instr, const char* format); | 332 void Format(Instruction* instr, const char* format); |
292 | 333 |
293 // Helpers for data value tracing. | 334 // Helpers for data value tracing. |
294 enum TraceType { BYTE, HALF, WORD, DWORD, FLOAT, DOUBLE, FLOAT_DOUBLE }; | 335 enum TraceType { BYTE, HALF, WORD, DWORD, FLOAT, DOUBLE, FLOAT_DOUBLE }; |
295 | 336 |
| 337 // MSA Data Format |
| 338 enum MSADataFormat { MSA_VECT = 0, MSA_BYTE, MSA_HALF, MSA_WORD, MSA_DWORD }; |
| 339 |
296 // Read and write memory. | 340 // Read and write memory. |
297 inline uint32_t ReadBU(int32_t addr); | 341 inline uint32_t ReadBU(int32_t addr); |
298 inline int32_t ReadB(int32_t addr); | 342 inline int32_t ReadB(int32_t addr); |
299 inline void WriteB(int32_t addr, uint8_t value); | 343 inline void WriteB(int32_t addr, uint8_t value); |
300 inline void WriteB(int32_t addr, int8_t value); | 344 inline void WriteB(int32_t addr, int8_t value); |
301 | 345 |
302 inline uint16_t ReadHU(int32_t addr, Instruction* instr); | 346 inline uint16_t ReadHU(int32_t addr, Instruction* instr); |
303 inline int16_t ReadH(int32_t addr, Instruction* instr); | 347 inline int16_t ReadH(int32_t addr, Instruction* instr); |
304 // Note: Overloaded on the sign of the value. | 348 // Note: Overloaded on the sign of the value. |
305 inline void WriteH(int32_t addr, uint16_t value, Instruction* instr); | 349 inline void WriteH(int32_t addr, uint16_t value, Instruction* instr); |
306 inline void WriteH(int32_t addr, int16_t value, Instruction* instr); | 350 inline void WriteH(int32_t addr, int16_t value, Instruction* instr); |
307 | 351 |
308 inline int ReadW(int32_t addr, Instruction* instr, TraceType t = WORD); | 352 inline int ReadW(int32_t addr, Instruction* instr, TraceType t = WORD); |
309 inline void WriteW(int32_t addr, int value, Instruction* instr); | 353 inline void WriteW(int32_t addr, int value, Instruction* instr); |
310 | 354 |
311 inline double ReadD(int32_t addr, Instruction* instr); | 355 inline double ReadD(int32_t addr, Instruction* instr); |
312 inline void WriteD(int32_t addr, double value, Instruction* instr); | 356 inline void WriteD(int32_t addr, double value, Instruction* instr); |
313 | 357 |
314 void TraceRegWr(int32_t value, TraceType t = WORD); | 358 void TraceRegWr(int32_t value, TraceType t = WORD); |
315 void TraceRegWr(int64_t value, TraceType t = DWORD); | 359 void TraceRegWr(int64_t value, TraceType t = DWORD); |
| 360 template <typename T> |
| 361 void TraceMSARegWr(T* value, TraceType t); |
316 void TraceMemWr(int32_t addr, int32_t value, TraceType t = WORD); | 362 void TraceMemWr(int32_t addr, int32_t value, TraceType t = WORD); |
317 void TraceMemRd(int32_t addr, int32_t value, TraceType t = WORD); | 363 void TraceMemRd(int32_t addr, int32_t value, TraceType t = WORD); |
318 void TraceMemWr(int32_t addr, int64_t value, TraceType t = DWORD); | 364 void TraceMemWr(int32_t addr, int64_t value, TraceType t = DWORD); |
319 void TraceMemRd(int32_t addr, int64_t value, TraceType t = DWORD); | 365 void TraceMemRd(int32_t addr, int64_t value, TraceType t = DWORD); |
320 EmbeddedVector<char, 128> trace_buf_; | 366 EmbeddedVector<char, 128> trace_buf_; |
321 | 367 |
322 // Operations depending on endianness. | 368 // Operations depending on endianness. |
323 // Get Double Higher / Lower word. | 369 // Get Double Higher / Lower word. |
324 inline int32_t GetDoubleHIW(double* addr); | 370 inline int32_t GetDoubleHIW(double* addr); |
325 inline int32_t GetDoubleLOW(double* addr); | 371 inline int32_t GetDoubleLOW(double* addr); |
(...skipping 19 matching lines...) Expand all Loading... |
345 | 391 |
346 // Called from DecodeTypeRegisterCOP1. | 392 // Called from DecodeTypeRegisterCOP1. |
347 void DecodeTypeRegisterSRsType(); | 393 void DecodeTypeRegisterSRsType(); |
348 | 394 |
349 void DecodeTypeRegisterDRsType(); | 395 void DecodeTypeRegisterDRsType(); |
350 | 396 |
351 void DecodeTypeRegisterWRsType(); | 397 void DecodeTypeRegisterWRsType(); |
352 | 398 |
353 void DecodeTypeRegisterLRsType(); | 399 void DecodeTypeRegisterLRsType(); |
354 | 400 |
| 401 int DecodeMsaDataFormat(); |
| 402 void DecodeTypeMsaI8(); |
| 403 void DecodeTypeMsaI5(); |
| 404 void DecodeTypeMsaI10(); |
| 405 void DecodeTypeMsaELM(); |
| 406 void DecodeTypeMsaBIT(); |
| 407 void DecodeTypeMsaMI10(); |
| 408 void DecodeTypeMsa3R(); |
| 409 void DecodeTypeMsa3RF(); |
| 410 void DecodeTypeMsaVec(); |
| 411 void DecodeTypeMsa2R(); |
| 412 void DecodeTypeMsa2RF(); |
| 413 |
355 inline int32_t rs_reg() const { return instr_.RsValue(); } | 414 inline int32_t rs_reg() const { return instr_.RsValue(); } |
356 inline int32_t rs() const { return get_register(rs_reg()); } | 415 inline int32_t rs() const { return get_register(rs_reg()); } |
357 inline uint32_t rs_u() const { | 416 inline uint32_t rs_u() const { |
358 return static_cast<uint32_t>(get_register(rs_reg())); | 417 return static_cast<uint32_t>(get_register(rs_reg())); |
359 } | 418 } |
360 inline int32_t rt_reg() const { return instr_.RtValue(); } | 419 inline int32_t rt_reg() const { return instr_.RtValue(); } |
361 inline int32_t rt() const { return get_register(rt_reg()); } | 420 inline int32_t rt() const { return get_register(rt_reg()); } |
362 inline uint32_t rt_u() const { | 421 inline uint32_t rt_u() const { |
363 return static_cast<uint32_t>(get_register(rt_reg())); | 422 return static_cast<uint32_t>(get_register(rt_reg())); |
364 } | 423 } |
365 inline int32_t rd_reg() const { return instr_.RdValue(); } | 424 inline int32_t rd_reg() const { return instr_.RdValue(); } |
366 inline int32_t fr_reg() const { return instr_.FrValue(); } | 425 inline int32_t fr_reg() const { return instr_.FrValue(); } |
367 inline int32_t fs_reg() const { return instr_.FsValue(); } | 426 inline int32_t fs_reg() const { return instr_.FsValue(); } |
368 inline int32_t ft_reg() const { return instr_.FtValue(); } | 427 inline int32_t ft_reg() const { return instr_.FtValue(); } |
369 inline int32_t fd_reg() const { return instr_.FdValue(); } | 428 inline int32_t fd_reg() const { return instr_.FdValue(); } |
370 inline int32_t sa() const { return instr_.SaValue(); } | 429 inline int32_t sa() const { return instr_.SaValue(); } |
371 inline int32_t lsa_sa() const { return instr_.LsaSaValue(); } | 430 inline int32_t lsa_sa() const { return instr_.LsaSaValue(); } |
| 431 inline int32_t ws_reg() const { return instr_.WsValue(); } |
| 432 inline int32_t wt_reg() const { return instr_.WtValue(); } |
| 433 inline int32_t wd_reg() const { return instr_.WdValue(); } |
372 | 434 |
373 inline void SetResult(int32_t rd_reg, int32_t alu_out) { | 435 inline void SetResult(int32_t rd_reg, int32_t alu_out) { |
374 set_register(rd_reg, alu_out); | 436 set_register(rd_reg, alu_out); |
375 TraceRegWr(alu_out); | 437 TraceRegWr(alu_out); |
376 } | 438 } |
377 | 439 |
378 inline void SetFPUWordResult(int32_t fd_reg, int32_t alu_out) { | 440 inline void SetFPUWordResult(int32_t fd_reg, int32_t alu_out) { |
379 set_fpu_register_word(fd_reg, alu_out); | 441 set_fpu_register_word(fd_reg, alu_out); |
380 TraceRegWr(get_fpu_register_word(fd_reg)); | 442 TraceRegWr(get_fpu_register_word(fd_reg)); |
381 } | 443 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 void SetFpResult(const double& result); | 535 void SetFpResult(const double& result); |
474 | 536 |
475 void CallInternal(byte* entry); | 537 void CallInternal(byte* entry); |
476 | 538 |
477 // Architecture state. | 539 // Architecture state. |
478 // Registers. | 540 // Registers. |
479 int32_t registers_[kNumSimuRegisters]; | 541 int32_t registers_[kNumSimuRegisters]; |
480 // Coprocessor Registers. | 542 // Coprocessor Registers. |
481 // Note: FP32 mode uses only the lower 32-bit part of each element, | 543 // Note: FP32 mode uses only the lower 32-bit part of each element, |
482 // the upper 32-bit is unpredictable. | 544 // the upper 32-bit is unpredictable. |
483 int64_t FPUregisters_[kNumFPURegisters]; | 545 // Note: FPUregisters_[] array is increased to 64 * 8B = 32 * 16B in |
| 546 // order to support MSA registers |
| 547 int64_t FPUregisters_[kNumFPURegisters * 2]; |
484 // FPU control register. | 548 // FPU control register. |
485 uint32_t FCSR_; | 549 uint32_t FCSR_; |
486 | 550 |
487 // Simulator support. | 551 // Simulator support. |
488 // Allocate 1MB for stack. | 552 // Allocate 1MB for stack. |
489 static const size_t stack_size_ = 1 * 1024*1024; | 553 static const size_t stack_size_ = 1 * 1024*1024; |
490 char* stack_; | 554 char* stack_; |
491 bool pc_modified_; | 555 bool pc_modified_; |
492 uint64_t icount_; | 556 uint64_t icount_; |
493 int break_count_; | 557 int break_count_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 static inline void UnregisterCTryCatch(Isolate* isolate) { | 614 static inline void UnregisterCTryCatch(Isolate* isolate) { |
551 Simulator::current(isolate)->PopAddress(); | 615 Simulator::current(isolate)->PopAddress(); |
552 } | 616 } |
553 }; | 617 }; |
554 | 618 |
555 } // namespace internal | 619 } // namespace internal |
556 } // namespace v8 | 620 } // namespace v8 |
557 | 621 |
558 #endif // !defined(USE_SIMULATOR) | 622 #endif // !defined(USE_SIMULATOR) |
559 #endif // V8_MIPS_SIMULATOR_MIPS_H_ | 623 #endif // V8_MIPS_SIMULATOR_MIPS_H_ |
OLD | NEW |