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" | |
10 #include "SkGeometry.h" | 9 #include "SkGeometry.h" |
11 #include "SkRandom.h" | 10 #include "SkRandom.h" |
12 #include "SkRect.h" | 11 #include "SkRect.h" |
13 | 12 |
14 class GeometryBench : public Benchmark { | 13 class GeometryBench : public Benchmark { |
15 public: | 14 public: |
16 GeometryBench(const char suffix[]) : fVolatileInt(0) { | 15 GeometryBench(const char suffix[]) : fVolatileInt(0) { |
17 fName.printf("geo_%s", suffix); | 16 fName.printf("geo_%s", suffix); |
18 } | 17 } |
19 | 18 |
(...skipping 18 matching lines...) Expand all Loading... |
38 | 37 |
39 private: | 38 private: |
40 SkString fName; | 39 SkString fName; |
41 }; | 40 }; |
42 | 41 |
43 class GeoRectBench : public GeometryBench { | 42 class GeoRectBench : public GeometryBench { |
44 public: | 43 public: |
45 GeoRectBench(const char suffix[]) : GeometryBench(suffix) {} | 44 GeoRectBench(const char suffix[]) : GeometryBench(suffix) {} |
46 | 45 |
47 protected: | 46 protected: |
48 // void* vptr; | |
49 size_t align_fRects_to_16Bytes[sizeof(void*) == 8 ? 1 : 3]; | |
50 | |
51 SkRect fRects[2048]; | 47 SkRect fRects[2048]; |
52 | 48 |
53 virtual void onPreDraw() { | 49 virtual void onPreDraw() { |
54 const SkScalar min = -100; | 50 const SkScalar min = -100; |
55 const SkScalar max = 100; | 51 const SkScalar max = 100; |
56 SkRandom rand; | 52 SkRandom rand; |
57 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { | 53 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
58 SkScalar x = rand.nextRangeScalar(min, max); | 54 SkScalar x = rand.nextRangeScalar(min, max); |
59 SkScalar y = rand.nextRangeScalar(min, max); | 55 SkScalar y = rand.nextRangeScalar(min, max); |
60 SkScalar w = rand.nextRangeScalar(min, max); | 56 SkScalar w = rand.nextRangeScalar(min, max); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 count += r.intersect(fRects[0], fRects[i]); | 90 count += r.intersect(fRects[0], fRects[i]); |
95 } | 91 } |
96 this->virtualCallToFoilOptimizers(count); | 92 this->virtualCallToFoilOptimizers(count); |
97 } | 93 } |
98 } | 94 } |
99 }; | 95 }; |
100 | 96 |
101 class GeoRectBench_Intersects : public GeoRectBench { | 97 class GeoRectBench_Intersects : public GeoRectBench { |
102 public: | 98 public: |
103 GeoRectBench_Intersects() : GeoRectBench("rect_Intersects") {} | 99 GeoRectBench_Intersects() : GeoRectBench("rect_Intersects") {} |
104 | 100 |
105 protected: | 101 protected: |
106 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 102 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
107 for (int outer = 0; outer < loops; ++outer) { | 103 for (int outer = 0; outer < loops; ++outer) { |
108 int count = 0; | 104 int count = 0; |
109 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { | 105 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
110 count += SkRect::Intersects(fRects[0], fRects[i]); | 106 count += SkRect::Intersects(fRects[0], fRects[i]); |
111 } | 107 } |
112 this->virtualCallToFoilOptimizers(count); | 108 this->virtualCallToFoilOptimizers(count); |
113 } | 109 } |
114 } | 110 } |
115 }; | 111 }; |
116 | 112 |
117 class GeoRectBench_sort : public GeoRectBench { | 113 class GeoRectBench_sort : public GeoRectBench { |
118 public: | 114 public: |
119 GeoRectBench_sort() : GeoRectBench("rect_sort") {} | 115 GeoRectBench_sort() : GeoRectBench("rect_sort") {} |
120 | 116 |
121 protected: | 117 protected: |
122 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 118 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
123 for (int outer = 0; outer < loops; ++outer) { | 119 for (int outer = 0; outer < loops; ++outer) { |
124 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { | 120 for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) { |
125 fRects[i].sort(); | 121 fRects[i].sort(); |
126 } | 122 } |
127 } | 123 } |
128 } | 124 } |
129 }; | 125 }; |
130 | 126 |
131 DEF_BENCH( return new GeoRectBench_intersect; ) | 127 DEF_BENCH( return new GeoRectBench_intersect; ) |
132 DEF_BENCH( return new GeoRectBench_intersect_rect; ) | 128 DEF_BENCH( return new GeoRectBench_intersect_rect; ) |
133 DEF_BENCH( return new GeoRectBench_Intersects; ) | 129 DEF_BENCH( return new GeoRectBench_Intersects; ) |
134 | 130 |
135 DEF_BENCH( return new GeoRectBench_sort; ) | 131 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 |