aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/MathBench.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-08-09 11:06:53 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-08-09 16:07:24 +0000
commit828f1d51958c17d716ac95182051a866be785e01 (patch)
tree325bab378605660b8905381aa5d6c907a2c1c215 /bench/MathBench.cpp
parent74c627f0bde675f13587b12069d6556868edf45e (diff)
handle overflows in float->int
rects are already auto-vectorized, so no need to explicitly write a 4f version of SkRect::round() Bug: skia: Change-Id: I098945767bfcaa7093d770c376bd17ff3bdc9983 Reviewed-on: https://skia-review.googlesource.com/32060 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'bench/MathBench.cpp')
-rw-r--r--bench/MathBench.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/bench/MathBench.cpp b/bench/MathBench.cpp
index 7768253544..1ae683aab8 100644
--- a/bench/MathBench.cpp
+++ b/bench/MathBench.cpp
@@ -598,3 +598,67 @@ DEF_BENCH( return new CLZBench(true); )
DEF_BENCH( return new NormalizeBench(); )
DEF_BENCH( return new FixedMathBench(); )
+
+//////////////////////////////////////////////////////////////
+
+#include "../private/SkFloatBits.h"
+class Floor2IntBench : public Benchmark {
+ enum {
+ ARRAY = 1000,
+ };
+ float fData[ARRAY];
+ const bool fSat;
+public:
+
+ Floor2IntBench(bool sat) : fSat(sat) {
+ SkRandom rand;
+
+ for (int i = 0; i < ARRAY; ++i) {
+ fData[i] = SkBits2Float(rand.nextU());
+ }
+
+ if (sat) {
+ fName = "floor2int_sat";
+ } else {
+ fName = "floor2int_undef";
+ }
+ }
+
+ bool isSuitableFor(Backend backend) override {
+ return backend == kNonRendering_Backend;
+ }
+
+ // These exist to try to stop the compiler from detecting what we doing, and throwing
+ // parts away (or knowing exactly how big the loop counts are).
+ virtual void process(int) {}
+ virtual int count() { return ARRAY; }
+
+protected:
+ void onDraw(int loops, SkCanvas*) override {
+ int accum = 0;
+
+ for (int j = 0; j < loops; ++j) {
+ int n = this->count();
+ if (fSat) {
+ for (int i = 0; i < n; ++i) {
+ accum += sk_float_floor2int(fData[i]);
+ }
+ } else {
+ for (int i = 0; i < n; ++i) {
+ accum += sk_float_floor2int_no_saturate(fData[i]);
+ }
+ }
+ this->process(accum);
+ }
+ }
+
+ const char* onGetName() override { return fName; }
+
+private:
+ const char* fName;
+
+ typedef Benchmark INHERITED;
+};
+DEF_BENCH( return new Floor2IntBench(false); )
+DEF_BENCH( return new Floor2IntBench(true); )
+