Revision: 17123
Author:   [email protected]
Date:     Thu Oct 10 08:45:40 2013 UTC
Log:      Ensure only whitelisted stubs have sse2 versions in the snapshot.

BUG=
[email protected]

Review URL: https://codereview.chromium.org/26680002
http://code.google.com/p/v8/source/detail?r=17123

Modified:
 /branches/bleeding_edge/src/arm/assembler-arm.cc
 /branches/bleeding_edge/src/arm/assembler-arm.h
 /branches/bleeding_edge/src/assembler.cc
 /branches/bleeding_edge/src/assembler.h
 /branches/bleeding_edge/src/code-stubs.cc
 /branches/bleeding_edge/src/code-stubs.h
 /branches/bleeding_edge/src/ia32/assembler-ia32.cc
 /branches/bleeding_edge/src/ia32/assembler-ia32.h
 /branches/bleeding_edge/src/mips/assembler-mips.cc
 /branches/bleeding_edge/src/mips/assembler-mips.h
 /branches/bleeding_edge/src/x64/assembler-x64.cc
 /branches/bleeding_edge/src/x64/assembler-x64.h

=======================================
--- /branches/bleeding_edge/src/arm/assembler-arm.cc Thu Sep 12 10:37:42 2013 UTC +++ /branches/bleeding_edge/src/arm/assembler-arm.cc Thu Oct 10 08:45:40 2013 UTC
@@ -50,6 +50,7 @@
 #endif
 unsigned CpuFeatures::supported_ = 0;
 unsigned CpuFeatures::found_by_runtime_probing_only_ = 0;
+unsigned CpuFeatures::cross_compile_ = 0;
 unsigned CpuFeatures::cache_line_size_ = 64;


=======================================
--- /branches/bleeding_edge/src/arm/assembler-arm.h Fri Sep 27 13:59:28 2013 UTC +++ /branches/bleeding_edge/src/arm/assembler-arm.h Thu Oct 10 08:45:40 2013 UTC
@@ -64,23 +64,41 @@
   // Check whether a feature is supported by the target CPU.
   static bool IsSupported(CpuFeature f) {
     ASSERT(initialized_);
-    return (supported_ & (1u << f)) != 0;
+    return Check(f, supported_);
   }

   static bool IsFoundByRuntimeProbingOnly(CpuFeature f) {
     ASSERT(initialized_);
-    return (found_by_runtime_probing_only_ &
-            (static_cast<uint64_t>(1) << f)) != 0;
+    return Check(f, found_by_runtime_probing_only_);
   }

   static bool IsSafeForSnapshot(CpuFeature f) {
-    return (IsSupported(f) &&
+    return Check(f, cross_compile_) ||
+           (IsSupported(f) &&
             (!Serializer::enabled() || !IsFoundByRuntimeProbingOnly(f)));
   }

   static unsigned cache_line_size() { return cache_line_size_; }
+
+  static bool VerifyCrossCompiling() {
+    return cross_compile_ == 0;
+  }
+
+  static bool VerifyCrossCompiling(CpuFeature f) {
+    unsigned mask = flag2set(f);
+    return cross_compile_ == 0 ||
+           (cross_compile_ & mask) == mask;
+  }

  private:
+  static bool Check(CpuFeature f, unsigned set) {
+    return (set & flag2set(f)) != 0;
+  }
+
+  static unsigned flag2set(CpuFeature f) {
+    return 1u << f;
+  }
+
 #ifdef DEBUG
   static bool initialized_;
 #endif
@@ -88,6 +106,8 @@
   static unsigned found_by_runtime_probing_only_;
   static unsigned cache_line_size_;

+  static unsigned cross_compile_;
+
   friend class ExternalReference;
   friend class PlatformFeatureScope;
   DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
=======================================
--- /branches/bleeding_edge/src/assembler.cc    Tue Sep 17 13:02:25 2013 UTC
+++ /branches/bleeding_edge/src/assembler.cc    Thu Oct 10 08:45:40 2013 UTC
@@ -210,19 +210,14 @@
 // Implementation of PlatformFeatureScope

 PlatformFeatureScope::PlatformFeatureScope(CpuFeature f)
-    : old_supported_(CpuFeatures::supported_),
-      old_found_by_runtime_probing_only_(
-          CpuFeatures::found_by_runtime_probing_only_) {
+    : old_cross_compile_(CpuFeatures::cross_compile_) {
   uint64_t mask = static_cast<uint64_t>(1) << f;
-  CpuFeatures::supported_ |= mask;
-  CpuFeatures::found_by_runtime_probing_only_ &= ~mask;
+  CpuFeatures::cross_compile_ |= mask;
 }


 PlatformFeatureScope::~PlatformFeatureScope() {
-  CpuFeatures::supported_ = old_supported_;
-  CpuFeatures::found_by_runtime_probing_only_ =
-      old_found_by_runtime_probing_only_;
+  CpuFeatures::cross_compile_ = old_cross_compile_;
 }


=======================================
--- /branches/bleeding_edge/src/assembler.h     Tue Sep 17 13:02:25 2013 UTC
+++ /branches/bleeding_edge/src/assembler.h     Thu Oct 10 08:45:40 2013 UTC
@@ -142,8 +142,7 @@
   ~PlatformFeatureScope();

  private:
-  uint64_t old_supported_;
-  uint64_t old_found_by_runtime_probing_only_;
+  uint64_t old_cross_compile_;
 };


=======================================
--- /branches/bleeding_edge/src/code-stubs.cc   Fri Oct  4 08:17:11 2013 UTC
+++ /branches/bleeding_edge/src/code-stubs.cc   Thu Oct 10 08:45:40 2013 UTC
@@ -127,6 +127,11 @@
       desc, flags, masm.CodeObject(), NeedsImmovableCode());
   return new_object;
 }
+
+
+void CodeStub::VerifyPlatformFeatures(Isolate* isolate) {
+  ASSERT(CpuFeatures::VerifyCrossCompiling());
+}


 Handle<Code> CodeStub::GetCode(Isolate* isolate) {
@@ -140,6 +145,10 @@
     ASSERT(GetCodeKind() == code->kind());
     return Handle<Code>(code);
   }
+
+#ifdef DEBUG
+  VerifyPlatformFeatures(isolate);
+#endif

   {
     HandleScope scope(isolate);
@@ -297,8 +306,6 @@
// expensive at runtime. When solved we should be able to add most binops to
   // the snapshot instead of hand-picking them.
   // Generated list of commonly used stubs
-  Generate(Token::ADD, GENERIC, STRING, STRING, NO_OVERWRITE, isolate);
-  Generate(Token::ADD, GENERIC, STRING, STRING, OVERWRITE_RIGHT, isolate);
   Generate(Token::ADD, INT32, INT32, INT32, NO_OVERWRITE, isolate);
   Generate(Token::ADD, INT32, INT32, INT32, OVERWRITE_LEFT, isolate);
   Generate(Token::ADD, INT32, INT32, NUMBER, NO_OVERWRITE, isolate);
@@ -326,12 +333,6 @@
   Generate(Token::ADD, SMI, NUMBER, NUMBER, OVERWRITE_RIGHT, isolate);
   Generate(Token::ADD, SMI, SMI, INT32, OVERWRITE_LEFT, isolate);
   Generate(Token::ADD, SMI, SMI, SMI, OVERWRITE_RIGHT, isolate);
-  Generate(Token::ADD, STRING, GENERIC, STRING, NO_OVERWRITE, isolate);
-  Generate(Token::ADD, STRING, GENERIC, STRING, OVERWRITE_LEFT, isolate);
-  Generate(Token::ADD, STRING, GENERIC, STRING, OVERWRITE_RIGHT, isolate);
-  Generate(Token::ADD, STRING, STRING, STRING, NO_OVERWRITE, isolate);
-  Generate(Token::ADD, STRING, STRING, STRING, OVERWRITE_LEFT, isolate);
-  Generate(Token::ADD, STRING, STRING, STRING, OVERWRITE_RIGHT, isolate);
   Generate(Token::BIT_AND, INT32, INT32, INT32, NO_OVERWRITE, isolate);
   Generate(Token::BIT_AND, INT32, INT32, INT32, OVERWRITE_LEFT, isolate);
   Generate(Token::BIT_AND, INT32, INT32, INT32, OVERWRITE_RIGHT, isolate);
=======================================
--- /branches/bleeding_edge/src/code-stubs.h    Fri Oct  4 08:17:11 2013 UTC
+++ /branches/bleeding_edge/src/code-stubs.h    Thu Oct 10 08:45:40 2013 UTC
@@ -209,6 +209,7 @@
   // Generates the assembler code for the stub.
   virtual Handle<Code> GenerateCode(Isolate* isolate) = 0;

+  virtual void VerifyPlatformFeatures(Isolate* isolate);

// Returns whether the code generated for this stub needs to be allocated as
   // a fixed (non-moveable) code object.
@@ -1042,6 +1043,10 @@
     if (Max(left_state_, right_state_) == GENERIC) return MEGAMORPHIC;
     return MONOMORPHIC;
   }
+
+  virtual void VerifyPlatformFeatures(Isolate* isolate) V8_OVERRIDE {
+    ASSERT(CpuFeatures::VerifyCrossCompiling(SSE2));
+  }

   virtual Code::ExtraICState GetExtraICState() {
bool sse_field = Max(result_state_, Max(left_state_, right_state_)) > SMI &&
@@ -1348,6 +1353,11 @@
   virtual bool IsPregenerated(Isolate* isolate) V8_OVERRIDE;
   static void GenerateAheadOfTime(Isolate* isolate);

+ protected:
+  virtual void VerifyPlatformFeatures(Isolate* isolate) V8_OVERRIDE {
+    ASSERT(CpuFeatures::VerifyCrossCompiling(SSE2));
+  };
+
  private:
   void GenerateCore(MacroAssembler* masm,
                     Label* throw_normal_exception,
@@ -1765,6 +1775,11 @@
   void Generate(MacroAssembler* masm);

   virtual bool SometimesSetsUpAFrame() { return false; }
+
+ protected:
+  virtual void VerifyPlatformFeatures(Isolate* isolate) V8_OVERRIDE {
+    ASSERT(CpuFeatures::VerifyCrossCompiling(SSE2));
+  }

  private:
   static const int kBitsPerRegisterNumber = 6;
=======================================
--- /branches/bleeding_edge/src/ia32/assembler-ia32.cc Mon Sep 23 16:55:48 2013 UTC +++ /branches/bleeding_edge/src/ia32/assembler-ia32.cc Thu Oct 10 08:45:40 2013 UTC
@@ -53,6 +53,7 @@
 #endif
 uint64_t CpuFeatures::supported_ = 0;
 uint64_t CpuFeatures::found_by_runtime_probing_only_ = 0;
+uint64_t CpuFeatures::cross_compile_ = 0;


 ExternalReference ExternalReference::cpu_features() {
=======================================
--- /branches/bleeding_edge/src/ia32/assembler-ia32.h Mon Sep 23 16:55:48 2013 UTC +++ /branches/bleeding_edge/src/ia32/assembler-ia32.h Thu Oct 10 08:45:40 2013 UTC
@@ -535,31 +535,52 @@
   // Check whether a feature is supported by the target CPU.
   static bool IsSupported(CpuFeature f) {
     ASSERT(initialized_);
+    if (Check(f, cross_compile_)) return true;
     if (f == SSE2 && !FLAG_enable_sse2) return false;
     if (f == SSE3 && !FLAG_enable_sse3) return false;
     if (f == SSE4_1 && !FLAG_enable_sse4_1) return false;
     if (f == CMOV && !FLAG_enable_cmov) return false;
-    return (supported_ & (static_cast<uint64_t>(1) << f)) != 0;
+    return Check(f, supported_);
   }

   static bool IsFoundByRuntimeProbingOnly(CpuFeature f) {
     ASSERT(initialized_);
-    return (found_by_runtime_probing_only_ &
-            (static_cast<uint64_t>(1) << f)) != 0;
+    return Check(f, found_by_runtime_probing_only_);
   }

   static bool IsSafeForSnapshot(CpuFeature f) {
-    return (IsSupported(f) &&
+    return Check(f, cross_compile_) ||
+           (IsSupported(f) &&
             (!Serializer::enabled() || !IsFoundByRuntimeProbingOnly(f)));
   }
+
+  static bool VerifyCrossCompiling() {
+    return cross_compile_ == 0;
+  }
+
+  static bool VerifyCrossCompiling(CpuFeature f) {
+    uint64_t mask = flag2set(f);
+    return cross_compile_ == 0 ||
+           (cross_compile_ & mask) == mask;
+  }

  private:
+  static bool Check(CpuFeature f, uint64_t set) {
+    return (set & flag2set(f)) != 0;
+  }
+
+  static uint64_t flag2set(CpuFeature f) {
+    return static_cast<uint64_t>(1) << f;
+  }
+
 #ifdef DEBUG
   static bool initialized_;
 #endif
   static uint64_t supported_;
   static uint64_t found_by_runtime_probing_only_;

+  static uint64_t cross_compile_;
+
   friend class ExternalReference;
   friend class PlatformFeatureScope;
   DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
=======================================
--- /branches/bleeding_edge/src/mips/assembler-mips.cc Wed Sep 11 14:36:27 2013 UTC +++ /branches/bleeding_edge/src/mips/assembler-mips.cc Thu Oct 10 08:45:40 2013 UTC
@@ -48,6 +48,7 @@
 #endif
 unsigned CpuFeatures::supported_ = 0;
 unsigned CpuFeatures::found_by_runtime_probing_only_ = 0;
+unsigned CpuFeatures::cross_compile_ = 0;


 ExternalReference ExternalReference::cpu_features() {
=======================================
--- /branches/bleeding_edge/src/mips/assembler-mips.h Tue Oct 1 21:01:25 2013 UTC +++ /branches/bleeding_edge/src/mips/assembler-mips.h Thu Oct 10 08:45:40 2013 UTC
@@ -411,27 +411,47 @@
   // Check whether a feature is supported by the target CPU.
   static bool IsSupported(CpuFeature f) {
     ASSERT(initialized_);
-    return (supported_ & (1u << f)) != 0;
+    return Check(f, supported_);
   }

   static bool IsFoundByRuntimeProbingOnly(CpuFeature f) {
     ASSERT(initialized_);
-    return (found_by_runtime_probing_only_ &
-            (static_cast<uint64_t>(1) << f)) != 0;
+    return Check(f, found_by_runtime_probing_only_);
   }

   static bool IsSafeForSnapshot(CpuFeature f) {
-    return (IsSupported(f) &&
+    return Check(f, cross_compile_) ||
+           (IsSupported(f) &&
             (!Serializer::enabled() || !IsFoundByRuntimeProbingOnly(f)));
   }
+
+  static bool VerifyCrossCompiling() {
+    return cross_compile_ == 0;
+  }
+
+  static bool VerifyCrossCompiling(CpuFeature f) {
+    unsigned mask = flag2set(f);
+    return cross_compile_ == 0 ||
+           (cross_compile_ & mask) == mask;
+  }

  private:
+  static bool Check(CpuFeature f, unsigned set) {
+    return (set & flag2set(f)) != 0;
+  }
+
+  static unsigned flag2set(CpuFeature f) {
+    return 1u << f;
+  }
+
 #ifdef DEBUG
   static bool initialized_;
 #endif
   static unsigned supported_;
   static unsigned found_by_runtime_probing_only_;

+  static unsigned cross_compile_;
+
   friend class ExternalReference;
   friend class PlatformFeatureScope;
   DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
=======================================
--- /branches/bleeding_edge/src/x64/assembler-x64.cc Mon Sep 23 16:55:48 2013 UTC +++ /branches/bleeding_edge/src/x64/assembler-x64.cc Thu Oct 10 08:45:40 2013 UTC
@@ -44,7 +44,7 @@
 #endif
 uint64_t CpuFeatures::supported_ = CpuFeatures::kDefaultCpuFeatures;
 uint64_t CpuFeatures::found_by_runtime_probing_only_ = 0;
-
+uint64_t CpuFeatures::cross_compile_ = 0;

 ExternalReference ExternalReference::cpu_features() {
   ASSERT(CpuFeatures::initialized_);
=======================================
--- /branches/bleeding_edge/src/x64/assembler-x64.h Tue Sep 17 13:02:25 2013 UTC +++ /branches/bleeding_edge/src/x64/assembler-x64.h Thu Oct 10 08:45:40 2013 UTC
@@ -471,26 +471,45 @@

   // Check whether a feature is supported by the target CPU.
   static bool IsSupported(CpuFeature f) {
+    if (Check(f, cross_compile_)) return true;
     ASSERT(initialized_);
     if (f == SSE3 && !FLAG_enable_sse3) return false;
     if (f == SSE4_1 && !FLAG_enable_sse4_1) return false;
     if (f == CMOV && !FLAG_enable_cmov) return false;
     if (f == SAHF && !FLAG_enable_sahf) return false;
-    return (supported_ & (static_cast<uint64_t>(1) << f)) != 0;
+    return Check(f, supported_);
   }

   static bool IsFoundByRuntimeProbingOnly(CpuFeature f) {
     ASSERT(initialized_);
-    return (found_by_runtime_probing_only_ &
-            (static_cast<uint64_t>(1) << f)) != 0;
+    return Check(f, found_by_runtime_probing_only_);
   }

   static bool IsSafeForSnapshot(CpuFeature f) {
-    return (IsSupported(f) &&
+    return Check(f, cross_compile_) ||
+           (IsSupported(f) &&
             (!Serializer::enabled() || !IsFoundByRuntimeProbingOnly(f)));
   }
+
+  static bool VerifyCrossCompiling() {
+    return cross_compile_ == 0;
+  }
+
+  static bool VerifyCrossCompiling(CpuFeature f) {
+    uint64_t mask = flag2set(f);
+    return cross_compile_ == 0 ||
+           (cross_compile_ & mask) == mask;
+  }

  private:
+  static bool Check(CpuFeature f, uint64_t set) {
+    return (set & flag2set(f)) != 0;
+  }
+
+  static uint64_t flag2set(CpuFeature f) {
+    return static_cast<uint64_t>(1) << f;
+  }
+
   // Safe defaults include CMOV for X64. It is always available, if
   // anyone checks, but they shouldn't need to check.
// The required user mode extensions in X64 are (from AMD64 ABI Table A.1):
@@ -503,6 +522,8 @@
   static uint64_t supported_;
   static uint64_t found_by_runtime_probing_only_;

+  static uint64_t cross_compile_;
+
   friend class ExternalReference;
   friend class PlatformFeatureScope;
   DISALLOW_COPY_AND_ASSIGN(CpuFeatures);

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to