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

Side by Side Diff: src/ia32/assembler-ia32.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/assembler.cc ('k') | src/ia32/assembler-ia32.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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 498
499 class TypeField: public BitField<Type, 0, 2> {}; 499 class TypeField: public BitField<Type, 0, 2> {};
500 class NextField: public BitField<int, 2, 32-2> {}; 500 class NextField: public BitField<int, 2, 32-2> {};
501 501
502 void init(Label* L, Type type); 502 void init(Label* L, Type type);
503 }; 503 };
504 504
505 505
506 506
507 // CpuFeatures keeps track of which features are supported by the target CPU. 507 // CpuFeatures keeps track of which features are supported by the target CPU.
508 // Supported features must be enabled by a Scope before use. 508 // Supported features must be enabled by a CpuFeatureScope before use.
509 // Example: 509 // Example:
510 // if (CpuFeatures::IsSupported(SSE2)) { 510 // if (assembler->IsSupported(SSE2)) {
511 // CpuFeatures::Scope fscope(SSE2); 511 // CpuFeatureScope fscope(assembler, SSE2);
512 // // Generate SSE2 floating point code. 512 // // Generate SSE2 floating point code.
513 // } else { 513 // } else {
514 // // Generate standard x87 floating point code. 514 // // Generate standard x87 floating point code.
515 // } 515 // }
516 class CpuFeatures : public AllStatic { 516 class CpuFeatures : public AllStatic {
517 public: 517 public:
518 // Detect features of the target CPU. Set safe defaults if the serializer 518 // Detect features of the target CPU. Set safe defaults if the serializer
519 // is enabled (snapshots must be portable). 519 // is enabled (snapshots must be portable).
520 static void Probe(); 520 static void Probe();
521 521
522 // Check whether a feature is supported by the target CPU. 522 // Check whether a feature is supported by the target CPU.
523 static bool IsSupported(CpuFeature f) { 523 static bool IsSupported(CpuFeature f) {
524 ASSERT(initialized_); 524 ASSERT(initialized_);
525 if (f == SSE2 && !FLAG_enable_sse2) return false; 525 if (f == SSE2 && !FLAG_enable_sse2) return false;
526 if (f == SSE3 && !FLAG_enable_sse3) return false; 526 if (f == SSE3 && !FLAG_enable_sse3) return false;
527 if (f == SSE4_1 && !FLAG_enable_sse4_1) return false; 527 if (f == SSE4_1 && !FLAG_enable_sse4_1) return false;
528 if (f == CMOV && !FLAG_enable_cmov) return false; 528 if (f == CMOV && !FLAG_enable_cmov) return false;
529 if (f == RDTSC && !FLAG_enable_rdtsc) return false; 529 if (f == RDTSC && !FLAG_enable_rdtsc) return false;
530 return (supported_ & (static_cast<uint64_t>(1) << f)) != 0; 530 return (supported_ & (static_cast<uint64_t>(1) << f)) != 0;
531 } 531 }
532 532
533 #ifdef DEBUG 533 static bool IsFoundByRuntimeProbingOnly(CpuFeature f) {
534 // Check whether a feature is currently enabled.
535 static bool IsEnabled(CpuFeature f) {
536 ASSERT(initialized_); 534 ASSERT(initialized_);
537 Isolate* isolate = Isolate::UncheckedCurrent(); 535 return (found_by_runtime_probing_only_ &
538 if (isolate == NULL) { 536 (static_cast<uint64_t>(1) << f)) != 0;
539 // When no isolate is available, work as if we're running in
540 // release mode.
541 return IsSupported(f);
542 }
543 uint64_t enabled = isolate->enabled_cpu_features();
544 return (enabled & (static_cast<uint64_t>(1) << f)) != 0;
545 } 537 }
546 #endif
547
548 // Enable a specified feature within a scope.
549 class Scope BASE_EMBEDDED {
550 #ifdef DEBUG
551
552 public:
553 explicit Scope(CpuFeature f) {
554 uint64_t mask = static_cast<uint64_t>(1) << f;
555 ASSERT(CpuFeatures::IsSupported(f));
556 ASSERT(!Serializer::enabled() ||
557 (CpuFeatures::found_by_runtime_probing_ & mask) == 0);
558 isolate_ = Isolate::UncheckedCurrent();
559 old_enabled_ = 0;
560 if (isolate_ != NULL) {
561 old_enabled_ = isolate_->enabled_cpu_features();
562 isolate_->set_enabled_cpu_features(old_enabled_ | mask);
563 }
564 }
565 ~Scope() {
566 ASSERT_EQ(Isolate::UncheckedCurrent(), isolate_);
567 if (isolate_ != NULL) {
568 isolate_->set_enabled_cpu_features(old_enabled_);
569 }
570 }
571
572 private:
573 Isolate* isolate_;
574 uint64_t old_enabled_;
575 #else
576
577 public:
578 explicit Scope(CpuFeature f) {}
579 #endif
580 };
581 538
582 class TryForceFeatureScope BASE_EMBEDDED { 539 class TryForceFeatureScope BASE_EMBEDDED {
583 public: 540 public:
584 explicit TryForceFeatureScope(CpuFeature f) 541 explicit TryForceFeatureScope(CpuFeature f)
585 : old_supported_(CpuFeatures::supported_) { 542 : old_supported_(CpuFeatures::supported_) {
586 if (CanForce()) { 543 if (CanForce()) {
587 CpuFeatures::supported_ |= (static_cast<uint64_t>(1) << f); 544 CpuFeatures::supported_ |= (static_cast<uint64_t>(1) << f);
588 } 545 }
589 } 546 }
590 547
(...skipping 12 matching lines...) Expand all
603 } 560 }
604 561
605 const uint64_t old_supported_; 562 const uint64_t old_supported_;
606 }; 563 };
607 564
608 private: 565 private:
609 #ifdef DEBUG 566 #ifdef DEBUG
610 static bool initialized_; 567 static bool initialized_;
611 #endif 568 #endif
612 static uint64_t supported_; 569 static uint64_t supported_;
613 static uint64_t found_by_runtime_probing_; 570 static uint64_t found_by_runtime_probing_only_;
614 571
615 friend class ExternalReference; 572 friend class ExternalReference;
616 DISALLOW_COPY_AND_ASSIGN(CpuFeatures); 573 DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
617 }; 574 };
618 575
619 576
620 class Assembler : public AssemblerBase { 577 class Assembler : public AssemblerBase {
621 private: 578 private:
622 // We check before assembling an instruction that there is sufficient 579 // We check before assembling an instruction that there is sufficient
623 // space to write an instruction and its relocation information. 580 // space to write an instruction and its relocation information.
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 private: 1229 private:
1273 Assembler* assembler_; 1230 Assembler* assembler_;
1274 #ifdef DEBUG 1231 #ifdef DEBUG
1275 int space_before_; 1232 int space_before_;
1276 #endif 1233 #endif
1277 }; 1234 };
1278 1235
1279 } } // namespace v8::internal 1236 } } // namespace v8::internal
1280 1237
1281 #endif // V8_IA32_ASSEMBLER_IA32_H_ 1238 #endif // V8_IA32_ASSEMBLER_IA32_H_
OLDNEW
« no previous file with comments | « src/assembler.cc ('k') | src/ia32/assembler-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698