| OLD | NEW |
| 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. | 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 // All Rights Reserved. | 2 // All Rights Reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // - Redistributions of source code must retain the above copyright notice, | 8 // - Redistributions of source code must retain the above copyright notice, |
| 9 // this list of conditions and the following disclaimer. | 9 // this list of conditions and the following disclaimer. |
| 10 // | 10 // |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 // Adds operand displacement fields (offsets added to the memory address). | 435 // Adds operand displacement fields (offsets added to the memory address). |
| 436 // Needs to be called after set_sib, not before it. | 436 // Needs to be called after set_sib, not before it. |
| 437 inline void set_disp8(int disp); | 437 inline void set_disp8(int disp); |
| 438 inline void set_disp32(int disp); | 438 inline void set_disp32(int disp); |
| 439 | 439 |
| 440 friend class Assembler; | 440 friend class Assembler; |
| 441 }; | 441 }; |
| 442 | 442 |
| 443 | 443 |
| 444 // CpuFeatures keeps track of which features are supported by the target CPU. | 444 // CpuFeatures keeps track of which features are supported by the target CPU. |
| 445 // Supported features must be enabled by a Scope before use. | 445 // Supported features must be enabled by a CpuFeatureScope before use. |
| 446 // Example: | 446 // Example: |
| 447 // if (CpuFeatures::IsSupported(SSE3)) { | 447 // if (assembler->IsSupported(SSE3)) { |
| 448 // CpuFeatures::Scope fscope(SSE3); | 448 // CpuFeatureScope fscope(assembler, SSE3); |
| 449 // // Generate SSE3 floating point code. | 449 // // Generate SSE3 floating point code. |
| 450 // } else { | 450 // } else { |
| 451 // // Generate standard x87 or SSE2 floating point code. | 451 // // Generate standard x87 or SSE2 floating point code. |
| 452 // } | 452 // } |
| 453 class CpuFeatures : public AllStatic { | 453 class CpuFeatures : public AllStatic { |
| 454 public: | 454 public: |
| 455 // Detect features of the target CPU. Set safe defaults if the serializer | 455 // Detect features of the target CPU. Set safe defaults if the serializer |
| 456 // is enabled (snapshots must be portable). | 456 // is enabled (snapshots must be portable). |
| 457 static void Probe(); | 457 static void Probe(); |
| 458 | 458 |
| 459 // Check whether a feature is supported by the target CPU. | 459 // Check whether a feature is supported by the target CPU. |
| 460 static bool IsSupported(CpuFeature f) { | 460 static bool IsSupported(CpuFeature f) { |
| 461 ASSERT(initialized_); | 461 ASSERT(initialized_); |
| 462 if (f == SSE2 && !FLAG_enable_sse2) return false; | 462 if (f == SSE2 && !FLAG_enable_sse2) return false; |
| 463 if (f == SSE3 && !FLAG_enable_sse3) return false; | 463 if (f == SSE3 && !FLAG_enable_sse3) return false; |
| 464 if (f == SSE4_1 && !FLAG_enable_sse4_1) return false; | 464 if (f == SSE4_1 && !FLAG_enable_sse4_1) return false; |
| 465 if (f == CMOV && !FLAG_enable_cmov) return false; | 465 if (f == CMOV && !FLAG_enable_cmov) return false; |
| 466 if (f == RDTSC && !FLAG_enable_rdtsc) return false; | 466 if (f == RDTSC && !FLAG_enable_rdtsc) return false; |
| 467 if (f == SAHF && !FLAG_enable_sahf) return false; | 467 if (f == SAHF && !FLAG_enable_sahf) return false; |
| 468 return (supported_ & (V8_UINT64_C(1) << f)) != 0; | 468 return (supported_ & (static_cast<uint64_t>(1) << f)) != 0; |
| 469 } | 469 } |
| 470 | 470 |
| 471 #ifdef DEBUG | 471 static bool IsFoundByRuntimeProbingOnly(CpuFeature f) { |
| 472 // Check whether a feature is currently enabled. | |
| 473 static bool IsEnabled(CpuFeature f) { | |
| 474 ASSERT(initialized_); | 472 ASSERT(initialized_); |
| 475 Isolate* isolate = Isolate::UncheckedCurrent(); | 473 return (found_by_runtime_probing_only_ & |
| 476 if (isolate == NULL) { | 474 (static_cast<uint64_t>(1) << f)) != 0; |
| 477 // When no isolate is available, work as if we're running in | |
| 478 // release mode. | |
| 479 return IsSupported(f); | |
| 480 } | |
| 481 uint64_t enabled = isolate->enabled_cpu_features(); | |
| 482 return (enabled & (V8_UINT64_C(1) << f)) != 0; | |
| 483 } | 475 } |
| 484 #endif | |
| 485 | |
| 486 // Enable a specified feature within a scope. | |
| 487 class Scope BASE_EMBEDDED { | |
| 488 #ifdef DEBUG | |
| 489 | |
| 490 public: | |
| 491 explicit Scope(CpuFeature f) { | |
| 492 uint64_t mask = V8_UINT64_C(1) << f; | |
| 493 ASSERT(CpuFeatures::IsSupported(f)); | |
| 494 ASSERT(!Serializer::enabled() || | |
| 495 (CpuFeatures::found_by_runtime_probing_ & mask) == 0); | |
| 496 isolate_ = Isolate::UncheckedCurrent(); | |
| 497 old_enabled_ = 0; | |
| 498 if (isolate_ != NULL) { | |
| 499 old_enabled_ = isolate_->enabled_cpu_features(); | |
| 500 isolate_->set_enabled_cpu_features(old_enabled_ | mask); | |
| 501 } | |
| 502 } | |
| 503 ~Scope() { | |
| 504 ASSERT_EQ(Isolate::UncheckedCurrent(), isolate_); | |
| 505 if (isolate_ != NULL) { | |
| 506 isolate_->set_enabled_cpu_features(old_enabled_); | |
| 507 } | |
| 508 } | |
| 509 | |
| 510 private: | |
| 511 Isolate* isolate_; | |
| 512 uint64_t old_enabled_; | |
| 513 #else | |
| 514 | |
| 515 public: | |
| 516 explicit Scope(CpuFeature f) {} | |
| 517 #endif | |
| 518 }; | |
| 519 | 476 |
| 520 private: | 477 private: |
| 521 // Safe defaults include SSE2 and CMOV for X64. It is always available, if | 478 // Safe defaults include SSE2 and CMOV for X64. It is always available, if |
| 522 // anyone checks, but they shouldn't need to check. | 479 // anyone checks, but they shouldn't need to check. |
| 523 // The required user mode extensions in X64 are (from AMD64 ABI Table A.1): | 480 // The required user mode extensions in X64 are (from AMD64 ABI Table A.1): |
| 524 // fpu, tsc, cx8, cmov, mmx, sse, sse2, fxsr, syscall | 481 // fpu, tsc, cx8, cmov, mmx, sse, sse2, fxsr, syscall |
| 525 static const uint64_t kDefaultCpuFeatures = (1 << SSE2 | 1 << CMOV); | 482 static const uint64_t kDefaultCpuFeatures = (1 << SSE2 | 1 << CMOV); |
| 526 | 483 |
| 527 #ifdef DEBUG | 484 #ifdef DEBUG |
| 528 static bool initialized_; | 485 static bool initialized_; |
| 529 #endif | 486 #endif |
| 530 static uint64_t supported_; | 487 static uint64_t supported_; |
| 531 static uint64_t found_by_runtime_probing_; | 488 static uint64_t found_by_runtime_probing_only_; |
| 532 | 489 |
| 533 friend class ExternalReference; | 490 friend class ExternalReference; |
| 534 DISALLOW_COPY_AND_ASSIGN(CpuFeatures); | 491 DISALLOW_COPY_AND_ASSIGN(CpuFeatures); |
| 535 }; | 492 }; |
| 536 | 493 |
| 537 | 494 |
| 538 class Assembler : public AssemblerBase { | 495 class Assembler : public AssemblerBase { |
| 539 private: | 496 private: |
| 540 // We check before assembling an instruction that there is sufficient | 497 // We check before assembling an instruction that there is sufficient |
| 541 // space to write an instruction and its relocation information. | 498 // space to write an instruction and its relocation information. |
| (...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1669 private: | 1626 private: |
| 1670 Assembler* assembler_; | 1627 Assembler* assembler_; |
| 1671 #ifdef DEBUG | 1628 #ifdef DEBUG |
| 1672 int space_before_; | 1629 int space_before_; |
| 1673 #endif | 1630 #endif |
| 1674 }; | 1631 }; |
| 1675 | 1632 |
| 1676 } } // namespace v8::internal | 1633 } } // namespace v8::internal |
| 1677 | 1634 |
| 1678 #endif // V8_X64_ASSEMBLER_X64_H_ | 1635 #endif // V8_X64_ASSEMBLER_X64_H_ |
| OLD | NEW |