test+bench new swizzle SkOpts
BUG=skia:skia:4767
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1564233002
Review URL: https://codereview.chromium.org/1564233002
diff --git a/bench/SwizzleBench.cpp b/bench/SwizzleBench.cpp
new file mode 100644
index 0000000..13b2003
--- /dev/null
+++ b/bench/SwizzleBench.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Benchmark.h"
+#include "SkOpts.h"
+
+class SwizzleBench : public Benchmark {
+public:
+ SwizzleBench(const char* name, SkOpts::Swizzle_8888_8888 fn) : fName(name), fFn(fn) {}
+
+ bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
+ const char* onGetName() override { return fName; }
+ void onDraw(int loops, SkCanvas*) override {
+ static const int K = 1023; // Arbitrary, but nice to be a non-power-of-two to trip up SIMD.
+ uint32_t dst[K], src[K];
+ while (loops --> 0) {
+ fFn(dst, src, K);
+ }
+ }
+private:
+ const char* fName;
+ SkOpts::Swizzle_8888_8888 fFn;
+};
+
+
+DEF_BENCH(return new SwizzleBench("SkOpts::premul_xxxa", SkOpts::premul_xxxa));
+DEF_BENCH(return new SwizzleBench("SkOpts::swaprb_xxxa", SkOpts::swaprb_xxxa));
+DEF_BENCH(return new SwizzleBench("SkOpts::premul_swaprb_xxxa", SkOpts::premul_swaprb_xxxa));
diff --git a/tests/SwizzlerTest.cpp b/tests/SwizzlerTest.cpp
index 95aaf38..f67cfee 100644
--- a/tests/SwizzlerTest.cpp
+++ b/tests/SwizzlerTest.cpp
@@ -7,6 +7,7 @@
#include "SkSwizzler.h"
#include "Test.h"
+#include "SkOpts.h"
// These are the values that we will look for to indicate that the fill was successful
static const uint8_t kFillIndex = 0x11;
@@ -124,3 +125,35 @@
}
}
}
+
+DEF_TEST(SwizzleOpts, r) {
+ uint32_t dst, src;
+
+ // forall c, c*255 == c, c*0 == 0
+ for (int c = 0; c <= 255; c++) {
+ src = (255<<24) | c;
+ SkOpts::premul_xxxa(&dst, &src, 1);
+ REPORTER_ASSERT(r, dst == src);
+ SkOpts::premul_swaprb_xxxa(&dst, &src, 1);
+ REPORTER_ASSERT(r, dst == (uint32_t)((255<<24) | (c<<16)));
+
+ src = (0<<24) | c;
+ SkOpts::premul_xxxa(&dst, &src, 1);
+ REPORTER_ASSERT(r, dst == 0);
+ SkOpts::premul_swaprb_xxxa(&dst, &src, 1);
+ REPORTER_ASSERT(r, dst == 0);
+ }
+
+ // check a totally arbitrary color
+ src = 0xFACEB004;
+ SkOpts::premul_xxxa(&dst, &src, 1);
+ REPORTER_ASSERT(r, dst == 0xFACAAD04);
+
+ // swap red and blue
+ SkOpts::swaprb_xxxa(&dst, &src, 1);
+ REPORTER_ASSERT(r, dst == 0xFA04B0CE);
+
+ // all together now
+ SkOpts::premul_swaprb_xxxa(&dst, &src, 1);
+ REPORTER_ASSERT(r, dst == 0xFA04ADCA);
+}