Skip to content

Commit 56ca75e

Browse files
committed
crc32: build a whole special Extend function for SSE 4.2.
Disassembling the Extend function shows something that looks much more healthy now. The SSE 4.2 instructions are right there in the body of the function. Intel(R) Core(TM) i7-3540M CPU @ 3.00GHz Before: crc32c: 1.305 micros/op 766260 ops/sec; 2993.2 MB/s (4K per op) After: crc32c: 0.442 micros/op 2263843 ops/sec; 8843.1 MB/s (4K per op)
1 parent 284c365 commit 56ca75e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

util/crc32c.cc

+14-13
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,8 @@ static bool isSSE42() {
334334
#endif
335335
}
336336

337-
typedef void (*Function)(uint64_t*, uint8_t const**);
338-
339-
static inline Function Choose_CRC32() {
340-
return isSSE42() ? Fast_CRC32 : Slow_CRC32;
341-
}
342-
343-
static Function func = Choose_CRC32();
344-
345-
static inline void CRC32(uint64_t* l, uint8_t const **p) {
346-
func(l, p);
347-
}
348-
349-
uint32_t Extend(uint32_t crc, const char* buf, size_t size) {
337+
template<void (*CRC32)(uint64_t*, uint8_t const**)>
338+
uint32_t ExtendImpl(uint32_t crc, const char* buf, size_t size) {
350339
const uint8_t *p = reinterpret_cast<const uint8_t *>(buf);
351340
const uint8_t *e = p + size;
352341
uint64_t l = crc ^ 0xffffffffu;
@@ -388,5 +377,17 @@ uint32_t Extend(uint32_t crc, const char* buf, size_t size) {
388377
return l ^ 0xffffffffu;
389378
}
390379

380+
typedef uint32_t (*Function)(uint32_t, const char*, size_t);
381+
382+
static inline Function Choose_Extend() {
383+
return isSSE42() ? ExtendImpl<Fast_CRC32> : ExtendImpl<Slow_CRC32>;
384+
}
385+
386+
Function ChosenExtend = Choose_Extend();
387+
388+
uint32_t Extend(uint32_t crc, const char* buf, size_t size) {
389+
return ChosenExtend(crc, buf, size);
390+
}
391+
391392
} // namespace crc32c
392393
} // namespace rocksdb

0 commit comments

Comments
 (0)