OLD | NEW |
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 { | 13 namespace SkOpts { |
14 extern void (*memset16)(uint16_t[], uint16_t, int); | 14 extern void (*memset16)(uint16_t[], uint16_t, int); |
15 extern void (*memset32)(uint32_t[], uint32_t, int); | 15 extern void (*memset32)(uint32_t[], uint32_t, int); |
16 } | 16 } |
17 | 17 |
18 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
19 | 19 |
20 // Inlining heuristics were determined by using perf.skia.org and bench/MemsetBe
nch.cpp. | 20 // The inlining heuristics below were determined using bench/MemsetBench.cpp |
21 // When using MSVC, inline is better >= 1K and worse <= 100. The Nexus Player w
as the opposite. | 21 // on a x86 desktop, a Nexus 7 with and without NEON, and a Nexus 9: |
22 // Otherwise, when NEON or SSE is available to GCC or Clang, they can handle it
best. | 22 // - on x86, inlining was never faster, |
23 // See https://code.google.com/p/chromium/issues/detail?id=516426#c15 for more d
etails. | 23 // - on ARMv7, inlining was faster for N<=10. Putting this check inside the N
EON |
24 // See also skia:4316; it might be a good idea to use rep stosw/stosd here. | 24 // code was not helpful; it's got to be here outside. |
| 25 // - NEON code generation for ARMv8 with GCC 4.9 is terrible, |
| 26 // making the NEON code ~8x slower that just a serial loop. |
25 | 27 |
26 /** Similar to memset(), but it assigns a 16bit value into the buffer. | 28 /** Similar to memset(), but it assigns a 16bit value into the buffer. |
27 @param buffer The memory to have value copied into it | 29 @param buffer The memory to have value copied into it |
28 @param value The 16bit value to be copied into buffer | 30 @param value The 16bit value to be copied into buffer |
29 @param count The number of times value should be copied into the buffer. | 31 @param count The number of times value should be copied into the buffer. |
30 */ | 32 */ |
31 static inline void sk_memset16(uint16_t buffer[], uint16_t value, int count) { | 33 static inline void sk_memset16(uint16_t buffer[], uint16_t value, int count) { |
32 #if defined(_MSC_VER) | 34 #if defined(SK_CPU_ARM64) |
33 if (count > 300) { while (count --> 0) { *buffer++ = value; } return; } | 35 while (count --> 0) { *buffer++ = value; } return; |
34 #elif defined(SK_BUILD_FOR_ANDROID) && defined(SK_CPU_X86) | 36 #elif defined(SK_CPU_ARM32) |
35 if (count < 300) { while (count --> 0) { *buffer++ = value; } return; } | 37 if (count <= 10) { while (count --> 0) { *buffer++ = value; } return; } |
36 #elif defined(SK_ARM_HAS_NEON) || SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | |
37 { while (count --> 0) { *buffer++ = value; } return; } | |
38 #endif | 38 #endif |
39 SkOpts::memset16(buffer, value, count); | 39 SkOpts::memset16(buffer, value, count); |
40 } | 40 } |
41 | 41 |
42 /** Similar to memset(), but it assigns a 32bit value into the buffer. | 42 /** Similar to memset(), but it assigns a 32bit value into the buffer. |
43 @param buffer The memory to have value copied into it | 43 @param buffer The memory to have value copied into it |
44 @param value The 32bit value to be copied into buffer | 44 @param value The 32bit value to be copied into buffer |
45 @param count The number of times value should be copied into the buffer. | 45 @param count The number of times value should be copied into the buffer. |
46 */ | 46 */ |
47 static inline void sk_memset32(uint32_t buffer[], uint32_t value, int count) { | 47 static inline void sk_memset32(uint32_t buffer[], uint32_t value, int count) { |
48 #if defined(_MSC_VER) | 48 #if defined(SK_CPU_ARM64) |
49 if (count > 300) { while (count --> 0) { *buffer++ = value; } return; } | 49 while (count --> 0) { *buffer++ = value; } return; |
50 #elif defined(SK_BUILD_FOR_ANDROID) && defined(SK_CPU_X86) | 50 #elif defined(SK_CPU_ARM32) |
51 if (count < 300) { while (count --> 0) { *buffer++ = value; } return; } | 51 if (count <= 10) { while (count --> 0) { *buffer++ = value; } return; } |
52 #elif defined(SK_ARM_HAS_NEON) || SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | |
53 { while (count --> 0) { *buffer++ = value; } return; } | |
54 #endif | 52 #endif |
55 SkOpts::memset32(buffer, value, count); | 53 SkOpts::memset32(buffer, value, count); |
56 } | 54 } |
57 | 55 |
58 | 56 |
59 /////////////////////////////////////////////////////////////////////////////// | 57 /////////////////////////////////////////////////////////////////////////////// |
60 | 58 |
61 #define kMaxBytesInUTF8Sequence 4 | 59 #define kMaxBytesInUTF8Sequence 4 |
62 | 60 |
63 #ifdef SK_DEBUG | 61 #ifdef SK_DEBUG |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 124 } |
127 ~SkAutoTrace() { | 125 ~SkAutoTrace() { |
128 SkDebugf("--- trace: %s Leave\n", fLabel); | 126 SkDebugf("--- trace: %s Leave\n", fLabel); |
129 } | 127 } |
130 private: | 128 private: |
131 const char* fLabel; | 129 const char* fLabel; |
132 }; | 130 }; |
133 #define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace) | 131 #define SkAutoTrace(...) SK_REQUIRE_LOCAL_VAR(SkAutoTrace) |
134 | 132 |
135 #endif | 133 #endif |
OLD | NEW |