add #defines to limit SkCpu

I just noticed we don't really have any CPU test bots that have less
than AVX anymore.  I'd like to make sure we're testing each mode of
SkJumper at least, so I've added flags to let us limit to SSE2 or
SSE4.1, the modes currently missing coverage.

Add the bots to test these modes too.

CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE2,Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE41

Change-Id: I7c2b061332e7f037538488260583076c34ae7b1e
Reviewed-on: https://skia-review.googlesource.com/14405
Reviewed-by: Eric Boren <borenet@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/infra/bots/jobs.json b/infra/bots/jobs.json
index d1778a8..7a63434 100644
--- a/infra/bots/jobs.json
+++ b/infra/bots/jobs.json
@@ -38,6 +38,8 @@
   "Build-Ubuntu-Clang-x86_64-Release-Mini",
   "Build-Ubuntu-Clang-x86_64-Release-TSAN",
   "Build-Ubuntu-Clang-x86_64-Release-Vulkan",
+  "Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE2",
+  "Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE41",
   "Build-Ubuntu-GCC-arm-Debug-Chromecast",
   "Build-Ubuntu-GCC-arm-Release-Chromecast",
   "Build-Ubuntu-GCC-x86-Debug",
@@ -276,6 +278,8 @@
   "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-ASAN",
   "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-Fast",
   "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-TSAN",
+  "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE2",
+  "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE41",
   "Test-Ubuntu-Clang-Golo-GPU-GT610-x86_64-Debug-ASAN",
   "Test-Ubuntu-Clang-Golo-GPU-GT610-x86_64-Release-ASAN",
   "Test-Ubuntu-Clang-Golo-GPU-GT610-x86_64-Release-TSAN",
diff --git a/infra/bots/tasks.json b/infra/bots/tasks.json
index 48bbbdc..1e430ed 100644
--- a/infra/bots/tasks.json
+++ b/infra/bots/tasks.json
@@ -222,6 +222,18 @@
         "Build-Ubuntu-Clang-x86_64-Release-Mini"
       ]
     },
+    "Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE2": {
+      "priority": 0.8,
+      "tasks": [
+        "Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE2"
+      ]
+    },
+    "Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE41": {
+      "priority": 0.8,
+      "tasks": [
+        "Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE41"
+      ]
+    },
     "Build-Ubuntu-Clang-x86_64-Release-TSAN": {
       "priority": 0.8,
       "tasks": [
@@ -1658,6 +1670,18 @@
         "Upload-Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-Fast"
       ]
     },
+    "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE2": {
+      "priority": 0.8,
+      "tasks": [
+        "Upload-Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE2"
+      ]
+    },
+    "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE41": {
+      "priority": 0.8,
+      "tasks": [
+        "Upload-Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE41"
+      ]
+    },
     "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-TSAN": {
       "priority": 0.8,
       "tasks": [
@@ -3287,6 +3311,66 @@
       "isolate": "compile_skia.isolate",
       "priority": 0.8
     },
+    "Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE2": {
+      "cipd_packages": [
+        {
+          "name": "skia/bots/clang_linux",
+          "path": "clang_linux",
+          "version": "version:8"
+        }
+      ],
+      "dimensions": [
+        "cpu:x86-64-avx2",
+        "gpu:none",
+        "os:Ubuntu-14.04",
+        "pool:Skia"
+      ],
+      "extra_args": [
+        "--workdir",
+        "../../..",
+        "compile",
+        "repository=<(REPO)",
+        "buildername=Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE2",
+        "swarm_out_dir=${ISOLATED_OUTDIR}",
+        "revision=<(REVISION)",
+        "patch_repo=<(PATCH_REPO)",
+        "patch_storage=<(PATCH_STORAGE)",
+        "patch_issue=<(ISSUE)",
+        "patch_set=<(PATCHSET)"
+      ],
+      "isolate": "compile_skia.isolate",
+      "priority": 0.8
+    },
+    "Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE41": {
+      "cipd_packages": [
+        {
+          "name": "skia/bots/clang_linux",
+          "path": "clang_linux",
+          "version": "version:8"
+        }
+      ],
+      "dimensions": [
+        "cpu:x86-64-avx2",
+        "gpu:none",
+        "os:Ubuntu-14.04",
+        "pool:Skia"
+      ],
+      "extra_args": [
+        "--workdir",
+        "../../..",
+        "compile",
+        "repository=<(REPO)",
+        "buildername=Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE41",
+        "swarm_out_dir=${ISOLATED_OUTDIR}",
+        "revision=<(REVISION)",
+        "patch_repo=<(PATCH_REPO)",
+        "patch_storage=<(PATCH_STORAGE)",
+        "patch_issue=<(ISSUE)",
+        "patch_set=<(PATCHSET)"
+      ],
+      "isolate": "compile_skia.isolate",
+      "priority": 0.8
+    },
     "Build-Ubuntu-Clang-x86_64-Release-TSAN": {
       "cipd_packages": [
         {
@@ -13898,6 +13982,102 @@
       "max_attempts": 1,
       "priority": 0.8
     },
+    "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE2": {
+      "cipd_packages": [
+        {
+          "name": "skia/bots/skimage",
+          "path": "skimage",
+          "version": "version:24"
+        },
+        {
+          "name": "skia/bots/skp",
+          "path": "skp",
+          "version": "version:50"
+        },
+        {
+          "name": "skia/bots/svg",
+          "path": "svg",
+          "version": "version:5"
+        }
+      ],
+      "dependencies": [
+        "Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE2",
+        "Housekeeper-PerCommit-BundleRecipes"
+      ],
+      "dimensions": [
+        "cpu:x86-64-avx2",
+        "gpu:none",
+        "os:Ubuntu-14.04",
+        "pool:Skia"
+      ],
+      "execution_timeout_ns": 14400000000000,
+      "expiration_ns": 72000000000000,
+      "extra_args": [
+        "--workdir",
+        "../../..",
+        "test",
+        "repository=<(REPO)",
+        "buildername=Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE2",
+        "swarm_out_dir=${ISOLATED_OUTDIR}",
+        "revision=<(REVISION)",
+        "patch_repo=<(PATCH_REPO)",
+        "patch_storage=<(PATCH_STORAGE)",
+        "patch_issue=<(ISSUE)",
+        "patch_set=<(PATCHSET)"
+      ],
+      "io_timeout_ns": 2400000000000,
+      "isolate": "test_skia_bundled_unix.isolate",
+      "max_attempts": 1,
+      "priority": 0.8
+    },
+    "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE41": {
+      "cipd_packages": [
+        {
+          "name": "skia/bots/skimage",
+          "path": "skimage",
+          "version": "version:24"
+        },
+        {
+          "name": "skia/bots/skp",
+          "path": "skp",
+          "version": "version:50"
+        },
+        {
+          "name": "skia/bots/svg",
+          "path": "svg",
+          "version": "version:5"
+        }
+      ],
+      "dependencies": [
+        "Build-Ubuntu-Clang-x86_64-Release-SK_CPU_LIMIT_SSE41",
+        "Housekeeper-PerCommit-BundleRecipes"
+      ],
+      "dimensions": [
+        "cpu:x86-64-avx2",
+        "gpu:none",
+        "os:Ubuntu-14.04",
+        "pool:Skia"
+      ],
+      "execution_timeout_ns": 14400000000000,
+      "expiration_ns": 72000000000000,
+      "extra_args": [
+        "--workdir",
+        "../../..",
+        "test",
+        "repository=<(REPO)",
+        "buildername=Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE41",
+        "swarm_out_dir=${ISOLATED_OUTDIR}",
+        "revision=<(REVISION)",
+        "patch_repo=<(PATCH_REPO)",
+        "patch_storage=<(PATCH_STORAGE)",
+        "patch_issue=<(ISSUE)",
+        "patch_set=<(PATCHSET)"
+      ],
+      "io_timeout_ns": 2400000000000,
+      "isolate": "test_skia_bundled_unix.isolate",
+      "max_attempts": 1,
+      "priority": 0.8
+    },
     "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-TSAN": {
       "cipd_packages": [
         {
@@ -21597,6 +21777,60 @@
       "isolate": "upload_dm_results.isolate",
       "priority": 0.8
     },
+    "Upload-Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE2": {
+      "dependencies": [
+        "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE2"
+      ],
+      "dimensions": [
+        "cpu:x86-64-avx2",
+        "gpu:none",
+        "os:Ubuntu-14.04",
+        "pool:Skia"
+      ],
+      "extra_args": [
+        "--workdir",
+        "../../..",
+        "upload_dm_results",
+        "repository=<(REPO)",
+        "buildername=Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE2",
+        "swarm_out_dir=${ISOLATED_OUTDIR}",
+        "revision=<(REVISION)",
+        "patch_repo=<(PATCH_REPO)",
+        "patch_storage=<(PATCH_STORAGE)",
+        "patch_issue=<(ISSUE)",
+        "patch_set=<(PATCHSET)",
+        "gs_bucket=skia-infra-gm"
+      ],
+      "isolate": "upload_dm_results.isolate",
+      "priority": 0.8
+    },
+    "Upload-Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE41": {
+      "dependencies": [
+        "Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE41"
+      ],
+      "dimensions": [
+        "cpu:x86-64-avx2",
+        "gpu:none",
+        "os:Ubuntu-14.04",
+        "pool:Skia"
+      ],
+      "extra_args": [
+        "--workdir",
+        "../../..",
+        "upload_dm_results",
+        "repository=<(REPO)",
+        "buildername=Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Release-SK_CPU_LIMIT_SSE41",
+        "swarm_out_dir=${ISOLATED_OUTDIR}",
+        "revision=<(REVISION)",
+        "patch_repo=<(PATCH_REPO)",
+        "patch_storage=<(PATCH_STORAGE)",
+        "patch_issue=<(ISSUE)",
+        "patch_set=<(PATCHSET)",
+        "gs_bucket=skia-infra-gm"
+      ],
+      "isolate": "upload_dm_results.isolate",
+      "priority": 0.8
+    },
     "Upload-Test-Ubuntu-GCC-GCE-CPU-AVX2-x86-Debug": {
       "dependencies": [
         "Test-Ubuntu-GCC-GCE-CPU-AVX2-x86-Debug"
diff --git a/src/core/SkCpu.h b/src/core/SkCpu.h
index 24428d9..a9ed906 100644
--- a/src/core/SkCpu.h
+++ b/src/core/SkCpu.h
@@ -87,6 +87,12 @@
     // It's available on Haswell+ just like AVX2, but it's technically a different bit.
     // TODO: circle back on this if we find ourselves limited by lack of compile-time FMA
 
+    #if defined(SK_CPU_LIMIT_SSE41)
+    features &= (SkCpu::SSE1 | SkCpu::SSE2 | SkCpu::SSE3 | SkCpu::SSSE3 | SkCpu::SSE41);
+    #elif defined(SK_CPU_LIMIT_SSE2)
+    features &= (SkCpu::SSE1 | SkCpu::SSE2);
+    #endif
+
 #else
     #if defined(SK_ARM_HAS_NEON)
     features |= NEON;