add knob to turn off fancy SkJumper features

This is a new public API for testing (layout tests).

Change-Id: I10345231bad373c741b1e9656e546000538121b3
Reviewed-on: https://skia-review.googlesource.com/17712
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/include/core/SkGraphics.h b/include/core/SkGraphics.h
index 4b62e55..5900044 100644
--- a/include/core/SkGraphics.h
+++ b/include/core/SkGraphics.h
@@ -26,6 +26,10 @@
     // We're in the middle of cleaning this up.
     static void Term() {}
 
+    // If called immediately after Init(), SkJumper will use only a per-CPU baseline
+    // feature set, ignoring any more advanced instructions that may be available.
+    static void DisableFancySkJumperFeatures();
+
     /**
      *  Return the version numbers for the library. If the parameter is not
      *  null, it is set to the version number.
diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp
index 803b743..015b820 100644
--- a/src/core/SkGraphics.cpp
+++ b/src/core/SkGraphics.cpp
@@ -28,6 +28,7 @@
 #include "SkTSearch.h"
 #include "SkTime.h"
 #include "SkUtils.h"
+#include "../jumper/SkJumper.h"
 
 #include <stdlib.h>
 
@@ -109,3 +110,7 @@
         flags = nextSemi + 1;
     } while (nextSemi);
 }
+
+void SkGraphics::DisableFancySkJumperFeatures() {
+    gSkJumperEnableFancyFeatures = false;
+}
diff --git a/src/jumper/SkJumper.cpp b/src/jumper/SkJumper.cpp
index 8daf29e..f8354ce 100644
--- a/src/jumper/SkJumper.cpp
+++ b/src/jumper/SkJumper.cpp
@@ -114,6 +114,8 @@
 static SkJumper_Engine gPlatform = kPortable;
 static SkOnce gChooseEngineOnce;
 
+bool gSkJumperEnableFancyFeatures = true;
+
 static SkJumper_Engine choose_engine() {
 #if __has_feature(memory_sanitizer)
     // We'll just run portable code.
@@ -137,7 +139,7 @@
     }
 
 #elif defined(__x86_64__) || defined(_M_X64)
-    if (1 && SkCpu::Supports(SkCpu::HSW)) {
+    if (gSkJumperEnableFancyFeatures && SkCpu::Supports(SkCpu::HSW)) {
         return {
         #define M(stage) ASM(stage, hsw),
             { SK_RASTER_PIPELINE_STAGES(M) },
@@ -145,7 +147,7 @@
         #undef M
         };
     }
-    if (1 && SkCpu::Supports(SkCpu::AVX)) {
+    if (gSkJumperEnableFancyFeatures && SkCpu::Supports(SkCpu::AVX)) {
         return {
         #define M(stage) ASM(stage, avx),
             { SK_RASTER_PIPELINE_STAGES(M) },
@@ -153,7 +155,7 @@
         #undef M
         };
     }
-    if (1 && SkCpu::Supports(SkCpu::SSE41)) {
+    if (gSkJumperEnableFancyFeatures && SkCpu::Supports(SkCpu::SSE41)) {
         return {
         #define M(stage) ASM(stage, sse41),
             { SK_RASTER_PIPELINE_STAGES(M) },
diff --git a/src/jumper/SkJumper.h b/src/jumper/SkJumper.h
index 7d6d0af..b0a781c 100644
--- a/src/jumper/SkJumper.h
+++ b/src/jumper/SkJumper.h
@@ -8,6 +8,8 @@
 #ifndef SkJumper_DEFINED
 #define SkJumper_DEFINED
 
+extern bool gSkJumperEnableFancyFeatures;
+
 // This file contains definitions shared by SkJumper.cpp (compiled normally as part of Skia)
 // and SkJumper_stages.cpp (compiled into Skia _and_ offline into SkJumper_generated.h).
 // Keep it simple!