Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2015-06-15 17:58:42 +00:00
|
|
|
#include "Sk4px.h"
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
#include "SkNx.h"
|
2015-05-15 00:53:04 +00:00
|
|
|
#include "SkRandom.h"
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2015-11-09 16:33:53 +00:00
|
|
|
template <int N>
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
static void test_Nf(skiatest::Reporter* r) {
|
|
|
|
|
2015-11-20 21:53:19 +00:00
|
|
|
auto assert_nearly_eq = [&](float eps, const SkNx<N, float>& v,
|
|
|
|
float a, float b, float c, float d) {
|
2015-11-09 16:33:53 +00:00
|
|
|
auto close = [=](float a, float b) { return fabsf(a-b) <= eps; };
|
|
|
|
float vals[4];
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
v.store(vals);
|
2015-04-03 13:16:13 +00:00
|
|
|
bool ok = close(vals[0], a) && close(vals[1], b)
|
|
|
|
&& close(v.template kth<0>(), a) && close(v.template kth<1>(), b);
|
|
|
|
REPORTER_ASSERT(r, ok);
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
if (N == 4) {
|
2015-04-03 13:16:13 +00:00
|
|
|
ok = close(vals[2], c) && close(vals[3], d)
|
|
|
|
&& close(v.template kth<2>(), c) && close(v.template kth<3>(), d);
|
|
|
|
REPORTER_ASSERT(r, ok);
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
}
|
|
|
|
};
|
2015-11-20 21:53:19 +00:00
|
|
|
auto assert_eq = [&](const SkNx<N, float>& v, float a, float b, float c, float d) {
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
return assert_nearly_eq(0, v, a,b,c,d);
|
|
|
|
};
|
|
|
|
|
2015-11-09 16:33:53 +00:00
|
|
|
float vals[] = {3, 4, 5, 6};
|
2015-11-20 21:53:19 +00:00
|
|
|
SkNx<N,float> a = SkNx<N,float>::Load(vals),
|
|
|
|
b(a),
|
|
|
|
c = a;
|
|
|
|
SkNx<N,float> d;
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
d = a;
|
|
|
|
|
|
|
|
assert_eq(a, 3, 4, 5, 6);
|
|
|
|
assert_eq(b, 3, 4, 5, 6);
|
|
|
|
assert_eq(c, 3, 4, 5, 6);
|
|
|
|
assert_eq(d, 3, 4, 5, 6);
|
|
|
|
|
|
|
|
assert_eq(a+b, 6, 8, 10, 12);
|
|
|
|
assert_eq(a*b, 9, 16, 25, 36);
|
|
|
|
assert_eq(a*b-b, 6, 12, 20, 30);
|
|
|
|
assert_eq((a*b).sqrt(), 3, 4, 5, 6);
|
|
|
|
assert_eq(a/b, 1, 1, 1, 1);
|
2015-11-20 21:53:19 +00:00
|
|
|
assert_eq(SkNx<N,float>(0)-a, -3, -4, -5, -6);
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
|
2015-11-20 21:53:19 +00:00
|
|
|
SkNx<N,float> fours(4);
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
|
|
|
|
assert_eq(fours.sqrt(), 2,2,2,2);
|
2015-11-09 16:33:53 +00:00
|
|
|
assert_nearly_eq(0.001f, fours.rsqrt0(), 0.5, 0.5, 0.5, 0.5);
|
|
|
|
assert_nearly_eq(0.001f, fours.rsqrt1(), 0.5, 0.5, 0.5, 0.5);
|
|
|
|
assert_nearly_eq(0.001f, fours.rsqrt2(), 0.5, 0.5, 0.5, 0.5);
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
|
2015-11-09 16:33:53 +00:00
|
|
|
assert_eq( fours. invert(), 0.25, 0.25, 0.25, 0.25);
|
|
|
|
assert_nearly_eq(0.001f, fours.approxInvert(), 0.25, 0.25, 0.25, 0.25);
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
|
2015-11-20 21:53:19 +00:00
|
|
|
assert_eq(SkNx<N,float>::Min(a, fours), 3, 4, 4, 4);
|
|
|
|
assert_eq(SkNx<N,float>::Max(a, fours), 4, 4, 5, 6);
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
|
|
|
|
// Test some comparisons. This is not exhaustive.
|
|
|
|
REPORTER_ASSERT(r, (a == b).allTrue());
|
|
|
|
REPORTER_ASSERT(r, (a+b == a*b-b).anyTrue());
|
|
|
|
REPORTER_ASSERT(r, !(a+b == a*b-b).allTrue());
|
|
|
|
REPORTER_ASSERT(r, !(a+b == a*b).anyTrue());
|
|
|
|
REPORTER_ASSERT(r, !(a != b).anyTrue());
|
|
|
|
REPORTER_ASSERT(r, (a < fours).anyTrue());
|
|
|
|
REPORTER_ASSERT(r, (a <= fours).anyTrue());
|
|
|
|
REPORTER_ASSERT(r, !(a > fours).allTrue());
|
|
|
|
REPORTER_ASSERT(r, !(a >= fours).allTrue());
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkNf, r) {
|
2015-11-09 16:33:53 +00:00
|
|
|
test_Nf<2>(r);
|
|
|
|
test_Nf<4>(r);
|
Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T>
The primary feature this delivers is SkNf and SkNd for arbitrary power-of-two N. Non-specialized types or types larger than 128 bits should now Just Work (and we can drop in a specialization to make them faster). Sk4s is now just a typedef for SkNf<4, SkScalar>; Sk4d is SkNf<4, double>, Sk2f SkNf<2, float>, etc.
This also makes implementing new specializations easier and more encapsulated. We're now using template specialization, which means the specialized versions don't have to leak out so much from SkNx_sse.h and SkNx_neon.h.
This design leaves us room to grow up, e.g to SkNf<8, SkScalar> == Sk8s, and to grown down too, to things like SkNi<8, uint16_t> == Sk8h.
To simplify things, I've stripped away most APIs (swizzles, casts, reinterpret_casts) that no one's using yet. I will happily add them back if they seem useful.
You shouldn't feel bad about using any of the typedef Sk4s, Sk4f, Sk4d, Sk2s, Sk2f, Sk2d, Sk4i, etc. Here's how you should feel:
- Sk4f, Sk4s, Sk2d: feel awesome
- Sk2f, Sk2s, Sk4d: feel pretty good
No public API changes.
TBR=reed@google.com
BUG=skia:3592
Review URL: https://codereview.chromium.org/1048593002
2015-03-30 17:50:27 +00:00
|
|
|
}
|
2015-04-14 21:02:52 +00:00
|
|
|
|
|
|
|
template <int N, typename T>
|
|
|
|
void test_Ni(skiatest::Reporter* r) {
|
2015-11-20 21:53:19 +00:00
|
|
|
auto assert_eq = [&](const SkNx<N,T>& v, T a, T b, T c, T d, T e, T f, T g, T h) {
|
2015-04-14 21:02:52 +00:00
|
|
|
T vals[8];
|
|
|
|
v.store(vals);
|
|
|
|
|
|
|
|
switch (N) {
|
|
|
|
case 8: REPORTER_ASSERT(r, vals[4] == e && vals[5] == f && vals[6] == g && vals[7] == h);
|
|
|
|
case 4: REPORTER_ASSERT(r, vals[2] == c && vals[3] == d);
|
|
|
|
case 2: REPORTER_ASSERT(r, vals[0] == a && vals[1] == b);
|
|
|
|
}
|
2015-04-27 19:08:01 +00:00
|
|
|
switch (N) {
|
|
|
|
case 8: REPORTER_ASSERT(r, v.template kth<4>() == e && v.template kth<5>() == f &&
|
|
|
|
v.template kth<6>() == g && v.template kth<7>() == h);
|
|
|
|
case 4: REPORTER_ASSERT(r, v.template kth<2>() == c && v.template kth<3>() == d);
|
|
|
|
case 2: REPORTER_ASSERT(r, v.template kth<0>() == a && v.template kth<1>() == b);
|
|
|
|
}
|
2015-04-14 21:02:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
T vals[] = { 1,2,3,4,5,6,7,8 };
|
2015-11-20 21:53:19 +00:00
|
|
|
SkNx<N,T> a = SkNx<N,T>::Load(vals),
|
2015-04-14 21:02:52 +00:00
|
|
|
b(a),
|
|
|
|
c = a;
|
2015-11-20 21:53:19 +00:00
|
|
|
SkNx<N,T> d;
|
2015-04-14 21:02:52 +00:00
|
|
|
d = a;
|
|
|
|
|
|
|
|
assert_eq(a, 1,2,3,4,5,6,7,8);
|
|
|
|
assert_eq(b, 1,2,3,4,5,6,7,8);
|
|
|
|
assert_eq(c, 1,2,3,4,5,6,7,8);
|
|
|
|
assert_eq(d, 1,2,3,4,5,6,7,8);
|
|
|
|
|
|
|
|
assert_eq(a+a, 2,4,6,8,10,12,14,16);
|
|
|
|
assert_eq(a*a, 1,4,9,16,25,36,49,64);
|
|
|
|
assert_eq(a*a-a, 0,2,6,12,20,30,42,56);
|
|
|
|
|
|
|
|
assert_eq(a >> 2, 0,0,0,1,1,1,1,2);
|
|
|
|
assert_eq(a << 1, 2,4,6,8,10,12,14,16);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, a.template kth<1>() == 2);
|
|
|
|
}
|
|
|
|
|
2015-11-20 21:53:19 +00:00
|
|
|
DEF_TEST(SkNx, r) {
|
2015-04-14 21:02:52 +00:00
|
|
|
test_Ni<2, uint16_t>(r);
|
|
|
|
test_Ni<4, uint16_t>(r);
|
|
|
|
test_Ni<8, uint16_t>(r);
|
2015-04-27 19:08:01 +00:00
|
|
|
|
|
|
|
test_Ni<2, int>(r);
|
|
|
|
test_Ni<4, int>(r);
|
|
|
|
test_Ni<8, int>(r);
|
2015-04-14 21:02:52 +00:00
|
|
|
}
|
2015-05-15 00:53:04 +00:00
|
|
|
|
2015-07-13 19:06:33 +00:00
|
|
|
DEF_TEST(SkNi_min_lt, r) {
|
2015-05-15 00:53:04 +00:00
|
|
|
// Exhaustively check the 8x8 bit space.
|
|
|
|
for (int a = 0; a < (1<<8); a++) {
|
|
|
|
for (int b = 0; b < (1<<8); b++) {
|
2015-07-13 19:06:33 +00:00
|
|
|
Sk16b aw(a), bw(b);
|
|
|
|
REPORTER_ASSERT(r, Sk16b::Min(aw, bw).kth<0>() == SkTMin(a, b));
|
|
|
|
REPORTER_ASSERT(r, !(aw < bw).kth<0>() == !(a < b));
|
2015-05-15 00:53:04 +00:00
|
|
|
}}
|
|
|
|
|
|
|
|
// Exhausting the 16x16 bit space is kind of slow, so only do that in release builds.
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
SkRandom rand;
|
|
|
|
for (int i = 0; i < (1<<16); i++) {
|
|
|
|
uint16_t a = rand.nextU() >> 16,
|
|
|
|
b = rand.nextU() >> 16;
|
|
|
|
REPORTER_ASSERT(r, Sk8h::Min(Sk8h(a), Sk8h(b)).kth<0>() == SkTMin(a, b));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
for (int a = 0; a < (1<<16); a++) {
|
|
|
|
for (int b = 0; b < (1<<16); b++) {
|
|
|
|
REPORTER_ASSERT(r, Sk8h::Min(Sk8h(a), Sk8h(b)).kth<0>() == SkTMin(a, b));
|
|
|
|
}}
|
|
|
|
#endif
|
|
|
|
}
|
2015-06-15 17:58:42 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkNi_saturatedAdd, r) {
|
|
|
|
for (int a = 0; a < (1<<8); a++) {
|
|
|
|
for (int b = 0; b < (1<<8); b++) {
|
|
|
|
int exact = a+b;
|
|
|
|
if (exact > 255) { exact = 255; }
|
|
|
|
if (exact < 0) { exact = 0; }
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, Sk16b(a).saturatedAdd(Sk16b(b)).kth<0>() == exact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Sk4px_muldiv255round, r) {
|
|
|
|
for (int a = 0; a < (1<<8); a++) {
|
|
|
|
for (int b = 0; b < (1<<8); b++) {
|
|
|
|
int exact = (a*b+127)/255;
|
|
|
|
|
|
|
|
// Duplicate a and b 16x each.
|
2015-06-22 17:39:38 +00:00
|
|
|
auto av = Sk4px::DupAlpha(a),
|
|
|
|
bv = Sk4px::DupAlpha(b);
|
2015-06-15 17:58:42 +00:00
|
|
|
|
|
|
|
// This way should always be exactly correct.
|
2015-06-22 17:39:38 +00:00
|
|
|
int correct = (av * bv).div255().kth<0>();
|
2015-06-15 17:58:42 +00:00
|
|
|
REPORTER_ASSERT(r, correct == exact);
|
|
|
|
|
|
|
|
// We're a bit more flexible on this method: correct for 0 or 255, otherwise off by <=1.
|
2015-06-22 17:39:38 +00:00
|
|
|
int fast = av.approxMulDiv255(bv).kth<0>();
|
2015-06-15 17:58:42 +00:00
|
|
|
REPORTER_ASSERT(r, fast-exact >= -1 && fast-exact <= 1);
|
|
|
|
if (a == 0 || a == 255 || b == 0 || b == 255) {
|
|
|
|
REPORTER_ASSERT(r, fast == exact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-14 17:54:19 +00:00
|
|
|
|
|
|
|
DEF_TEST(Sk4px_widening, r) {
|
|
|
|
SkPMColor colors[] = {
|
|
|
|
SkPreMultiplyColor(0xff00ff00),
|
|
|
|
SkPreMultiplyColor(0x40008000),
|
|
|
|
SkPreMultiplyColor(0x7f020406),
|
|
|
|
SkPreMultiplyColor(0x00000000),
|
|
|
|
};
|
|
|
|
auto packed = Sk4px::Load4(colors);
|
|
|
|
|
|
|
|
auto wideLo = packed.widenLo(),
|
|
|
|
wideHi = packed.widenHi(),
|
|
|
|
wideLoHi = packed.widenLoHi(),
|
|
|
|
wideLoHiAlt = wideLo + wideHi;
|
|
|
|
REPORTER_ASSERT(r, 0 == memcmp(&wideLoHi, &wideLoHiAlt, sizeof(wideLoHi)));
|
|
|
|
}
|
2015-09-01 13:29:45 +00:00
|
|
|
|
2015-11-20 21:53:19 +00:00
|
|
|
DEF_TEST(SkNx_cast, r) {
|
|
|
|
Sk4f fs(-1.7f, -1.4f, 0.5f, 1.9f);
|
|
|
|
Sk4i is = SkNx_cast<int>(fs);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, is.kth<0>() == -1);
|
|
|
|
REPORTER_ASSERT(r, is.kth<1>() == -1);
|
|
|
|
REPORTER_ASSERT(r, is.kth<2>() == 0);
|
|
|
|
REPORTER_ASSERT(r, is.kth<3>() == 1);
|
|
|
|
}
|