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

Function Extend

src/leveldb/util/crc32c.cc:276–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274}
275
276uint32_t Extend(uint32_t crc, const char* data, size_t n) {
277 static bool accelerate = CanAccelerateCRC32C();
278 if (accelerate) {
279 return port::AcceleratedCRC32C(crc, data, n);
280 }
281
282 const uint8_t* p = reinterpret_cast<const uint8_t*>(data);
283 const uint8_t* e = p + n;
284 uint32_t l = crc ^ kCRC32Xor;
285
286// Process one byte at a time.
287#define STEP1 \
288 do { \
289 int c = (l & 0xff) ^ *p++; \
290 l = kByteExtensionTable[c] ^ (l >> 8); \
291 } while (0)
292
293// Process one of the 4 strides of 4-byte data.
294#define STEP4(s) \
295 do { \
296 crc##s = ReadUint32LE(p + s * 4) ^ kStrideExtensionTable3[crc##s & 0xff] ^ \
297 kStrideExtensionTable2[(crc##s >> 8) & 0xff] ^ \
298 kStrideExtensionTable1[(crc##s >> 16) & 0xff] ^ \
299 kStrideExtensionTable0[crc##s >> 24]; \
300 } while (0)
301
302// Process a 16-byte swath of 4 strides, each of which has 4 bytes of data.
303#define STEP16 \
304 do { \
305 STEP4(0); \
306 STEP4(1); \
307 STEP4(2); \
308 STEP4(3); \
309 p += 16; \
310 } while (0)
311
312// Process 4 bytes that were already loaded into a word.
313#define STEP4W(w) \
314 do { \
315 w ^= l; \
316 for (size_t i = 0; i < 4; ++i) { \
317 w = (w >> 8) ^ kByteExtensionTable[w & 0xff]; \
318 } \
319 l = w; \
320 } while (0)
321
322 // Point x at first 4-byte aligned byte in the buffer. This might be past the
323 // end of the buffer.
324 const uint8_t* x = RoundUp<4>(p);
325 if (x <= e) {
326 // Process bytes p is 4-byte aligned.
327 while (p != x) {
328 STEP1;
329 }
330 }
331
332 if ((e - p) >= 16) {
333 // Load a 16-byte swath into the stride partial results.

Callers 5

TESTFunction · 0.70
ValueFunction · 0.70
AcceleratedCRC32CFunction · 0.50
WriteRawBlockMethod · 0.50
EmitPhysicalRecordMethod · 0.50

Calls 3

CanAccelerateCRC32CFunction · 0.85
AcceleratedCRC32CFunction · 0.85
ReadUint32LEFunction · 0.70

Tested by 1

TESTFunction · 0.56