Skip to content

Commit

Permalink
Merge pull request #153 from tszumski/optimization-changes-v3
Browse files Browse the repository at this point in the history
Adds avx2 optimization for block encoding and decoding.
  • Loading branch information
aous72 authored Sep 9, 2024
2 parents 987c654 + cc8cec4 commit 58ed06d
Show file tree
Hide file tree
Showing 7 changed files with 3,284 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ file(GLOB CODESTREAM_WASM "codestream/*_wasm.cpp")
file(GLOB CODING "coding/*.cpp" "coding/*.h")
file(GLOB CODING_SSSE3 "coding/*_ssse3.cpp")
file(GLOB CODING_WASM "coding/*_wasm.cpp")
file(GLOB CODING_AVX2 "coding/*_avx2.cpp")
file(GLOB CODING_AVX512 "coding/*_avx512.cpp")
file(GLOB COMMON "common/*.h")
file(GLOB OTHERS "others/*.cpp")
Expand All @@ -22,7 +23,7 @@ file(GLOB TRANSFORM_AVX512 "transform/*_avx512.cpp")
file(GLOB TRANSFORM_WASM "transform/*_wasm.cpp")

list(REMOVE_ITEM CODESTREAM ${CODESTREAM_SSE} ${CODESTREAM_SSE2} ${CODESTREAM_AVX} ${CODESTREAM_AVX2} ${CODESTREAM_WASM})
list(REMOVE_ITEM CODING ${CODING_SSSE3} ${CODING_WASM} ${CODING_AVX512})
list(REMOVE_ITEM CODING ${CODING_SSSE3} ${CODING_WASM} ${CODING_AVX2} ${CODING_AVX512})
list(REMOVE_ITEM TRANSFORM ${TRANSFORM_SSE} ${TRANSFORM_SSE2} ${TRANSFORM_AVX} ${TRANSFORM_AVX2} ${TRANSFORM_AVX512} ${TRANSFORM_WASM})
list(APPEND SOURCES ${CODESTREAM} ${CODING} ${COMMON} ${OTHERS} ${TRANSFORM})

Expand Down Expand Up @@ -70,9 +71,10 @@ else()
source_group("transform" FILES ${TRANSFORM_AVX})
endif()
if (NOT OJPH_DISABLE_AVX2)
list(APPEND SOURCES ${CODESTREAM_AVX2} ${TRANSFORM_AVX2})
list(APPEND SOURCES ${CODESTREAM_AVX2} ${TRANSFORM_AVX2} ${CODING_AVX2})
source_group("codestream" FILES ${CODESTREAM_AVX2})
source_group("transform" FILES ${TRANSFORM_AVX2})
source_group("coding" FILES ${CODING_AVX2})
endif()
if ((NOT OJPH_DISABLE_AVX512) AND ("${OJPH_TARGET_ARCH}" MATCHES "OJPH_ARCH_X86_64"))
list(APPEND SOURCES ${CODING_AVX512} ${TRANSFORM_AVX512})
Expand All @@ -84,6 +86,8 @@ else()
if (MSVC)
set_source_files_properties(codestream/ojph_codestream_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX")
set_source_files_properties(codestream/ojph_codestream_avx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
set_source_files_properties(coding/ojph_block_decoder_avx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
set_source_files_properties(coding/ojph_block_encoder_avx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
set_source_files_properties(coding/ojph_block_encoder_avx512.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX512")
set_source_files_properties(transform/ojph_colour_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX")
set_source_files_properties(transform/ojph_colour_avx2.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX2")
Expand All @@ -94,6 +98,8 @@ else()
set_source_files_properties(codestream/ojph_codestream_avx.cpp PROPERTIES COMPILE_FLAGS -mavx)
set_source_files_properties(codestream/ojph_codestream_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
set_source_files_properties(coding/ojph_block_decoder_ssse3.cpp PROPERTIES COMPILE_FLAGS -mssse3)
set_source_files_properties(coding/ojph_block_decoder_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
set_source_files_properties(coding/ojph_block_encoder_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
set_source_files_properties(coding/ojph_block_encoder_avx512.cpp PROPERTIES COMPILE_FLAGS -mavx512cd)
set_source_files_properties(transform/ojph_colour_avx.cpp PROPERTIES COMPILE_FLAGS -mavx)
set_source_files_properties(transform/ojph_colour_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
Expand Down
2 changes: 2 additions & 0 deletions src/core/codestream/ojph_codeblock_fun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ namespace ojph {
tx_to_cb = avx2_irv_tx_to_cb;
tx_from_cb = avx2_irv_tx_from_cb;
}
encode_cb = ojph_encode_codeblock_avx2;
decode_cb = ojph_decode_codeblock_avx2;
}
#endif // !OJPH_DISABLE_AVX2

Expand Down
6 changes: 6 additions & 0 deletions src/core/coding/ojph_block_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ namespace ojph {
ui32 missing_msbs, ui32 num_passes, ui32 lengths1, ui32 lengths2,
ui32 width, ui32 height, ui32 stride, bool stripe_causal);

// AVX2-accelerated decoder
bool
ojph_decode_codeblock_avx2(ui8* coded_data, ui32* decoded_data,
ui32 missing_msbs, ui32 num_passes, ui32 lengths1, ui32 lengths2,
ui32 width, ui32 height, ui32 stride, bool stripe_causal);

// WASM SIMD-accelerated decoder
bool
ojph_decode_codeblock_wasm(ui8* coded_data, ui32* decoded_data,
Expand Down
Loading

0 comments on commit 58ed06d

Please sign in to comment.