Skip to content

Commit

Permalink
Merge pull request #199 from ashvardanian/main-dev
Browse files Browse the repository at this point in the history
Checksums in AVX-512, AVX2, NEON
  • Loading branch information
ashvardanian authored Dec 1, 2024
2 parents 98f857e + ad5fa2c commit d528548
Show file tree
Hide file tree
Showing 7 changed files with 557 additions and 125 deletions.
7 changes: 7 additions & 0 deletions c/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ typedef struct sz_implementations_t {
sz_move_t move;
sz_fill_t fill;
sz_look_up_transform_t look_up_transform;
sz_checksum_t checksum;

sz_find_byte_t find_byte;
sz_find_byte_t rfind_byte;
Expand Down Expand Up @@ -155,6 +156,7 @@ static void sz_dispatch_table_init(void) {
impl->move = sz_move_serial;
impl->fill = sz_fill_serial;
impl->look_up_transform = sz_look_up_transform_serial;
impl->checksum = sz_checksum_serial;

impl->find = sz_find_serial;
impl->rfind = sz_rfind_serial;
Expand All @@ -176,6 +178,7 @@ static void sz_dispatch_table_init(void) {
impl->move = sz_move_avx2;
impl->fill = sz_fill_avx2;
impl->look_up_transform = sz_look_up_transform_avx2;
impl->checksum = sz_checksum_avx2;

impl->find_byte = sz_find_byte_avx2;
impl->rfind_byte = sz_rfind_byte_avx2;
Expand Down Expand Up @@ -209,6 +212,7 @@ static void sz_dispatch_table_init(void) {
impl->rfind_from_set = sz_rfind_charset_avx512;
impl->alignment_score = sz_alignment_score_avx512;
impl->look_up_transform = sz_look_up_transform_avx512;
impl->checksum = sz_checksum_avx512;
}
#endif

Expand All @@ -220,6 +224,7 @@ static void sz_dispatch_table_init(void) {
impl->move = sz_move_neon;
impl->fill = sz_fill_neon;
impl->look_up_transform = sz_look_up_transform_neon;
impl->checksum = sz_checksum_neon;

impl->find = sz_find_neon;
impl->rfind = sz_rfind_neon;
Expand Down Expand Up @@ -251,6 +256,8 @@ BOOL WINAPI DllMain(HINSTANCE hints, DWORD forward_reason, LPVOID lp) {
__attribute__((constructor)) static void sz_dispatch_table_init_on_gcc_or_clang(void) { sz_dispatch_table_init(); }
#endif

SZ_DYNAMIC sz_u64_t sz_checksum(sz_cptr_t text, sz_size_t length) { return sz_dispatch_table.checksum(text, length); }

SZ_DYNAMIC sz_bool_t sz_equal(sz_cptr_t a, sz_cptr_t b, sz_size_t length) {
return sz_dispatch_table.equal(a, b, length);
}
Expand Down
296 changes: 296 additions & 0 deletions include/stringzilla/stringzilla.h

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions include/stringzilla/stringzilla.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,9 @@ class basic_string_slice {
/** @brief Hashes the string, equivalent to `std::hash<string_view>{}(str)`. */
size_type hash() const noexcept { return static_cast<size_type>(sz_hash(start_, length_)); }

/** @brief Aggregates the values of individual bytes of a string. */
size_type checksum() const noexcept { return static_cast<size_type>(sz_checksum(start_, length_)); }

/** @brief Populate a character set with characters present in this string. */
char_set as_set() const noexcept {
char_set set;
Expand Down Expand Up @@ -3303,6 +3306,9 @@ class basic_string {
/** @brief Hashes the string, equivalent to `std::hash<string_view>{}(str)`. */
size_type hash() const noexcept { return view().hash(); }

/** @brief Aggregates the values of individual bytes of a string. */
size_type checksum() const noexcept { return view().checksum(); }

/**
* @brief Overwrites the string with random characters from the given alphabet using the random generator.
*
Expand Down
Loading

0 comments on commit d528548

Please sign in to comment.