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

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

Issue 12391055: Cleaned up CpuFeature scope handling. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed nits Created 7 years, 9 months 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
« no previous file with comments | « src/isolate.h ('k') | src/mips/assembler-mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 386 }
387 387
388 private: 388 private:
389 int32_t offset_; 389 int32_t offset_;
390 390
391 friend class Assembler; 391 friend class Assembler;
392 }; 392 };
393 393
394 394
395 // CpuFeatures keeps track of which features are supported by the target CPU. 395 // CpuFeatures keeps track of which features are supported by the target CPU.
396 // Supported features must be enabled by a Scope before use. 396 // Supported features must be enabled by a CpuFeatureScope before use.
397 class CpuFeatures : public AllStatic { 397 class CpuFeatures : public AllStatic {
398 public: 398 public:
399 // Detect features of the target CPU. Set safe defaults if the serializer 399 // Detect features of the target CPU. Set safe defaults if the serializer
400 // is enabled (snapshots must be portable). 400 // is enabled (snapshots must be portable).
401 static void Probe(); 401 static void Probe();
402 402
403 // Check whether a feature is supported by the target CPU. 403 // Check whether a feature is supported by the target CPU.
404 static bool IsSupported(CpuFeature f) { 404 static bool IsSupported(CpuFeature f) {
405 ASSERT(initialized_); 405 ASSERT(initialized_);
406 if (f == FPU && !FLAG_enable_fpu) return false; 406 if (f == FPU && !FLAG_enable_fpu) return false;
407 return (supported_ & (1u << f)) != 0; 407 return (supported_ & (1u << f)) != 0;
408 } 408 }
409 409
410 410 static bool IsFoundByRuntimeProbingOnly(CpuFeature f) {
411 #ifdef DEBUG
412 // Check whether a feature is currently enabled.
413 static bool IsEnabled(CpuFeature f) {
414 ASSERT(initialized_); 411 ASSERT(initialized_);
415 Isolate* isolate = Isolate::UncheckedCurrent(); 412 return (found_by_runtime_probing_only_ &
416 if (isolate == NULL) { 413 (static_cast<uint64_t>(1) << f)) != 0;
417 // When no isolate is available, work as if we're running in
418 // release mode.
419 return IsSupported(f);
420 }
421 unsigned enabled = static_cast<unsigned>(isolate->enabled_cpu_features());
422 return (enabled & (1u << f)) != 0;
423 } 414 }
424 #endif
425
426 // Enable a specified feature within a scope.
427 class Scope BASE_EMBEDDED {
428 #ifdef DEBUG
429
430 public:
431 explicit Scope(CpuFeature f) {
432 unsigned mask = 1u << f;
433 ASSERT(CpuFeatures::IsSupported(f));
434 ASSERT(!Serializer::enabled() ||
435 (CpuFeatures::found_by_runtime_probing_ & mask) == 0);
436 isolate_ = Isolate::UncheckedCurrent();
437 old_enabled_ = 0;
438 if (isolate_ != NULL) {
439 old_enabled_ = static_cast<unsigned>(isolate_->enabled_cpu_features());
440 isolate_->set_enabled_cpu_features(old_enabled_ | mask);
441 }
442 }
443 ~Scope() {
444 ASSERT_EQ(Isolate::UncheckedCurrent(), isolate_);
445 if (isolate_ != NULL) {
446 isolate_->set_enabled_cpu_features(old_enabled_);
447 }
448 }
449
450 private:
451 Isolate* isolate_;
452 unsigned old_enabled_;
453 #else
454
455 public:
456 explicit Scope(CpuFeature f) {}
457 #endif
458 };
459 415
460 class TryForceFeatureScope BASE_EMBEDDED { 416 class TryForceFeatureScope BASE_EMBEDDED {
461 public: 417 public:
462 explicit TryForceFeatureScope(CpuFeature f) 418 explicit TryForceFeatureScope(CpuFeature f)
463 : old_supported_(CpuFeatures::supported_) { 419 : old_supported_(CpuFeatures::supported_) {
464 if (CanForce()) { 420 if (CanForce()) {
465 CpuFeatures::supported_ |= (1u << f); 421 CpuFeatures::supported_ |= (1u << f);
466 } 422 }
467 } 423 }
468 424
(...skipping 12 matching lines...) Expand all
481 } 437 }
482 438
483 const unsigned old_supported_; 439 const unsigned old_supported_;
484 }; 440 };
485 441
486 private: 442 private:
487 #ifdef DEBUG 443 #ifdef DEBUG
488 static bool initialized_; 444 static bool initialized_;
489 #endif 445 #endif
490 static unsigned supported_; 446 static unsigned supported_;
491 static unsigned found_by_runtime_probing_; 447 static unsigned found_by_runtime_probing_only_;
492 448
493 friend class ExternalReference; 449 friend class ExternalReference;
494 DISALLOW_COPY_AND_ASSIGN(CpuFeatures); 450 DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
495 }; 451 };
496 452
497 453
498 class Assembler : public AssemblerBase { 454 class Assembler : public AssemblerBase {
499 public: 455 public:
500 // Create an assembler. Instructions and relocation information are emitted 456 // Create an assembler. Instructions and relocation information are emitted
501 // into a buffer, with the instructions starting from the beginning and the 457 // into a buffer, with the instructions starting from the beginning and the
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 class EnsureSpace BASE_EMBEDDED { 1229 class EnsureSpace BASE_EMBEDDED {
1274 public: 1230 public:
1275 explicit EnsureSpace(Assembler* assembler) { 1231 explicit EnsureSpace(Assembler* assembler) {
1276 assembler->CheckBuffer(); 1232 assembler->CheckBuffer();
1277 } 1233 }
1278 }; 1234 };
1279 1235
1280 } } // namespace v8::internal 1236 } } // namespace v8::internal
1281 1237
1282 #endif // V8_ARM_ASSEMBLER_MIPS_H_ 1238 #endif // V8_ARM_ASSEMBLER_MIPS_H_
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/mips/assembler-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698