Skip to content

Commit

Permalink
Fix segfault in decoder init
Browse files Browse the repository at this point in the history
  • Loading branch information
animetosho committed Mar 21, 2024
1 parent eae08db commit f79a4e4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static inline void decoder_set_native_funcs() {
# else
# include "decoder_sse_base.h"
static inline void decoder_set_native_funcs() {
decoder_sse_init();
decoder_sse_init(lookups);
decoder_init_lut(lookups->compact);
_do_decode = &do_decode_simd<false, false, sizeof(__m128i)*2, do_decode_sse<false, false, ISA_NATIVE> >;
_do_decode_raw = &do_decode_simd<true, false, sizeof(__m128i)*2, do_decode_sse<true, false, ISA_NATIVE> >;
Expand Down
2 changes: 1 addition & 1 deletion src/decoder_avx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "decoder_common.h"
#include "decoder_sse_base.h"
void decoder_set_avx_funcs() {
decoder_sse_init();
decoder_sse_init(lookups);
decoder_init_lut(lookups->compact);
_do_decode = &do_decode_simd<false, false, sizeof(__m128i)*2, do_decode_sse<false, false, ISA_LEVEL_SSE4_POPCNT> >;
_do_decode_raw = &do_decode_simd<true, false, sizeof(__m128i)*2, do_decode_sse<true, false, ISA_LEVEL_SSE4_POPCNT> >;
Expand Down
4 changes: 4 additions & 0 deletions src/decoder_common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "decoder.h"

#if defined(PLATFORM_ARM) && !defined(__aarch64__)
#define YENC_DEC_USE_THINTABLE 1
#endif

// TODO: need to support max output length somehow
// TODO: add branch probabilities

Expand Down
3 changes: 0 additions & 3 deletions src/decoder_neon.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "common.h"
#ifdef __ARM_NEON

#ifndef __aarch64__
#define YENC_DEC_USE_THINTABLE 1
#endif
#include "decoder_common.h"


Expand Down
6 changes: 3 additions & 3 deletions src/decoder_sse2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "decoder_common.h"
#include "decoder_sse_base.h"

void decoder_sse_init() {
ALIGN_ALLOC(lookups, sizeof(*lookups), 16);
void decoder_sse_init(SSELookups* HEDLEY_RESTRICT& lookups) {
ALIGN_ALLOC(lookups, sizeof(SSELookups), 16);
for(int i=0; i<256; i++) {
lookups->BitsSetTable256inv[i] = 8 - (
(i & 1) + ((i>>1) & 1) + ((i>>2) & 1) + ((i>>3) & 1) + ((i>>4) & 1) + ((i>>5) & 1) + ((i>>6) & 1) + ((i>>7) & 1)
Expand All @@ -26,7 +26,7 @@ void decoder_sse_init() {
}

void decoder_set_sse2_funcs() {
decoder_sse_init();
decoder_sse_init(lookups);
decoder_init_lut(lookups->compact);
_do_decode = &do_decode_simd<false, false, sizeof(__m128i)*2, do_decode_sse<false, false, ISA_LEVEL_SSE2> >;
_do_decode_raw = &do_decode_simd<true, false, sizeof(__m128i)*2, do_decode_sse<true, false, ISA_LEVEL_SSE2> >;
Expand Down
7 changes: 4 additions & 3 deletions src/decoder_sse_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
#endif

#pragma pack(16)
static struct {
typedef struct {
unsigned char BitsSetTable256inv[256];
/*align16*/ struct { char bytes[16]; } compact[32768];
/*align8*/ uint64_t eqAdd[256];
/*align16*/ int8_t unshufMask[32*16];
} * HEDLEY_RESTRICT lookups;
} SSELookups;
static SSELookups* HEDLEY_RESTRICT lookups;
#pragma pack()


Expand All @@ -44,7 +45,7 @@ static HEDLEY_ALWAYS_INLINE __m128i force_align_read_128(const void* p) {
#endif
}

void decoder_sse_init(); // defined in decoder_sse2.cc
void decoder_sse_init(SSELookups* HEDLEY_RESTRICT& lookups); // defined in decoder_sse2.cc


// for LZCNT/BSR
Expand Down
2 changes: 1 addition & 1 deletion src/decoder_ssse3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "decoder_common.h"
#include "decoder_sse_base.h"
void decoder_set_ssse3_funcs() {
decoder_sse_init();
decoder_sse_init(lookups);
decoder_init_lut(lookups->compact);
_do_decode = &do_decode_simd<false, false, sizeof(__m128i)*2, do_decode_sse<false, false, ISA_LEVEL_SSSE3> >;
_do_decode_raw = &do_decode_simd<true, false, sizeof(__m128i)*2, do_decode_sse<true, false, ISA_LEVEL_SSSE3> >;
Expand Down

0 comments on commit f79a4e4

Please sign in to comment.