-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from Sarwate's algorithm to byte-order free Slicing-by-8. The specialized so files for the built-in CRCs by digest-crc contain only the initialization functions of the library and the table data. Each table data file is generated by `extconf.rb`. User-defined CRC classes are also accelerated since a generic `Digest::CRC#update` is provided. However, the `Digest::CRC::POLYNOMIAL` constants must be overridden. Also, at build time, the environment variable "RUBY_DIGEST_CRC_ENABLE_SLICING_BY_16=1" can be used to enable "Slicing-by-16" for a further slight speedup.
- Loading branch information
Showing
135 changed files
with
1,017 additions
and
2,528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#ifndef RUBY_DIGEST_CRC_H | ||
#define RUBY_DIGEST_CRC_H 1 | ||
|
||
#include <ruby.h> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
enum crc_input_direction { | ||
crc_normal_input = 0, | ||
crc_reflect_input = 1 | ||
}; | ||
|
||
enum crc_allocation_type { | ||
crc_alloc_static = 0, | ||
crc_alloc_heap = 1 | ||
}; | ||
|
||
struct crc_model | ||
{ | ||
int bitwidth : 8; | ||
enum crc_input_direction reflect_input : 1; | ||
enum crc_allocation_type table_heap : 1; | ||
uint64_t polynomial; | ||
const void *table; | ||
}; | ||
|
||
/* | ||
* This structure is materialized in each shared object file that defines | ||
* a CRC. Therefore, instead of checking the structure address, the | ||
* `wrap_struct_name` field is simply checked. This is to avoid link errors | ||
* at build time. | ||
*/ | ||
static const rb_data_type_t crc_model_const_type = { | ||
"digest-crc:model-const", | ||
{ | ||
NULL, | ||
NULL, | ||
NULL, | ||
NULL | ||
} | ||
}; | ||
|
||
static inline void ruby_digest_crc_model_implant(VALUE crc_class, const struct crc_model *model) | ||
{ | ||
ID id_model = rb_intern("digest-crc-model"); | ||
VALUE obj = rb_data_typed_object_wrap(rb_cObject, (void *)(uintptr_t)model, &crc_model_const_type); | ||
rb_obj_freeze(obj); | ||
rb_ivar_set(crc_class, id_model, obj); | ||
} | ||
|
||
#if !defined(HAVE_RB_EXT_RACTOR_SAFE) | ||
static inline void ruby_digest_crc_ensure_ractor_main(const char *mesg) | ||
{ | ||
(void)mesg; | ||
} | ||
#else | ||
#include <ruby/ractor.h> | ||
|
||
static inline void ruby_digest_crc_ensure_ractor_main(const char *mesg) | ||
{ | ||
if (rb_funcallv(rb_cRactor, rb_intern("main"), 0, NULL) != | ||
rb_funcallv(rb_cRactor, rb_intern("current"), 0, NULL)) { | ||
VALUE ractor = rb_const_get(rb_cObject, rb_intern("Ractor")); | ||
VALUE ractor_error = rb_const_get(ractor, rb_intern("Error")); | ||
rb_raise(ractor_error, "%s", mesg); | ||
} | ||
} | ||
#endif | ||
|
||
#endif // RUBY_DIGEST_CRC_H |
Oops, something went wrong.