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

Side by Side Diff: bench/ScalarBench.cpp

Issue 305033002: TSAN caught us racing in ScalarBench.cpp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix windows? Created 6 years, 6 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 | « no previous file | 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 2011 Google Inc. 3 * Copyright 2011 Google Inc.
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 #include "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkFloatBits.h" 9 #include "SkFloatBits.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
(...skipping 23 matching lines...) Expand all
34 virtual void onDraw(const int loops, SkCanvas* canvas) { 34 virtual void onDraw(const int loops, SkCanvas* canvas) {
35 for (int i = 0; i < loops; i++) { 35 for (int i = 0; i < loops; i++) {
36 this->performTest(); 36 this->performTest();
37 } 37 }
38 } 38 }
39 39
40 private: 40 private:
41 typedef SkBenchmark INHERITED; 41 typedef SkBenchmark INHERITED;
42 }; 42 };
43 43
44 // we want to stop the compiler from eliminating code that it thinks is a no-op
45 // so we have a non-static global we increment, hoping that will convince the
46 // compiler to execute everything
47 int gScalarBench_NonStaticGlobal;
48
49 #define always_do(pred) \
50 do { \
51 if (pred) { \
52 ++gScalarBench_NonStaticGlobal; \
53 } \
54 } while (0)
55
56 // having unknown values in our arrays can throw off the timing a lot, perhaps 44 // having unknown values in our arrays can throw off the timing a lot, perhaps
57 // handling NaN values is a lot slower. Anyway, this guy is just meant to put 45 // handling NaN values is a lot slower. Anyway, this guy is just meant to put
58 // reasonable values in our arrays. 46 // reasonable values in our arrays.
59 template <typename T> void init9(T array[9]) { 47 template <typename T> void init9(T array[9]) {
60 SkRandom rand; 48 SkRandom rand;
61 for (int i = 0; i < 9; i++) { 49 for (int i = 0; i < 9; i++) {
62 array[i] = rand.nextSScalar1(); 50 array[i] = rand.nextSScalar1();
63 } 51 }
64 } 52 }
65 53
66 class FloatComparisonBench : public ScalarBench { 54 class FloatComparisonBench : public ScalarBench {
67 public: 55 public:
68 FloatComparisonBench() : INHERITED("compare_float") { 56 FloatComparisonBench() : INHERITED("compare_float") {
69 init9(fArray); 57 init9(fArray);
70 } 58 }
71 protected: 59 protected:
72 virtual int mulLoopCount() const { return 4; } 60 virtual int mulLoopCount() const { return 4; }
73 virtual void performTest() { 61 virtual void performTest() {
74 always_do(fArray[6] != 0.0f || fArray[7] != 0.0f || fArray[8] != 1.0f); 62 // xoring into a volatile prevents the compiler from optimizing these ch ecks away.
75 always_do(fArray[2] != 0.0f || fArray[5] != 0.0f); 63 volatile bool junk = false;
64 junk ^= (fArray[6] != 0.0f || fArray[7] != 0.0f || fArray[8] != 1.0f);
65 junk ^= (fArray[2] != 0.0f || fArray[5] != 0.0f);
76 } 66 }
77 private: 67 private:
78 float fArray[9]; 68 float fArray[9];
79 typedef ScalarBench INHERITED; 69 typedef ScalarBench INHERITED;
80 }; 70 };
81 71
82 class ForcedIntComparisonBench : public ScalarBench { 72 class ForcedIntComparisonBench : public ScalarBench {
83 public: 73 public:
84 ForcedIntComparisonBench() 74 ForcedIntComparisonBench()
85 : INHERITED("compare_forced_int") { 75 : INHERITED("compare_forced_int") {
86 init9(fArray); 76 init9(fArray);
87 } 77 }
88 protected: 78 protected:
89 virtual int mulLoopCount() const { return 4; } 79 virtual int mulLoopCount() const { return 4; }
90 virtual void performTest() { 80 virtual void performTest() {
91 always_do(SkScalarAs2sCompliment(fArray[6]) | 81 // xoring into a volatile prevents the compiler from optimizing these ch ecks away.
92 SkScalarAs2sCompliment(fArray[7]) | 82 volatile int32_t junk = 0;
93 (SkScalarAs2sCompliment(fArray[8]) - kPersp1Int)); 83 junk ^= (SkScalarAs2sCompliment(fArray[6]) |
94 always_do(SkScalarAs2sCompliment(fArray[2]) | 84 SkScalarAs2sCompliment(fArray[7]) |
95 SkScalarAs2sCompliment(fArray[5])); 85 (SkScalarAs2sCompliment(fArray[8]) - kPersp1Int));
86 junk ^= (SkScalarAs2sCompliment(fArray[2]) |
87 SkScalarAs2sCompliment(fArray[5]));
96 } 88 }
97 private: 89 private:
98 static const int32_t kPersp1Int = 0x3f800000; 90 static const int32_t kPersp1Int = 0x3f800000;
99 SkScalar fArray[9]; 91 SkScalar fArray[9];
100 typedef ScalarBench INHERITED; 92 typedef ScalarBench INHERITED;
101 }; 93 };
102 94
103 class IsFiniteScalarBench : public ScalarBench { 95 class IsFiniteScalarBench : public ScalarBench {
104 public: 96 public:
105 IsFiniteScalarBench() : INHERITED("isfinite") { 97 IsFiniteScalarBench() : INHERITED("isfinite") {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 private: 159 private:
168 typedef SkBenchmark INHERITED; 160 typedef SkBenchmark INHERITED;
169 }; 161 };
170 162
171 /////////////////////////////////////////////////////////////////////////////// 163 ///////////////////////////////////////////////////////////////////////////////
172 164
173 DEF_BENCH( return new FloatComparisonBench(); ) 165 DEF_BENCH( return new FloatComparisonBench(); )
174 DEF_BENCH( return new ForcedIntComparisonBench(); ) 166 DEF_BENCH( return new ForcedIntComparisonBench(); )
175 DEF_BENCH( return new RectBoundsBench(); ) 167 DEF_BENCH( return new RectBoundsBench(); )
176 DEF_BENCH( return new IsFiniteScalarBench(); ) 168 DEF_BENCH( return new IsFiniteScalarBench(); )
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698