diff options
author | Mike Klein <mtklein@chromium.org> | 2016-10-15 00:13:29 -0400 |
---|---|---|
committer | Mike Klein <mtklein@chromium.org> | 2016-10-15 04:35:04 +0000 |
commit | 511ea17b967914ae8342d7861c6695ec8d492bcc (patch) | |
tree | 2cf94ab09b450dd172dbb220eef1dc0b283124fb /src/core/SkNx.h | |
parent | 1e76464f87ea55a8749eb94b8e6c79638983d65a (diff) |
SkNx_abi for passing Sk4f as function arguments, etc.
CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot,Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-ASAN-Trybot
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3422
Change-Id: Idc0a192faa7ff843aef023229186580c69baf1f7
Reviewed-on: https://skia-review.googlesource.com/3422
Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core/SkNx.h')
-rw-r--r-- | src/core/SkNx.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/core/SkNx.h b/src/core/SkNx.h index afba75a487..6d9af9fe47 100644 --- a/src/core/SkNx.h +++ b/src/core/SkNx.h @@ -16,6 +16,11 @@ #include <math.h> #include <type_traits> +// These _abi types are data-only, and so can be used to store SkNx in structs or +// pass them as function parameters or return values, even across compilation units. +template <int N, typename T> struct SkNx_abi { SkNx_abi<N/2,T> lo, hi; }; +template < typename T> struct SkNx_abi<1,T> { T val; }; + namespace { #define SI static inline @@ -42,6 +47,9 @@ struct SkNx { static_assert(N==16, ""); } + SkNx(const SkNx_abi<N,T>& a) : fLo(a.lo), fHi(a.hi) {} + operator SkNx_abi<N,T>() const { return { (SkNx_abi<N/2,T>)fLo, (SkNx_abi<N/2,T>)fHi }; } + T operator[](int k) const { SkASSERT(0 <= k && k < N); return k < N/2 ? fLo[k] : fHi[k-N/2]; @@ -129,6 +137,9 @@ struct SkNx<1,T> { SkNx() = default; SkNx(T v) : fVal(v) {} + SkNx(const SkNx_abi<1,T>& a) : fVal(a.val) {} + operator SkNx_abi<1,T>() const { return { fVal }; } + // Android complains against unused parameters, so we guard it T operator[](int SkDEBUGCODE(k)) const { SkASSERT(k == 0); |