diff options
author | mtklein <mtklein@chromium.org> | 2014-10-16 15:21:43 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-16 15:21:43 -0700 |
commit | 90c7992bfc6330f070f7704d63372a0ec8410170 (patch) | |
tree | a1938fcd7386f6c59eaf079bfdb173042a730727 /bench/GeometryBench.cpp | |
parent | 70171683e6977af7472f0f465bd81852d0644ddd (diff) |
Start to vectorize SkTileGrid.
This adds Sk4x.h to help.
BUG=skia:
Review URL: https://codereview.chromium.org/634543004
Diffstat (limited to 'bench/GeometryBench.cpp')
-rw-r--r-- | bench/GeometryBench.cpp | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/bench/GeometryBench.cpp b/bench/GeometryBench.cpp index a5c4643f9e..65398fa34a 100644 --- a/bench/GeometryBench.cpp +++ b/bench/GeometryBench.cpp @@ -6,6 +6,7 @@ */ #include "Benchmark.h" +#include "Sk4x.h" #include "SkGeometry.h" #include "SkRandom.h" #include "SkRect.h" @@ -44,6 +45,9 @@ public: GeoRectBench(const char suffix[]) : GeometryBench(suffix) {} protected: + // void* vptr; + size_t align_fRects_to_16Bytes[sizeof(void*) == 8 ? 1 : 3]; + SkRect fRects[2048]; virtual void onPreDraw() { @@ -97,7 +101,7 @@ protected: class GeoRectBench_Intersects : public GeoRectBench { public: GeoRectBench_Intersects() : GeoRectBench("rect_Intersects") {} - + protected: virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { for (int outer = 0; outer < loops; ++outer) { @@ -113,7 +117,7 @@ protected: class GeoRectBench_sort : public GeoRectBench { public: GeoRectBench_sort() : GeoRectBench("rect_sort") {} - + protected: virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { for (int outer = 0; outer < loops; ++outer) { @@ -129,3 +133,59 @@ DEF_BENCH( return new GeoRectBench_intersect_rect; ) DEF_BENCH( return new GeoRectBench_Intersects; ) DEF_BENCH( return new GeoRectBench_sort; ) + +class GeoRectBench_sort_4f : public GeoRectBench { +public: + GeoRectBench_sort_4f() : GeoRectBench("rect_sort_4f") { } + +protected: + static SkRect Sort(const SkRect& rect) { + // To sort: + // left, right = minmax(left, right) + // top, bottom = minmax(top, bottom) + Sk4f ltrb(&rect.fLeft), + rblt = ltrb.zwxy(), + ltlt = Sk4f::Min(ltrb, rblt), // Holds (2 copies of) new left and top. + rbrb = Sk4f::Max(ltrb, rblt), // Holds (2 copies of) new right and bottom. + sort = Sk4f::XYAB(ltlt, rbrb); + + SkRect sorted; + sort.store(&sorted.fLeft); + return sorted; + } + + virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { + for (int outer = 0; outer < loops; ++outer) { + for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { + fRects[i] = Sort(fRects[i]); + } + } + } +}; +DEF_BENCH( return new GeoRectBench_sort_4f; ) + +class GeoRectBench_Intersects_4f : public GeoRectBench { +public: + GeoRectBench_Intersects_4f() : GeoRectBench("rect_Intersects_4f") {} + +protected: + static bool Intersects(const SkRect& a, const SkRect& b) { + Sk4f r1(&a.fLeft), + r2(&b.fLeft), + lt = Sk4f::XYAB(r1, r2), // a.L a.T b.L b.T < + rb = Sk4f::ZWCD(r2, r1); // b.R b.B a.R a.B ? + return lt.lessThan(rb).allTrue(); + } + + virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { + for (int outer = 0; outer < loops; ++outer) { + int count = 0; + for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { + count += Intersects(fRects[0], fRects[i]); + } + this->virtualCallToFoilOptimizers(count); + } + } +}; +DEF_BENCH( return new GeoRectBench_Intersects_4f; ) + |