| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // Coprocessor registers. | 182 // Coprocessor registers. |
| 183 // Generated code will always use doubles. So we will only use even registers. | 183 // Generated code will always use doubles. So we will only use even registers. |
| 184 enum FPURegister { | 184 enum FPURegister { |
| 185 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, | 185 f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, |
| 186 f12, f13, f14, f15, // f12 and f14 are arguments FPURegisters. | 186 f12, f13, f14, f15, // f12 and f14 are arguments FPURegisters. |
| 187 f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, | 187 f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, |
| 188 f26, f27, f28, f29, f30, f31, | 188 f26, f27, f28, f29, f30, f31, |
| 189 kNumFPURegisters | 189 kNumFPURegisters |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 // MSA registers |
| 193 enum MSARegister { |
| 194 w0, |
| 195 w1, |
| 196 w2, |
| 197 w3, |
| 198 w4, |
| 199 w5, |
| 200 w6, |
| 201 w7, |
| 202 w8, |
| 203 w9, |
| 204 w10, |
| 205 w11, |
| 206 w12, |
| 207 w13, |
| 208 w14, |
| 209 w15, |
| 210 w16, |
| 211 w17, |
| 212 w18, |
| 213 w19, |
| 214 w20, |
| 215 w21, |
| 216 w22, |
| 217 w23, |
| 218 w24, |
| 219 w25, |
| 220 w26, |
| 221 w27, |
| 222 w28, |
| 223 w29, |
| 224 w30, |
| 225 w31, |
| 226 kNumMSARegisters |
| 227 }; |
| 228 |
| 192 explicit Simulator(Isolate* isolate); | 229 explicit Simulator(Isolate* isolate); |
| 193 ~Simulator(); | 230 ~Simulator(); |
| 194 | 231 |
| 195 // The currently executing Simulator instance. Potentially there can be one | 232 // The currently executing Simulator instance. Potentially there can be one |
| 196 // for each native thread. | 233 // for each native thread. |
| 197 static Simulator* current(v8::internal::Isolate* isolate); | 234 static Simulator* current(v8::internal::Isolate* isolate); |
| 198 | 235 |
| 199 // Accessors for register state. Reading the pc value adheres to the MIPS | 236 // Accessors for register state. Reading the pc value adheres to the MIPS |
| 200 // architecture specification and is off by a 8 from the currently executing | 237 // architecture specification and is off by a 8 from the currently executing |
| 201 // instruction. | 238 // instruction. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 215 void set_fpu_register_word_invalid_result(float original, float rounded); | 252 void set_fpu_register_word_invalid_result(float original, float rounded); |
| 216 void set_fpu_register_invalid_result64(double original, double rounded); | 253 void set_fpu_register_invalid_result64(double original, double rounded); |
| 217 void set_fpu_register_invalid_result(double original, double rounded); | 254 void set_fpu_register_invalid_result(double original, double rounded); |
| 218 void set_fpu_register_word_invalid_result(double original, double rounded); | 255 void set_fpu_register_word_invalid_result(double original, double rounded); |
| 219 int64_t get_fpu_register(int fpureg) const; | 256 int64_t get_fpu_register(int fpureg) const; |
| 220 int32_t get_fpu_register_word(int fpureg) const; | 257 int32_t get_fpu_register_word(int fpureg) const; |
| 221 int32_t get_fpu_register_signed_word(int fpureg) const; | 258 int32_t get_fpu_register_signed_word(int fpureg) const; |
| 222 int32_t get_fpu_register_hi_word(int fpureg) const; | 259 int32_t get_fpu_register_hi_word(int fpureg) const; |
| 223 float get_fpu_register_float(int fpureg) const; | 260 float get_fpu_register_float(int fpureg) const; |
| 224 double get_fpu_register_double(int fpureg) const; | 261 double get_fpu_register_double(int fpureg) const; |
| 262 template <typename T> |
| 263 void get_msa_register(int wreg, T* value); |
| 264 template <typename T> |
| 265 void set_msa_register(int wreg, const T* value); |
| 225 void set_fcsr_bit(uint32_t cc, bool value); | 266 void set_fcsr_bit(uint32_t cc, bool value); |
| 226 bool test_fcsr_bit(uint32_t cc); | 267 bool test_fcsr_bit(uint32_t cc); |
| 227 bool set_fcsr_round_error(double original, double rounded); | 268 bool set_fcsr_round_error(double original, double rounded); |
| 228 bool set_fcsr_round64_error(double original, double rounded); | 269 bool set_fcsr_round64_error(double original, double rounded); |
| 229 bool set_fcsr_round_error(float original, float rounded); | 270 bool set_fcsr_round_error(float original, float rounded); |
| 230 bool set_fcsr_round64_error(float original, float rounded); | 271 bool set_fcsr_round64_error(float original, float rounded); |
| 231 void round_according_to_fcsr(double toRound, double& rounded, | 272 void round_according_to_fcsr(double toRound, double& rounded, |
| 232 int32_t& rounded_int, double fs); | 273 int32_t& rounded_int, double fs); |
| 233 void round64_according_to_fcsr(double toRound, double& rounded, | 274 void round64_according_to_fcsr(double toRound, double& rounded, |
| 234 int64_t& rounded_int, double fs); | 275 int64_t& rounded_int, double fs); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 BYTE, | 345 BYTE, |
| 305 HALF, | 346 HALF, |
| 306 WORD, | 347 WORD, |
| 307 DWORD, | 348 DWORD, |
| 308 FLOAT, | 349 FLOAT, |
| 309 DOUBLE, | 350 DOUBLE, |
| 310 FLOAT_DOUBLE, | 351 FLOAT_DOUBLE, |
| 311 WORD_DWORD | 352 WORD_DWORD |
| 312 }; | 353 }; |
| 313 | 354 |
| 355 // MSA Data Format |
| 356 enum MSADataFormat { MSA_VECT = 0, MSA_BYTE, MSA_HALF, MSA_WORD, MSA_DWORD }; |
| 357 |
| 314 // Read and write memory. | 358 // Read and write memory. |
| 315 inline uint32_t ReadBU(int64_t addr); | 359 inline uint32_t ReadBU(int64_t addr); |
| 316 inline int32_t ReadB(int64_t addr); | 360 inline int32_t ReadB(int64_t addr); |
| 317 inline void WriteB(int64_t addr, uint8_t value); | 361 inline void WriteB(int64_t addr, uint8_t value); |
| 318 inline void WriteB(int64_t addr, int8_t value); | 362 inline void WriteB(int64_t addr, int8_t value); |
| 319 | 363 |
| 320 inline uint16_t ReadHU(int64_t addr, Instruction* instr); | 364 inline uint16_t ReadHU(int64_t addr, Instruction* instr); |
| 321 inline int16_t ReadH(int64_t addr, Instruction* instr); | 365 inline int16_t ReadH(int64_t addr, Instruction* instr); |
| 322 // Note: Overloaded on the sign of the value. | 366 // Note: Overloaded on the sign of the value. |
| 323 inline void WriteH(int64_t addr, uint16_t value, Instruction* instr); | 367 inline void WriteH(int64_t addr, uint16_t value, Instruction* instr); |
| 324 inline void WriteH(int64_t addr, int16_t value, Instruction* instr); | 368 inline void WriteH(int64_t addr, int16_t value, Instruction* instr); |
| 325 | 369 |
| 326 inline uint32_t ReadWU(int64_t addr, Instruction* instr); | 370 inline uint32_t ReadWU(int64_t addr, Instruction* instr); |
| 327 inline int32_t ReadW(int64_t addr, Instruction* instr, TraceType t = WORD); | 371 inline int32_t ReadW(int64_t addr, Instruction* instr, TraceType t = WORD); |
| 328 inline void WriteW(int64_t addr, int32_t value, Instruction* instr); | 372 inline void WriteW(int64_t addr, int32_t value, Instruction* instr); |
| 329 inline int64_t Read2W(int64_t addr, Instruction* instr); | 373 inline int64_t Read2W(int64_t addr, Instruction* instr); |
| 330 inline void Write2W(int64_t addr, int64_t value, Instruction* instr); | 374 inline void Write2W(int64_t addr, int64_t value, Instruction* instr); |
| 331 | 375 |
| 332 inline double ReadD(int64_t addr, Instruction* instr); | 376 inline double ReadD(int64_t addr, Instruction* instr); |
| 333 inline void WriteD(int64_t addr, double value, Instruction* instr); | 377 inline void WriteD(int64_t addr, double value, Instruction* instr); |
| 334 | 378 |
| 335 // Helper for debugging memory access. | 379 // Helper for debugging memory access. |
| 336 inline void DieOrDebug(); | 380 inline void DieOrDebug(); |
| 337 | 381 |
| 338 void TraceRegWr(int64_t value, TraceType t = DWORD); | 382 void TraceRegWr(int64_t value, TraceType t = DWORD); |
| 383 template <typename T> |
| 384 void TraceMSARegWr(T* value, TraceType t); |
| 339 void TraceMemWr(int64_t addr, int64_t value, TraceType t); | 385 void TraceMemWr(int64_t addr, int64_t value, TraceType t); |
| 340 void TraceMemRd(int64_t addr, int64_t value, TraceType t = DWORD); | 386 void TraceMemRd(int64_t addr, int64_t value, TraceType t = DWORD); |
| 341 | 387 |
| 342 // Operations depending on endianness. | 388 // Operations depending on endianness. |
| 343 // Get Double Higher / Lower word. | 389 // Get Double Higher / Lower word. |
| 344 inline int32_t GetDoubleHIW(double* addr); | 390 inline int32_t GetDoubleHIW(double* addr); |
| 345 inline int32_t GetDoubleLOW(double* addr); | 391 inline int32_t GetDoubleLOW(double* addr); |
| 346 // Set Double Higher / Lower word. | 392 // Set Double Higher / Lower word. |
| 347 inline int32_t SetDoubleHIW(double* addr); | 393 inline int32_t SetDoubleHIW(double* addr); |
| 348 inline int32_t SetDoubleLOW(double* addr); | 394 inline int32_t SetDoubleLOW(double* addr); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 362 void DecodeTypeRegisterSPECIAL3(); | 408 void DecodeTypeRegisterSPECIAL3(); |
| 363 | 409 |
| 364 void DecodeTypeRegisterSRsType(); | 410 void DecodeTypeRegisterSRsType(); |
| 365 | 411 |
| 366 void DecodeTypeRegisterDRsType(); | 412 void DecodeTypeRegisterDRsType(); |
| 367 | 413 |
| 368 void DecodeTypeRegisterWRsType(); | 414 void DecodeTypeRegisterWRsType(); |
| 369 | 415 |
| 370 void DecodeTypeRegisterLRsType(); | 416 void DecodeTypeRegisterLRsType(); |
| 371 | 417 |
| 418 int DecodeMsaDataFormat(); |
| 419 void DecodeTypeMsaI8(); |
| 420 void DecodeTypeMsaI5(); |
| 421 void DecodeTypeMsaI10(); |
| 422 void DecodeTypeMsaELM(); |
| 423 void DecodeTypeMsaBIT(); |
| 424 void DecodeTypeMsaMI10(); |
| 425 void DecodeTypeMsa3R(); |
| 426 void DecodeTypeMsa3RF(); |
| 427 void DecodeTypeMsaVec(); |
| 428 void DecodeTypeMsa2R(); |
| 429 void DecodeTypeMsa2RF(); |
| 430 |
| 372 // Executing is handled based on the instruction type. | 431 // Executing is handled based on the instruction type. |
| 373 void DecodeTypeRegister(); | 432 void DecodeTypeRegister(); |
| 374 | 433 |
| 375 inline int32_t rs_reg() const { return instr_.RsValue(); } | 434 inline int32_t rs_reg() const { return instr_.RsValue(); } |
| 376 inline int64_t rs() const { return get_register(rs_reg()); } | 435 inline int64_t rs() const { return get_register(rs_reg()); } |
| 377 inline uint64_t rs_u() const { | 436 inline uint64_t rs_u() const { |
| 378 return static_cast<uint64_t>(get_register(rs_reg())); | 437 return static_cast<uint64_t>(get_register(rs_reg())); |
| 379 } | 438 } |
| 380 inline int32_t rt_reg() const { return instr_.RtValue(); } | 439 inline int32_t rt_reg() const { return instr_.RtValue(); } |
| 381 inline int64_t rt() const { return get_register(rt_reg()); } | 440 inline int64_t rt() const { return get_register(rt_reg()); } |
| 382 inline uint64_t rt_u() const { | 441 inline uint64_t rt_u() const { |
| 383 return static_cast<uint64_t>(get_register(rt_reg())); | 442 return static_cast<uint64_t>(get_register(rt_reg())); |
| 384 } | 443 } |
| 385 inline int32_t rd_reg() const { return instr_.RdValue(); } | 444 inline int32_t rd_reg() const { return instr_.RdValue(); } |
| 386 inline int32_t fr_reg() const { return instr_.FrValue(); } | 445 inline int32_t fr_reg() const { return instr_.FrValue(); } |
| 387 inline int32_t fs_reg() const { return instr_.FsValue(); } | 446 inline int32_t fs_reg() const { return instr_.FsValue(); } |
| 388 inline int32_t ft_reg() const { return instr_.FtValue(); } | 447 inline int32_t ft_reg() const { return instr_.FtValue(); } |
| 389 inline int32_t fd_reg() const { return instr_.FdValue(); } | 448 inline int32_t fd_reg() const { return instr_.FdValue(); } |
| 390 inline int32_t sa() const { return instr_.SaValue(); } | 449 inline int32_t sa() const { return instr_.SaValue(); } |
| 391 inline int32_t lsa_sa() const { return instr_.LsaSaValue(); } | 450 inline int32_t lsa_sa() const { return instr_.LsaSaValue(); } |
| 451 inline int32_t ws_reg() const { return instr_.WsValue(); } |
| 452 inline int32_t wt_reg() const { return instr_.WtValue(); } |
| 453 inline int32_t wd_reg() const { return instr_.WdValue(); } |
| 392 | 454 |
| 393 inline void SetResult(const int32_t rd_reg, const int64_t alu_out) { | 455 inline void SetResult(const int32_t rd_reg, const int64_t alu_out) { |
| 394 set_register(rd_reg, alu_out); | 456 set_register(rd_reg, alu_out); |
| 395 TraceRegWr(alu_out); | 457 TraceRegWr(alu_out); |
| 396 } | 458 } |
| 397 | 459 |
| 398 inline void SetFPUWordResult(int32_t fd_reg, int32_t alu_out) { | 460 inline void SetFPUWordResult(int32_t fd_reg, int32_t alu_out) { |
| 399 set_fpu_register_word(fd_reg, alu_out); | 461 set_fpu_register_word(fd_reg, alu_out); |
| 400 TraceRegWr(get_fpu_register(fd_reg), WORD); | 462 TraceRegWr(get_fpu_register(fd_reg), WORD); |
| 401 } | 463 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 // Handle arguments and return value for runtime FP functions. | 563 // Handle arguments and return value for runtime FP functions. |
| 502 void GetFpArgs(double* x, double* y, int32_t* z); | 564 void GetFpArgs(double* x, double* y, int32_t* z); |
| 503 void SetFpResult(const double& result); | 565 void SetFpResult(const double& result); |
| 504 | 566 |
| 505 void CallInternal(byte* entry); | 567 void CallInternal(byte* entry); |
| 506 | 568 |
| 507 // Architecture state. | 569 // Architecture state. |
| 508 // Registers. | 570 // Registers. |
| 509 int64_t registers_[kNumSimuRegisters]; | 571 int64_t registers_[kNumSimuRegisters]; |
| 510 // Coprocessor Registers. | 572 // Coprocessor Registers. |
| 511 int64_t FPUregisters_[kNumFPURegisters]; | 573 // Note: FPUregisters_[] array is increased to 64 * 8B = 32 * 16B in |
| 574 // order to support MSA registers |
| 575 int64_t FPUregisters_[kNumFPURegisters * 2]; |
| 512 // FPU control register. | 576 // FPU control register. |
| 513 uint32_t FCSR_; | 577 uint32_t FCSR_; |
| 514 | 578 |
| 515 // Simulator support. | 579 // Simulator support. |
| 516 // Allocate 1MB for stack. | 580 // Allocate 1MB for stack. |
| 517 size_t stack_size_; | 581 size_t stack_size_; |
| 518 char* stack_; | 582 char* stack_; |
| 519 bool pc_modified_; | 583 bool pc_modified_; |
| 520 int64_t icount_; | 584 int64_t icount_; |
| 521 int break_count_; | 585 int break_count_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 static inline void UnregisterCTryCatch(Isolate* isolate) { | 646 static inline void UnregisterCTryCatch(Isolate* isolate) { |
| 583 Simulator::current(isolate)->PopAddress(); | 647 Simulator::current(isolate)->PopAddress(); |
| 584 } | 648 } |
| 585 }; | 649 }; |
| 586 | 650 |
| 587 } // namespace internal | 651 } // namespace internal |
| 588 } // namespace v8 | 652 } // namespace v8 |
| 589 | 653 |
| 590 #endif // !defined(USE_SIMULATOR) | 654 #endif // !defined(USE_SIMULATOR) |
| 591 #endif // V8_MIPS_SIMULATOR_MIPS_H_ | 655 #endif // V8_MIPS_SIMULATOR_MIPS_H_ |
| OLD | NEW |