Skip to content

Commit 3292374

Browse files
committed
This is to address issue #157.
1 parent 6386daf commit 3292374

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

src/core/codestream/ojph_codeblock_fun.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ namespace ojph {
205205

206206
#ifndef OJPH_DISABLE_AVX2
207207
if (get_cpu_ext_level() >= X86_CPU_EXT_LEVEL_AVX2) {
208+
decode_cb32 = ojph_decode_codeblock_avx2;
208209
find_max_val32 = avx2_find_max_val32;
209210
if (reversible) {
210211
tx_to_cb32 = avx2_rev_tx_to_cb32;
@@ -215,7 +216,8 @@ namespace ojph {
215216
tx_from_cb32 = avx2_irv_tx_from_cb32;
216217
}
217218
encode_cb32 = ojph_encode_codeblock_avx2;
218-
decode_cb32 = ojph_decode_codeblock_avx2;
219+
bool result = initialize_block_encoder_tables_avx2();
220+
assert(result);
219221

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

233235
#if (defined(OJPH_ARCH_X86_64) && !defined(OJPH_DISABLE_AVX512))
234-
if (get_cpu_ext_level() >= X86_CPU_EXT_LEVEL_AVX512)
236+
if (get_cpu_ext_level() >= X86_CPU_EXT_LEVEL_AVX512) {
235237
encode_cb32 = ojph_encode_codeblock_avx512;
238+
bool result = initialize_block_encoder_tables_avx512();
239+
assert(result);
240+
}
236241
#endif // !OJPH_DISABLE_AVX512
237242

238243
#elif defined(OJPH_ARCH_ARM)

src/core/coding/ojph_block_encoder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ namespace ojph {
7878
ui32 stride, ui32* lengths,
7979
ojph::mem_elastic_allocator *elastic,
8080
ojph::coded_lists *& coded);
81+
82+
bool initialize_block_encoder_tables_avx2();
83+
bool initialize_block_encoder_tables_avx512();
8184
}
8285
}
8386

src/core/coding/ojph_block_encoder_avx2.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,22 +218,19 @@ namespace ojph {
218218
}
219219

220220
/////////////////////////////////////////////////////////////////////////
221-
bool initialize_tables_avx2() {
222-
if (get_cpu_ext_level() >= X86_CPU_EXT_LEVEL_AVX2) {
221+
static bool tables_initialized = false;
222+
223+
/////////////////////////////////////////////////////////////////////////
224+
bool initialize_block_encoder_tables_avx2() {
225+
if (!tables_initialized) {
223226
memset(vlc_tbl0, 0, 2048 * sizeof(ui32));
224227
memset(vlc_tbl1, 0, 2048 * sizeof(ui32));
225-
226-
bool result;
227-
result = vlc_init_tables();
228-
result = result && uvlc_init_tables();
229-
return result;
228+
tables_initialized = vlc_init_tables();
229+
tables_initialized = tables_initialized && uvlc_init_tables();
230230
}
231-
return false;
231+
return tables_initialized;
232232
}
233233

234-
/////////////////////////////////////////////////////////////////////////
235-
static bool tables_initialized = initialize_tables_avx2();
236-
237234
/////////////////////////////////////////////////////////////////////////
238235
//
239236
/////////////////////////////////////////////////////////////////////////

src/core/coding/ojph_block_encoder_avx512.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,19 @@ namespace ojph {
218218
}
219219

220220
/////////////////////////////////////////////////////////////////////////
221-
bool initialize_tables() {
222-
if (get_cpu_ext_level() >= X86_CPU_EXT_LEVEL_AVX512)
223-
{
221+
static bool tables_initialized = false;
222+
223+
/////////////////////////////////////////////////////////////////////////
224+
bool initialize_block_encoder_tables_avx512() {
225+
if (!tables_initialized) {
224226
memset(vlc_tbl0, 0, 2048 * sizeof(ui32));
225227
memset(vlc_tbl1, 0, 2048 * sizeof(ui32));
226-
227-
bool result;
228-
result = vlc_init_tables();
229-
result = result && uvlc_init_tables();
230-
return result;
228+
tables_initialized = vlc_init_tables();
229+
tables_initialized = tables_initialized && uvlc_init_tables();
231230
}
232-
return false;
231+
return tables_initialized;
233232
}
234233

235-
/////////////////////////////////////////////////////////////////////////
236-
static bool tables_initialized = initialize_tables();
237-
238234
/////////////////////////////////////////////////////////////////////////
239235
//
240236
/////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)