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

Side by Side Diff: tests/SkNxTest.cpp

Issue 1411563008: prune unused SkNx features (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 0.001f Created 5 years, 1 month 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 | « src/opts/SkNx_sse.h ('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 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "Sk4px.h" 8 #include "Sk4px.h"
9 #include "SkNx.h" 9 #include "SkNx.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
11 #include "Test.h" 11 #include "Test.h"
12 12
13 template <int N, typename T> 13 template <int N>
14 static void test_Nf(skiatest::Reporter* r) { 14 static void test_Nf(skiatest::Reporter* r) {
15 15
16 auto assert_nearly_eq = [&](double eps, const SkNf<N,T>& v, T a, T b, T c, T d) { 16 auto assert_nearly_eq = [&](float eps, const SkNf<N>& v, float a, float b, f loat c, float d) {
17 auto close = [=](T a, T b) { return fabs(a-b) <= eps; }; 17 auto close = [=](float a, float b) { return fabsf(a-b) <= eps; };
18 T vals[4]; 18 float vals[4];
19 v.store(vals); 19 v.store(vals);
20 bool ok = close(vals[0], a) && close(vals[1], b) 20 bool ok = close(vals[0], a) && close(vals[1], b)
21 && close(v.template kth<0>(), a) && close(v.template kth<1>(), b) ; 21 && close(v.template kth<0>(), a) && close(v.template kth<1>(), b) ;
22 REPORTER_ASSERT(r, ok); 22 REPORTER_ASSERT(r, ok);
23 if (N == 4) { 23 if (N == 4) {
24 ok = close(vals[2], c) && close(vals[3], d) 24 ok = close(vals[2], c) && close(vals[3], d)
25 && close(v.template kth<2>(), c) && close(v.template kth<3>(), d); 25 && close(v.template kth<2>(), c) && close(v.template kth<3>(), d);
26 REPORTER_ASSERT(r, ok); 26 REPORTER_ASSERT(r, ok);
27 } 27 }
28 }; 28 };
29 auto assert_eq = [&](const SkNf<N,T>& v, T a, T b, T c, T d) { 29 auto assert_eq = [&](const SkNf<N>& v, float a, float b, float c, float d) {
30 return assert_nearly_eq(0, v, a,b,c,d); 30 return assert_nearly_eq(0, v, a,b,c,d);
31 }; 31 };
32 32
33 T vals[] = {3, 4, 5, 6}; 33 float vals[] = {3, 4, 5, 6};
34 SkNf<N,T> a = SkNf<N,T>::Load(vals), 34 SkNf<N> a = SkNf<N>::Load(vals),
35 b(a), 35 b(a),
36 c = a; 36 c = a;
37 SkNf<N,T> d; 37 SkNf<N> d;
38 d = a; 38 d = a;
39 39
40 assert_eq(a, 3, 4, 5, 6); 40 assert_eq(a, 3, 4, 5, 6);
41 assert_eq(b, 3, 4, 5, 6); 41 assert_eq(b, 3, 4, 5, 6);
42 assert_eq(c, 3, 4, 5, 6); 42 assert_eq(c, 3, 4, 5, 6);
43 assert_eq(d, 3, 4, 5, 6); 43 assert_eq(d, 3, 4, 5, 6);
44 44
45 assert_eq(a+b, 6, 8, 10, 12); 45 assert_eq(a+b, 6, 8, 10, 12);
46 assert_eq(a*b, 9, 16, 25, 36); 46 assert_eq(a*b, 9, 16, 25, 36);
47 assert_eq(a*b-b, 6, 12, 20, 30); 47 assert_eq(a*b-b, 6, 12, 20, 30);
48 assert_eq((a*b).sqrt(), 3, 4, 5, 6); 48 assert_eq((a*b).sqrt(), 3, 4, 5, 6);
49 assert_eq(a/b, 1, 1, 1, 1); 49 assert_eq(a/b, 1, 1, 1, 1);
50 assert_eq(SkNf<N,T>(0)-a, -3, -4, -5, -6); 50 assert_eq(SkNf<N>(0)-a, -3, -4, -5, -6);
51 51
52 SkNf<N,T> fours(4); 52 SkNf<N> fours(4);
53 53
54 assert_eq(fours.sqrt(), 2,2,2,2); 54 assert_eq(fours.sqrt(), 2,2,2,2);
55 assert_nearly_eq(0.001, fours.rsqrt0(), 0.5, 0.5, 0.5, 0.5); 55 assert_nearly_eq(0.001f, fours.rsqrt0(), 0.5, 0.5, 0.5, 0.5);
56 assert_nearly_eq(0.001, fours.rsqrt1(), 0.5, 0.5, 0.5, 0.5); 56 assert_nearly_eq(0.001f, fours.rsqrt1(), 0.5, 0.5, 0.5, 0.5);
57 assert_nearly_eq(0.001, fours.rsqrt2(), 0.5, 0.5, 0.5, 0.5); 57 assert_nearly_eq(0.001f, fours.rsqrt2(), 0.5, 0.5, 0.5, 0.5);
58 58
59 assert_eq( fours. invert(), 0.25, 0.25, 0.25, 0.25); 59 assert_eq( fours. invert(), 0.25, 0.25, 0.25, 0.25);
60 assert_nearly_eq(0.001, fours.approxInvert(), 0.25, 0.25, 0.25, 0.25); 60 assert_nearly_eq(0.001f, fours.approxInvert(), 0.25, 0.25, 0.25, 0.25);
61 61
62 assert_eq(SkNf<N,T>::Min(a, fours), 3, 4, 4, 4); 62 assert_eq(SkNf<N>::Min(a, fours), 3, 4, 4, 4);
63 assert_eq(SkNf<N,T>::Max(a, fours), 4, 4, 5, 6); 63 assert_eq(SkNf<N>::Max(a, fours), 4, 4, 5, 6);
64 64
65 // Test some comparisons. This is not exhaustive. 65 // Test some comparisons. This is not exhaustive.
66 REPORTER_ASSERT(r, (a == b).allTrue()); 66 REPORTER_ASSERT(r, (a == b).allTrue());
67 REPORTER_ASSERT(r, (a+b == a*b-b).anyTrue()); 67 REPORTER_ASSERT(r, (a+b == a*b-b).anyTrue());
68 REPORTER_ASSERT(r, !(a+b == a*b-b).allTrue()); 68 REPORTER_ASSERT(r, !(a+b == a*b-b).allTrue());
69 REPORTER_ASSERT(r, !(a+b == a*b).anyTrue()); 69 REPORTER_ASSERT(r, !(a+b == a*b).anyTrue());
70 REPORTER_ASSERT(r, !(a != b).anyTrue()); 70 REPORTER_ASSERT(r, !(a != b).anyTrue());
71 REPORTER_ASSERT(r, (a < fours).anyTrue()); 71 REPORTER_ASSERT(r, (a < fours).anyTrue());
72 REPORTER_ASSERT(r, (a <= fours).anyTrue()); 72 REPORTER_ASSERT(r, (a <= fours).anyTrue());
73 REPORTER_ASSERT(r, !(a > fours).allTrue()); 73 REPORTER_ASSERT(r, !(a > fours).allTrue());
74 REPORTER_ASSERT(r, !(a >= fours).allTrue()); 74 REPORTER_ASSERT(r, !(a >= fours).allTrue());
75 } 75 }
76 76
77 DEF_TEST(SkNf, r) { 77 DEF_TEST(SkNf, r) {
78 test_Nf<2, float>(r); 78 test_Nf<2>(r);
79 test_Nf<2, double>(r); 79 test_Nf<4>(r);
80
81 test_Nf<4, float>(r);
82 test_Nf<4, double>(r);
83 } 80 }
84 81
85 template <int N, typename T> 82 template <int N, typename T>
86 void test_Ni(skiatest::Reporter* r) { 83 void test_Ni(skiatest::Reporter* r) {
87 auto assert_eq = [&](const SkNi<N,T>& v, T a, T b, T c, T d, T e, T f, T g, T h) { 84 auto assert_eq = [&](const SkNi<N,T>& v, T a, T b, T c, T d, T e, T f, T g, T h) {
88 T vals[8]; 85 T vals[8];
89 v.store(vals); 86 v.store(vals);
90 87
91 switch (N) { 88 switch (N) {
92 case 8: REPORTER_ASSERT(r, vals[4] == e && vals[5] == f && vals[6] == g && vals[7] == h); 89 case 8: REPORTER_ASSERT(r, vals[4] == e && vals[5] == f && vals[6] == g && vals[7] == h);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 Sk4f(0.7f).toBytes(bytes); 213 Sk4f(0.7f).toBytes(bytes);
217 REPORTER_ASSERT(r, bytes[0] == 0); 214 REPORTER_ASSERT(r, bytes[0] == 0);
218 215
219 // Clamping edge cases. 216 // Clamping edge cases.
220 Sk4f(-2.0f, -0.7f, 255.9f, 256.0f).toBytes(bytes); 217 Sk4f(-2.0f, -0.7f, 255.9f, 256.0f).toBytes(bytes);
221 REPORTER_ASSERT(r, bytes[0] == 0); 218 REPORTER_ASSERT(r, bytes[0] == 0);
222 REPORTER_ASSERT(r, bytes[1] == 0); 219 REPORTER_ASSERT(r, bytes[1] == 0);
223 REPORTER_ASSERT(r, bytes[2] == 255); 220 REPORTER_ASSERT(r, bytes[2] == 255);
224 REPORTER_ASSERT(r, bytes[3] == 255); 221 REPORTER_ASSERT(r, bytes[3] == 255);
225 } 222 }
OLDNEW
« no previous file with comments | « src/opts/SkNx_sse.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698