OpenJPH
Open-source implementation of JPEG2000 Part-15
ojph_codeblock_fun.cpp
Go to the documentation of this file.
1//***************************************************************************/
2// This software is released under the 2-Clause BSD license, included
3// below.
4//
5// Copyright (c) 2019, Aous Naman
6// Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
7// Copyright (c) 2019, The University of New South Wales, Australia
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13// 1. Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//
16// 2. Redistributions in binary form must reproduce the above copyright
17// notice, this list of conditions and the following disclaimer in the
18// documentation and/or other materials provided with the distribution.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31//***************************************************************************/
32// This file is part of the OpenJPH software implementation.
33// File: ojph_codeblock_fun.cpp
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38
39#include <climits>
40#include <cmath>
41
42#include "ojph_file.h"
43#include "ojph_mem.h"
44#include "ojph_params.h"
45#include "ojph_codestream.h"
47#include "ojph_codeblock_fun.h"
48
49#include "../transform/ojph_colour.h"
50#include "../transform/ojph_transform.h"
51#include "../coding/ojph_block_decoder.h"
52#include "../coding/ojph_block_encoder.h"
53
54namespace ojph {
55
56 namespace local
57 {
58
60 void gen_mem_clear(void* addr, size_t count);
61 void sse_mem_clear(void* addr, size_t count);
62 void avx_mem_clear(void* addr, size_t count);
63 void wasm_mem_clear(void* addr, size_t count);
64
74
75
77 void gen_rev_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max,
78 float delta_inv, ui32 count, ui32* max_val);
79 void sse2_rev_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max,
80 float delta_inv, ui32 count, ui32* max_val);
81 void avx2_rev_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max,
82 float delta_inv, ui32 count, ui32* max_val);
83 void gen_irv_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max,
84 float delta_inv, ui32 count, ui32* max_val);
85 void sse2_irv_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max,
86 float delta_inv, ui32 count, ui32* max_val);
87 void avx2_irv_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max,
88 float delta_inv, ui32 count, ui32* max_val);
89 void wasm_rev_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max,
90 float delta_inv, ui32 count, ui32* max_val);
91 void wasm_irv_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max,
92 float delta_inv, ui32 count, ui32* max_val);
93
94 void gen_rev_tx_to_cb64(const void *sp, ui64 *dp, ui32 K_max,
95 float delta_inv, ui32 count, ui64* max_val);
96 void sse2_rev_tx_to_cb64(const void *sp, ui64 *dp, ui32 K_max,
97 float delta_inv, ui32 count, ui64* max_val);
98 void avx2_rev_tx_to_cb64(const void *sp, ui64 *dp, ui32 K_max,
99 float delta_inv, ui32 count, ui64* max_val);
100 void wasm_rev_tx_to_cb64(const void *sp, ui64 *dp, ui32 K_max,
101 float delta_inv, ui32 count, ui64* max_val);
102
104 void gen_rev_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max,
105 float delta, ui32 count);
106 void sse2_rev_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max,
107 float delta, ui32 count);
108 void avx2_rev_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max,
109 float delta, ui32 count);
110 void gen_irv_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max,
111 float delta, ui32 count);
112 void sse2_irv_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max,
113 float delta, ui32 count);
114 void avx2_irv_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max,
115 float delta, ui32 count);
116 void wasm_rev_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max,
117 float delta, ui32 count);
118 void wasm_irv_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max,
119 float delta, ui32 count);
120
121 void gen_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max,
122 float delta, ui32 count);
123 void sse2_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max,
124 float delta, ui32 count);
125 void avx2_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max,
126 float delta, ui32 count);
127 void wasm_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max,
128 float delta, ui32 count);
129
130 void codeblock_fun::init(bool reversible) {
131
132#if !defined(OJPH_ENABLE_WASM_SIMD) || !defined(OJPH_EMSCRIPTEN)
133
134 // Default path, no acceleration. We may change this later
138 if (reversible) {
141 }
142 else
143 {
146 }
148
151 if (reversible) {
154 }
155 else
156 {
157 tx_to_cb64 = NULL;
158 tx_from_cb64 = NULL;
159 }
161 bool result = initialize_block_encoder_tables();
162 assert(result); ojph_unused(result);
163
164 #ifndef OJPH_DISABLE_SIMD
165
166 #if (defined(OJPH_ARCH_X86_64) || defined(OJPH_ARCH_I386))
167
168 // Accelerated functions for INTEL/AMD CPUs
169 #ifndef OJPH_DISABLE_SSE
172 #endif // !OJPH_DISABLE_SSE
173
174 #ifndef OJPH_DISABLE_SSE2
177 if (reversible) {
180 }
181 else {
184 }
186 if (reversible) {
189 }
190 else
191 {
192 tx_to_cb64 = NULL;
193 tx_from_cb64 = NULL;
194 }
195 }
196 #endif // !OJPH_DISABLE_SSE2
197
198 #ifndef OJPH_DISABLE_SSSE3
201 #endif // !OJPH_DISABLE_SSSE3
202
203 #ifndef OJPH_DISABLE_AVX
206 #endif // !OJPH_DISABLE_AVX
207
208 #ifndef OJPH_DISABLE_AVX2
212 if (reversible) {
215 }
216 else {
219 }
222 assert(result); ojph_unused(result);
223
225 if (reversible) {
228 }
229 else
230 {
231 tx_to_cb64 = NULL;
232 tx_from_cb64 = NULL;
233 }
234 }
235 #endif // !OJPH_DISABLE_AVX2
236
237 #if (defined(OJPH_ARCH_X86_64) && !defined(OJPH_DISABLE_AVX512))
241 assert(result); ojph_unused(result);
242 }
243 #endif // !OJPH_DISABLE_AVX512
244
245 #elif defined(OJPH_ARCH_ARM)
246
247 #endif // !(defined(OJPH_ARCH_X86_64) || defined(OJPH_ARCH_I386))
248
249 #endif // !OJPH_DISABLE_SIMD
250
251#else // OJPH_ENABLE_WASM_SIMD
252
253 // Accelerated functions for WASM SIMD.
257 if (reversible) {
260 }
261 else {
264 }
266
269 if (reversible) {
272 }
273 else
274 {
275 tx_to_cb64 = NULL;
276 tx_from_cb64 = NULL;
277 }
279
280#endif // !OJPH_ENABLE_WASM_SIMD
281
282 }
283 } // local
284} // ojph
bool ojph_decode_codeblock_wasm(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)
Decodes one codeblock, processing the cleanup, siginificance propagation, and magnitude refinement pa...
void gen_rev_tx_to_cb64(const void *sp, ui64 *dp, ui32 K_max, float delta_inv, ui32 count, ui64 *max_val)
ui64 avx2_find_max_val64(ui64 *address)
void wasm_rev_tx_to_cb64(const void *sp, ui64 *dp, ui32 K_max, float delta_inv, ui32 count, ui64 *max_val)
void avx2_irv_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
bool initialize_block_encoder_tables_avx512()
void sse2_rev_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void avx2_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max, float delta, ui32 count)
ui32 sse2_find_max_val32(ui32 *address)
ui32 wasm_find_max_val32(ui32 *address)
ui64 sse2_find_max_val64(ui64 *address)
bool ojph_decode_codeblock_ssse3(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)
Decodes one codeblock, processing the cleanup, siginificance propagation, and magnitude refinement pa...
void wasm_rev_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void avx_mem_clear(void *addr, size_t count)
ui32 avx2_find_max_val32(ui32 *address)
void avx2_rev_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void wasm_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void ojph_encode_codeblock32(ui32 *buf, ui32 missing_msbs, ui32 num_passes, ui32 width, ui32 height, ui32 stride, ui32 *lengths, ojph::mem_elastic_allocator *elastic, ojph::coded_lists *&coded)
void ojph_encode_codeblock64(ui64 *buf, ui32 missing_msbs, ui32 num_passes, ui32 width, ui32 height, ui32 stride, ui32 *lengths, ojph::mem_elastic_allocator *elastic, ojph::coded_lists *&coded)
void sse2_rev_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void gen_irv_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void gen_irv_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void ojph_encode_codeblock_avx2(ui32 *buf, ui32 missing_msbs, ui32 num_passes, ui32 width, ui32 height, ui32 stride, ui32 *lengths, ojph::mem_elastic_allocator *elastic, ojph::coded_lists *&coded)
void wasm_irv_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
ui64 wasm_find_max_val64(ui64 *address)
void sse2_rev_tx_to_cb64(const void *sp, ui64 *dp, ui32 K_max, float delta_inv, ui32 count, ui64 *max_val)
void gen_mem_clear(void *addr, size_t count)
void gen_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void sse_mem_clear(void *addr, size_t count)
bool ojph_decode_codeblock32(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)
Decodes one codeblock, processing the cleanup, siginificance propagation, and magnitude refinement pa...
void avx2_rev_tx_to_cb64(const void *sp, ui64 *dp, ui32 K_max, float delta_inv, ui32 count, ui64 *max_val)
ui64 gen_find_max_val64(ui64 *address)
void sse2_irv_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void wasm_mem_clear(void *addr, size_t count)
void gen_rev_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void wasm_rev_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void avx2_rev_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
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)
Decodes one codeblock, processing the cleanup, siginificance propagation, and magnitude refinement pa...
void sse2_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max, float delta, ui32 count)
bool initialize_block_encoder_tables()
void gen_rev_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
bool initialize_block_encoder_tables_avx2()
ui32 gen_find_max_val32(ui32 *address)
void wasm_irv_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void sse2_irv_tx_to_cb32(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void ojph_encode_codeblock_avx512(ui32 *buf, ui32 missing_msbs, ui32 num_passes, ui32 width, ui32 height, ui32 stride, ui32 *lengths, ojph::mem_elastic_allocator *elastic, ojph::coded_lists *&coded)
void avx2_irv_tx_from_cb32(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
bool ojph_decode_codeblock64(ui8 *coded_data, ui64 *decoded_data, ui32 missing_msbs, ui32 num_passes, ui32 lengths1, ui32 lengths2, ui32 width, ui32 height, ui32 stride, bool stripe_causal)
Decodes one codeblock, processing the cleanup, siginificance propagation, and magnitude refinement pa...
@ X86_CPU_EXT_LEVEL_AVX2
Definition: ojph_arch.h:138
@ X86_CPU_EXT_LEVEL_AVX
Definition: ojph_arch.h:137
@ X86_CPU_EXT_LEVEL_AVX512
Definition: ojph_arch.h:140
@ X86_CPU_EXT_LEVEL_SSE2
Definition: ojph_arch.h:132
@ X86_CPU_EXT_LEVEL_SSE
Definition: ojph_arch.h:131
@ X86_CPU_EXT_LEVEL_SSSE3
Definition: ojph_arch.h:134
uint64_t ui64
Definition: ojph_defs.h:56
OJPH_EXPORT int get_cpu_ext_level()
Definition: ojph_arch.cpp:244
uint32_t ui32
Definition: ojph_defs.h:54
#define ojph_unused(x)
Definition: ojph_defs.h:78
find_max_val_fun32 find_max_val32
find_max_val_fun64 find_max_val64