Skip to content

Commit

Permalink
This is to address issue #157.
Browse files Browse the repository at this point in the history
  • Loading branch information
aous72 committed Nov 9, 2024
1 parent 6386daf commit 3292374
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
9 changes: 7 additions & 2 deletions src/core/codestream/ojph_codeblock_fun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ namespace ojph {

#ifndef OJPH_DISABLE_AVX2
if (get_cpu_ext_level() >= X86_CPU_EXT_LEVEL_AVX2) {
decode_cb32 = ojph_decode_codeblock_avx2;
find_max_val32 = avx2_find_max_val32;
if (reversible) {
tx_to_cb32 = avx2_rev_tx_to_cb32;
Expand All @@ -215,7 +216,8 @@ namespace ojph {
tx_from_cb32 = avx2_irv_tx_from_cb32;
}
encode_cb32 = ojph_encode_codeblock_avx2;
decode_cb32 = ojph_decode_codeblock_avx2;
bool result = initialize_block_encoder_tables_avx2();
assert(result);

find_max_val64 = avx2_find_max_val64;
if (reversible) {
Expand All @@ -231,8 +233,11 @@ namespace ojph {
#endif // !OJPH_DISABLE_AVX2

#if (defined(OJPH_ARCH_X86_64) && !defined(OJPH_DISABLE_AVX512))
if (get_cpu_ext_level() >= X86_CPU_EXT_LEVEL_AVX512)
if (get_cpu_ext_level() >= X86_CPU_EXT_LEVEL_AVX512) {
encode_cb32 = ojph_encode_codeblock_avx512;
bool result = initialize_block_encoder_tables_avx512();
assert(result);
}
#endif // !OJPH_DISABLE_AVX512

#elif defined(OJPH_ARCH_ARM)
Expand Down
3 changes: 3 additions & 0 deletions src/core/coding/ojph_block_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ namespace ojph {
ui32 stride, ui32* lengths,
ojph::mem_elastic_allocator *elastic,
ojph::coded_lists *& coded);

bool initialize_block_encoder_tables_avx2();
bool initialize_block_encoder_tables_avx512();
}
}

Expand Down
19 changes: 8 additions & 11 deletions src/core/coding/ojph_block_encoder_avx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,19 @@ namespace ojph {
}

/////////////////////////////////////////////////////////////////////////
bool initialize_tables_avx2() {
if (get_cpu_ext_level() >= X86_CPU_EXT_LEVEL_AVX2) {
static bool tables_initialized = false;

/////////////////////////////////////////////////////////////////////////
bool initialize_block_encoder_tables_avx2() {
if (!tables_initialized) {
memset(vlc_tbl0, 0, 2048 * sizeof(ui32));
memset(vlc_tbl1, 0, 2048 * sizeof(ui32));

bool result;
result = vlc_init_tables();
result = result && uvlc_init_tables();
return result;
tables_initialized = vlc_init_tables();
tables_initialized = tables_initialized && uvlc_init_tables();
}
return false;
return tables_initialized;
}

/////////////////////////////////////////////////////////////////////////
static bool tables_initialized = initialize_tables_avx2();

/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
Expand Down
20 changes: 8 additions & 12 deletions src/core/coding/ojph_block_encoder_avx512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,19 @@ namespace ojph {
}

/////////////////////////////////////////////////////////////////////////
bool initialize_tables() {
if (get_cpu_ext_level() >= X86_CPU_EXT_LEVEL_AVX512)
{
static bool tables_initialized = false;

/////////////////////////////////////////////////////////////////////////
bool initialize_block_encoder_tables_avx512() {
if (!tables_initialized) {
memset(vlc_tbl0, 0, 2048 * sizeof(ui32));
memset(vlc_tbl1, 0, 2048 * sizeof(ui32));

bool result;
result = vlc_init_tables();
result = result && uvlc_init_tables();
return result;
tables_initialized = vlc_init_tables();
tables_initialized = tables_initialized && uvlc_init_tables();
}
return false;
return tables_initialized;
}

/////////////////////////////////////////////////////////////////////////
static bool tables_initialized = initialize_tables();

/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 3292374

Please sign in to comment.