Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: src/ia32/assembler-ia32.h

Issue 391051: Allow a platform to indicate that some CPU features are always... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 2006-2008 the V8 project authors. All rights reserved. 33 // Copyright 2006-2008 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 "serialize.h"
41
40 namespace v8 { 42 namespace v8 {
41 namespace internal { 43 namespace internal {
42 44
43 // CPU Registers. 45 // CPU Registers.
44 // 46 //
45 // 1) We would prefer to use an enum, but enum values are assignment- 47 // 1) We would prefer to use an enum, but enum values are assignment-
46 // compatible with int, which has caused code-generation bugs. 48 // compatible with int, which has caused code-generation bugs.
47 // 49 //
48 // 2) We would prefer to use a class instead of a struct but we don't like 50 // 2) We would prefer to use a class instead of a struct but we don't like
49 // the register initialization to depend on the particular initialization 51 // the register initialization to depend on the particular initialization
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 // Supported features must be enabled by a Scope before use. 353 // Supported features must be enabled by a Scope before use.
352 // Example: 354 // Example:
353 // if (CpuFeatures::IsSupported(SSE2)) { 355 // if (CpuFeatures::IsSupported(SSE2)) {
354 // CpuFeatures::Scope fscope(SSE2); 356 // CpuFeatures::Scope fscope(SSE2);
355 // // Generate SSE2 floating point code. 357 // // Generate SSE2 floating point code.
356 // } else { 358 // } else {
357 // // Generate standard x87 floating point code. 359 // // Generate standard x87 floating point code.
358 // } 360 // }
359 class CpuFeatures : public AllStatic { 361 class CpuFeatures : public AllStatic {
360 public: 362 public:
361 // Feature flags bit positions. They are mostly based on the CPUID spec.
362 // (We assign CPUID itself to one of the currently reserved bits --
363 // feel free to change this if needed.)
364 enum Feature { SSE3 = 32, SSE2 = 26, CMOV = 15, RDTSC = 4, CPUID = 10 };
365 // Detect features of the target CPU. Set safe defaults if the serializer 363 // Detect features of the target CPU. Set safe defaults if the serializer
366 // is enabled (snapshots must be portable). 364 // is enabled (snapshots must be portable).
367 static void Probe(); 365 static void Probe();
368 // Check whether a feature is supported by the target CPU. 366 // Check whether a feature is supported by the target CPU.
369 static bool IsSupported(Feature f) { 367 static bool IsSupported(CpuFeature f) {
370 if (f == SSE2 && !FLAG_enable_sse2) return false; 368 if (f == SSE2 && !FLAG_enable_sse2) return false;
371 if (f == SSE3 && !FLAG_enable_sse3) return false; 369 if (f == SSE3 && !FLAG_enable_sse3) return false;
372 if (f == CMOV && !FLAG_enable_cmov) return false; 370 if (f == CMOV && !FLAG_enable_cmov) return false;
373 if (f == RDTSC && !FLAG_enable_rdtsc) return false; 371 if (f == RDTSC && !FLAG_enable_rdtsc) return false;
374 return (supported_ & (static_cast<uint64_t>(1) << f)) != 0; 372 return (supported_ & (static_cast<uint64_t>(1) << f)) != 0;
375 } 373 }
376 // Check whether a feature is currently enabled. 374 // Check whether a feature is currently enabled.
377 static bool IsEnabled(Feature f) { 375 static bool IsEnabled(CpuFeature f) {
378 return (enabled_ & (static_cast<uint64_t>(1) << f)) != 0; 376 return (enabled_ & (static_cast<uint64_t>(1) << f)) != 0;
379 } 377 }
380 // Enable a specified feature within a scope. 378 // Enable a specified feature within a scope.
381 class Scope BASE_EMBEDDED { 379 class Scope BASE_EMBEDDED {
382 #ifdef DEBUG 380 #ifdef DEBUG
383 public: 381 public:
384 explicit Scope(Feature f) { 382 explicit Scope(CpuFeature f) {
383 uint64_t mask = static_cast<uint64_t>(1) << f;
385 ASSERT(CpuFeatures::IsSupported(f)); 384 ASSERT(CpuFeatures::IsSupported(f));
385 ASSERT(!Serializer::enabled() || (found_by_runtime_probing_ & mask) == 0);
386 old_enabled_ = CpuFeatures::enabled_; 386 old_enabled_ = CpuFeatures::enabled_;
387 CpuFeatures::enabled_ |= (static_cast<uint64_t>(1) << f); 387 CpuFeatures::enabled_ |= mask;
388 } 388 }
389 ~Scope() { CpuFeatures::enabled_ = old_enabled_; } 389 ~Scope() { CpuFeatures::enabled_ = old_enabled_; }
390 private: 390 private:
391 uint64_t old_enabled_; 391 uint64_t old_enabled_;
392 #else 392 #else
393 public: 393 public:
394 explicit Scope(Feature f) {} 394 explicit Scope(CpuFeature f) {}
395 #endif 395 #endif
396 }; 396 };
397 private: 397 private:
398 static uint64_t supported_; 398 static uint64_t supported_;
399 static uint64_t enabled_; 399 static uint64_t enabled_;
400 static uint64_t found_by_runtime_probing_;
400 }; 401 };
401 402
402 403
403 class Assembler : public Malloced { 404 class Assembler : public Malloced {
404 private: 405 private:
405 // We check before assembling an instruction that there is sufficient 406 // We check before assembling an instruction that there is sufficient
406 // space to write an instruction and its relocation information. 407 // space to write an instruction and its relocation information.
407 // The relocation writer's position must be kGap bytes above the end of 408 // The relocation writer's position must be kGap bytes above the end of
408 // the generated instructions. This leaves enough space for the 409 // the generated instructions. This leaves enough space for the
409 // longest possible ia32 instruction, 15 bytes, and the longest possible 410 // longest possible ia32 instruction, 15 bytes, and the longest possible
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 private: 893 private:
893 Assembler* assembler_; 894 Assembler* assembler_;
894 #ifdef DEBUG 895 #ifdef DEBUG
895 int space_before_; 896 int space_before_;
896 #endif 897 #endif
897 }; 898 };
898 899
899 } } // namespace v8::internal 900 } } // namespace v8::internal
900 901
901 #endif // V8_IA32_ASSEMBLER_IA32_H_ 902 #endif // V8_IA32_ASSEMBLER_IA32_H_
OLDNEW
« src/arm/assembler-arm.h ('K') | « src/globals.h ('k') | src/ia32/assembler-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698