Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: src/core/SkRect.cpp

Issue 1015633004: Use Sk4x to speed-up bounds of an array of points (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add comment Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/ScalarBench.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkRect.h" 9 #include "SkRect.h"
10 10
(...skipping 27 matching lines...) Expand all
38 38
39 void SkRect::toQuad(SkPoint quad[4]) const { 39 void SkRect::toQuad(SkPoint quad[4]) const {
40 SkASSERT(quad); 40 SkASSERT(quad);
41 41
42 quad[0].set(fLeft, fTop); 42 quad[0].set(fLeft, fTop);
43 quad[1].set(fRight, fTop); 43 quad[1].set(fRight, fTop);
44 quad[2].set(fRight, fBottom); 44 quad[2].set(fRight, fBottom);
45 quad[3].set(fLeft, fBottom); 45 quad[3].set(fLeft, fBottom);
46 } 46 }
47 47
48 //#include "Sk2x.h"
49 #include "Sk4x.h"
50
51 static inline bool is_finite(const Sk4f& value) {
52 Sk4i finite = value * Sk4f(0) == Sk4f(0);
53 return finite.allTrue();
54 }
55
48 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) { 56 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) {
49 SkASSERT((pts && count > 0) || count == 0); 57 SkASSERT((pts && count > 0) || count == 0);
50 58
51 bool isFinite = true; 59 bool isFinite = true;
52 60
53 if (count <= 0) { 61 if (count <= 0) {
54 sk_bzero(this, sizeof(SkRect)); 62 sk_bzero(this, sizeof(SkRect));
55 } else { 63 } else {
64 #if 0
56 SkScalar l, t, r, b; 65 SkScalar l, t, r, b;
57 66
58 l = r = pts[0].fX; 67 l = r = pts[0].fX;
59 t = b = pts[0].fY; 68 t = b = pts[0].fY;
60 69
61 // If all of the points are finite, accum should stay 0. If we encounter 70 // If all of the points are finite, accum should stay 0. If we encounter
62 // a NaN or infinity, then accum should become NaN. 71 // a NaN or infinity, then accum should become NaN.
63 float accum = 0; 72 float accum = 0;
64 accum *= l; accum *= t; 73 accum *= l; accum *= t;
65 74
66 for (int i = 1; i < count; i++) { 75 for (int i = 1; i < count; i++) {
67 SkScalar x = pts[i].fX; 76 SkScalar x = pts[i].fX;
68 SkScalar y = pts[i].fY; 77 SkScalar y = pts[i].fY;
69 78
70 accum *= x; accum *= y; 79 accum *= x; accum *= y;
71 80
72 // we use if instead of if/else, so we can generate min/max 81 // we use if instead of if/else, so we can generate min/max
73 // float instructions (at least on SSE) 82 // float instructions (at least on SSE)
74 if (x < l) l = x; 83 if (x < l) l = x;
75 if (x > r) r = x; 84 if (x > r) r = x;
76 85
77 if (y < t) t = y; 86 if (y < t) t = y;
78 if (y > b) b = y; 87 if (y > b) b = y;
79 } 88 }
80 89
81 SkASSERT(!accum || !SkScalarIsFinite(accum)); 90 SkASSERT(!accum || !SkScalarIsFinite(accum));
91 accum = 0;
82 if (accum) { 92 if (accum) {
83 l = t = r = b = 0; 93 l = t = r = b = 0;
84 isFinite = false; 94 isFinite = false;
85 } 95 }
86 this->set(l, t, r, b); 96 this->set(l, t, r, b);
97 #else
98 Sk4f min, max, accum;
99
100 if (count & 1) {
101 min = Sk4f(pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY);
102 pts += 1;
103 count -= 1;
104 } else {
105 min = Sk4f::Load(&pts[0].fX);
106 pts += 2;
107 count -= 2;
108 }
109 accum = max = min;
110 accum *= Sk4f(0);
111
112 count >>= 1;
113 for (int i = 0; i < count; ++i) {
114 Sk4f xy = Sk4f::Load(&pts->fX);
115 accum *= xy;
116 min = Sk4f::Min(min, xy);
117 max = Sk4f::Max(max, xy);
118 pts += 2;
119 }
120
121 /**
122 * With some trickery, we may be able to use Min/Max to also propogate non-finites,
123 * in which case we could eliminate accum entirely, and just check min and max for
124 * "is_finite".
125 */
126 if (is_finite(accum)) {
127 float minArray[4], maxArray[4];
128 min.store(minArray);
129 max.store(maxArray);
130 this->set(SkTMin(minArray[0], minArray[2]), SkTMin(minArray[1], minA rray[3]),
131 SkTMax(maxArray[0], maxArray[2]), SkTMax(maxArray[1], maxA rray[3]));
132 } else {
133 // we hit a non-finite value, so zero everything and return false
134 this->setEmpty();
135 isFinite = false;
136 }
137 #endif
87 } 138 }
88 139
89 return isFinite; 140 return isFinite;
90 } 141 }
91 142
92 #define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \ 143 #define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \
93 SkScalar L = SkMaxScalar(al, bl); \ 144 SkScalar L = SkMaxScalar(al, bl); \
94 SkScalar R = SkMinScalar(ar, br); \ 145 SkScalar R = SkMinScalar(ar, br); \
95 SkScalar T = SkMaxScalar(at, bt); \ 146 SkScalar T = SkMaxScalar(at, bt); \
96 SkScalar B = SkMinScalar(ab, bb); \ 147 SkScalar B = SkMinScalar(ab, bb); \
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 SkString strL, strT, strR, strB; 205 SkString strL, strT, strR, strB;
155 SkAppendScalarDec(&strL, fLeft); 206 SkAppendScalarDec(&strL, fLeft);
156 SkAppendScalarDec(&strT, fTop); 207 SkAppendScalarDec(&strT, fTop);
157 SkAppendScalarDec(&strR, fRight); 208 SkAppendScalarDec(&strR, fRight);
158 SkAppendScalarDec(&strB, fBottom); 209 SkAppendScalarDec(&strB, fBottom);
159 line.printf("SkRect::MakeLTRB(%s, %s, %s, %s);", 210 line.printf("SkRect::MakeLTRB(%s, %s, %s, %s);",
160 strL.c_str(), strT.c_str(), strR.c_str(), strB.c_str()); 211 strL.c_str(), strT.c_str(), strR.c_str(), strB.c_str());
161 } 212 }
162 SkDebugf("%s\n", line.c_str()); 213 SkDebugf("%s\n", line.c_str());
163 } 214 }
OLDNEW
« no previous file with comments | « bench/ScalarBench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698