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

shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Loongson MMI optimizations for libjpeg-turbo
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB</ossman@cendio.se>
shun-iwasawa 82a8f5
 * Copyright (C) 2015, 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
 *           SunZhangzhi <sunzhangzhi-cq@loongson.cn></sunzhangzhi-cq@loongson.cn>
shun-iwasawa 82a8f5
 *           CaiWanwei   <caiwanwei@loongson.cn></caiwanwei@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
/* This file is included by jdcolor-mmi.c */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#if RGB_RED == 0
shun-iwasawa 82a8f5
#define mmA  mm0
shun-iwasawa 82a8f5
#define mmB  mm1
shun-iwasawa 82a8f5
#elif RGB_GREEN == 0
shun-iwasawa 82a8f5
#define mmA  mm2
shun-iwasawa 82a8f5
#define mmB  mm3
shun-iwasawa 82a8f5
#elif RGB_BLUE == 0
shun-iwasawa 82a8f5
#define mmA  mm4
shun-iwasawa 82a8f5
#define mmB  mm5
shun-iwasawa 82a8f5
#else
shun-iwasawa 82a8f5
#define mmA  mm6
shun-iwasawa 82a8f5
#define mmB  mm7
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#if RGB_RED == 1
shun-iwasawa 82a8f5
#define mmC  mm0
shun-iwasawa 82a8f5
#define mmD  mm1
shun-iwasawa 82a8f5
#elif RGB_GREEN == 1
shun-iwasawa 82a8f5
#define mmC  mm2
shun-iwasawa 82a8f5
#define mmD  mm3
shun-iwasawa 82a8f5
#elif RGB_BLUE == 1
shun-iwasawa 82a8f5
#define mmC  mm4
shun-iwasawa 82a8f5
#define mmD  mm5
shun-iwasawa 82a8f5
#else
shun-iwasawa 82a8f5
#define mmC  mm6
shun-iwasawa 82a8f5
#define mmD  mm7
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#if RGB_RED == 2
shun-iwasawa 82a8f5
#define mmE  mm0
shun-iwasawa 82a8f5
#define mmF  mm1
shun-iwasawa 82a8f5
#elif RGB_GREEN == 2
shun-iwasawa 82a8f5
#define mmE  mm2
shun-iwasawa 82a8f5
#define mmF  mm3
shun-iwasawa 82a8f5
#elif RGB_BLUE == 2
shun-iwasawa 82a8f5
#define mmE  mm4
shun-iwasawa 82a8f5
#define mmF  mm5
shun-iwasawa 82a8f5
#else
shun-iwasawa 82a8f5
#define mmE  mm6
shun-iwasawa 82a8f5
#define mmF  mm7
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#if RGB_RED == 3
shun-iwasawa 82a8f5
#define mmG  mm0
shun-iwasawa 82a8f5
#define mmH  mm1
shun-iwasawa 82a8f5
#elif RGB_GREEN == 3
shun-iwasawa 82a8f5
#define mmG  mm2
shun-iwasawa 82a8f5
#define mmH  mm3
shun-iwasawa 82a8f5
#elif RGB_BLUE == 3
shun-iwasawa 82a8f5
#define mmG  mm4
shun-iwasawa 82a8f5
#define mmH  mm5
shun-iwasawa 82a8f5
#else
shun-iwasawa 82a8f5
#define mmG  mm6
shun-iwasawa 82a8f5
#define mmH  mm7
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
void jsimd_ycc_rgb_convert_mmi(JDIMENSION out_width, JSAMPIMAGE input_buf,
shun-iwasawa 82a8f5
                               JDIMENSION input_row, JSAMPARRAY output_buf,
shun-iwasawa 82a8f5
                               int num_rows)
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
  JSAMPROW outptr, inptr0, inptr1, inptr2;
shun-iwasawa 82a8f5
  int num_cols, col;
shun-iwasawa 82a8f5
  __m64 mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7;
shun-iwasawa 82a8f5
  __m64 mm8, wk[2];
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  while (--num_rows >= 0) {
shun-iwasawa 82a8f5
    inptr0 = input_buf[0][input_row];
shun-iwasawa 82a8f5
    inptr1 = input_buf[1][input_row];
shun-iwasawa 82a8f5
    inptr2 = input_buf[2][input_row];
shun-iwasawa 82a8f5
    input_row++;
shun-iwasawa 82a8f5
    outptr = *output_buf++;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    for (num_cols = out_width; num_cols > 0; num_cols -= 8,
shun-iwasawa 82a8f5
         inptr0 += 8, inptr1 += 8, inptr2 += 8) {
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm5 = _mm_load_si64((__m64 *)inptr1);
shun-iwasawa 82a8f5
      mm1 = _mm_load_si64((__m64 *)inptr2);
shun-iwasawa 82a8f5
      mm8 = _mm_load_si64((__m64 *)inptr0);
shun-iwasawa 82a8f5
      mm4 = 0;
shun-iwasawa 82a8f5
      mm7 = 0;
shun-iwasawa 82a8f5
      mm4 = _mm_cmpeq_pi16(mm4, mm4);
shun-iwasawa 82a8f5
      mm7 = _mm_cmpeq_pi16(mm7, mm7);
shun-iwasawa 82a8f5
      mm4 = _mm_srli_pi16(mm4, BYTE_BIT);
shun-iwasawa 82a8f5
      mm7 = _mm_slli_pi16(mm7, 7);      /* mm7={0xFF80 0xFF80 0xFF80 0xFF80} */
shun-iwasawa 82a8f5
      mm0 = mm4;                        /* mm0=mm4={0xFF 0x00 0xFF 0x00 ..} */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm4 = _mm_and_si64(mm4, mm5);           /* mm4=Cb(0246)=CbE */
shun-iwasawa 82a8f5
      mm5 = _mm_srli_pi16(mm5, BYTE_BIT);     /* mm5=Cb(1357)=CbO */
shun-iwasawa 82a8f5
      mm0 = _mm_and_si64(mm0, mm1);           /* mm0=Cr(0246)=CrE */
shun-iwasawa 82a8f5
      mm1 = _mm_srli_pi16(mm1, BYTE_BIT);     /* mm1=Cr(1357)=CrO */
shun-iwasawa 82a8f5
      mm4 = _mm_add_pi16(mm4, mm7);
shun-iwasawa 82a8f5
      mm5 = _mm_add_pi16(mm5, mm7);
shun-iwasawa 82a8f5
      mm0 = _mm_add_pi16(mm0, mm7);
shun-iwasawa 82a8f5
      mm1 = _mm_add_pi16(mm1, mm7);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      /* (Original)
shun-iwasawa 82a8f5
       * R = Y                + 1.40200 * Cr
shun-iwasawa 82a8f5
       * G = Y - 0.34414 * Cb - 0.71414 * Cr
shun-iwasawa 82a8f5
       * B = Y + 1.77200 * Cb
shun-iwasawa 82a8f5
       *
shun-iwasawa 82a8f5
       * (This implementation)
shun-iwasawa 82a8f5
       * R = Y                + 0.40200 * Cr + Cr
shun-iwasawa 82a8f5
       * G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
shun-iwasawa 82a8f5
       * B = Y - 0.22800 * Cb + Cb + Cb
shun-iwasawa 82a8f5
       */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm2 = mm4;                              /* mm2 = CbE */
shun-iwasawa 82a8f5
      mm3 = mm5;                              /* mm3 = CbO */
shun-iwasawa 82a8f5
      mm4 = _mm_add_pi16(mm4, mm4);           /* mm4 = 2*CbE */
shun-iwasawa 82a8f5
      mm5 = _mm_add_pi16(mm5, mm5);           /* mm5 = 2*CbO */
shun-iwasawa 82a8f5
      mm6 = mm0;                              /* mm6 = CrE */
shun-iwasawa 82a8f5
      mm7 = mm1;                              /* mm7 = CrO */
shun-iwasawa 82a8f5
      mm0 = _mm_add_pi16(mm0, mm0);           /* mm0 = 2*CrE */
shun-iwasawa 82a8f5
      mm1 = _mm_add_pi16(mm1, mm1);           /* mm1 = 2*CrO */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm4 = _mm_mulhi_pi16(mm4, PW_MF0228);   /* mm4=(2*CbE * -FIX(0.22800) */
shun-iwasawa 82a8f5
      mm5 = _mm_mulhi_pi16(mm5, PW_MF0228);   /* mm5=(2*CbO * -FIX(0.22800) */
shun-iwasawa 82a8f5
      mm0 = _mm_mulhi_pi16(mm0, PW_F0402);    /* mm0=(2*CrE * FIX(0.40200)) */
shun-iwasawa 82a8f5
      mm1 = _mm_mulhi_pi16(mm1, PW_F0402);    /* mm1=(2*CrO * FIX(0.40200)) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm4 = _mm_add_pi16(mm4, PW_ONE);
shun-iwasawa 82a8f5
      mm5 = _mm_add_pi16(mm5, PW_ONE);
shun-iwasawa 82a8f5
      mm4 = _mm_srai_pi16(mm4, 1);            /* mm4=(CbE * -FIX(0.22800)) */
shun-iwasawa 82a8f5
      mm5 = _mm_srai_pi16(mm5, 1);            /* mm5=(CbO * -FIX(0.22800)) */
shun-iwasawa 82a8f5
      mm0 = _mm_add_pi16(mm0, PW_ONE);
shun-iwasawa 82a8f5
      mm1 = _mm_add_pi16(mm1, PW_ONE);
shun-iwasawa 82a8f5
      mm0 = _mm_srai_pi16(mm0, 1);            /* mm0=(CrE * FIX(0.40200)) */
shun-iwasawa 82a8f5
      mm1 = _mm_srai_pi16(mm1, 1);            /* mm1=(CrO * FIX(0.40200)) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm4 = _mm_add_pi16(mm4, mm2);
shun-iwasawa 82a8f5
      mm5 = _mm_add_pi16(mm5, mm3);
shun-iwasawa 82a8f5
      mm4 = _mm_add_pi16(mm4, mm2);       /* mm4=(CbE * FIX(1.77200))=(B-Y)E */
shun-iwasawa 82a8f5
      mm5 = _mm_add_pi16(mm5, mm3);       /* mm5=(CbO * FIX(1.77200))=(B-Y)O */
shun-iwasawa 82a8f5
      mm0 = _mm_add_pi16(mm0, mm6);       /* mm0=(CrE * FIX(1.40200))=(R-Y)E */
shun-iwasawa 82a8f5
      mm1 = _mm_add_pi16(mm1, mm7);       /* mm1=(CrO * FIX(1.40200))=(R-Y)O */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      wk[0] = mm4;                            /* wk(0)=(B-Y)E */
shun-iwasawa 82a8f5
      wk[1] = mm5;                            /* wk(1)=(B-Y)O */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm4 = mm2;
shun-iwasawa 82a8f5
      mm5 = mm3;
shun-iwasawa 82a8f5
      mm2 = _mm_unpacklo_pi16(mm2, mm6);
shun-iwasawa 82a8f5
      mm4 = _mm_unpackhi_pi16(mm4, mm6);
shun-iwasawa 82a8f5
      mm2 = _mm_madd_pi16(mm2, PW_MF0344_F0285);
shun-iwasawa 82a8f5
      mm4 = _mm_madd_pi16(mm4, PW_MF0344_F0285);
shun-iwasawa 82a8f5
      mm3 = _mm_unpacklo_pi16(mm3, mm7);
shun-iwasawa 82a8f5
      mm5 = _mm_unpackhi_pi16(mm5, mm7);
shun-iwasawa 82a8f5
      mm3 = _mm_madd_pi16(mm3, PW_MF0344_F0285);
shun-iwasawa 82a8f5
      mm5 = _mm_madd_pi16(mm5, PW_MF0344_F0285);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm2 = _mm_add_pi32(mm2, PD_ONEHALF);
shun-iwasawa 82a8f5
      mm4 = _mm_add_pi32(mm4, PD_ONEHALF);
shun-iwasawa 82a8f5
      mm2 = _mm_srai_pi32(mm2, SCALEBITS);
shun-iwasawa 82a8f5
      mm4 = _mm_srai_pi32(mm4, SCALEBITS);
shun-iwasawa 82a8f5
      mm3 = _mm_add_pi32(mm3, PD_ONEHALF);
shun-iwasawa 82a8f5
      mm5 = _mm_add_pi32(mm5, PD_ONEHALF);
shun-iwasawa 82a8f5
      mm3 = _mm_srai_pi32(mm3, SCALEBITS);
shun-iwasawa 82a8f5
      mm5 = _mm_srai_pi32(mm5, SCALEBITS);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm2 = _mm_packs_pi32(mm2, mm4);  /* mm2=CbE*-FIX(0.344)+CrE*FIX(0.285) */
shun-iwasawa 82a8f5
      mm3 = _mm_packs_pi32(mm3, mm5);  /* mm3=CbO*-FIX(0.344)+CrO*FIX(0.285) */
shun-iwasawa 82a8f5
      mm2 = _mm_sub_pi16(mm2, mm6);  /* mm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E */
shun-iwasawa 82a8f5
      mm3 = _mm_sub_pi16(mm3, mm7);  /* mm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm5 = mm8;                              /* mm5=Y(01234567) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm4 = _mm_cmpeq_pi16(mm4, mm4);
shun-iwasawa 82a8f5
      mm4 = _mm_srli_pi16(mm4, BYTE_BIT);    /* mm4={0xFF 0x00 0xFF 0x00 ..} */
shun-iwasawa 82a8f5
      mm4 = _mm_and_si64(mm4, mm5);          /* mm4=Y(0246)=YE */
shun-iwasawa 82a8f5
      mm5 = _mm_srli_pi16(mm5, BYTE_BIT);    /* mm5=Y(1357)=YO */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm0 = _mm_add_pi16(mm0, mm4);      /* mm0=((R-Y)E+YE)=RE=(R0 R2 R4 R6) */
shun-iwasawa 82a8f5
      mm1 = _mm_add_pi16(mm1, mm5);      /* mm1=((R-Y)O+YO)=RO=(R1 R3 R5 R7) */
shun-iwasawa 82a8f5
      mm0 = _mm_packs_pu16(mm0, mm0);    /* mm0=(R0 R2 R4 R6 ** ** ** **) */
shun-iwasawa 82a8f5
      mm1 = _mm_packs_pu16(mm1, mm1);    /* mm1=(R1 R3 R5 R7 ** ** ** **) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm2 = _mm_add_pi16(mm2, mm4);      /* mm2=((G-Y)E+YE)=GE=(G0 G2 G4 G6) */
shun-iwasawa 82a8f5
      mm3 = _mm_add_pi16(mm3, mm5);      /* mm3=((G-Y)O+YO)=GO=(G1 G3 G5 G7) */
shun-iwasawa 82a8f5
      mm2 = _mm_packs_pu16(mm2, mm2);    /* mm2=(G0 G2 G4 G6 ** ** ** **) */
shun-iwasawa 82a8f5
      mm3 = _mm_packs_pu16(mm3, mm3);    /* mm3=(G1 G3 G5 G7 ** ** ** **) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mm4 = _mm_add_pi16(mm4, wk[0]);    /* mm4=(YE+(B-Y)E)=BE=(B0 B2 B4 B6) */
shun-iwasawa 82a8f5
      mm5 = _mm_add_pi16(mm5, wk[1]);    /* mm5=(YO+(B-Y)O)=BO=(B1 B3 B5 B7) */
shun-iwasawa 82a8f5
      mm4 = _mm_packs_pu16(mm4, mm4);    /* mm4=(B0 B2 B4 B6 ** ** ** **) */
shun-iwasawa 82a8f5
      mm5 = _mm_packs_pu16(mm5, mm5);    /* mm5=(B1 B3 B5 B7 ** ** ** **) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#if RGB_PIXELSIZE == 3
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      /* mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **) */
shun-iwasawa 82a8f5
      /* mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **) */
shun-iwasawa 82a8f5
      mmA = _mm_unpacklo_pi8(mmA, mmC);     /* mmA=(00 10 02 12 04 14 06 16) */
shun-iwasawa 82a8f5
      mmE = _mm_unpacklo_pi8(mmE, mmB);     /* mmE=(20 01 22 03 24 05 26 07) */
shun-iwasawa 82a8f5
      mmD = _mm_unpacklo_pi8(mmD, mmF);     /* mmD=(11 21 13 23 15 25 17 27) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mmG = mmA;
shun-iwasawa 82a8f5
      mmH = mmA;
shun-iwasawa 82a8f5
      mmA = _mm_unpacklo_pi16(mmA, mmE);    /* mmA=(00 10 20 01 02 12 22 03) */
shun-iwasawa 82a8f5
      mmG = _mm_unpackhi_pi16(mmG, mmE);    /* mmG=(04 14 24 05 06 16 26 07) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mmH = _mm_srli_si64(mmH, 2 * BYTE_BIT);
shun-iwasawa 82a8f5
      mmE = _mm_srli_si64(mmE, 2 * BYTE_BIT);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mmC = mmD;
shun-iwasawa 82a8f5
      mmB = mmD;
shun-iwasawa 82a8f5
      mmD = _mm_unpacklo_pi16(mmD, mmH);    /* mmD=(11 21 02 12 13 23 04 14) */
shun-iwasawa 82a8f5
      mmC = _mm_unpackhi_pi16(mmC, mmH);    /* mmC=(15 25 06 16 17 27 -- --) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mmB = _mm_srli_si64(mmB, 2 * BYTE_BIT); /* mmB=(13 23 15 25 17 27 -- --) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mmF = mmE;
shun-iwasawa 82a8f5
      mmE = _mm_unpacklo_pi16(mmE, mmB);    /* mmE=(22 03 13 23 24 05 15 25) */
shun-iwasawa 82a8f5
      mmF = _mm_unpackhi_pi16(mmF, mmB);    /* mmF=(26 07 17 27 -- -- -- --) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mmA = _mm_unpacklo_pi32(mmA, mmD);    /* mmA=(00 10 20 01 11 21 02 12) */
shun-iwasawa 82a8f5
      mmE = _mm_unpacklo_pi32(mmE, mmG);    /* mmE=(22 03 13 23 04 14 24 05) */
shun-iwasawa 82a8f5
      mmC = _mm_unpacklo_pi32(mmC, mmF);    /* mmC=(15 25 06 16 26 07 17 27) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      if (num_cols >= 8) {
shun-iwasawa 82a8f5
        _mm_store_si64((__m64 *)outptr, mmA);
shun-iwasawa 82a8f5
        _mm_store_si64((__m64 *)(outptr + 8), mmE);
shun-iwasawa 82a8f5
        _mm_store_si64((__m64 *)(outptr + 16), mmC);
shun-iwasawa 82a8f5
        outptr += RGB_PIXELSIZE * 8;
shun-iwasawa 82a8f5
      } else {
shun-iwasawa 82a8f5
        col = num_cols * 3;
shun-iwasawa 82a8f5
        asm(".set noreorder\r\n"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
            "li      $8, 16\r\n"
shun-iwasawa 82a8f5
            "move    $9, %4\r\n"
shun-iwasawa 82a8f5
            "mov.s   $f4, %1\r\n"
shun-iwasawa 82a8f5
            "mov.s   $f6, %3\r\n"
shun-iwasawa 82a8f5
            "move    $10, %5\r\n"
shun-iwasawa 82a8f5
            "bltu    $9, $8, 1f\r\n"
shun-iwasawa 82a8f5
            "nop     \r\n"
shun-iwasawa 82a8f5
            "gssdlc1 $f4, 7($10)\r\n"
shun-iwasawa 82a8f5
            "gssdrc1 $f4, 0($10)\r\n"
shun-iwasawa 82a8f5
            "gssdlc1 $f6, 7+8($10)\r\n"
shun-iwasawa 82a8f5
            "gssdrc1 $f6, 8($10)\r\n"
shun-iwasawa 82a8f5
            "mov.s   $f4, %2\r\n"
shun-iwasawa 82a8f5
            "subu    $9, $9, 16\r\n"
shun-iwasawa 82a8f5
            "daddu   $10, $10, 16\r\n"
shun-iwasawa 82a8f5
            "b       2f\r\n"
shun-iwasawa 82a8f5
            "nop     \r\n"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
            "1:      \r\n"
shun-iwasawa 82a8f5
            "li      $8, 8\r\n"               /* st8 */
shun-iwasawa 82a8f5
            "bltu    $9, $8, 2f\r\n"
shun-iwasawa 82a8f5
            "nop     \r\n"
shun-iwasawa 82a8f5
            "gssdlc1 $f4, 7($10)\r\n"
shun-iwasawa 82a8f5
            "gssdrc1 $f4, ($10)\r\n"
shun-iwasawa 82a8f5
            "mov.s   $f4, %3\r\n"
shun-iwasawa 82a8f5
            "subu    $9, $9, 8\r\n"
shun-iwasawa 82a8f5
            "daddu   $10, $10, 8\r\n"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
            "2:      \r\n"
shun-iwasawa 82a8f5
            "li      $8, 4\r\n"               /* st4 */
shun-iwasawa 82a8f5
            "mfc1    $11, $f4\r\n"
shun-iwasawa 82a8f5
            "bltu    $9, $8, 3f\r\n"
shun-iwasawa 82a8f5
            "nop     \r\n"
shun-iwasawa 82a8f5
            "swl     $11, 3($10)\r\n"
shun-iwasawa 82a8f5
            "swr     $11, 0($10)\r\n"
shun-iwasawa 82a8f5
            "li      $8, 32\r\n"
shun-iwasawa 82a8f5
            "mtc1    $8, $f6\r\n"
shun-iwasawa 82a8f5
            "dsrl    $f4, $f4, $f6\r\n"
shun-iwasawa 82a8f5
            "mfc1    $11, $f4\r\n"
shun-iwasawa 82a8f5
            "subu    $9, $9, 4\r\n"
shun-iwasawa 82a8f5
            "daddu   $10, $10, 4\r\n"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
            "3:      \r\n"
shun-iwasawa 82a8f5
            "li      $8, 2\r\n"               /* st2 */
shun-iwasawa 82a8f5
            "bltu    $9, $8, 4f\r\n"
shun-iwasawa 82a8f5
            "nop     \r\n"
shun-iwasawa 82a8f5
            "ush     $11, 0($10)\r\n"
shun-iwasawa 82a8f5
            "srl     $11, 16\r\n"
shun-iwasawa 82a8f5
            "subu    $9, $9, 2\r\n"
shun-iwasawa 82a8f5
            "daddu   $10, $10, 2\r\n"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
            "4:      \r\n"
shun-iwasawa 82a8f5
            "li      $8, 1\r\n"               /* st1 */
shun-iwasawa 82a8f5
            "bltu    $9, $8, 5f\r\n"
shun-iwasawa 82a8f5
            "nop     \r\n"
shun-iwasawa 82a8f5
            "sb      $11, 0($10)\r\n"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
            "5:      \r\n"
shun-iwasawa 82a8f5
            "nop     \r\n"                    /* end */
shun-iwasawa 82a8f5
            : "=m" (*outptr)
shun-iwasawa 82a8f5
            : "f" (mmA), "f" (mmC), "f" (mmE), "r" (col), "r" (outptr)
shun-iwasawa 82a8f5
            : "$f4", "$f6", "$8", "$9", "$10", "$11", "memory"
shun-iwasawa 82a8f5
           );
shun-iwasawa 82a8f5
      }
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#else  /* RGB_PIXELSIZE == 4 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#ifdef RGBX_FILLER_0XFF
shun-iwasawa 82a8f5
      mm6 = _mm_cmpeq_pi8(mm6, mm6);
shun-iwasawa 82a8f5
      mm7 = _mm_cmpeq_pi8(mm7, mm7);
shun-iwasawa 82a8f5
#else
shun-iwasawa 82a8f5
      mm6 = _mm_xor_si64(mm6, mm6);
shun-iwasawa 82a8f5
      mm7 = _mm_xor_si64(mm7, mm7);
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
      /* mmA=(00 02 04 06 ** ** ** **), mmB=(01 03 05 07 ** ** ** **) */
shun-iwasawa 82a8f5
      /* mmC=(10 12 14 16 ** ** ** **), mmD=(11 13 15 17 ** ** ** **) */
shun-iwasawa 82a8f5
      /* mmE=(20 22 24 26 ** ** ** **), mmF=(21 23 25 27 ** ** ** **) */
shun-iwasawa 82a8f5
      /* mmG=(30 32 34 36 ** ** ** **), mmH=(31 33 35 37 ** ** ** **) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mmA = _mm_unpacklo_pi8(mmA, mmC);     /* mmA=(00 10 02 12 04 14 06 16) */
shun-iwasawa 82a8f5
      mmE = _mm_unpacklo_pi8(mmE, mmG);     /* mmE=(20 30 22 32 24 34 26 36) */
shun-iwasawa 82a8f5
      mmB = _mm_unpacklo_pi8(mmB, mmD);     /* mmB=(01 11 03 13 05 15 07 17) */
shun-iwasawa 82a8f5
      mmF = _mm_unpacklo_pi8(mmF, mmH);     /* mmF=(21 31 23 33 25 35 27 37) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mmC = mmA;
shun-iwasawa 82a8f5
      mmA = _mm_unpacklo_pi16(mmA, mmE);    /* mmA=(00 10 20 30 02 12 22 32) */
shun-iwasawa 82a8f5
      mmC = _mm_unpackhi_pi16(mmC, mmE);    /* mmC=(04 14 24 34 06 16 26 36) */
shun-iwasawa 82a8f5
      mmG = mmB;
shun-iwasawa 82a8f5
      mmB = _mm_unpacklo_pi16(mmB, mmF);    /* mmB=(01 11 21 31 03 13 23 33) */
shun-iwasawa 82a8f5
      mmG = _mm_unpackhi_pi16(mmG, mmF);    /* mmG=(05 15 25 35 07 17 27 37) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      mmD = mmA;
shun-iwasawa 82a8f5
      mmA = _mm_unpacklo_pi32(mmA, mmB);    /* mmA=(00 10 20 30 01 11 21 31) */
shun-iwasawa 82a8f5
      mmD = _mm_unpackhi_pi32(mmD, mmB);    /* mmD=(02 12 22 32 03 13 23 33) */
shun-iwasawa 82a8f5
      mmH = mmC;
shun-iwasawa 82a8f5
      mmC = _mm_unpacklo_pi32(mmC, mmG);    /* mmC=(04 14 24 34 05 15 25 35) */
shun-iwasawa 82a8f5
      mmH = _mm_unpackhi_pi32(mmH, mmG);    /* mmH=(06 16 26 36 07 17 27 37) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
      if (num_cols >= 8) {
shun-iwasawa 82a8f5
        _mm_store_si64((__m64 *)outptr, mmA);
shun-iwasawa 82a8f5
        _mm_store_si64((__m64 *)(outptr + 8), mmD);
shun-iwasawa 82a8f5
        _mm_store_si64((__m64 *)(outptr + 16), mmC);
shun-iwasawa 82a8f5
        _mm_store_si64((__m64 *)(outptr + 24), mmH);
shun-iwasawa 82a8f5
        outptr += RGB_PIXELSIZE * 8;
shun-iwasawa 82a8f5
      } else {
shun-iwasawa 82a8f5
        col = num_cols;
shun-iwasawa 82a8f5
        asm(".set noreorder\r\n"              /* st16 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
            "li      $8, 4\r\n"
shun-iwasawa 82a8f5
            "move    $9, %6\r\n"
shun-iwasawa 82a8f5
            "move    $10, %7\r\n"
shun-iwasawa 82a8f5
            "mov.s   $f4, %2\r\n"
shun-iwasawa 82a8f5
            "mov.s   $f6, %4\r\n"
shun-iwasawa 82a8f5
            "bltu    $9, $8, 1f\r\n"
shun-iwasawa 82a8f5
            "nop     \r\n"
shun-iwasawa 82a8f5
            "gssdlc1 $f4, 7($10)\r\n"
shun-iwasawa 82a8f5
            "gssdrc1 $f4, ($10)\r\n"
shun-iwasawa 82a8f5
            "gssdlc1 $f6, 7+8($10)\r\n"
shun-iwasawa 82a8f5
            "gssdrc1 $f6, 8($10)\r\n"
shun-iwasawa 82a8f5
            "mov.s   $f4, %3\r\n"
shun-iwasawa 82a8f5
            "mov.s   $f6, %5\r\n"
shun-iwasawa 82a8f5
            "subu    $9, $9, 4\r\n"
shun-iwasawa 82a8f5
            "daddu   $10, $10, 16\r\n"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
            "1:      \r\n"
shun-iwasawa 82a8f5
            "li      $8, 2\r\n"               /* st8 */
shun-iwasawa 82a8f5
            "bltu    $9, $8, 2f\r\n"
shun-iwasawa 82a8f5
            "nop     \r\n"
shun-iwasawa 82a8f5
            "gssdlc1 $f4, 7($10)\r\n"
shun-iwasawa 82a8f5
            "gssdrc1 $f4, 0($10)\r\n"
shun-iwasawa 82a8f5
            "mov.s   $f4, $f6\r\n"
shun-iwasawa 82a8f5
            "subu    $9, $9, 2\r\n"
shun-iwasawa 82a8f5
            "daddu   $10, $10, 8\r\n"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
            "2:      \r\n"
shun-iwasawa 82a8f5
            "li      $8, 1\r\n"               /* st4 */
shun-iwasawa 82a8f5
            "bltu    $9, $8, 3f\r\n"
shun-iwasawa 82a8f5
            "nop     \r\n"
shun-iwasawa 82a8f5
            "gsswlc1 $f4, 3($10)\r\n"
shun-iwasawa 82a8f5
            "gsswrc1 $f4, 0($10)\r\n"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
            "3:      \r\n"
shun-iwasawa 82a8f5
            "li      %1, 0\r\n"               /* end */
shun-iwasawa 82a8f5
            : "=m" (*outptr), "=r" (col)
shun-iwasawa 82a8f5
            : "f" (mmA), "f" (mmC), "f" (mmD), "f" (mmH), "r" (col),
shun-iwasawa 82a8f5
              "r" (outptr)
shun-iwasawa 82a8f5
            : "$f4", "$f6", "$8", "$9", "$10", "memory"
shun-iwasawa 82a8f5
           );
shun-iwasawa 82a8f5
      }
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    }
shun-iwasawa 82a8f5
  }
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#undef mmA
shun-iwasawa 82a8f5
#undef mmB
shun-iwasawa 82a8f5
#undef mmC
shun-iwasawa 82a8f5
#undef mmD
shun-iwasawa 82a8f5
#undef mmE
shun-iwasawa 82a8f5
#undef mmF
shun-iwasawa 82a8f5
#undef mmG
shun-iwasawa 82a8f5
#undef mmH