| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // The original source code covered by the above license above has been | 31 // The original source code covered by the above license above has been |
| 32 // modified significantly by Google Inc. | 32 // modified significantly by Google Inc. |
| 33 // Copyright 2011 the V8 project authors. All rights reserved. | 33 // Copyright 2011 the V8 project authors. All rights reserved. |
| 34 | 34 |
| 35 // A light-weight IA32 Assembler. | 35 // A light-weight IA32 Assembler. |
| 36 | 36 |
| 37 #ifndef V8_IA32_ASSEMBLER_IA32_H_ | 37 #ifndef V8_IA32_ASSEMBLER_IA32_H_ |
| 38 #define V8_IA32_ASSEMBLER_IA32_H_ | 38 #define V8_IA32_ASSEMBLER_IA32_H_ |
| 39 | 39 |
| 40 #include "isolate.h" |
| 40 #include "serialize.h" | 41 #include "serialize.h" |
| 41 | 42 |
| 42 namespace v8 { | 43 namespace v8 { |
| 43 namespace internal { | 44 namespace internal { |
| 44 | 45 |
| 45 // CPU Registers. | 46 // CPU Registers. |
| 46 // | 47 // |
| 47 // 1) We would prefer to use an enum, but enum values are assignment- | 48 // 1) We would prefer to use an enum, but enum values are assignment- |
| 48 // compatible with int, which has caused code-generation bugs. | 49 // compatible with int, which has caused code-generation bugs. |
| 49 // | 50 // |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 | 441 |
| 441 // CpuFeatures keeps track of which features are supported by the target CPU. | 442 // CpuFeatures keeps track of which features are supported by the target CPU. |
| 442 // Supported features must be enabled by a Scope before use. | 443 // Supported features must be enabled by a Scope before use. |
| 443 // Example: | 444 // Example: |
| 444 // if (CpuFeatures::IsSupported(SSE2)) { | 445 // if (CpuFeatures::IsSupported(SSE2)) { |
| 445 // CpuFeatures::Scope fscope(SSE2); | 446 // CpuFeatures::Scope fscope(SSE2); |
| 446 // // Generate SSE2 floating point code. | 447 // // Generate SSE2 floating point code. |
| 447 // } else { | 448 // } else { |
| 448 // // Generate standard x87 floating point code. | 449 // // Generate standard x87 floating point code. |
| 449 // } | 450 // } |
| 450 class CpuFeatures : public AllStatic { | 451 class CpuFeatures { |
| 451 public: | 452 public: |
| 452 // Detect features of the target CPU. If the portable flag is set, | 453 // Detect features of the target CPU. If the portable flag is set, |
| 453 // the method sets safe defaults if the serializer is enabled | 454 // the method sets safe defaults if the serializer is enabled |
| 454 // (snapshots must be portable). | 455 // (snapshots must be portable). |
| 455 static void Probe(bool portable); | 456 void Probe(bool portable); |
| 456 static void Clear() { supported_ = 0; } | 457 void Clear() { supported_ = 0; } |
| 457 | 458 |
| 458 // Check whether a feature is supported by the target CPU. | 459 // Check whether a feature is supported by the target CPU. |
| 459 static bool IsSupported(CpuFeature f) { | 460 bool IsSupported(CpuFeature f) const { |
| 460 if (f == SSE2 && !FLAG_enable_sse2) return false; | 461 if (f == SSE2 && !FLAG_enable_sse2) return false; |
| 461 if (f == SSE3 && !FLAG_enable_sse3) return false; | 462 if (f == SSE3 && !FLAG_enable_sse3) return false; |
| 462 if (f == SSE4_1 && !FLAG_enable_sse4_1) return false; | 463 if (f == SSE4_1 && !FLAG_enable_sse4_1) return false; |
| 463 if (f == CMOV && !FLAG_enable_cmov) return false; | 464 if (f == CMOV && !FLAG_enable_cmov) return false; |
| 464 if (f == RDTSC && !FLAG_enable_rdtsc) return false; | 465 if (f == RDTSC && !FLAG_enable_rdtsc) return false; |
| 465 return (supported_ & (static_cast<uint64_t>(1) << f)) != 0; | 466 return (supported_ & (static_cast<uint64_t>(1) << f)) != 0; |
| 466 } | 467 } |
| 467 // Check whether a feature is currently enabled. | 468 // Check whether a feature is currently enabled. |
| 468 static bool IsEnabled(CpuFeature f) { | 469 bool IsEnabled(CpuFeature f) const { |
| 469 return (enabled_ & (static_cast<uint64_t>(1) << f)) != 0; | 470 return (enabled_ & (static_cast<uint64_t>(1) << f)) != 0; |
| 470 } | 471 } |
| 471 // Enable a specified feature within a scope. | 472 // Enable a specified feature within a scope. |
| 472 class Scope BASE_EMBEDDED { | 473 class Scope BASE_EMBEDDED { |
| 473 #ifdef DEBUG | 474 #ifdef DEBUG |
| 474 public: | 475 public: |
| 475 explicit Scope(CpuFeature f) { | 476 explicit Scope(CpuFeature f) |
| 477 : cpu_features_(Isolate::Current()->cpu_features()), |
| 478 isolate_(Isolate::Current()) { |
| 476 uint64_t mask = static_cast<uint64_t>(1) << f; | 479 uint64_t mask = static_cast<uint64_t>(1) << f; |
| 477 ASSERT(CpuFeatures::IsSupported(f)); | 480 ASSERT(cpu_features_->IsSupported(f)); |
| 478 ASSERT(!Serializer::enabled() || (found_by_runtime_probing_ & mask) == 0); | 481 ASSERT(!Serializer::enabled() || |
| 479 old_enabled_ = CpuFeatures::enabled_; | 482 (cpu_features_->found_by_runtime_probing_ & mask) == 0); |
| 480 CpuFeatures::enabled_ |= mask; | 483 old_enabled_ = cpu_features_->enabled_; |
| 484 cpu_features_->enabled_ |= mask; |
| 481 } | 485 } |
| 482 ~Scope() { CpuFeatures::enabled_ = old_enabled_; } | 486 ~Scope() { |
| 487 ASSERT_EQ(Isolate::Current(), isolate_); |
| 488 cpu_features_->enabled_ = old_enabled_; |
| 489 } |
| 483 private: | 490 private: |
| 484 uint64_t old_enabled_; | 491 uint64_t old_enabled_; |
| 492 CpuFeatures* cpu_features_; |
| 493 Isolate* isolate_; |
| 485 #else | 494 #else |
| 486 public: | 495 public: |
| 487 explicit Scope(CpuFeature f) {} | 496 explicit Scope(CpuFeature f) {} |
| 488 #endif | 497 #endif |
| 489 }; | 498 }; |
| 499 |
| 490 private: | 500 private: |
| 491 static uint64_t supported_; | 501 CpuFeatures(); |
| 492 static uint64_t enabled_; | 502 |
| 493 static uint64_t found_by_runtime_probing_; | 503 uint64_t supported_; |
| 504 uint64_t enabled_; |
| 505 uint64_t found_by_runtime_probing_; |
| 506 |
| 507 friend class Isolate; |
| 508 |
| 509 DISALLOW_COPY_AND_ASSIGN(CpuFeatures); |
| 494 }; | 510 }; |
| 495 | 511 |
| 496 | 512 |
| 497 class Assembler : public Malloced { | 513 class Assembler : public Malloced { |
| 498 private: | 514 private: |
| 499 // We check before assembling an instruction that there is sufficient | 515 // We check before assembling an instruction that there is sufficient |
| 500 // space to write an instruction and its relocation information. | 516 // space to write an instruction and its relocation information. |
| 501 // The relocation writer's position must be kGap bytes above the end of | 517 // The relocation writer's position must be kGap bytes above the end of |
| 502 // the generated instructions. This leaves enough space for the | 518 // the generated instructions. This leaves enough space for the |
| 503 // longest possible ia32 instruction, 15 bytes, and the longest possible | 519 // longest possible ia32 instruction, 15 bytes, and the longest possible |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 | 1074 |
| 1059 friend class CodePatcher; | 1075 friend class CodePatcher; |
| 1060 friend class EnsureSpace; | 1076 friend class EnsureSpace; |
| 1061 | 1077 |
| 1062 // Code buffer: | 1078 // Code buffer: |
| 1063 // The buffer into which code and relocation info are generated. | 1079 // The buffer into which code and relocation info are generated. |
| 1064 byte* buffer_; | 1080 byte* buffer_; |
| 1065 int buffer_size_; | 1081 int buffer_size_; |
| 1066 // True if the assembler owns the buffer, false if buffer is external. | 1082 // True if the assembler owns the buffer, false if buffer is external. |
| 1067 bool own_buffer_; | 1083 bool own_buffer_; |
| 1068 // A previously allocated buffer of kMinimalBufferSize bytes, or NULL. | |
| 1069 static byte* spare_buffer_; | |
| 1070 | 1084 |
| 1071 // code generation | 1085 // code generation |
| 1072 byte* pc_; // the program counter; moves forward | 1086 byte* pc_; // the program counter; moves forward |
| 1073 RelocInfoWriter reloc_info_writer; | 1087 RelocInfoWriter reloc_info_writer; |
| 1074 | 1088 |
| 1075 // push-pop elimination | 1089 // push-pop elimination |
| 1076 byte* last_pc_; | 1090 byte* last_pc_; |
| 1077 | 1091 |
| 1078 PositionsRecorder positions_recorder_; | 1092 PositionsRecorder positions_recorder_; |
| 1079 | 1093 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1106 private: | 1120 private: |
| 1107 Assembler* assembler_; | 1121 Assembler* assembler_; |
| 1108 #ifdef DEBUG | 1122 #ifdef DEBUG |
| 1109 int space_before_; | 1123 int space_before_; |
| 1110 #endif | 1124 #endif |
| 1111 }; | 1125 }; |
| 1112 | 1126 |
| 1113 } } // namespace v8::internal | 1127 } } // namespace v8::internal |
| 1114 | 1128 |
| 1115 #endif // V8_IA32_ASSEMBLER_IA32_H_ | 1129 #endif // V8_IA32_ASSEMBLER_IA32_H_ |
| OLD | NEW |