MCPcopy Create free account
hub / github.com/ElementsProject/elements / ExtendPortable

Function ExtendPortable

src/crc32c/src/crc32c_portable.cc:247–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245namespace crc32c {
246
247uint32_t ExtendPortable(uint32_t crc, const uint8_t* data, size_t size) {
248 const uint8_t* p = data;
249 const uint8_t* e = p + size;
250 uint32_t l = crc ^ kCRC32Xor;
251
252// Process one byte at a time.
253#define STEP1 \
254 do { \
255 int c = (l & 0xff) ^ *p++; \
256 l = kByteExtensionTable[c] ^ (l >> 8); \
257 } while (0)
258
259// Process one of the 4 strides of 4-byte data.
260#define STEP4(s) \
261 do { \
262 crc##s = ReadUint32LE(p + s * 4) ^ kStrideExtensionTable3[crc##s & 0xff] ^ \
263 kStrideExtensionTable2[(crc##s >> 8) & 0xff] ^ \
264 kStrideExtensionTable1[(crc##s >> 16) & 0xff] ^ \
265 kStrideExtensionTable0[crc##s >> 24]; \
266 } while (0)
267
268// Process a 16-byte swath of 4 strides, each of which has 4 bytes of data.
269#define STEP16 \
270 do { \
271 STEP4(0); \
272 STEP4(1); \
273 STEP4(2); \
274 STEP4(3); \
275 p += 16; \
276 } while (0)
277
278// Process 4 bytes that were already loaded into a word.
279#define STEP4W(w) \
280 do { \
281 w ^= l; \
282 for (size_t i = 0; i < 4; ++i) { \
283 w = (w >> 8) ^ kByteExtensionTable[w & 0xff]; \
284 } \
285 l = w; \
286 } while (0)
287
288 // Point x at first 4-byte aligned byte in the buffer. This might be past the
289 // end of the buffer.
290 const uint8_t* x = RoundUp<4>(p);
291 if (x <= e) {
292 // Process bytes p is 4-byte aligned.
293 while (p != x) {
294 STEP1;
295 }
296 }
297
298 if ((e - p) >= 16) {
299 // Load a 16-byte swath into the stride partial results.
300 uint32_t crc0 = ReadUint32LE(p + 0 * 4) ^ l;
301 uint32_t crc1 = ReadUint32LE(p + 1 * 4);
302 uint32_t crc2 = ReadUint32LE(p + 2 * 4);
303 uint32_t crc3 = ReadUint32LE(p + 3 * 4);
304 p += 16;

Callers 3

ExtendFunction · 0.85
ExtendMethod · 0.85

Calls 2

RequestPrefetchFunction · 0.85
ReadUint32LEFunction · 0.70

Tested by 1

ExtendMethod · 0.68