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

Side by Side Diff: include/core/SkUtils.h

Issue 1639863002: try plain-old code for sk_memset16/32 now that NEON is compile-time (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: for Created 4 years, 10 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 | « no previous file | src/core/SkOpts.h » ('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 namespace SkOpts {
14 extern void (*memset16)(uint16_t[], uint16_t, int);
15 extern void (*memset32)(uint32_t[], uint32_t, int);
16 }
17
18 ///////////////////////////////////////////////////////////////////////////////
19
20 // Inlining heuristics were determined by using perf.skia.org and bench/MemsetBe nch.cpp.
21 // When using MSVC, inline is better >= 1K and worse <= 100. The Nexus Player w as the opposite.
22 // Otherwise, when NEON or SSE is available to GCC or Clang, they can handle it best.
23 // See https://code.google.com/p/chromium/issues/detail?id=516426#c15 for more d etails.
24 // See also skia:4316; it might be a good idea to use rep stosw/stosd here.
25 #define INLINE_IF(cond) if (cond) { while (count --> 0) { *buffer++ = value; } r eturn; }
26
27 /** Similar to memset(), but it assigns a 16bit value into the buffer. 13 /** Similar to memset(), but it assigns a 16bit value into the buffer.
28 @param buffer The memory to have value copied into it 14 @param buffer The memory to have value copied into it
29 @param value The 16bit value to be copied into buffer 15 @param value The 16bit value to be copied into buffer
30 @param count The number of times value should be copied into the buffer. 16 @param count The number of times value should be copied into the buffer.
31 */ 17 */
32 static inline void sk_memset16(uint16_t buffer[], uint16_t value, int count) { 18 static inline void sk_memset16(uint16_t buffer[], uint16_t value, int count) {
33 #if defined(_MSC_VER) 19 for (int i = 0; i < count; i++) {
34 INLINE_IF(count > 300) 20 buffer[i] = value;
35 #elif defined(SK_BUILD_FOR_ANDROID) && defined(SK_CPU_X86) 21 }
36 INLINE_IF(count < 300)
37 #elif defined(SK_ARM_HAS_NEON) || SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
38 INLINE_IF(true)
39 #else
40 INLINE_IF(count <= 10)
41 #endif
42 SkOpts::memset16(buffer, value, count);
43 } 22 }
44 23
45 /** Similar to memset(), but it assigns a 32bit value into the buffer. 24 /** Similar to memset(), but it assigns a 32bit value into the buffer.
46 @param buffer The memory to have value copied into it 25 @param buffer The memory to have value copied into it
47 @param value The 32bit value to be copied into buffer 26 @param value The 32bit value to be copied into buffer
48 @param count The number of times value should be copied into the buffer. 27 @param count The number of times value should be copied into the buffer.
49 */ 28 */
50 static inline void sk_memset32(uint32_t buffer[], uint32_t value, int count) { 29 static inline void sk_memset32(uint32_t buffer[], uint32_t value, int count) {
51 #if defined(_MSC_VER) 30 for (int i = 0; i < count; i++) {
52 INLINE_IF(count > 300) 31 buffer[i] = value;
53 #elif defined(SK_BUILD_FOR_ANDROID) && defined(SK_CPU_X86) 32 }
54 INLINE_IF(count < 300)
55 #elif defined(SK_ARM_HAS_NEON) || SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
56 INLINE_IF(true)
57 #else
58 INLINE_IF(count <= 10)
59 #endif
60 SkOpts::memset32(buffer, value, count);
61 } 33 }
62 34
63 #undef INLINE_IF
64
65 /////////////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////////////
66 36
67 #define kMaxBytesInUTF8Sequence 4 37 #define kMaxBytesInUTF8Sequence 4
68 38
69 #ifdef SK_DEBUG 39 #ifdef SK_DEBUG
70 int SkUTF8_LeadByteToCount(unsigned c); 40 int SkUTF8_LeadByteToCount(unsigned c);
71 #else 41 #else
72 #define SkUTF8_LeadByteToCount(c) ((((0xE5 << 24) >> ((unsigned)c >> 4 << 1)) & 3) + 1) 42 #define SkUTF8_LeadByteToCount(c) ((((0xE5 << 24) >> ((unsigned)c >> 4 << 1)) & 3) + 1)
73 #endif 43 #endif
74 44
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 102 }
133 ~SkAutoTrace() { 103 ~SkAutoTrace() {
134 SkDebugf("--- trace: %s Leave\n", fLabel); 104 SkDebugf("--- trace: %s Leave\n", fLabel);
135 } 105 }
136 private: 106 private:
137 const char* fLabel; 107 const char* fLabel;
138 }; 108 };
139 #define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace) 109 #define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace)
140 110
141 #endif 111 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkOpts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698