diff options
author | Mika Lindqvist <postmaster@raasu.org> | 2017-05-03 20:14:57 +0300 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2017-05-03 19:14:57 +0200 |
commit | 5adc2052ebdd2578fde4ee3ebc500d71e967b8ae (patch) | |
tree | aee917ad21a950e5f1d8616446d38682b55100de /functable.c | |
parent | a7c7119009a65f2bf554faab19583650bf5fa0f7 (diff) |
Lazily initialize functable members. (#108)
- Split functableInit() function as separate functions for each functable member, so we don't need to initialize full functable in multiple places in the zlib-ng code, or to check for NULL on every invocation.
- Optimized function for each functable member is detected on first invocation and the functable item is updated for subsequent invocations.
- Remove NULL check in adler32() and adler32_z() as it is no longer needed.
Diffstat (limited to 'functable.c')
-rw-r--r-- | functable.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/functable.c b/functable.c index 7d34fad..5ebd355 100644 --- a/functable.c +++ b/functable.c @@ -12,37 +12,36 @@ #endif +/* insert_string */ +ZLIB_INTERNAL Pos insert_string_stub(deflate_state *const s, const Pos str, unsigned int count); #ifdef X86_SSE4_2_CRC_HASH extern Pos insert_string_sse(deflate_state *const s, const Pos str, unsigned int count); #elif defined(ARM_ACLE_CRC_HASH) extern Pos insert_string_acle(deflate_state *const s, const Pos str, unsigned int count); #endif +/* fill_window */ +ZLIB_INTERNAL void fill_window_stub(deflate_state *s); #ifdef X86_SSE2_FILL_WINDOW extern void fill_window_sse(deflate_state *s); #elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) extern void fill_window_arm(deflate_state *s); #endif +/* adler32 */ +ZLIB_INTERNAL uint32_t adler32_stub(uint32_t adler, const unsigned char *buf, size_t len); #if (defined(__ARM_NEON__) || defined(__ARM_NEON)) extern uint32_t adler32_neon(uint32_t adler, const unsigned char *buf, size_t len); #endif -/* ========================================================================= - * Initialize functable - */ - -struct functable_s functable = {NULL,NULL,NULL}; +struct functable_s functable = {fill_window_stub,insert_string_stub,adler32_stub}; - -ZLIB_INTERNAL void functableInit() { - // Initialize defaults +/* stub functions */ +ZLIB_INTERNAL Pos insert_string_stub(deflate_state *const s, const Pos str, unsigned int count) { + // Initialize default functable.insert_string=&insert_string_c; - functable.fill_window=&fill_window_c; - functable.adler32=&adler32_c; - // insert_string #ifdef X86_SSE4_2_CRC_HASH if (x86_cpu_has_sse42) functable.insert_string=&insert_string_sse; @@ -50,7 +49,13 @@ ZLIB_INTERNAL void functableInit() { functable.insert_string=&insert_string_acle; #endif - // fill_window + return functable.insert_string(s, str, count); +} + +ZLIB_INTERNAL void fill_window_stub(deflate_state *s) { + // Initialize default + functable.fill_window=&fill_window_c; + #ifdef X86_SSE2_FILL_WINDOW # ifndef X86_NOCHECK_SSE2 if (x86_cpu_has_sse2) @@ -60,8 +65,16 @@ ZLIB_INTERNAL void functableInit() { functable.fill_window=&fill_window_arm; #endif - // adler32 + functable.fill_window(s); +} + +ZLIB_INTERNAL uint32_t adler32_stub(uint32_t adler, const unsigned char *buf, size_t len) { + // Initialize default + functable.adler32=&adler32_c; + #if (defined(__ARM_NEON__) || defined(__ARM_NEON)) functable.adler32=&adler32_neon; #endif + + return functable.adler32(adler, buf, len); } |