Blame thirdparty/libjpeg-turbo/libjpeg-turbo-2.0.6/simd/loongson/jcsample-mmi.c

shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Loongson MMI optimizations for libjpeg-turbo
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * Copyright (C) 2015, 2018, D. R. Commander.  All Rights Reserved.
shun-iwasawa 82a8f5
 * Copyright (C) 2016-2017, Loongson Technology Corporation Limited, BeiJing.
shun-iwasawa 82a8f5
 *                          All Rights Reserved.
shun-iwasawa 82a8f5
 * Authors:  ZhuChen     <zhuchen@loongson.cn></zhuchen@loongson.cn>
shun-iwasawa 82a8f5
 *           CaiWanwei   <caiwanwei@loongson.cn></caiwanwei@loongson.cn>
shun-iwasawa 82a8f5
 *           SunZhangzhi <sunzhangzhi-cq@loongson.cn></sunzhangzhi-cq@loongson.cn>
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * Based on the x86 SIMD extension for IJG JPEG library
shun-iwasawa 82a8f5
 * Copyright (C) 1999-2006, MIYASAKA Masaru.
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_mmi.h"
shun-iwasawa 82a8f5
#include "jcsample.h"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
void jsimd_h2v2_downsample_mmi(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, bias;
shun-iwasawa 82a8f5
  JDIMENSION output_cols = width_in_blocks * DCTSIZE;
shun-iwasawa 82a8f5
  JSAMPROW inptr0, inptr1, outptr;
shun-iwasawa 82a8f5
  __m64 mm0, mm1, mm2, mm3, mm4, mm5, mm6 = 0.0, mm7;
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
  bias = (1 << 17) + 1;                      /* 0x00020001 (bias pattern) */
shun-iwasawa 82a8f5
  mm7 = _mm_set1_pi32(bias);                 /* mm7={1, 2, 1, 2} */
shun-iwasawa 82a8f5
  mm6 = _mm_cmpeq_pi16(mm6, mm6);
shun-iwasawa 82a8f5
  mm6 = _mm_srli_pi16(mm6, BYTE_BIT);        /* mm6={0xFF 0x00 0xFF 0x00 ..} */
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 -= 8, inptr0 += 16, inptr1 += 16, outptr += 8) {
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm0 = _mm_load_si64((__m64 *)&inptr0[0]);
shun-iwasawa 82a8f5
      mm1 = _mm_load_si64((__m64 *)&inptr1[0]);
shun-iwasawa 82a8f5
      mm2 = _mm_load_si64((__m64 *)&inptr0[8]);
shun-iwasawa 82a8f5
      mm3 = _mm_load_si64((__m64 *)&inptr1[8]);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm4 = mm0;
shun-iwasawa 82a8f5
      mm5 = mm1;
shun-iwasawa 82a8f5
      mm0 = _mm_and_si64(mm0, mm6);
shun-iwasawa 82a8f5
      mm4 = _mm_srli_pi16(mm4, BYTE_BIT);
shun-iwasawa 82a8f5
      mm1 = _mm_and_si64(mm1, mm6);
shun-iwasawa 82a8f5
      mm5 = _mm_srli_pi16(mm5, BYTE_BIT);
shun-iwasawa 82a8f5
      mm0 = _mm_add_pi16(mm0, mm4);
shun-iwasawa 82a8f5
      mm1 = _mm_add_pi16(mm1, mm5);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm4 = mm2;
shun-iwasawa 82a8f5
      mm5 = mm3;
shun-iwasawa 82a8f5
      mm2 = _mm_and_si64(mm2, mm6);
shun-iwasawa 82a8f5
      mm4 = _mm_srli_pi16(mm4, BYTE_BIT);
shun-iwasawa 82a8f5
      mm3 = _mm_and_si64(mm3, mm6);
shun-iwasawa 82a8f5
      mm5 = _mm_srli_pi16(mm5, BYTE_BIT);
shun-iwasawa 82a8f5
      mm2 = _mm_add_pi16(mm2, mm4);
shun-iwasawa 82a8f5
      mm3 = _mm_add_pi16(mm3, mm5);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm0 = _mm_add_pi16(mm0, mm1);
shun-iwasawa 82a8f5
      mm2 = _mm_add_pi16(mm2, mm3);
shun-iwasawa 82a8f5
      mm0 = _mm_add_pi16(mm0, mm7);
shun-iwasawa 82a8f5
      mm2 = _mm_add_pi16(mm2, mm7);
shun-iwasawa 82a8f5
      mm0 = _mm_srli_pi16(mm0, 2);
shun-iwasawa 82a8f5
      mm2 = _mm_srli_pi16(mm2, 2);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm0 = _mm_packs_pu16(mm0, mm2);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      _mm_store_si64((__m64 *)&outptr[0], mm0);
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}