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

Side by Side 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: generalize 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 unified diff | Download patch
« no previous file with comments | « bench/MemsetBench.cpp ('k') | src/core/SkUtils.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkUtils_DEFINED 8 #ifndef SkUtils_DEFINED
9 #define SkUtils_DEFINED 9 #define SkUtils_DEFINED
10 10
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 12
13 /////////////////////////////////////////////////////////////////////////////// 13 ///////////////////////////////////////////////////////////////////////////////
14 14
15 // Determined empirically using bench/MemsetBench.cpp on a Nexus 7, Nexus 9, and desktop.
16 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 || defined(SK_ARM_HAS_NEON)
17 // Platforms where we can assume an autovectorizer will give us a good inlin e memset.
18 #define SK_SMALL_MEMSET 1000
reed1 2015/04/09 20:30:24 I know I suggested this be a #define. Since this i
mtklein 2015/04/09 20:36:42 Hmm. Actually, I can just undef it when we're don
19 #else
20 // Platforms like Chrome on ARMv7 that don't typically compile with NEON glo bally.
21 #define SK_SMALL_MEMSET 10
22 #endif
23
24
15 /** Similar to memset(), but it assigns a 16bit value into the buffer. 25 /** Similar to memset(), but it assigns a 16bit value into the buffer.
16 @param buffer The memory to have value copied into it 26 @param buffer The memory to have value copied into it
17 @param value The 16bit value to be copied into buffer 27 @param value The 16bit value to be copied into buffer
18 @param count The number of times value should be copied into the buffer. 28 @param count The number of times value should be copied into the buffer.
19 */ 29 */
20 void sk_memset16(uint16_t dst[], uint16_t value, int count); 30 void sk_memset16_large(uint16_t dst[], uint16_t value, int count);
reed1 2015/04/09 20:30:24 These two "large" functions. I know they have to b
mtklein 2015/04/09 20:36:42 Moving this code around sounds good to me. I hadn
31 inline void sk_memset16(uint16_t dst[], uint16_t value, int count) {
32 if (count <= SK_SMALL_MEMSET) {
33 for (int i = 0; i < count; i++) {
34 dst[i] = value;
35 }
36 } else {
37 sk_memset16_large(dst, value, count);
38 }
39 }
21 typedef void (*SkMemset16Proc)(uint16_t dst[], uint16_t value, int count); 40 typedef void (*SkMemset16Proc)(uint16_t dst[], uint16_t value, int count);
22 SkMemset16Proc SkMemset16GetPlatformProc(); 41 SkMemset16Proc SkMemset16GetPlatformProc();
23 42
24 /** Similar to memset(), but it assigns a 32bit value into the buffer. 43 /** Similar to memset(), but it assigns a 32bit value into the buffer.
25 @param buffer The memory to have value copied into it 44 @param buffer The memory to have value copied into it
26 @param value The 32bit value to be copied into buffer 45 @param value The 32bit value to be copied into buffer
27 @param count The number of times value should be copied into the buffer. 46 @param count The number of times value should be copied into the buffer.
28 */ 47 */
29 void sk_memset32(uint32_t dst[], uint32_t value, int count); 48 void sk_memset32_large(uint32_t dst[], uint32_t value, int count);
49 inline void sk_memset32(uint32_t dst[], uint32_t value, int count) {
50 if (count <= SK_SMALL_MEMSET) {
51 for (int i = 0; i < count; i++) {
52 dst[i] = value;
53 }
54 } else {
55 sk_memset32_large(dst, value, count);
56 }
57 }
58
30 typedef void (*SkMemset32Proc)(uint32_t dst[], uint32_t value, int count); 59 typedef void (*SkMemset32Proc)(uint32_t dst[], uint32_t value, int count);
31 SkMemset32Proc SkMemset32GetPlatformProc(); 60 SkMemset32Proc SkMemset32GetPlatformProc();
32 61
33 /** Similar to memcpy(), but it copies count 32bit values from src to dst. 62 /** Similar to memcpy(), but it copies count 32bit values from src to dst.
34 @param dst The memory to have value copied into it 63 @param dst The memory to have value copied into it
35 @param src The memory to have value copied from it 64 @param src The memory to have value copied from it
36 @param count The number of values should be copied. 65 @param count The number of values should be copied.
37 */ 66 */
38 void sk_memcpy32(uint32_t dst[], const uint32_t src[], int count); 67 void sk_memcpy32(uint32_t dst[], const uint32_t src[], int count);
39 typedef void (*SkMemcpy32Proc)(uint32_t dst[], const uint32_t src[], int count); 68 typedef void (*SkMemcpy32Proc)(uint32_t dst[], const uint32_t src[], int count);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 138 }
110 ~SkAutoTrace() { 139 ~SkAutoTrace() {
111 SkDebugf("--- trace: %s Leave\n", fLabel); 140 SkDebugf("--- trace: %s Leave\n", fLabel);
112 } 141 }
113 private: 142 private:
114 const char* fLabel; 143 const char* fLabel;
115 }; 144 };
116 #define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace) 145 #define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace)
117 146
118 #endif 147 #endif
OLDNEW
« 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