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
66 ui32 gen_find_max_val(ui32* address);
67 ui32 sse2_find_max_val(ui32* address);
68 ui32 avx2_find_max_val(ui32* address);
69 ui32 wasm_find_max_val(ui32* address);
70
72 void gen_rev_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max,
73 float delta_inv, ui32 count, ui32* max_val);
74 void sse2_rev_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max,
75 float delta_inv, ui32 count, ui32* max_val);
76 void avx2_rev_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max,
77 float delta_inv, ui32 count, ui32* max_val);
78 void gen_irv_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max,
79 float delta_inv, ui32 count, ui32* max_val);
80 void sse2_irv_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max,
81 float delta_inv, ui32 count, ui32* max_val);
82 void avx2_irv_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max,
83 float delta_inv, ui32 count, ui32* max_val);
84 void wasm_rev_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max,
85 float delta_inv, ui32 count, ui32* max_val);
86 void wasm_irv_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max,
87 float delta_inv, ui32 count, ui32* max_val);
88
90 void gen_rev_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max,
91 float delta, ui32 count);
92 void sse2_rev_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max,
93 float delta, ui32 count);
94 void avx2_rev_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max,
95 float delta, ui32 count);
96 void gen_irv_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max,
97 float delta, ui32 count);
98 void sse2_irv_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max,
99 float delta, ui32 count);
100 void avx2_irv_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max,
101 float delta, ui32 count);
102 void wasm_rev_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max,
103 float delta, ui32 count);
104 void wasm_irv_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max,
105 float delta, ui32 count);
106
107
108 void codeblock_fun::init(bool reversible) {
109
110#if !defined(OJPH_ENABLE_WASM_SIMD) || !defined(OJPH_EMSCRIPTEN)
111
112 // Default path, no acceleration. We may change this later
116 if (reversible) {
119 }
120 else
121 {
124 }
126
127#ifndef OJPH_DISABLE_INTEL_SIMD
128
129 // Accelerated functions for INTEL/AMD CPUs
132
135 if (reversible) {
138 }
139 else {
142 }
143 }
144
147
148
151
154 if (reversible) {
157 }
158 else {
161 }
162 }
163
164#ifdef OJPH_ENABLE_INTEL_AVX512
167#endif // !OJPH_ENABLE_INTEL_AVX512
168
169#endif // !OJPH_DISABLE_INTEL_SIMD
170
171#else // OJPH_ENABLE_WASM_SIMD
172
173 // Accelerated functions for WASM SIMD.
177 if (reversible) {
180 }
181 else {
184 }
186
187#endif // !OJPH_ENABLE_WASM_SIMD
188
189 }
190 } // local
191} // 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...
ui32 avx2_find_max_val(ui32 *address)
void avx2_irv_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void gen_rev_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
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 sse2_irv_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void gen_rev_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void avx_mem_clear(void *addr, size_t count)
void gen_irv_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void gen_irv_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void wasm_irv_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void avx2_rev_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void wasm_irv_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void sse2_irv_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void gen_mem_clear(void *addr, size_t count)
void sse_mem_clear(void *addr, size_t count)
void wasm_rev_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void sse2_rev_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void sse2_rev_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void wasm_mem_clear(void *addr, size_t count)
ui32 sse2_find_max_val(ui32 *address)
void wasm_rev_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
void avx2_rev_tx_from_cb(const ui32 *sp, void *dp, ui32 K_max, float delta, ui32 count)
ui32 gen_find_max_val(ui32 *address)
bool ojph_decode_codeblock(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_irv_tx_to_cb(const void *sp, ui32 *dp, ui32 K_max, float delta_inv, ui32 count, ui32 *max_val)
void ojph_encode_codeblock(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_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)
ui32 wasm_find_max_val(ui32 *address)
@ X86_CPU_EXT_LEVEL_AVX2
Definition: ojph_arch.h:104
@ X86_CPU_EXT_LEVEL_AVX
Definition: ojph_arch.h:103
@ X86_CPU_EXT_LEVEL_AVX512
Definition: ojph_arch.h:106
@ X86_CPU_EXT_LEVEL_SSE2
Definition: ojph_arch.h:98
@ X86_CPU_EXT_LEVEL_SSE
Definition: ojph_arch.h:97
@ X86_CPU_EXT_LEVEL_SSSE3
Definition: ojph_arch.h:100
OJPH_EXPORT int get_cpu_ext_level()
Definition: ojph_arch.cpp:184
uint32_t ui32
Definition: ojph_defs.h:54