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

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: 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 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
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);
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
62 #undef SK_SMALL_MEMSET
63
33 /** Similar to memcpy(), but it copies count 32bit values from src to dst. 64 /** Similar to memcpy(), but it copies count 32bit values from src to dst.
34 @param dst The memory to have value copied into it 65 @param dst The memory to have value copied into it
35 @param src The memory to have value copied from it 66 @param src The memory to have value copied from it
36 @param count The number of values should be copied. 67 @param count The number of values should be copied.
37 */ 68 */
38 void sk_memcpy32(uint32_t dst[], const uint32_t src[], int count); 69 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); 70 typedef void (*SkMemcpy32Proc)(uint32_t dst[], const uint32_t src[], int count);
40 SkMemcpy32Proc SkMemcpy32GetPlatformProc(); 71 SkMemcpy32Proc SkMemcpy32GetPlatformProc();
41 72
42 /////////////////////////////////////////////////////////////////////////////// 73 ///////////////////////////////////////////////////////////////////////////////
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 140 }
110 ~SkAutoTrace() { 141 ~SkAutoTrace() {
111 SkDebugf("--- trace: %s Leave\n", fLabel); 142 SkDebugf("--- trace: %s Leave\n", fLabel);
112 } 143 }
113 private: 144 private:
114 const char* fLabel; 145 const char* fLabel;
115 }; 146 };
116 #define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace) 147 #define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace)
117 148
118 #endif 149 #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