|
shun-iwasawa |
82a8f5 |
/*
|
|
shun-iwasawa |
82a8f5 |
* AltiVec optimizations for libjpeg-turbo
|
|
shun-iwasawa |
82a8f5 |
*
|
|
shun-iwasawa |
82a8f5 |
* Copyright (C) 2015, D. R. Commander. All Rights Reserved.
|
|
shun-iwasawa |
82a8f5 |
*
|
|
shun-iwasawa |
82a8f5 |
* This software is provided 'as-is', without any express or implied
|
|
shun-iwasawa |
82a8f5 |
* warranty. In no event will the authors be held liable for any damages
|
|
shun-iwasawa |
82a8f5 |
* arising from the use of this software.
|
|
shun-iwasawa |
82a8f5 |
*
|
|
shun-iwasawa |
82a8f5 |
* Permission is granted to anyone to use this software for any purpose,
|
|
shun-iwasawa |
82a8f5 |
* including commercial applications, and to alter it and redistribute it
|
|
shun-iwasawa |
82a8f5 |
* freely, subject to the following restrictions:
|
|
shun-iwasawa |
82a8f5 |
*
|
|
shun-iwasawa |
82a8f5 |
* 1. The origin of this software must not be misrepresented; you must not
|
|
shun-iwasawa |
82a8f5 |
* claim that you wrote the original software. If you use this software
|
|
shun-iwasawa |
82a8f5 |
* in a product, an acknowledgment in the product documentation would be
|
|
shun-iwasawa |
82a8f5 |
* appreciated but is not required.
|
|
shun-iwasawa |
82a8f5 |
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
shun-iwasawa |
82a8f5 |
* misrepresented as being the original software.
|
|
shun-iwasawa |
82a8f5 |
* 3. This notice may not be removed or altered from any source distribution.
|
|
shun-iwasawa |
82a8f5 |
*/
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* CHROMA DOWNSAMPLING */
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
#include "jsimd_altivec.h"
|
|
shun-iwasawa |
82a8f5 |
#include "jcsample.h"
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
void jsimd_h2v1_downsample_altivec(JDIMENSION image_width,
|
|
shun-iwasawa |
82a8f5 |
int max_v_samp_factor,
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION v_samp_factor,
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION width_in_blocks,
|
|
shun-iwasawa |
82a8f5 |
JSAMPARRAY input_data,
|
|
shun-iwasawa |
82a8f5 |
JSAMPARRAY output_data)
|
|
shun-iwasawa |
82a8f5 |
{
|
|
shun-iwasawa |
82a8f5 |
int outrow, outcol;
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION output_cols = width_in_blocks * DCTSIZE;
|
|
shun-iwasawa |
82a8f5 |
JSAMPROW inptr, outptr;
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
__vector unsigned char this0, next0, out;
|
|
shun-iwasawa |
82a8f5 |
__vector unsigned short this0e, this0o, next0e, next0o, outl, outh;
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Constants */
|
|
shun-iwasawa |
82a8f5 |
__vector unsigned short pw_bias = { __4X2(0, 1) },
|
|
shun-iwasawa |
82a8f5 |
pw_one = { __8X(1) };
|
|
shun-iwasawa |
82a8f5 |
__vector unsigned char even_odd_index =
|
|
shun-iwasawa |
82a8f5 |
{ 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15 },
|
|
shun-iwasawa |
82a8f5 |
pb_zero = { __16X(0) };
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
expand_right_edge(input_data, max_v_samp_factor, image_width,
|
|
shun-iwasawa |
82a8f5 |
output_cols * 2);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
for (outrow = 0; outrow < v_samp_factor; outrow++) {
|
|
shun-iwasawa |
82a8f5 |
outptr = output_data[outrow];
|
|
shun-iwasawa |
82a8f5 |
inptr = input_data[outrow];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
for (outcol = output_cols; outcol > 0;
|
|
shun-iwasawa |
82a8f5 |
outcol -= 16, inptr += 32, outptr += 16) {
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
this0 = vec_ld(0, inptr);
|
|
shun-iwasawa |
82a8f5 |
this0 = vec_perm(this0, this0, even_odd_index);
|
|
shun-iwasawa |
82a8f5 |
this0e = (__vector unsigned short)VEC_UNPACKHU(this0);
|
|
shun-iwasawa |
82a8f5 |
this0o = (__vector unsigned short)VEC_UNPACKLU(this0);
|
|
shun-iwasawa |
82a8f5 |
outl = vec_add(this0e, this0o);
|
|
shun-iwasawa |
82a8f5 |
outl = vec_add(outl, pw_bias);
|
|
shun-iwasawa |
82a8f5 |
outl = vec_sr(outl, pw_one);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
if (outcol > 8) {
|
|
shun-iwasawa |
82a8f5 |
next0 = vec_ld(16, inptr);
|
|
shun-iwasawa |
82a8f5 |
next0 = vec_perm(next0, next0, even_odd_index);
|
|
shun-iwasawa |
82a8f5 |
next0e = (__vector unsigned short)VEC_UNPACKHU(next0);
|
|
shun-iwasawa |
82a8f5 |
next0o = (__vector unsigned short)VEC_UNPACKLU(next0);
|
|
shun-iwasawa |
82a8f5 |
outh = vec_add(next0e, next0o);
|
|
shun-iwasawa |
82a8f5 |
outh = vec_add(outh, pw_bias);
|
|
shun-iwasawa |
82a8f5 |
outh = vec_sr(outh, pw_one);
|
|
shun-iwasawa |
82a8f5 |
} else
|
|
shun-iwasawa |
82a8f5 |
outh = vec_splat_u16(0);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
out = vec_pack(outl, outh);
|
|
shun-iwasawa |
82a8f5 |
vec_st(out, 0, outptr);
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
void
|
|
shun-iwasawa |
82a8f5 |
jsimd_h2v2_downsample_altivec(JDIMENSION image_width, int max_v_samp_factor,
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION v_samp_factor,
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION width_in_blocks,
|
|
shun-iwasawa |
82a8f5 |
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
|
shun-iwasawa |
82a8f5 |
{
|
|
shun-iwasawa |
82a8f5 |
int inrow, outrow, outcol;
|
|
shun-iwasawa |
82a8f5 |
JDIMENSION output_cols = width_in_blocks * DCTSIZE;
|
|
shun-iwasawa |
82a8f5 |
JSAMPROW inptr0, inptr1, outptr;
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
__vector unsigned char this0, next0, this1, next1, out;
|
|
shun-iwasawa |
82a8f5 |
__vector unsigned short this0e, this0o, next0e, next0o, this1e, this1o,
|
|
shun-iwasawa |
82a8f5 |
next1e, next1o, out0l, out0h, out1l, out1h, outl, outh;
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
/* Constants */
|
|
shun-iwasawa |
82a8f5 |
__vector unsigned short pw_bias = { __4X2(1, 2) },
|
|
shun-iwasawa |
82a8f5 |
pw_two = { __8X(2) };
|
|
shun-iwasawa |
82a8f5 |
__vector unsigned char even_odd_index =
|
|
shun-iwasawa |
82a8f5 |
{ 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15 },
|
|
shun-iwasawa |
82a8f5 |
pb_zero = { __16X(0) };
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
expand_right_edge(input_data, max_v_samp_factor, image_width,
|
|
shun-iwasawa |
82a8f5 |
output_cols * 2);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
for (inrow = 0, outrow = 0; outrow < v_samp_factor;
|
|
shun-iwasawa |
82a8f5 |
inrow += 2, outrow++) {
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
inptr0 = input_data[inrow];
|
|
shun-iwasawa |
82a8f5 |
inptr1 = input_data[inrow + 1];
|
|
shun-iwasawa |
82a8f5 |
outptr = output_data[outrow];
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
for (outcol = output_cols; outcol > 0;
|
|
shun-iwasawa |
82a8f5 |
outcol -= 16, inptr0 += 32, inptr1 += 32, outptr += 16) {
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
this0 = vec_ld(0, inptr0);
|
|
shun-iwasawa |
82a8f5 |
this0 = vec_perm(this0, this0, even_odd_index);
|
|
shun-iwasawa |
82a8f5 |
this0e = (__vector unsigned short)VEC_UNPACKHU(this0);
|
|
shun-iwasawa |
82a8f5 |
this0o = (__vector unsigned short)VEC_UNPACKLU(this0);
|
|
shun-iwasawa |
82a8f5 |
out0l = vec_add(this0e, this0o);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
this1 = vec_ld(0, inptr1);
|
|
shun-iwasawa |
82a8f5 |
this1 = vec_perm(this1, this1, even_odd_index);
|
|
shun-iwasawa |
82a8f5 |
this1e = (__vector unsigned short)VEC_UNPACKHU(this1);
|
|
shun-iwasawa |
82a8f5 |
this1o = (__vector unsigned short)VEC_UNPACKLU(this1);
|
|
shun-iwasawa |
82a8f5 |
out1l = vec_add(this1e, this1o);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
outl = vec_add(out0l, out1l);
|
|
shun-iwasawa |
82a8f5 |
outl = vec_add(outl, pw_bias);
|
|
shun-iwasawa |
82a8f5 |
outl = vec_sr(outl, pw_two);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
if (outcol > 8) {
|
|
shun-iwasawa |
82a8f5 |
next0 = vec_ld(16, inptr0);
|
|
shun-iwasawa |
82a8f5 |
next0 = vec_perm(next0, next0, even_odd_index);
|
|
shun-iwasawa |
82a8f5 |
next0e = (__vector unsigned short)VEC_UNPACKHU(next0);
|
|
shun-iwasawa |
82a8f5 |
next0o = (__vector unsigned short)VEC_UNPACKLU(next0);
|
|
shun-iwasawa |
82a8f5 |
out0h = vec_add(next0e, next0o);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
next1 = vec_ld(16, inptr1);
|
|
shun-iwasawa |
82a8f5 |
next1 = vec_perm(next1, next1, even_odd_index);
|
|
shun-iwasawa |
82a8f5 |
next1e = (__vector unsigned short)VEC_UNPACKHU(next1);
|
|
shun-iwasawa |
82a8f5 |
next1o = (__vector unsigned short)VEC_UNPACKLU(next1);
|
|
shun-iwasawa |
82a8f5 |
out1h = vec_add(next1e, next1o);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
outh = vec_add(out0h, out1h);
|
|
shun-iwasawa |
82a8f5 |
outh = vec_add(outh, pw_bias);
|
|
shun-iwasawa |
82a8f5 |
outh = vec_sr(outh, pw_two);
|
|
shun-iwasawa |
82a8f5 |
} else
|
|
shun-iwasawa |
82a8f5 |
outh = vec_splat_u16(0);
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
out = vec_pack(outl, outh);
|
|
shun-iwasawa |
82a8f5 |
vec_st(out, 0, outptr);
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
}
|
|
shun-iwasawa |
82a8f5 |
}
|