| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
| 9 #include "Sk4x.h" |
| 9 #include "SkGeometry.h" | 10 #include "SkGeometry.h" |
| 10 #include "SkRandom.h" | 11 #include "SkRandom.h" |
| 11 #include "SkRect.h" | 12 #include "SkRect.h" |
| 12 | 13 |
| 13 class GeometryBench : public Benchmark { | 14 class GeometryBench : public Benchmark { |
| 14 public: | 15 public: |
| 15 GeometryBench(const char suffix[]) : fVolatileInt(0) { | 16 GeometryBench(const char suffix[]) : fVolatileInt(0) { |
| 16 fName.printf("geo_%s", suffix); | 17 fName.printf("geo_%s", suffix); |
| 17 } | 18 } |
| 18 | 19 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 37 | 38 |
| 38 private: | 39 private: |
| 39 SkString fName; | 40 SkString fName; |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 class GeoRectBench : public GeometryBench { | 43 class GeoRectBench : public GeometryBench { |
| 43 public: | 44 public: |
| 44 GeoRectBench(const char suffix[]) : GeometryBench(suffix) {} | 45 GeoRectBench(const char suffix[]) : GeometryBench(suffix) {} |
| 45 | 46 |
| 46 protected: | 47 protected: |
| 48 // void* vptr; |
| 49 size_t align_fRects_to_16Bytes[sizeof(void*) == 8 ? 1 : 3]; |
| 50 |
| 47 SkRect fRects[2048]; | 51 SkRect fRects[2048]; |
| 48 | 52 |
| 49 virtual void onPreDraw() { | 53 virtual void onPreDraw() { |
| 50 const SkScalar min = -100; | 54 const SkScalar min = -100; |
| 51 const SkScalar max = 100; | 55 const SkScalar max = 100; |
| 52 SkRandom rand; | 56 SkRandom rand; |
| 53 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { | 57 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
| 54 SkScalar x = rand.nextRangeScalar(min, max); | 58 SkScalar x = rand.nextRangeScalar(min, max); |
| 55 SkScalar y = rand.nextRangeScalar(min, max); | 59 SkScalar y = rand.nextRangeScalar(min, max); |
| 56 SkScalar w = rand.nextRangeScalar(min, max); | 60 SkScalar w = rand.nextRangeScalar(min, max); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 count += r.intersect(fRects[0], fRects[i]); | 94 count += r.intersect(fRects[0], fRects[i]); |
| 91 } | 95 } |
| 92 this->virtualCallToFoilOptimizers(count); | 96 this->virtualCallToFoilOptimizers(count); |
| 93 } | 97 } |
| 94 } | 98 } |
| 95 }; | 99 }; |
| 96 | 100 |
| 97 class GeoRectBench_Intersects : public GeoRectBench { | 101 class GeoRectBench_Intersects : public GeoRectBench { |
| 98 public: | 102 public: |
| 99 GeoRectBench_Intersects() : GeoRectBench("rect_Intersects") {} | 103 GeoRectBench_Intersects() : GeoRectBench("rect_Intersects") {} |
| 100 | 104 |
| 101 protected: | 105 protected: |
| 102 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 106 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 103 for (int outer = 0; outer < loops; ++outer) { | 107 for (int outer = 0; outer < loops; ++outer) { |
| 104 int count = 0; | 108 int count = 0; |
| 105 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { | 109 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
| 106 count += SkRect::Intersects(fRects[0], fRects[i]); | 110 count += SkRect::Intersects(fRects[0], fRects[i]); |
| 107 } | 111 } |
| 108 this->virtualCallToFoilOptimizers(count); | 112 this->virtualCallToFoilOptimizers(count); |
| 109 } | 113 } |
| 110 } | 114 } |
| 111 }; | 115 }; |
| 112 | 116 |
| 113 class GeoRectBench_sort : public GeoRectBench { | 117 class GeoRectBench_sort : public GeoRectBench { |
| 114 public: | 118 public: |
| 115 GeoRectBench_sort() : GeoRectBench("rect_sort") {} | 119 GeoRectBench_sort() : GeoRectBench("rect_sort") {} |
| 116 | 120 |
| 117 protected: | 121 protected: |
| 118 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 122 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 119 for (int outer = 0; outer < loops; ++outer) { | 123 for (int outer = 0; outer < loops; ++outer) { |
| 120 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { | 124 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
| 121 fRects[i].sort(); | 125 fRects[i].sort(); |
| 122 } | 126 } |
| 123 } | 127 } |
| 124 } | 128 } |
| 125 }; | 129 }; |
| 126 | 130 |
| 127 DEF_BENCH( return new GeoRectBench_intersect; ) | 131 DEF_BENCH( return new GeoRectBench_intersect; ) |
| 128 DEF_BENCH( return new GeoRectBench_intersect_rect; ) | 132 DEF_BENCH( return new GeoRectBench_intersect_rect; ) |
| 129 DEF_BENCH( return new GeoRectBench_Intersects; ) | 133 DEF_BENCH( return new GeoRectBench_Intersects; ) |
| 130 | 134 |
| 131 DEF_BENCH( return new GeoRectBench_sort; ) | 135 DEF_BENCH( return new GeoRectBench_sort; ) |
| 136 |
| 137 class GeoRectBench_sort_4f : public GeoRectBench { |
| 138 public: |
| 139 GeoRectBench_sort_4f() : GeoRectBench("rect_sort_4f") { } |
| 140 |
| 141 protected: |
| 142 static SkRect Sort(const SkRect& rect) { |
| 143 // To sort: |
| 144 // left, right = minmax(left, right) |
| 145 // top, bottom = minmax(top, bottom) |
| 146 Sk4f ltrb(&rect.fLeft), |
| 147 rblt = ltrb.zwxy(), |
| 148 ltlt = Sk4f::Min(ltrb, rblt), // Holds (2 copies of) new left and
top. |
| 149 rbrb = Sk4f::Max(ltrb, rblt), // Holds (2 copies of) new right and
bottom. |
| 150 sort = Sk4f::XYAB(ltlt, rbrb); |
| 151 |
| 152 SkRect sorted; |
| 153 sort.store(&sorted.fLeft); |
| 154 return sorted; |
| 155 } |
| 156 |
| 157 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 158 for (int outer = 0; outer < loops; ++outer) { |
| 159 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
| 160 fRects[i] = Sort(fRects[i]); |
| 161 } |
| 162 } |
| 163 } |
| 164 }; |
| 165 DEF_BENCH( return new GeoRectBench_sort_4f; ) |
| 166 |
| 167 class GeoRectBench_Intersects_4f : public GeoRectBench { |
| 168 public: |
| 169 GeoRectBench_Intersects_4f() : GeoRectBench("rect_Intersects_4f") {} |
| 170 |
| 171 protected: |
| 172 static bool Intersects(const SkRect& a, const SkRect& b) { |
| 173 Sk4f r1(&a.fLeft), |
| 174 r2(&b.fLeft), |
| 175 lt = Sk4f::XYAB(r1, r2), // a.L a.T b.L b.T < |
| 176 rb = Sk4f::ZWCD(r2, r1); // b.R b.B a.R a.B ? |
| 177 return lt.lessThan(rb).allTrue(); |
| 178 } |
| 179 |
| 180 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 181 for (int outer = 0; outer < loops; ++outer) { |
| 182 int count = 0; |
| 183 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
| 184 count += Intersects(fRects[0], fRects[i]); |
| 185 } |
| 186 this->virtualCallToFoilOptimizers(count); |
| 187 } |
| 188 } |
| 189 }; |
| 190 DEF_BENCH( return new GeoRectBench_Intersects_4f; ) |
| 191 |
| OLD | NEW |