Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 namespace v8 { | 44 namespace v8 { |
| 45 | 45 |
| 46 // Forward declarations. | 46 // Forward declarations. |
| 47 class ApiFunction; | 47 class ApiFunction; |
| 48 | 48 |
| 49 namespace internal { | 49 namespace internal { |
| 50 | 50 |
| 51 // Forward declarations. | 51 // Forward declarations. |
| 52 class StatsCounter; | 52 class StatsCounter; |
| 53 | 53 |
| 54 | |
| 55 // CpuFeatures keeps track of which features are supported by the target CPU. | |
| 56 // Supported features must be enabled by a CpuFeatureScope before use. | |
| 57 // Example: | |
| 58 // if (assembler->IsSupported(SSE3)) { | |
| 59 // CpuFeatureScope fscope(assembler, SSE3); | |
| 60 // // Generate code containing SSE3 instructions. | |
| 61 // } else { | |
| 62 // // Generate alternative code. | |
| 63 // } | |
| 64 class CpuFeatures : public AllStatic { | |
|
Michael Starzinger
2015/09/11 11:40:03
I don't see a particular need to move this up here
Michael Lippautz
2015/09/11 11:54:52
Done. This was needed when the methods were still
| |
| 65 public: | |
| 66 static void Probe(bool cross_compile) { | |
| 67 STATIC_ASSERT(NUMBER_OF_CPU_FEATURES <= kBitsPerInt); | |
| 68 if (initialized_) return; | |
| 69 initialized_ = true; | |
| 70 ProbeImpl(cross_compile); | |
| 71 } | |
| 72 | |
| 73 static unsigned SupportedFeatures() { | |
| 74 Probe(false); | |
| 75 return supported_; | |
| 76 } | |
| 77 | |
| 78 static bool IsSupported(CpuFeature f) { | |
| 79 return (supported_ & (1u << f)) != 0; | |
| 80 } | |
| 81 | |
| 82 static inline bool SupportsCrankshaft(); | |
| 83 | |
| 84 static inline unsigned cache_line_size() { | |
| 85 DCHECK(cache_line_size_ != 0); | |
| 86 return cache_line_size_; | |
| 87 } | |
| 88 | |
| 89 static void PrintTarget(); | |
| 90 static void PrintFeatures(); | |
| 91 | |
| 92 // Flush instruction cache. | |
| 93 static void FlushICache(void* start, size_t size); | |
| 94 | |
| 95 private: | |
| 96 // Platform-dependent implementation. | |
| 97 static void ProbeImpl(bool cross_compile); | |
| 98 | |
| 99 static unsigned supported_; | |
| 100 static unsigned cache_line_size_; | |
| 101 static bool initialized_; | |
| 102 friend class ExternalReference; | |
| 103 DISALLOW_COPY_AND_ASSIGN(CpuFeatures); | |
| 104 }; | |
| 105 | |
| 106 | |
| 54 // ----------------------------------------------------------------------------- | 107 // ----------------------------------------------------------------------------- |
| 55 // Platform independent assembler base class. | 108 // Platform independent assembler base class. |
| 56 | 109 |
| 57 class AssemblerBase: public Malloced { | 110 class AssemblerBase: public Malloced { |
| 58 public: | 111 public: |
| 59 AssemblerBase(Isolate* isolate, void* buffer, int buffer_size); | 112 AssemblerBase(Isolate* isolate, void* buffer, int buffer_size); |
| 60 virtual ~AssemblerBase(); | 113 virtual ~AssemblerBase(); |
| 61 | 114 |
| 62 Isolate* isolate() const { return isolate_; } | 115 Isolate* isolate() const { return isolate_; } |
| 63 int jit_cookie() const { return jit_cookie_; } | 116 int jit_cookie() const { return jit_cookie_; } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 148 |
| 96 int pc_offset() const { return static_cast<int>(pc_ - buffer_); } | 149 int pc_offset() const { return static_cast<int>(pc_ - buffer_); } |
| 97 | 150 |
| 98 // This function is called when code generation is aborted, so that | 151 // This function is called when code generation is aborted, so that |
| 99 // the assembler could clean up internal data structures. | 152 // the assembler could clean up internal data structures. |
| 100 virtual void AbortedCodeGeneration() { } | 153 virtual void AbortedCodeGeneration() { } |
| 101 | 154 |
| 102 static const int kMinimalBufferSize = 4*KB; | 155 static const int kMinimalBufferSize = 4*KB; |
| 103 | 156 |
| 104 protected: | 157 protected: |
| 158 static void FlushICache(Isolate* isolate, void* start, size_t size); | |
| 159 | |
| 160 // TODO(all): Help get rid of this one. | |
| 161 static void FlushICacheWithoutIsolate(void* start, size_t size); | |
| 162 | |
| 105 // The buffer into which code and relocation info are generated. It could | 163 // The buffer into which code and relocation info are generated. It could |
| 106 // either be owned by the assembler or be provided externally. | 164 // either be owned by the assembler or be provided externally. |
| 107 byte* buffer_; | 165 byte* buffer_; |
| 108 int buffer_size_; | 166 int buffer_size_; |
| 109 bool own_buffer_; | 167 bool own_buffer_; |
| 110 | 168 |
| 111 void set_constant_pool_available(bool available) { | 169 void set_constant_pool_available(bool available) { |
| 112 if (FLAG_enable_embedded_constant_pool) { | 170 if (FLAG_enable_embedded_constant_pool) { |
| 113 constant_pool_available_ = available; | 171 constant_pool_available_ = available; |
| 114 } else { | 172 } else { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 | 238 |
| 181 private: | 239 private: |
| 182 AssemblerBase* assembler_; | 240 AssemblerBase* assembler_; |
| 183 uint64_t old_enabled_; | 241 uint64_t old_enabled_; |
| 184 #else | 242 #else |
| 185 CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) {} | 243 CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) {} |
| 186 #endif | 244 #endif |
| 187 }; | 245 }; |
| 188 | 246 |
| 189 | 247 |
| 190 // CpuFeatures keeps track of which features are supported by the target CPU. | |
| 191 // Supported features must be enabled by a CpuFeatureScope before use. | |
| 192 // Example: | |
| 193 // if (assembler->IsSupported(SSE3)) { | |
| 194 // CpuFeatureScope fscope(assembler, SSE3); | |
| 195 // // Generate code containing SSE3 instructions. | |
| 196 // } else { | |
| 197 // // Generate alternative code. | |
| 198 // } | |
| 199 class CpuFeatures : public AllStatic { | |
| 200 public: | |
| 201 static void Probe(bool cross_compile) { | |
| 202 STATIC_ASSERT(NUMBER_OF_CPU_FEATURES <= kBitsPerInt); | |
| 203 if (initialized_) return; | |
| 204 initialized_ = true; | |
| 205 ProbeImpl(cross_compile); | |
| 206 } | |
| 207 | |
| 208 static unsigned SupportedFeatures() { | |
| 209 Probe(false); | |
| 210 return supported_; | |
| 211 } | |
| 212 | |
| 213 static bool IsSupported(CpuFeature f) { | |
| 214 return (supported_ & (1u << f)) != 0; | |
| 215 } | |
| 216 | |
| 217 static inline bool SupportsCrankshaft(); | |
| 218 | |
| 219 static inline unsigned cache_line_size() { | |
| 220 DCHECK(cache_line_size_ != 0); | |
| 221 return cache_line_size_; | |
| 222 } | |
| 223 | |
| 224 static void PrintTarget(); | |
| 225 static void PrintFeatures(); | |
| 226 | |
| 227 // Flush instruction cache. | |
| 228 static void FlushICache(void* start, size_t size); | |
| 229 | |
| 230 private: | |
| 231 // Platform-dependent implementation. | |
| 232 static void ProbeImpl(bool cross_compile); | |
| 233 | |
| 234 static unsigned supported_; | |
| 235 static unsigned cache_line_size_; | |
| 236 static bool initialized_; | |
| 237 friend class ExternalReference; | |
| 238 DISALLOW_COPY_AND_ASSIGN(CpuFeatures); | |
| 239 }; | |
| 240 | |
| 241 | |
| 242 // ----------------------------------------------------------------------------- | 248 // ----------------------------------------------------------------------------- |
| 243 // Labels represent pc locations; they are typically jump or call targets. | 249 // Labels represent pc locations; they are typically jump or call targets. |
| 244 // After declaration, a label can be freely used to denote known or (yet) | 250 // After declaration, a label can be freely used to denote known or (yet) |
| 245 // unknown pc location. Assembler::bind() is used to bind a label to the | 251 // unknown pc location. Assembler::bind() is used to bind a label to the |
| 246 // current pc. A label can be bound only once. | 252 // current pc. A label can be bound only once. |
| 247 | 253 |
| 248 class Label { | 254 class Label { |
| 249 public: | 255 public: |
| 250 enum Distance { | 256 enum Distance { |
| 251 kNear, kFar | 257 kNear, kFar |
| (...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1267 }; | 1273 }; |
| 1268 | 1274 |
| 1269 Label emitted_label_; // Records pc_offset of emitted pool | 1275 Label emitted_label_; // Records pc_offset of emitted pool |
| 1270 PerTypeEntryInfo info_[ConstantPoolEntry::NUMBER_OF_TYPES]; | 1276 PerTypeEntryInfo info_[ConstantPoolEntry::NUMBER_OF_TYPES]; |
| 1271 }; | 1277 }; |
| 1272 | 1278 |
| 1273 | 1279 |
| 1274 } } // namespace v8::internal | 1280 } } // namespace v8::internal |
| 1275 | 1281 |
| 1276 #endif // V8_ASSEMBLER_H_ | 1282 #endif // V8_ASSEMBLER_H_ |
| OLD | NEW |