Flutter Engine
The Flutter Engine
Macros | Typedefs | Functions | Variables
SkRasterPipelineOptsTest.cpp File Reference
#include "src/core/SkOpts.h"
#include "tests/Test.h"
#include <algorithm>
#include <array>
#include <cstddef>
#include "src/opts/SkRasterPipeline_opts.h"

Go to the source code of this file.

Macros

#define SK_OPTS_NS   RPOptsTest
 

Typedefs

using F = SK_OPTS_NS::F
 
using I32 = SK_OPTS_NS::I32
 

Functions

template<size_t N>
static std::array< int32_t, Nmake_masks (int bits)
 
 DEF_TEST (SkRasterPipelineOpts_Any, r)
 
 DEF_TEST (SkRasterPipelineOpts_All, r)
 
 DEF_TEST (SkRasterPipelineOpts_Sin, r)
 
 DEF_TEST (SkRasterPipelineOpts_Cos, r)
 
 DEF_TEST (SkRasterPipelineOpts_Tan, r)
 
 DEF_TEST (SkRasterPipelineOpts_Asin, r)
 
 DEF_TEST (SkRasterPipelineOpts_Acos, r)
 
 DEF_TEST (SkRasterPipelineOpts_Atan, r)
 
 DEF_TEST (SkRasterPipelineOpts_Atan2, r)
 
 DEF_TEST (SkRasterPipelineOpts_Log2, r)
 
 DEF_TEST (SkRasterPipelineOpts_Pow2, r)
 

Variables

constexpr auto F_ = SK_OPTS_NS::F_
 

Macro Definition Documentation

◆ SK_OPTS_NS

#define SK_OPTS_NS   RPOptsTest

Definition at line 15 of file SkRasterPipelineOptsTest.cpp.

Typedef Documentation

◆ F

using F = SK_OPTS_NS::F

Definition at line 35 of file SkRasterPipelineOptsTest.cpp.

◆ I32

Definition at line 36 of file SkRasterPipelineOptsTest.cpp.

Function Documentation

◆ DEF_TEST() [1/11]

DEF_TEST ( SkRasterPipelineOpts_Acos  ,
 
)

Definition at line 132 of file SkRasterPipelineOptsTest.cpp.

132 {
133 constexpr float kTolerance = 0.00175f;
134 for (float x = -1; x <= 1; x += 1.0f/64) {
136 F expected = F_(acosf(x));
137 F delta = SK_OPTS_NS::abs_(expected - result);
138
140 }
141}
static constexpr float kTolerance
Definition: GrQuadUtils.cpp:29
constexpr auto F_
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
GAsyncResult * result
double x
SI bool all(I32 c)
Definition: SkMD5.cpp:120

◆ DEF_TEST() [2/11]

DEF_TEST ( SkRasterPipelineOpts_All  ,
 
)

Definition at line 64 of file SkRasterPipelineOptsTest.cpp.

64 {
65 static constexpr size_t N = sizeof(I32) / sizeof(int32_t);
66
67 for (int value = 0; value < (1 << N); ++value) {
68 // Load masks corresponding to the bit-pattern of `value` into lanes of `i`.
69 std::array<int32_t, N> masks = make_masks<N>(value);
70 I32 i = sk_unaligned_load<I32>(masks.data());
71
72 // Verify that the raster pipeline all() matches expectations.
73 REPORTER_ASSERT(r, SK_OPTS_NS::all(i) == std::all_of(masks.begin(), masks.end(),
74 [](int32_t m) { return m != 0; }));
75 }
76}
SK_OPTS_NS::I32 I32
V< int32_t > I32
Definition: Transform_inl.h:15
#define N
Definition: beziers.cpp:19
uint8_t value

◆ DEF_TEST() [3/11]

DEF_TEST ( SkRasterPipelineOpts_Any  ,
 
)

Definition at line 50 of file SkRasterPipelineOptsTest.cpp.

50 {
51 static constexpr size_t N = sizeof(I32) / sizeof(int32_t);
52
53 for (int value = 0; value < (1 << N); ++value) {
54 // Load masks corresponding to the bit-pattern of `value` into lanes of `i`.
55 std::array<int32_t, N> masks = make_masks<N>(value);
56 I32 i = sk_unaligned_load<I32>(masks.data());
57
58 // Verify that the raster pipeline any() matches expectations.
59 REPORTER_ASSERT(r, SK_OPTS_NS::any(i) == std::any_of(masks.begin(), masks.end(),
60 [](int32_t m) { return m != 0; }));
61 }
62}
SI bool any(I32 c)

◆ DEF_TEST() [4/11]

DEF_TEST ( SkRasterPipelineOpts_Asin  ,
 
)

Definition at line 121 of file SkRasterPipelineOptsTest.cpp.

121 {
122 constexpr float kTolerance = 0.00175f;
123 for (float x = -1; x <= 1; x += 1.0f/64) {
125 F expected = F_(asinf(x));
126 F delta = SK_OPTS_NS::abs_(expected - result);
127
129 }
130}

◆ DEF_TEST() [5/11]

DEF_TEST ( SkRasterPipelineOpts_Atan  ,
 
)

Definition at line 143 of file SkRasterPipelineOptsTest.cpp.

143 {
144 constexpr float kTolerance = 0.00175f;
145 for (float x = -10.0f; x <= 10.0f; x += 0.1f) {
147 F expected = F_(atanf(x));
148 F delta = SK_OPTS_NS::abs_(expected - result);
149
151 }
152}

◆ DEF_TEST() [6/11]

DEF_TEST ( SkRasterPipelineOpts_Atan2  ,
 
)

Definition at line 154 of file SkRasterPipelineOptsTest.cpp.

154 {
155 constexpr float kTolerance = 0.00175f;
156 for (float y = -3.0f; y <= 3.0f; y += 0.1f) {
157 for (float x = -3.0f; x <= 3.0f; x += 0.1f) {
159 F expected = F_(std::atan2(y, x));
160 F delta = SK_OPTS_NS::abs_(expected - result);
161
163 }
164 }
165}
double y
SI F atan2_(F y0, F x0)

◆ DEF_TEST() [7/11]

DEF_TEST ( SkRasterPipelineOpts_Cos  ,
 
)

Definition at line 90 of file SkRasterPipelineOptsTest.cpp.

90 {
91 constexpr float Pi = SK_ScalarPI;
92 constexpr float kTolerance = 0.000875f;
93 for (float rad = -5*Pi; rad <= 5*Pi; rad += 0.1f) {
95 F expected = F_(std::cos(rad));
96 F delta = SK_OPTS_NS::abs_(expected - result);
97
99 }
100}
#define SK_ScalarPI
Definition: SkScalar.h:21

◆ DEF_TEST() [8/11]

DEF_TEST ( SkRasterPipelineOpts_Log2  ,
 
)

Definition at line 167 of file SkRasterPipelineOptsTest.cpp.

167 {
168 constexpr float kTolerance = 0.001f;
169 for (float value : {0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f}) {
171 F expected = F_(std::log2(value));
172 F delta = SK_OPTS_NS::abs_(expected - result);
173
175 }
176}

◆ DEF_TEST() [9/11]

DEF_TEST ( SkRasterPipelineOpts_Pow2  ,
 
)

Definition at line 178 of file SkRasterPipelineOptsTest.cpp.

178 {
179 constexpr float kTolerance = 0.001f;
180 for (float value : {-80, -5, -2, -1, 0, 1, 2, 3, 5}) {
182 F expected = F_(std::pow(2.0, value));
183 F delta = SK_OPTS_NS::abs_(expected - result);
184
186 }
187
189 REPORTER_ASSERT(r, SK_OPTS_NS::all(result == INFINITY));
190}

◆ DEF_TEST() [10/11]

DEF_TEST ( SkRasterPipelineOpts_Sin  ,
 
)

Definition at line 78 of file SkRasterPipelineOptsTest.cpp.

78 {
79 constexpr float Pi = SK_ScalarPI;
80 constexpr float kTolerance = 0.000875f;
81 for (float rad = -5*Pi; rad <= 5*Pi; rad += 0.1f) {
83 F expected = F_(std::sin(rad));
84 F delta = SK_OPTS_NS::abs_(expected - result);
85
87 }
88}

◆ DEF_TEST() [11/11]

DEF_TEST ( SkRasterPipelineOpts_Tan  ,
 
)

Definition at line 102 of file SkRasterPipelineOptsTest.cpp.

102 {
103 // Our tangent diverges more as we get near infinities (x near +- Pi/2),
104 // so we bring in the domain a little.
105 constexpr float Pi = SK_ScalarPI;
106 constexpr float kEpsilon = 0.16f;
107 constexpr float kTolerance = 0.00175f;
108
109 // Test against various multiples of Pi, to check our periodicity
110 for (float period : {0.0f, -3*Pi, 3*Pi}) {
111 for (float rad = -Pi/2 + kEpsilon; rad <= Pi/2 - kEpsilon; rad += 0.01f) {
112 F result = SK_OPTS_NS::tan_(F_(rad + period));
113 F expected = F_(std::tan(rad));
114 F delta = SK_OPTS_NS::abs_(expected - result);
115
117 }
118 }
119}
static constexpr double kEpsilon

◆ make_masks()

template<size_t N>
static std::array< int32_t, N > make_masks ( int  bits)
static

Definition at line 39 of file SkRasterPipelineOptsTest.cpp.

39 {
40 // Make an array of masks that correspond to the bit pattern of `bits`.
41 std::array<int32_t, N> masks;
42 for (size_t idx = 0; idx < N; ++idx) {
43 masks[idx] = (bits & 1) ? ~0 : 0;
44 bits >>= 1;
45 }
46 SkASSERT(!bits);
47 return masks;
48}
#define SkASSERT(cond)
Definition: SkAssert.h:116

Variable Documentation

◆ F_

constexpr auto F_ = SK_OPTS_NS::F_
constexpr

Definition at line 34 of file SkRasterPipelineOptsTest.cpp.