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

Side by Side Diff: src/opts/SkChecksum_opts.h

Issue 2322033002: Apple devices do not support CRC32 instructions. Don't believe Clang's lies. (Closed)
Patch Set: Created 4 years, 3 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 | « src/core/SkOpts.cpp ('k') | no next file » | 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 2016 Google Inc. 2 * Copyright 2016 Google Inc.
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 SkChecksum_opts_DEFINED 8 #ifndef SkChecksum_opts_DEFINED
9 #define SkChecksum_opts_DEFINED 9 #define SkChecksum_opts_DEFINED
10 10
11 #include "SkChecksum.h" 11 #include "SkChecksum.h"
12 #include "SkTypes.h" 12 #include "SkTypes.h"
13 13
14 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE42 14 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE42
15 #include <immintrin.h> 15 #include <immintrin.h>
16 #elif defined(SK_CPU_ARM64) && defined(__ARM_FEATURE_CRC32) 16 #elif defined(SK_CPU_ARM64) && defined(SK_ARM_HAS_CRC32)
17 #include <arm_acle.h> 17 #include <arm_acle.h>
18 #endif 18 #endif
19 19
20 namespace SK_OPTS_NS { 20 namespace SK_OPTS_NS {
21 21
22 template <typename T> 22 template <typename T>
23 static inline T unaligned_load(const uint8_t* src) { 23 static inline T unaligned_load(const uint8_t* src) {
24 T val; 24 T val;
25 memcpy(&val, src, sizeof(val)); 25 memcpy(&val, src, sizeof(val));
26 return val; 26 return val;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if (bytes & 2) { 120 if (bytes & 2) {
121 hash = _mm_crc32_u16(hash, unaligned_load<uint16_t>(data)); 121 hash = _mm_crc32_u16(hash, unaligned_load<uint16_t>(data));
122 data += 2; 122 data += 2;
123 } 123 }
124 if (bytes & 1) { 124 if (bytes & 1) {
125 hash = _mm_crc32_u8(hash, unaligned_load<uint8_t>(data)); 125 hash = _mm_crc32_u8(hash, unaligned_load<uint8_t>(data));
126 } 126 }
127 return hash; 127 return hash;
128 } 128 }
129 129
130 #elif defined(SK_CPU_ARM64) && defined(__ARM_FEATURE_CRC32) 130 #elif defined(SK_CPU_ARM64) && defined(SK_ARM_HAS_CRC32)
131 static uint32_t hash_fn(const void* vdata, size_t bytes, uint32_t hash) { 131 static uint32_t hash_fn(const void* vdata, size_t bytes, uint32_t hash) {
132 auto data = (const uint8_t*)vdata; 132 auto data = (const uint8_t*)vdata;
133 if (bytes >= 24) { 133 if (bytes >= 24) {
134 uint32_t a = hash, 134 uint32_t a = hash,
135 b = hash, 135 b = hash,
136 c = hash; 136 c = hash;
137 size_t steps = bytes/24; 137 size_t steps = bytes/24;
138 while (steps --> 0) { 138 while (steps --> 0) {
139 a = __crc32d(a, unaligned_load<uint64_t>(data+ 0)); 139 a = __crc32d(a, unaligned_load<uint64_t>(data+ 0));
140 b = __crc32d(b, unaligned_load<uint64_t>(data+ 8)); 140 b = __crc32d(b, unaligned_load<uint64_t>(data+ 8));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 207 }
208 208
209 hash ^= original_bytes; 209 hash ^= original_bytes;
210 return SkChecksum::Mix(hash); 210 return SkChecksum::Mix(hash);
211 } 211 }
212 #endif 212 #endif
213 213
214 } // namespace SK_OPTS_NS 214 } // namespace SK_OPTS_NS
215 215
216 #endif//SkChecksum_opts_DEFINED 216 #endif//SkChecksum_opts_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkOpts.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698