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

Unified Diff: include/core/SkUtils.h

Issue 1073863002: Rewrite memset benches, then use results to add a small-N optimization. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: undef Created 5 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bench/MemsetBench.cpp ('k') | src/core/SkUtils.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkUtils.h
diff --git a/include/core/SkUtils.h b/include/core/SkUtils.h
index d522ae0dea139555f6e8790ac06d8287e5771fd7..3c24b1f5992ceff769473b8b0aedef72b44407c5 100644
--- a/include/core/SkUtils.h
+++ b/include/core/SkUtils.h
@@ -12,12 +12,31 @@
///////////////////////////////////////////////////////////////////////////////
+// Determined empirically using bench/MemsetBench.cpp on a Nexus 7, Nexus 9, and desktop.
+#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 || defined(SK_ARM_HAS_NEON)
+ // Platforms where we can assume an autovectorizer will give us a good inline memset.
+ #define SK_SMALL_MEMSET 1000
+#else
+ // Platforms like Chrome on ARMv7 that don't typically compile with NEON globally.
+ #define SK_SMALL_MEMSET 10
+#endif
+
+
/** Similar to memset(), but it assigns a 16bit value into the buffer.
@param buffer The memory to have value copied into it
@param value The 16bit value to be copied into buffer
@param count The number of times value should be copied into the buffer.
*/
-void sk_memset16(uint16_t dst[], uint16_t value, int count);
+void sk_memset16_large(uint16_t dst[], uint16_t value, int count);
+inline void sk_memset16(uint16_t dst[], uint16_t value, int count) {
+ if (count <= SK_SMALL_MEMSET) {
+ for (int i = 0; i < count; i++) {
+ dst[i] = value;
+ }
+ } else {
+ sk_memset16_large(dst, value, count);
+ }
+}
typedef void (*SkMemset16Proc)(uint16_t dst[], uint16_t value, int count);
SkMemset16Proc SkMemset16GetPlatformProc();
@@ -26,10 +45,22 @@ SkMemset16Proc SkMemset16GetPlatformProc();
@param value The 32bit value to be copied into buffer
@param count The number of times value should be copied into the buffer.
*/
-void sk_memset32(uint32_t dst[], uint32_t value, int count);
+void sk_memset32_large(uint32_t dst[], uint32_t value, int count);
+inline void sk_memset32(uint32_t dst[], uint32_t value, int count) {
+ if (count <= SK_SMALL_MEMSET) {
+ for (int i = 0; i < count; i++) {
+ dst[i] = value;
+ }
+ } else {
+ sk_memset32_large(dst, value, count);
+ }
+}
+
typedef void (*SkMemset32Proc)(uint32_t dst[], uint32_t value, int count);
SkMemset32Proc SkMemset32GetPlatformProc();
+#undef SK_SMALL_MEMSET
+
/** Similar to memcpy(), but it copies count 32bit values from src to dst.
@param dst The memory to have value copied into it
@param src The memory to have value copied from it
« no previous file with comments | « bench/MemsetBench.cpp ('k') | src/core/SkUtils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698