From 87db00111596d432908882a13982adde79793a7c Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Tue, 23 May 2017 12:20:38 -0400 Subject: [PATCH] move sk_memset?? to SkOpts This lets the compiler generate AVX versions with wider writes. Change-Id: Ia63825e70c72bdb4d14bef97d8b4ea4be54c9d84 Reviewed-on: https://skia-review.googlesource.com/17715 Reviewed-by: Florin Malita Commit-Queue: Mike Klein --- src/core/SkOpts.cpp | 5 +++++ src/core/SkOpts.h | 4 ++++ src/core/SkUtils.cpp | 16 ---------------- src/core/SkUtils.h | 13 ++++++++++--- src/opts/SkOpts_avx.cpp | 11 ++++++++--- src/opts/SkUtils_opts.h | 31 +++++++++++++++++++++++++++++++ 6 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 src/opts/SkUtils_opts.h diff --git a/src/core/SkOpts.cpp b/src/core/SkOpts.cpp index 4666e73..33c3690 100644 --- a/src/core/SkOpts.cpp +++ b/src/core/SkOpts.cpp @@ -44,6 +44,7 @@ #include "SkChecksum_opts.h" #include "SkMorphologyImageFilter_opts.h" #include "SkSwizzler_opts.h" +#include "SkUtils_opts.h" #include "SkXfermode_opts.h" namespace SkOpts { @@ -81,6 +82,10 @@ namespace SkOpts { DEFINE_DEFAULT(srcover_srgb_srgb); + DEFINE_DEFAULT(memset16); + DEFINE_DEFAULT(memset32); + DEFINE_DEFAULT(memset64); + DEFINE_DEFAULT(hash_fn); DEFINE_DEFAULT(convolve_vertically); diff --git a/src/core/SkOpts.h b/src/core/SkOpts.h index bf9a963..31153f9 100644 --- a/src/core/SkOpts.h +++ b/src/core/SkOpts.h @@ -53,6 +53,10 @@ namespace SkOpts { // If nsrc < ndst, we loop over src to create a pattern. extern void (*srcover_srgb_srgb)(uint32_t* dst, const uint32_t* src, int ndst, int nsrc); + extern void (*memset16)(uint16_t[], uint16_t, int); + extern void (*memset32)(uint32_t[], uint32_t, int); + extern void (*memset64)(uint64_t[], uint64_t, int); + // The fastest high quality 32-bit hash we can provide on this platform. extern uint32_t (*hash_fn)(const void*, size_t, uint32_t seed); static inline uint32_t hash(const void* data, size_t bytes, uint32_t seed=0) { diff --git a/src/core/SkUtils.cpp b/src/core/SkUtils.cpp index 311394d..85ebb3e 100644 --- a/src/core/SkUtils.cpp +++ b/src/core/SkUtils.cpp @@ -8,22 +8,6 @@ #include "SkUtils.h" -void sk_memset16(uint16_t buffer[], uint16_t value, int count) { - for (int i = 0; i < count; i++) { - buffer[i] = value; - } -} -void sk_memset32(uint32_t buffer[], uint32_t value, int count) { - for (int i = 0; i < count; i++) { - buffer[i] = value; - } -} -void sk_memset64(uint64_t buffer[], uint64_t value, int count) { - for (int i = 0; i < count; i++) { - buffer[i] = value; - } -} - /* 0xxxxxxx 1 total 10xxxxxx // never a leading byte 110xxxxx 2 total diff --git a/src/core/SkUtils.h b/src/core/SkUtils.h index 241a61a..2ae6f87 100644 --- a/src/core/SkUtils.h +++ b/src/core/SkUtils.h @@ -10,15 +10,22 @@ #include "SkTypes.h" #include "SkMath.h" +#include "SkOpts.h" /** Similar to memset(), but it assigns a 16, 32, or 64-bit value into the buffer. @param buffer The memory to have value copied into it @param value The value to be copied into buffer @param count The number of times value should be copied into the buffer. */ -void sk_memset16(uint16_t buffer[], uint16_t value, int count); -void sk_memset32(uint32_t buffer[], uint32_t value, int count); -void sk_memset64(uint64_t buffer[], uint64_t value, int count); +static inline void sk_memset16(uint16_t buffer[], uint16_t value, int count) { + SkOpts::memset16(buffer, value, count); +} +static inline void sk_memset32(uint32_t buffer[], uint32_t value, int count) { + SkOpts::memset32(buffer, value, count); +} +static inline void sk_memset64(uint64_t buffer[], uint64_t value, int count) { + SkOpts::memset64(buffer, value, count); +} /////////////////////////////////////////////////////////////////////////////// #define kMaxBytesInUTF8Sequence 4 diff --git a/src/opts/SkOpts_avx.cpp b/src/opts/SkOpts_avx.cpp index 06e46d9..7e34330 100644 --- a/src/opts/SkOpts_avx.cpp +++ b/src/opts/SkOpts_avx.cpp @@ -8,12 +8,17 @@ #include "SkSafe_math.h" // Keep this first. #include "SkOpts.h" -#define SK_OPTS_NS avx - #if defined(_INC_MATH) && !defined(INC_MATH_IS_SAFE_NOW) #error We have included ucrt\math.h without protecting it against ODR violation. #endif +#define SK_OPTS_NS avx +#include "SkUtils_opts.h" + namespace SkOpts { - void Init_avx() { } + void Init_avx() { + memset16 = SK_OPTS_NS::memset16; + memset32 = SK_OPTS_NS::memset32; + memset64 = SK_OPTS_NS::memset64; + } } diff --git a/src/opts/SkUtils_opts.h b/src/opts/SkUtils_opts.h new file mode 100644 index 0000000..c9390af --- /dev/null +++ b/src/opts/SkUtils_opts.h @@ -0,0 +1,31 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkUtils_opts_DEFINED +#define SkUtils_opts_DEFINED + +namespace SK_OPTS_NS { + + static void memset16(uint16_t buffer[], uint16_t value, int count) { + for (int i = 0; i < count; i++) { + buffer[i] = value; + } + } + static void memset32(uint32_t buffer[], uint32_t value, int count) { + for (int i = 0; i < count; i++) { + buffer[i] = value; + } + } + static void memset64(uint64_t buffer[], uint64_t value, int count) { + for (int i = 0; i < count; i++) { + buffer[i] = value; + } + } + +} + +#endif//SkUtils_opts_DEFINED -- 2.7.4