OpenJPH
Open-source implementation of JPEG2000 Part-15
Loading...
Searching...
No Matches
ojph_transform_avx.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_transform_avx.cpp
34// Author: Aous Naman
35// Date: 28 August 2019
36//***************************************************************************/
37
38#include <cstdio>
39
40#include "ojph_defs.h"
41#include "ojph_arch.h"
42#include "ojph_mem.h"
43#include "ojph_transform.h"
45
46#include <immintrin.h>
47
48namespace ojph {
49 namespace local {
50
53 const line_buf* line_src2,
56 {
57 float *dst = line_dst->f32;
58 const float *src1 = line_src1->f32, *src2 = line_src2->f32;
59
61 for (ui32 i = (repeat + 7) >> 3; i > 0; --i, dst+=8, src1+=8, src2+=8)
62 {
68 }
69 }
70
74 {
75 float *dst = line_dst->f32;
76 const float *src = line_src->f32;
77
81 for (ui32 i = (repeat + 7) >> 3; i > 0; --i, dst+=8, src+=8)
82 {
85 }
86 }
87
88
91 line_buf *line_hdst, ui32 width,
92 bool even)
93 {
94 if (width > 1)
95 {
96 float *src = line_src->f32;
97 float *ldst = line_ldst->f32, *hdst = line_hdst->f32;
98
99 const ui32 L_width = (width + (even ? 1 : 0)) >> 1;
100 const ui32 H_width = (width + (even ? 0 : 1)) >> 1;
101
102 //extension
103 src[-1] = src[1];
104 src[width] = src[width-2];
105 // predict
106 const float* sp = src + (even ? 1 : 0);
107 float *dph = hdst;
109 for (ui32 i = (H_width + 3) >> 2; i > 0; --i)
110 { //this is doing twice the work it needs to do
111 //it can be definitely written better
117 sp += 8;
120 __m128 t = _mm_shuffle_ps(t1, t2, _MM_SHUFFLE(2, 0, 2, 0));
122 dph += 4;
123 }
124
125 // extension
126 hdst[-1] = hdst[0];
127 hdst[H_width] = hdst[H_width-1];
128 // update
130 sp = src + (even ? 0 : 1);
131 const float* sph = hdst + (even ? 0 : 1);
132 float *dpl = ldst;
133 for (ui32 i = (L_width + 3) >> 2; i > 0; --i, sp+=8, sph+=4, dpl+=4)
134 {
135 __m256 d1 = _mm256_loadu_ps(sp); //is there an advantage here?
138 __m128 d = _mm_shuffle_ps(t1, t2, _MM_SHUFFLE(2, 0, 2, 0));
139
140 __m128 s1 = _mm_loadu_ps(sph - 1);
143 d = _mm_add_ps(d, s1);
145 }
146
147 //extension
148 ldst[-1] = ldst[0];
149 ldst[L_width] = ldst[L_width-1];
150 //predict
152 const float* spl = ldst + (even ? 1 : 0);
153 dph = hdst;
154 for (ui32 i = (H_width + 7) >> 3; i > 0; --i, spl+=8, dph+=8)
155 {
160 d = _mm256_add_ps(d, s1);
162 }
163
164 // extension
165 hdst[-1] = hdst[0];
166 hdst[H_width] = hdst[H_width-1];
167 // update
169 sph = hdst + (even ? 0 : 1);
170 dpl = ldst;
171 for (ui32 i = (L_width + 7) >> 3; i > 0; --i, sph+=8, dpl+=8)
172 {
177 d = _mm256_add_ps(d, s1);
179 }
180
181 //multipliers
182 float *dp = ldst;
184 for (ui32 i = (L_width + 7) >> 3; i > 0; --i, dp+=8)
185 {
188 }
189 dp = hdst;
191 for (ui32 i = (H_width + 7) >> 3; i > 0; --i, dp+=8)
192 {
195 }
196 }
197 else
198 {
199 if (even)
200 line_ldst->f32[0] = line_src->f32[0];
201 else
202 line_hdst->f32[0] = line_src->f32[0] + line_src->f32[0];
203 }
204 }
205
208 line_buf *line_hsrc, ui32 width,
209 bool even)
210 {
211 if (width > 1)
212 {
213 float *lsrc = line_lsrc->f32, *hsrc = line_hsrc->f32;
214 float *dst = line_dst->f32;
215
216 const ui32 L_width = (width + (even ? 1 : 0)) >> 1;
217 const ui32 H_width = (width + (even ? 0 : 1)) >> 1;
218
219 //multipliers
220 float *dp = lsrc;
222 for (ui32 i = (L_width + 7) >> 3; i > 0; --i, dp+=8)
223 {
226 }
227 dp = hsrc;
229 for (ui32 i = (H_width + 7) >> 3; i > 0; --i, dp+=8)
230 {
233 }
234
235 //extension
236 hsrc[-1] = hsrc[0];
237 hsrc[H_width] = hsrc[H_width-1];
238 //inverse update
240 const float *sph = hsrc + (even ? 0 : 1);
241 float *dpl = lsrc;
242 for (ui32 i = (L_width + 7) >> 3; i > 0; --i, sph+=8, dpl+=8)
243 {
248 d = _mm256_add_ps(d, s1);
250 }
251
252 //extension
253 lsrc[-1] = lsrc[0];
254 lsrc[L_width] = lsrc[L_width-1];
255 //inverse perdict
257 const float *spl = lsrc + (even ? 0 : -1);
258 float *dph = hsrc;
259 for (ui32 i = (H_width + 7) >> 3; i > 0; --i, dph+=8, spl+=8)
260 {
265 d = _mm256_add_ps(d, s1);
267 }
268
269 //extension
270 hsrc[-1] = hsrc[0];
271 hsrc[H_width] = hsrc[H_width-1];
272 //inverse update
274 sph = hsrc + (even ? 0 : 1);
275 dpl = lsrc;
276 for (ui32 i = (L_width + 7) >> 3; i > 0; --i, dpl+=8, sph+=8)
277 {
282 d = _mm256_add_ps(d, s1);
284 }
285
286 //extension
287 lsrc[-1] = lsrc[0];
288 lsrc[L_width] = lsrc[L_width-1];
289 //inverse perdict and combine
291 dp = dst + (even ? 0 : -1);
292 spl = lsrc + (even ? 0 : -1);
293 sph = hsrc;
294 ui32 width = L_width + (even ? 0 : 1);
295 for (ui32 i = (width + 7) >> 3; i > 0; --i, spl+=8, sph+=8)
296 {
301 d = _mm256_add_ps(d, s2);
302
311
312// s2 = _mm256_unpackhi_ps(s1, d);
313// s1 = _mm256_unpacklo_ps(s1, d);
314// d = _mm256_permute2f128_ps(s1, s2, (2 << 4) | 0);
315// _mm256_storeu_ps(dp, d);
316// d = _mm256_permute2f128_ps(s1, s2, (3 << 4) | 1);
317// _mm256_storeu_ps(dp + 1, d);
318 }
319 }
320 else
321 {
322 if (even)
323 line_dst->f32[0] = line_lsrc->f32[0];
324 else
325 line_dst->f32[0] = line_hsrc->f32[0] * 0.5f;
326 }
327 }
328 }
329}
void avx_irrev_horz_wvlt_bwd_tx(line_buf *line_dst, line_buf *line_lsrc, line_buf *line_hsrc, ui32 width, bool even)
void avx_irrev_horz_wvlt_fwd_tx(line_buf *line_src, line_buf *line_ldst, line_buf *line_hdst, ui32 width, bool even)
void avx_irrev_vert_wvlt_K(const line_buf *line_src, line_buf *line_dst, bool L_analysis_or_H_synthesis, ui32 repeat)
void avx_irrev_vert_wvlt_step(const line_buf *line_src1, const line_buf *line_src2, line_buf *line_dst, int step_num, ui32 repeat)
uint32_t ui32
Definition ojph_defs.h:54