Skip to content

Commit

Permalink
crc
Browse files Browse the repository at this point in the history
  • Loading branch information
lihuiba committed Jan 3, 2025
1 parent b799c1e commit 83a6ffb
Show file tree
Hide file tree
Showing 9 changed files with 1,466 additions and 384 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ file(GLOB PHOTON_SRC RELATIVE "${PROJECT_SOURCE_DIR}"
rpc/*.cpp
thread/*.cpp
)
if ((${ARCH} STREQUAL aarch64) OR (${ARCH} STREQUAL arm64))
list(APPEND PHOTON_SRC common/checksum/crc64_ecma_refl_pmull.S)
endif ()
if (APPLE)
list(APPEND PHOTON_SRC io/kqueue.cpp)
else ()
Expand Down
412 changes: 81 additions & 331 deletions common/checksum/crc32c.cpp

Large diffs are not rendered by default.

32 changes: 20 additions & 12 deletions common/checksum/crc32c.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,36 @@ limitations under the License.
*/
#pragma once
#include <cstdint>
#include <string>
#include <photon/common/string_view.h>

uint32_t crc32c_sw(const uint8_t *buffer, size_t nbytes, uint32_t crc);

uint32_t crc32c_hw(const uint8_t *data, size_t nbytes, uint32_t crc);

/**
* @brief We recommand using of crc32c() and crc32c_extend(), which can exploit hardware
* acceleartion automatically. In case of using crc32c_hw() directly, please make sure invoking
* is_crc32c_hw_available() to detect whether hardware acceleartion is available at first;
*
*/
uint32_t crc32c(const void *data, size_t nbytes);

uint32_t crc32c_extend(const void *data, size_t nbytes, uint32_t crc);

inline uint32_t crc32c(const std::string &text) {
return crc32c_extend(text.data(), text.size(), 0);
inline uint32_t crc32c_extend(const void *data, size_t nbytes, uint32_t crc) {
extern uint32_t (*crc32c_auto)(const uint8_t *data, size_t nbytes, uint32_t crc);
return crc32c_auto((uint8_t*)data, nbytes, crc);
}

inline uint32_t crc32c_extend(const std::string &text, uint32_t crc) {
return crc32c_extend(text.data(), text.size(), crc);
inline uint32_t crc32c(const void *data, size_t nbytes) {
return crc32c_extend((uint8_t*)data, nbytes, 0);
}

uint32_t crc32c_sw(const uint8_t *buffer, size_t nbytes, uint32_t crc);
inline uint32_t crc32c_extend(std::string_view text, uint32_t crc) {
return crc32c_extend(text.data(), text.size(), crc);
}

uint32_t crc32c_hw(const uint8_t *data, size_t nbytes, uint32_t crc);
inline uint32_t crc32c(std::string_view text) {
return crc32c_extend(text, 0);
}

bool is_crc32c_hw_available();
inline bool is_crc32c_hw_available() {
extern uint32_t (*crc32c_auto)(const uint8_t *data, size_t nbytes, uint32_t crc);
return crc32c_auto == crc32c_hw;
}
Loading

0 comments on commit 83a6ffb

Please sign in to comment.