OpenJPH
Open-source implementation of JPEG2000 Part-15
Loading...
Searching...
No Matches
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
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 gen_irv_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max,
128 float delta, ui32 count);
129 void wasm_rev_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max,
130 float delta, ui32 count);
131
132 void codeblock_fun::init(bool reversible) {
133
134#if !defined(OJPH_ENABLE_WASM_SIMD) || !defined(OJPH_EMSCRIPTEN)
135
136 // Default path, no acceleration. We may change this later
140 if (reversible) {
143 }
144 else
145 {
148 }
150
153 if (reversible) {
156 }
157 else
158 {
159 tx_to_cb64 = NULL;
161 }
163 bool result = initialize_block_encoder_tables();
164 assert(result); ojph_unused(result);
165
166 #ifndef OJPH_DISABLE_SIMD
167
168 #if (defined(OJPH_ARCH_X86_64) || defined(OJPH_ARCH_I386))
169
170 // Accelerated functions for INTEL/AMD CPUs
171 #ifndef OJPH_DISABLE_SSE
174 #endif // !OJPH_DISABLE_SSE
175
176 #ifndef OJPH_DISABLE_SSE2
179 if (reversible) {
182 }
183 else {
186 }
188 if (reversible) {
191 }
192 else
193 {
194 tx_to_cb64 = NULL;
196 }
197 }
198 #endif // !OJPH_DISABLE_SSE2
199
200 #ifndef OJPH_DISABLE_SSSE3
203 #endif // !OJPH_DISABLE_SSSE3
204
205 #ifndef OJPH_DISABLE_AVX
208 #endif // !OJPH_DISABLE_AVX
209
210 #ifndef OJPH_DISABLE_AVX2
214 if (reversible) {
217 }
218 else {
221 }
224 assert(result); ojph_unused(result);
225
227 if (reversible) {
230 }
231 else
232 {
233 tx_to_cb64 = NULL;
235 }
236 }
237 #endif // !OJPH_DISABLE_AVX2
238
239 #if (defined(OJPH_ARCH_X86_64) && !defined(OJPH_DISABLE_AVX512))
243 assert(result); ojph_unused(result);
244 }
245 #endif // !OJPH_DISABLE_AVX512
246
247 #elif defined(OJPH_ARCH_ARM)
248
249 #endif // !(defined(OJPH_ARCH_X86_64) || defined(OJPH_ARCH_I386))
250
251 #endif // !OJPH_DISABLE_SIMD
252
253#else // OJPH_ENABLE_WASM_SIMD
254
255 // Accelerated functions for WASM SIMD.
259 if (reversible) {
262 }
263 else {
266 }
268
271 if (reversible) {
274 }
275 else
276 {
277 tx_to_cb64 = NULL;
279 }
281 bool result = initialize_block_encoder_tables();
282 assert(result); ojph_unused(result);
283
284#endif // !OJPH_ENABLE_WASM_SIMD
285
286 }
287 } // local
288} // ojph
void gen_irv_tx_from_cb64(const ui64 *sp, void *dp, ui32 K_max, float delta, ui32 count)
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)
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)
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...
uint64_t ui64
Definition ojph_defs.h:56
OJPH_EXPORT int get_cpu_ext_level()
uint32_t ui32
Definition ojph_defs.h:54
@ X86_CPU_EXT_LEVEL_AVX2
Definition ojph_arch.h:142
@ X86_CPU_EXT_LEVEL_AVX
Definition ojph_arch.h:141
@ X86_CPU_EXT_LEVEL_AVX512
Definition ojph_arch.h:144
@ X86_CPU_EXT_LEVEL_SSE2
Definition ojph_arch.h:136
@ X86_CPU_EXT_LEVEL_SSE
Definition ojph_arch.h:135
@ X86_CPU_EXT_LEVEL_SSSE3
Definition ojph_arch.h:138
#define ojph_unused(x)
Definition ojph_defs.h:78
find_max_val_fun32 find_max_val32
find_max_val_fun64 find_max_val64