Skip to content

Commit d34bab9

Browse files
committed
crc
1 parent b799c1e commit d34bab9

File tree

9 files changed

+1435
-359
lines changed

9 files changed

+1435
-359
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ file(GLOB PHOTON_SRC RELATIVE "${PROJECT_SOURCE_DIR}"
202202
rpc/*.cpp
203203
thread/*.cpp
204204
)
205+
if ((${ARCH} STREQUAL aarch64) OR (${ARCH} STREQUAL arm64))
206+
list(APPEND PHOTON_SRC common/checksum/crc64_ecma_refl_pmull.S)
207+
endif ()
205208
if (APPLE)
206209
list(APPEND PHOTON_SRC io/kqueue.cpp)
207210
else ()

common/checksum/crc32c.cpp

Lines changed: 58 additions & 306 deletions
Large diffs are not rendered by default.

common/checksum/crc32c.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,32 @@ limitations under the License.
1515
*/
1616
#pragma once
1717
#include <cstdint>
18-
#include <string>
18+
#include <photon/common/string_view.h>
19+
20+
uint32_t crc32c_sw(const uint8_t *buffer, size_t nbytes, uint32_t crc);
21+
22+
uint32_t crc32c_hw(const uint8_t *data, size_t nbytes, uint32_t crc);
1923

2024
/**
2125
* @brief We recommand using of crc32c() and crc32c_extend(), which can exploit hardware
2226
* acceleartion automatically. In case of using crc32c_hw() directly, please make sure invoking
2327
* is_crc32c_hw_available() to detect whether hardware acceleartion is available at first;
2428
*
2529
*/
26-
uint32_t crc32c(const void *data, size_t nbytes);
27-
28-
uint32_t crc32c_extend(const void *data, size_t nbytes, uint32_t crc);
30+
inline uint32_t crc32c_extend(const void *data, size_t nbytes, uint32_t crc) {
31+
extern uint32_t (*crc32c_auto)(const uint8_t *data, size_t nbytes, uint32_t crc);
32+
return crc32c_auto((uint8_t*)data, nbytes, crc);
33+
}
2934

30-
inline uint32_t crc32c(const std::string &text) {
31-
return crc32c_extend(text.data(), text.size(), 0);
35+
inline uint32_t crc32c(const void *data, size_t nbytes) {
36+
return crc32c_extend((uint8_t*)data, nbytes, 0);
3237
}
3338

34-
inline uint32_t crc32c_extend(const std::string &text, uint32_t crc) {
39+
inline uint32_t crc32c_extend(std::string_view text, uint32_t crc = 0) {
3540
return crc32c_extend(text.data(), text.size(), crc);
3641
}
3742

38-
uint32_t crc32c_sw(const uint8_t *buffer, size_t nbytes, uint32_t crc);
39-
40-
uint32_t crc32c_hw(const uint8_t *data, size_t nbytes, uint32_t crc);
41-
42-
bool is_crc32c_hw_available();
43+
inline bool is_crc32c_hw_available() {
44+
extern uint32_t (*crc32c_auto)(const uint8_t *data, size_t nbytes, uint32_t crc);
45+
return crc32c_auto == crc32c_hw;
46+
}

0 commit comments

Comments
 (0)