From b07bee3121680b53b98b780ac08d14d374dd4c6f Mon Sep 17 00:00:00 2001 From: mtklein Date: Wed, 12 Aug 2015 10:23:37 -0700 Subject: Refactor to put SkXfermode_opts inside SK_OPTS_NS. Without this refactor I was getting warnings previously about having code inside namespace SK_OPTS_NS (e.g. namespace sse2, namespace neon) referring to code inside an anonymous namespace (Sk4px, SkPMFloat, Sk4f, etc) [1]. That low-level code was in an anonymous namespace to allow multiple independent copies of its methods to be instantiated without the linker getting confused / offended about violating the One Definition Rule. This was only happening in Debug mode where the methods were not being inlined. To fix this all, I've force-inlined the methods of the low-level code and removed the anonymous namespace. BUG=skia:4117 [1] Here is what those errors looked like: In file included from ../../../../src/core/SkOpts.cpp:18:0: ../../../../src/opts/SkXfermode_opts.h:193:7: error: 'portable::Sk4pxXfermode' has a field 'portable::Sk4pxXfermode::fProc4' whose type uses the anonymous namespace [-Werror] class Sk4pxXfermode : public SkProcCoeffXfermode { ^ ../../../../src/opts/SkXfermode_opts.h:193:7: error: 'portable::Sk4pxXfermode' has a field 'portable::Sk4pxXfermode::fAAProc4' whose type uses the anonymous namespace [-Werror] ../../../../src/opts/SkXfermode_opts.h:235:7: error: 'portable::SkPMFloatXfermode' has a field 'portable::SkPMFloatXfermode::fProcF' whose type uses the anonymous namespace [-Werror] class SkPMFloatXfermode : public SkProcCoeffXfermode { ^ cc1plus: all warnings being treated as errors Review URL: https://codereview.chromium.org/1286093004 --- src/core/Sk4px.h | 9 ------- src/core/SkNx.h | 9 ------- src/core/SkOpts.cpp | 2 +- src/core/SkPMFloat.h | 9 ------- src/opts/Sk4px_NEON.h | 56 +++++++++++++++++++--------------------- src/opts/Sk4px_SSE2.h | 64 ++++++++++++++++++++++++---------------------- src/opts/Sk4px_none.h | 50 +++++++++++++++++------------------- src/opts/SkNx_neon.h | 4 --- src/opts/SkNx_sse.h | 5 ---- src/opts/SkOpts_neon.cpp | 2 +- src/opts/SkOpts_sse2.cpp | 2 +- src/opts/SkPMFloat_neon.h | 10 +++----- src/opts/SkPMFloat_none.h | 10 +++----- src/opts/SkPMFloat_sse.h | 10 +++----- src/opts/SkXfermode_opts.h | 4 +-- 15 files changed, 97 insertions(+), 149 deletions(-) diff --git a/src/core/Sk4px.h b/src/core/Sk4px.h index ffde1af504..1c8ed0df71 100644 --- a/src/core/Sk4px.h +++ b/src/core/Sk4px.h @@ -12,13 +12,6 @@ #include "SkColor.h" #include "SkColorPriv.h" -// This file may be included multiple times by .cpp files with different flags, leading -// to different definitions. Usually that doesn't matter because it's all inlined, but -// in Debug modes the compilers may not inline everything. So wrap everything in an -// anonymous namespace to give each includer their own silo of this code (or the linker -// will probably pick one randomly for us, which is rarely correct). -namespace { - // 1, 2 or 4 SkPMColors, generally vectorized. class Sk4px : public Sk16b { public: @@ -226,8 +219,6 @@ private: typedef Sk16b INHERITED; }; -} // namespace - #ifdef SKNX_NO_SIMD #include "../opts/Sk4px_none.h" #else diff --git a/src/core/SkNx.h b/src/core/SkNx.h index 84f9b69353..728e450ebb 100644 --- a/src/core/SkNx.h +++ b/src/core/SkNx.h @@ -17,13 +17,6 @@ #include #define REQUIRE(x) static_assert(x, #x) -// This file may be included multiple times by .cpp files with different flags, leading -// to different definitions. Usually that doesn't matter because it's all inlined, but -// in Debug modes the compilers may not inline everything. So wrap everything in an -// anonymous namespace to give each includer their own silo of this code (or the linker -// will probably pick one randomly for us, which is rarely correct). -namespace { - // The default implementations just fall back on a pair of size N/2. template @@ -252,8 +245,6 @@ protected: T fVal; }; -} // namespace - // Include platform specific specializations if available. #ifndef SKNX_NO_SIMD #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 diff --git a/src/core/SkOpts.cpp b/src/core/SkOpts.cpp index 2bfc1af899..986c7cf6a8 100644 --- a/src/core/SkOpts.cpp +++ b/src/core/SkOpts.cpp @@ -37,7 +37,7 @@ namespace SkOpts { decltype(rsqrt) rsqrt = portable::rsqrt; decltype(memset16) memset16 = portable::memset16; decltype(memset32) memset32 = portable::memset32; - decltype(create_xfermode) create_xfermode = SkCreate4pxXfermode; + decltype(create_xfermode) create_xfermode = portable::create_xfermode; decltype(box_blur_xx) box_blur_xx = portable::box_blur_xx; decltype(box_blur_xy) box_blur_xy = portable::box_blur_xy; diff --git a/src/core/SkPMFloat.h b/src/core/SkPMFloat.h index f97f25c9c6..7db689917e 100644 --- a/src/core/SkPMFloat.h +++ b/src/core/SkPMFloat.h @@ -13,13 +13,6 @@ #include "SkColorPriv.h" #include "SkNx.h" -// This file may be included multiple times by .cpp files with different flags, leading -// to different definitions. Usually that doesn't matter because it's all inlined, but -// in Debug modes the compilers may not inline everything. So wrap everything in an -// anonymous namespace to give each includer their own silo of this code (or the linker -// will probably pick one randomly for us, which is rarely correct). -namespace { - // A pre-multiplied color storing each component in the same order as SkPMColor, // but as a float in the range [0, 1]. class SkPMFloat : public Sk4f { @@ -59,8 +52,6 @@ private: typedef Sk4f INHERITED; }; -} // namespace - #ifdef SKNX_NO_SIMD // Platform implementations of SkPMFloat assume Sk4f uses SSE or NEON. _none is generic. #include "../opts/SkPMFloat_none.h" diff --git a/src/opts/Sk4px_NEON.h b/src/opts/Sk4px_NEON.h index 89841d927e..e88771d2a4 100644 --- a/src/opts/Sk4px_NEON.h +++ b/src/opts/Sk4px_NEON.h @@ -5,64 +5,64 @@ * found in the LICENSE file. */ -namespace { // See Sk4px.h - -inline Sk4px Sk4px::DupPMColor(SkPMColor px) { return Sk16b((uint8x16_t)vdupq_n_u32(px)); } +SK_ALWAYS_INLINE Sk4px Sk4px::DupPMColor(SkPMColor px) { + return Sk16b((uint8x16_t)vdupq_n_u32(px)); +} -inline Sk4px Sk4px::Load4(const SkPMColor px[4]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load4(const SkPMColor px[4]) { return Sk16b((uint8x16_t)vld1q_u32(px)); } -inline Sk4px Sk4px::Load2(const SkPMColor px[2]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load2(const SkPMColor px[2]) { uint32x2_t px2 = vld1_u32(px); return Sk16b((uint8x16_t)vcombine_u32(px2, px2)); } -inline Sk4px Sk4px::Load1(const SkPMColor px[1]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load1(const SkPMColor px[1]) { return Sk16b((uint8x16_t)vdupq_n_u32(*px)); } -inline void Sk4px::store4(SkPMColor px[4]) const { +SK_ALWAYS_INLINE void Sk4px::store4(SkPMColor px[4]) const { vst1q_u32(px, (uint32x4_t)this->fVec); } -inline void Sk4px::store2(SkPMColor px[2]) const { +SK_ALWAYS_INLINE void Sk4px::store2(SkPMColor px[2]) const { vst1_u32(px, (uint32x2_t)vget_low_u8(this->fVec)); } -inline void Sk4px::store1(SkPMColor px[1]) const { +SK_ALWAYS_INLINE void Sk4px::store1(SkPMColor px[1]) const { vst1q_lane_u32(px, (uint32x4_t)this->fVec, 0); } -inline Sk4px::Wide Sk4px::widenLo() const { +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenLo() const { return Sk16h(vmovl_u8(vget_low_u8 (this->fVec)), vmovl_u8(vget_high_u8(this->fVec))); } -inline Sk4px::Wide Sk4px::widenHi() const { +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenHi() const { return Sk16h(vshll_n_u8(vget_low_u8 (this->fVec), 8), vshll_n_u8(vget_high_u8(this->fVec), 8)); } -inline Sk4px::Wide Sk4px::widenLoHi() const { +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenLoHi() const { auto zipped = vzipq_u8(this->fVec, this->fVec); return Sk16h((uint16x8_t)zipped.val[0], (uint16x8_t)zipped.val[1]); } -inline Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { return Sk16h(vmull_u8(vget_low_u8 (this->fVec), vget_low_u8 (other.fVec)), vmull_u8(vget_high_u8(this->fVec), vget_high_u8(other.fVec))); } -inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { +SK_ALWAYS_INLINE Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { const Sk4px::Wide o(other); // Should be no code, but allows us to access fLo, fHi. return Sk16b(vcombine_u8(vaddhn_u16(this->fLo.fVec, o.fLo.fVec), vaddhn_u16(this->fHi.fVec, o.fHi.fVec))); } -inline Sk4px Sk4px::alphas() const { +SK_ALWAYS_INLINE Sk4px Sk4px::alphas() const { auto as = vshrq_n_u32((uint32x4_t)fVec, SK_A32_SHIFT); // ___3 ___2 ___1 ___0 return Sk16b((uint8x16_t)vmulq_n_u32(as, 0x01010101)); // 3333 2222 1111 0000 } -inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { uint8x16_t a8 = vdupq_n_u8(0); // ____ ____ ____ ____ a8 = vld1q_lane_u8(a+0, a8, 0); // ____ ____ ____ ___0 a8 = vld1q_lane_u8(a+1, a8, 4); // ____ ____ ___1 ___0 @@ -72,7 +72,7 @@ inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { return Sk16b((uint8x16_t)vmulq_n_u32(a32, 0x01010101)); // 3333 2222 1111 0000 } -inline Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { uint8x16_t a8 = vdupq_n_u8(0); // ____ ____ ____ ____ a8 = vld1q_lane_u8(a+0, a8, 0); // ____ ____ ____ ___0 a8 = vld1q_lane_u8(a+1, a8, 4); // ____ ____ ___1 ___0 @@ -80,16 +80,16 @@ inline Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { return Sk16b((uint8x16_t)vmulq_n_u32(a32, 0x01010101)); // ____ ____ 1111 0000 } -inline Sk4px Sk4px::zeroColors() const { +SK_ALWAYS_INLINE Sk4px Sk4px::zeroColors() const { return Sk16b(vandq_u8(this->fVec, (uint8x16_t)vdupq_n_u32(0xFF << SK_A32_SHIFT))); } -inline Sk4px Sk4px::zeroAlphas() const { +SK_ALWAYS_INLINE Sk4px Sk4px::zeroAlphas() const { // vbic(a,b) == a & ~b return Sk16b(vbicq_u8(this->fVec, (uint8x16_t)vdupq_n_u32(0xFF << SK_A32_SHIFT))); } -static inline uint8x16_t widen_to_8888(uint16x4_t v) { +static SK_ALWAYS_INLINE uint8x16_t widen_to_8888(uint16x4_t v) { // RGB565 format: |R....|G.....|B....| // Bit: 16 11 5 0 @@ -115,7 +115,7 @@ static inline uint8x16_t widen_to_8888(uint16x4_t v) { vdupq_n_u32(0xFF << SK_A32_SHIFT)))); } -static inline uint16x4_t narrow_to_565(uint8x16_t w8x16) { +static SK_ALWAYS_INLINE uint16x4_t narrow_to_565(uint8x16_t w8x16) { uint32x4_t w = (uint32x4_t)w8x16; // Extract out top RGB 565 bits of each pixel, with no rounding. @@ -136,29 +136,27 @@ static inline uint16x4_t narrow_to_565(uint8x16_t w8x16) { } -inline Sk4px Sk4px::Load4(const SkPMColor16 src[4]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load4(const SkPMColor16 src[4]) { return Sk16b(widen_to_8888(vld1_u16(src))); } -inline Sk4px Sk4px::Load2(const SkPMColor16 src[2]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load2(const SkPMColor16 src[2]) { auto src2 = ((uint32_t)src[0] ) | ((uint32_t)src[1] << 16); return Sk16b(widen_to_8888(vcreate_u16(src2))); } -inline Sk4px Sk4px::Load1(const SkPMColor16 src[1]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load1(const SkPMColor16 src[1]) { return Sk16b(widen_to_8888(vcreate_u16(src[0]))); } -inline void Sk4px::store4(SkPMColor16 dst[4]) const { +SK_ALWAYS_INLINE void Sk4px::store4(SkPMColor16 dst[4]) const { vst1_u16(dst, narrow_to_565(this->fVec)); } -inline void Sk4px::store2(SkPMColor16 dst[2]) const { +SK_ALWAYS_INLINE void Sk4px::store2(SkPMColor16 dst[2]) const { auto v = narrow_to_565(this->fVec); dst[0] = vget_lane_u16(v, 0); dst[1] = vget_lane_u16(v, 1); } -inline void Sk4px::store1(SkPMColor16 dst[1]) const { +SK_ALWAYS_INLINE void Sk4px::store1(SkPMColor16 dst[1]) const { dst[0] = vget_lane_u16(narrow_to_565(this->fVec), 0); } -} // namespace - diff --git a/src/opts/Sk4px_SSE2.h b/src/opts/Sk4px_SSE2.h index 5e97abf308..f235a1560e 100644 --- a/src/opts/Sk4px_SSE2.h +++ b/src/opts/Sk4px_SSE2.h @@ -5,42 +5,46 @@ * found in the LICENSE file. */ -namespace { // See Sk4px.h +SK_ALWAYS_INLINE Sk4px Sk4px::DupPMColor(SkPMColor px) { return Sk16b(_mm_set1_epi32(px)); } -inline Sk4px Sk4px::DupPMColor(SkPMColor px) { return Sk16b(_mm_set1_epi32(px)); } - -inline Sk4px Sk4px::Load4(const SkPMColor px[4]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load4(const SkPMColor px[4]) { return Sk16b(_mm_loadu_si128((const __m128i*)px)); } -inline Sk4px Sk4px::Load2(const SkPMColor px[2]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load2(const SkPMColor px[2]) { return Sk16b(_mm_loadl_epi64((const __m128i*)px)); } -inline Sk4px Sk4px::Load1(const SkPMColor px[1]) { return Sk16b(_mm_cvtsi32_si128(*px)); } +SK_ALWAYS_INLINE Sk4px Sk4px::Load1(const SkPMColor px[1]) { return Sk16b(_mm_cvtsi32_si128(*px)); } -inline void Sk4px::store4(SkPMColor px[4]) const { _mm_storeu_si128((__m128i*)px, this->fVec); } -inline void Sk4px::store2(SkPMColor px[2]) const { _mm_storel_epi64((__m128i*)px, this->fVec); } -inline void Sk4px::store1(SkPMColor px[1]) const { *px = _mm_cvtsi128_si32(this->fVec); } +SK_ALWAYS_INLINE void Sk4px::store4(SkPMColor px[4]) const { + _mm_storeu_si128((__m128i*)px, this->fVec); +} +SK_ALWAYS_INLINE void Sk4px::store2(SkPMColor px[2]) const { + _mm_storel_epi64((__m128i*)px, this->fVec); +} +SK_ALWAYS_INLINE void Sk4px::store1(SkPMColor px[1]) const { + *px = _mm_cvtsi128_si32(this->fVec); +} -inline Sk4px::Wide Sk4px::widenLo() const { +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenLo() const { return Sk16h(_mm_unpacklo_epi8(this->fVec, _mm_setzero_si128()), _mm_unpackhi_epi8(this->fVec, _mm_setzero_si128())); } -inline Sk4px::Wide Sk4px::widenHi() const { +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenHi() const { return Sk16h(_mm_unpacklo_epi8(_mm_setzero_si128(), this->fVec), _mm_unpackhi_epi8(_mm_setzero_si128(), this->fVec)); } -inline Sk4px::Wide Sk4px::widenLoHi() const { +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenLoHi() const { return Sk16h(_mm_unpacklo_epi8(this->fVec, this->fVec), _mm_unpackhi_epi8(this->fVec, this->fVec)); } -inline Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { return this->widenLo() * Sk4px(other).widenLo(); } -inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { +SK_ALWAYS_INLINE Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { Sk4px::Wide r = (*this + other) >> 8; return Sk4px(_mm_packus_epi16(r.fLo.fVec, r.fHi.fVec)); } @@ -49,19 +53,19 @@ inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { // These are safe on x86, often with no speed penalty. #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 - inline Sk4px Sk4px::alphas() const { + SK_ALWAYS_INLINE Sk4px Sk4px::alphas() const { static_assert(SK_A32_SHIFT == 24, "Intel's always little-endian."); __m128i splat = _mm_set_epi8(15,15,15,15, 11,11,11,11, 7,7,7,7, 3,3,3,3); return Sk16b(_mm_shuffle_epi8(this->fVec, splat)); } - inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { + SK_ALWAYS_INLINE Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { uint32_t as = *(const uint32_t*)a; __m128i splat = _mm_set_epi8(3,3,3,3, 2,2,2,2, 1,1,1,1, 0,0,0,0); return Sk16b(_mm_shuffle_epi8(_mm_cvtsi32_si128(as), splat)); } #else - inline Sk4px Sk4px::alphas() const { + SK_ALWAYS_INLINE Sk4px Sk4px::alphas() const { static_assert(SK_A32_SHIFT == 24, "Intel's always little-endian."); __m128i as = _mm_srli_epi32(this->fVec, 24); // ___3 ___2 ___1 ___0 as = _mm_or_si128(as, _mm_slli_si128(as, 1)); // __33 __22 __11 __00 @@ -69,7 +73,7 @@ inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { return Sk16b(as); } - inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { + SK_ALWAYS_INLINE Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { __m128i as = _mm_cvtsi32_si128(*(const uint32_t*)a); // ____ ____ ____ 3210 as = _mm_unpacklo_epi8 (as, _mm_setzero_si128()); // ____ ____ _3_2 _1_0 as = _mm_unpacklo_epi16(as, _mm_setzero_si128()); // ___3 ___2 ___1 ___0 @@ -79,21 +83,21 @@ inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { } #endif -inline Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { uint32_t as = *(const uint16_t*)a; // Aa -> Aa00 return Load4Alphas((const SkAlpha*)&as); } -inline Sk4px Sk4px::zeroColors() const { +SK_ALWAYS_INLINE Sk4px Sk4px::zeroColors() const { return Sk16b(_mm_and_si128(_mm_set1_epi32(0xFF << SK_A32_SHIFT), this->fVec)); } -inline Sk4px Sk4px::zeroAlphas() const { +SK_ALWAYS_INLINE Sk4px Sk4px::zeroAlphas() const { // andnot(a,b) == ~a & b return Sk16b(_mm_andnot_si128(_mm_set1_epi32(0xFF << SK_A32_SHIFT), this->fVec)); } -static inline __m128i widen_low_half_to_8888(__m128i v) { +static SK_ALWAYS_INLINE __m128i widen_low_half_to_8888(__m128i v) { // RGB565 format: |R....|G.....|B....| // Bit: 16 11 5 0 @@ -119,7 +123,7 @@ static inline __m128i widen_low_half_to_8888(__m128i v) { _mm_set1_epi32(0xFF << SK_A32_SHIFT)))); } -static inline __m128i narrow_to_565(__m128i w) { +static SK_ALWAYS_INLINE __m128i narrow_to_565(__m128i w) { // Extract out top RGB 565 bits of each pixel, with no rounding. auto r5 = _mm_and_si128(_mm_set1_epi32(31), _mm_srli_epi32(w, SK_R32_SHIFT + 3)), g6 = _mm_and_si128(_mm_set1_epi32(63), _mm_srli_epi32(w, SK_G32_SHIFT + 2)), @@ -143,29 +147,27 @@ static inline __m128i narrow_to_565(__m128i w) { return v; } -inline Sk4px Sk4px::Load4(const SkPMColor16 src[4]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load4(const SkPMColor16 src[4]) { return Sk16b(widen_low_half_to_8888(_mm_loadl_epi64((const __m128i*)src))); } -inline Sk4px Sk4px::Load2(const SkPMColor16 src[2]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load2(const SkPMColor16 src[2]) { auto src2 = ((uint32_t)src[0] ) | ((uint32_t)src[1] << 16); return Sk16b(widen_low_half_to_8888(_mm_cvtsi32_si128(src2))); } -inline Sk4px Sk4px::Load1(const SkPMColor16 src[1]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load1(const SkPMColor16 src[1]) { return Sk16b(widen_low_half_to_8888(_mm_insert_epi16(_mm_setzero_si128(), src[0], 0))); } -inline void Sk4px::store4(SkPMColor16 dst[4]) const { +SK_ALWAYS_INLINE void Sk4px::store4(SkPMColor16 dst[4]) const { _mm_storel_epi64((__m128i*)dst, narrow_to_565(this->fVec)); } -inline void Sk4px::store2(SkPMColor16 dst[2]) const { +SK_ALWAYS_INLINE void Sk4px::store2(SkPMColor16 dst[2]) const { uint32_t dst2 = _mm_cvtsi128_si32(narrow_to_565(this->fVec)); dst[0] = dst2; dst[1] = dst2 >> 16; } -inline void Sk4px::store1(SkPMColor16 dst[1]) const { +SK_ALWAYS_INLINE void Sk4px::store1(SkPMColor16 dst[1]) const { uint32_t dst2 = _mm_cvtsi128_si32(narrow_to_565(this->fVec)); dst[0] = dst2; } - -} // namespace diff --git a/src/opts/Sk4px_none.h b/src/opts/Sk4px_none.h index 540edb821d..d2231c9ba1 100644 --- a/src/opts/Sk4px_none.h +++ b/src/opts/Sk4px_none.h @@ -7,54 +7,52 @@ #include "SkUtils.h" -namespace { // See Sk4px.h - static_assert(sizeof(Sk4px) == 16, "This file uses memcpy / sk_memset32, so exact size matters."); -inline Sk4px Sk4px::DupPMColor(SkPMColor px) { +SK_ALWAYS_INLINE Sk4px Sk4px::DupPMColor(SkPMColor px) { Sk4px px4 = Sk16b(); sk_memset32((uint32_t*)&px4, px, 4); return px4; } -inline Sk4px Sk4px::Load4(const SkPMColor px[4]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load4(const SkPMColor px[4]) { Sk4px px4 = Sk16b(); memcpy(&px4, px, 16); return px4; } -inline Sk4px Sk4px::Load2(const SkPMColor px[2]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load2(const SkPMColor px[2]) { Sk4px px2 = Sk16b(); memcpy(&px2, px, 8); return px2; } -inline Sk4px Sk4px::Load1(const SkPMColor px[1]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load1(const SkPMColor px[1]) { Sk4px px1 = Sk16b(); memcpy(&px1, px, 4); return px1; } -inline void Sk4px::store4(SkPMColor px[4]) const { memcpy(px, this, 16); } -inline void Sk4px::store2(SkPMColor px[2]) const { memcpy(px, this, 8); } -inline void Sk4px::store1(SkPMColor px[1]) const { memcpy(px, this, 4); } +SK_ALWAYS_INLINE void Sk4px::store4(SkPMColor px[4]) const { memcpy(px, this, 16); } +SK_ALWAYS_INLINE void Sk4px::store2(SkPMColor px[2]) const { memcpy(px, this, 8); } +SK_ALWAYS_INLINE void Sk4px::store1(SkPMColor px[1]) const { memcpy(px, this, 4); } -inline Sk4px::Wide Sk4px::widenLo() const { +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenLo() const { return Sk16h(this->kth< 0>(), this->kth< 1>(), this->kth< 2>(), this->kth< 3>(), this->kth< 4>(), this->kth< 5>(), this->kth< 6>(), this->kth< 7>(), this->kth< 8>(), this->kth< 9>(), this->kth<10>(), this->kth<11>(), this->kth<12>(), this->kth<13>(), this->kth<14>(), this->kth<15>()); } -inline Sk4px::Wide Sk4px::widenHi() const { return this->widenLo() << 8; } +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenHi() const { return this->widenLo() << 8; } -inline Sk4px::Wide Sk4px::widenLoHi() const { return this->widenLo() + this->widenHi(); } +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::widenLoHi() const { return this->widenLo() + this->widenHi(); } -inline Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { +SK_ALWAYS_INLINE Sk4px::Wide Sk4px::mulWiden(const Sk16b& other) const { return this->widenLo() * Sk4px(other).widenLo(); } -inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { +SK_ALWAYS_INLINE Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { Sk4px::Wide r = (*this + other) >> 8; return Sk16b(r.kth< 0>(), r.kth< 1>(), r.kth< 2>(), r.kth< 3>(), r.kth< 4>(), r.kth< 5>(), r.kth< 6>(), r.kth< 7>(), @@ -62,7 +60,7 @@ inline Sk4px Sk4px::Wide::addNarrowHi(const Sk16h& other) const { r.kth<12>(), r.kth<13>(), r.kth<14>(), r.kth<15>()); } -inline Sk4px Sk4px::alphas() const { +SK_ALWAYS_INLINE Sk4px Sk4px::alphas() const { static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); return Sk16b(this->kth< 3>(), this->kth< 3>(), this->kth< 3>(), this->kth< 3>(), this->kth< 7>(), this->kth< 7>(), this->kth< 7>(), this->kth< 7>(), @@ -70,21 +68,21 @@ inline Sk4px Sk4px::alphas() const { this->kth<15>(), this->kth<15>(), this->kth<15>(), this->kth<15>()); } -inline Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load4Alphas(const SkAlpha a[4]) { return Sk16b(a[0], a[0], a[0], a[0], a[1], a[1], a[1], a[1], a[2], a[2], a[2], a[2], a[3], a[3], a[3], a[3]); } -inline Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load2Alphas(const SkAlpha a[2]) { return Sk16b(a[0], a[0], a[0], a[0], a[1], a[1], a[1], a[1], 0,0,0,0, 0,0,0,0); } -inline Sk4px Sk4px::zeroAlphas() const { +SK_ALWAYS_INLINE Sk4px Sk4px::zeroAlphas() const { static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); return Sk16b(this->kth< 0>(), this->kth< 1>(), this->kth< 2>(), 0, this->kth< 4>(), this->kth< 5>(), this->kth< 6>(), 0, @@ -92,7 +90,7 @@ inline Sk4px Sk4px::zeroAlphas() const { this->kth<12>(), this->kth<13>(), this->kth<14>(), 0); } -inline Sk4px Sk4px::zeroColors() const { +SK_ALWAYS_INLINE Sk4px Sk4px::zeroColors() const { static_assert(SK_A32_SHIFT == 24, "This method assumes little-endian."); return Sk16b(0,0,0, this->kth< 3>(), 0,0,0, this->kth< 7>(), @@ -100,35 +98,33 @@ inline Sk4px Sk4px::zeroColors() const { 0,0,0, this->kth<15>()); } -inline Sk4px Sk4px::Load4(const SkPMColor16 src[4]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load4(const SkPMColor16 src[4]) { SkPMColor src32[4]; for (int i = 0; i < 4; i++) { src32[i] = SkPixel16ToPixel32(src[i]); } return Load4(src32); } -inline Sk4px Sk4px::Load2(const SkPMColor16 src[2]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load2(const SkPMColor16 src[2]) { SkPMColor src32[2]; for (int i = 0; i < 2; i++) { src32[i] = SkPixel16ToPixel32(src[i]); } return Load2(src32); } -inline Sk4px Sk4px::Load1(const SkPMColor16 src[1]) { +SK_ALWAYS_INLINE Sk4px Sk4px::Load1(const SkPMColor16 src[1]) { SkPMColor src32 = SkPixel16ToPixel32(src[0]); return Load1(&src32); } -inline void Sk4px::store4(SkPMColor16 dst[4]) const { +SK_ALWAYS_INLINE void Sk4px::store4(SkPMColor16 dst[4]) const { SkPMColor dst32[4]; this->store4(dst32); for (int i = 0; i < 4; i++) { dst[i] = SkPixel32ToPixel16(dst32[i]); } } -inline void Sk4px::store2(SkPMColor16 dst[2]) const { +SK_ALWAYS_INLINE void Sk4px::store2(SkPMColor16 dst[2]) const { SkPMColor dst32[2]; this->store2(dst32); for (int i = 0; i < 2; i++) { dst[i] = SkPixel32ToPixel16(dst32[i]); } } -inline void Sk4px::store1(SkPMColor16 dst[1]) const { +SK_ALWAYS_INLINE void Sk4px::store1(SkPMColor16 dst[1]) const { SkPMColor dst32; this->store1(&dst32); dst[0] = SkPixel32ToPixel16(dst32); } - -} // namespace diff --git a/src/opts/SkNx_neon.h b/src/opts/SkNx_neon.h index 660b92c6b0..e9e7bf5230 100644 --- a/src/opts/SkNx_neon.h +++ b/src/opts/SkNx_neon.h @@ -8,8 +8,6 @@ #ifndef SkNx_neon_DEFINED #define SkNx_neon_DEFINED -namespace { // See SkNx.h - // Well, this is absurd. The shifts require compile-time constant arguments. #define SHIFT8(op, v, bits) switch(bits) { \ @@ -383,6 +381,4 @@ public: #undef SHIFT16 #undef SHIFT8 -} // namespace - #endif//SkNx_neon_DEFINED diff --git a/src/opts/SkNx_sse.h b/src/opts/SkNx_sse.h index e165f58737..75b35845a8 100644 --- a/src/opts/SkNx_sse.h +++ b/src/opts/SkNx_sse.h @@ -10,9 +10,6 @@ // This file may assume <= SSE2, but must check SK_CPU_SSE_LEVEL for anything more recent. -namespace { // See SkNx.h - - template <> class SkNf<2, float> { public: @@ -313,6 +310,4 @@ public: __m128i fVec; }; -} // namespace - #endif//SkNx_sse_DEFINED diff --git a/src/opts/SkOpts_neon.cpp b/src/opts/SkOpts_neon.cpp index 789a977238..a6d3f00d20 100644 --- a/src/opts/SkOpts_neon.cpp +++ b/src/opts/SkOpts_neon.cpp @@ -21,7 +21,7 @@ namespace SkOpts { rsqrt = neon::rsqrt; memset16 = neon::memset16; memset32 = neon::memset32; - create_xfermode = SkCreate4pxXfermode; + create_xfermode = neon::create_xfermode; box_blur_xx = neon::box_blur_xx; box_blur_xy = neon::box_blur_xy; diff --git a/src/opts/SkOpts_sse2.cpp b/src/opts/SkOpts_sse2.cpp index 3440676935..b2f0262263 100644 --- a/src/opts/SkOpts_sse2.cpp +++ b/src/opts/SkOpts_sse2.cpp @@ -18,7 +18,7 @@ namespace SkOpts { void Init_sse2() { memset16 = sse2::memset16; memset32 = sse2::memset32; - create_xfermode = SkCreate4pxXfermode; + create_xfermode = sse2::create_xfermode; box_blur_xx = sse2::box_blur_xx; box_blur_xy = sse2::box_blur_xy; diff --git a/src/opts/SkPMFloat_neon.h b/src/opts/SkPMFloat_neon.h index 8bee5b551a..edbbc58b5a 100644 --- a/src/opts/SkPMFloat_neon.h +++ b/src/opts/SkPMFloat_neon.h @@ -5,9 +5,7 @@ * found in the LICENSE file. */ -namespace { // See SkPMFloat.h - -inline SkPMFloat::SkPMFloat(SkPMColor c) { +SK_ALWAYS_INLINE SkPMFloat::SkPMFloat(SkPMColor c) { SkPMColorAssert(c); uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); uint16x8_t fix8_16 = vmovl_u8(fix8); @@ -16,7 +14,7 @@ inline SkPMFloat::SkPMFloat(SkPMColor c) { SkASSERT(this->isValid()); } -inline SkPMColor SkPMFloat::round() const { +SK_ALWAYS_INLINE SkPMColor SkPMFloat::round() const { // vcvt_u32_f32 truncates, so we round manually by adding a half before converting. float32x4_t rounded = vmlaq_f32(vdupq_n_f32(0.5f), fVec, vdupq_n_f32(255)); uint32x4_t fix8_32 = vcvtq_u32_f32(rounded); @@ -27,9 +25,7 @@ inline SkPMColor SkPMFloat::round() const { return c; } -inline Sk4f SkPMFloat::alphas() const { +SK_ALWAYS_INLINE Sk4f SkPMFloat::alphas() const { static_assert(SK_A32_SHIFT == 24, "Assuming little-endian."); return vdupq_lane_f32(vget_high_f32(fVec), 1); // Duplicate high lane of high half i.e. lane 3. } - -} // namespace diff --git a/src/opts/SkPMFloat_none.h b/src/opts/SkPMFloat_none.h index 518ad159ff..ca98b1ab7e 100644 --- a/src/opts/SkPMFloat_none.h +++ b/src/opts/SkPMFloat_none.h @@ -5,9 +5,7 @@ * found in the LICENSE file. */ -namespace { // See SkPMFloat.h - -inline SkPMFloat::SkPMFloat(SkPMColor c) { +SK_ALWAYS_INLINE SkPMFloat::SkPMFloat(SkPMColor c) { float inv255 = 1.0f/255; *this = SkPMFloat::FromARGB(SkGetPackedA32(c) * inv255, SkGetPackedR32(c) * inv255, @@ -16,7 +14,7 @@ inline SkPMFloat::SkPMFloat(SkPMColor c) { SkASSERT(this->isValid()); } -inline SkPMColor SkPMFloat::round() const { +SK_ALWAYS_INLINE SkPMColor SkPMFloat::round() const { float a = this->a(), r = this->r(), g = this->g(), @@ -30,8 +28,6 @@ inline SkPMColor SkPMFloat::round() const { return c; } -inline Sk4f SkPMFloat::alphas() const { +SK_ALWAYS_INLINE Sk4f SkPMFloat::alphas() const { return Sk4f(this->a()); } - -} // namespace diff --git a/src/opts/SkPMFloat_sse.h b/src/opts/SkPMFloat_sse.h index 28aa90bf29..016644e052 100644 --- a/src/opts/SkPMFloat_sse.h +++ b/src/opts/SkPMFloat_sse.h @@ -5,9 +5,7 @@ * found in the LICENSE file. */ -namespace { // See SkPMFloat.h - -inline SkPMFloat::SkPMFloat(SkPMColor c) { +SK_ALWAYS_INLINE SkPMFloat::SkPMFloat(SkPMColor c) { SkPMColorAssert(c); #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 const int _ = 255; // Zero these bytes. @@ -22,7 +20,7 @@ inline SkPMFloat::SkPMFloat(SkPMColor c) { SkASSERT(this->isValid()); } -inline SkPMColor SkPMFloat::round() const { +SK_ALWAYS_INLINE SkPMColor SkPMFloat::round() const { // We don't use _mm_cvtps_epi32, because we want precise control over how 0.5 rounds (up). __m128 scaled = _mm_mul_ps(_mm_set1_ps(255), fVec); __m128i fix8_32 = _mm_cvttps_epi32(_mm_add_ps(_mm_set1_ps(0.5f), scaled)), @@ -33,9 +31,7 @@ inline SkPMColor SkPMFloat::round() const { return c; } -inline Sk4f SkPMFloat::alphas() const { +SK_ALWAYS_INLINE Sk4f SkPMFloat::alphas() const { static_assert(SK_A32_SHIFT == 24, ""); return _mm_shuffle_ps(fVec, fVec, 0xff); // Read as 11 11 11 11, copying lane 3 to all lanes. } - -} // namespace diff --git a/src/opts/SkXfermode_opts.h b/src/opts/SkXfermode_opts.h index e5ca257a28..5394e636e7 100644 --- a/src/opts/SkXfermode_opts.h +++ b/src/opts/SkXfermode_opts.h @@ -12,7 +12,7 @@ #include "SkPMFloat.h" #include "SkXfermode_proccoeff.h" -namespace /* TODO: SK_OPTS_NS */ { +namespace SK_OPTS_NS { // Most xfermodes can be done most efficiently 4 pixels at a time in 8 or 16-bit fixed point. #define XFERMODE(Name) static Sk4px SK_VECTORCALL Name(Sk4px s, Sk4px d) @@ -274,7 +274,7 @@ private: typedef SkProcCoeffXfermode INHERITED; }; -static SkXfermode* SkCreate4pxXfermode(const ProcCoeff& rec, SkXfermode::Mode mode) { +static SkXfermode* create_xfermode(const ProcCoeff& rec, SkXfermode::Mode mode) { switch (mode) { #define CASE(Mode) case SkXfermode::k##Mode##_Mode: \ return SkNEW_ARGS(Sk4pxXfermode, (rec, mode, &Mode, &xfer_aa)) -- cgit v1.2.3