Blame thirdparty/libjpeg-turbo/libjpeg-turbo-2.0.6/simd/i386/jccolext-avx2.asm

shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; jccolext.asm - colorspace conversion (AVX2)
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; Copyright (C) 2015, Intel Corporation.
shun-iwasawa 82a8f5
; Copyright (C) 2016, D. R. Commander.
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
; For conditions of distribution and use, see copyright notice in jsimdext.inc
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; This file should be assembled with NASM (Netwide Assembler),
shun-iwasawa 82a8f5
; can *not* be assembled with Microsoft's MASM or any compatible
shun-iwasawa 82a8f5
; assembler (including Borland's Turbo Assembler).
shun-iwasawa 82a8f5
; NASM is available from http://nasm.sourceforge.net/ or
shun-iwasawa 82a8f5
; http://sourceforge.net/project/showfiles.php?group_id=6208
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%include "jcolsamp.inc"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
; --------------------------------------------------------------------------
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; Convert some rows of samples to the output colorspace.
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; GLOBAL(void)
shun-iwasawa 82a8f5
; jsimd_rgb_ycc_convert_avx2(JDIMENSION img_width, JSAMPARRAY input_buf,
shun-iwasawa 82a8f5
;                            JSAMPIMAGE output_buf, JDIMENSION output_row,
shun-iwasawa 82a8f5
;                            int num_rows);
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%define img_width(b)   (b) + 8          ; JDIMENSION img_width
shun-iwasawa 82a8f5
%define input_buf(b)   (b) + 12         ; JSAMPARRAY input_buf
shun-iwasawa 82a8f5
%define output_buf(b)  (b) + 16         ; JSAMPIMAGE output_buf
shun-iwasawa 82a8f5
%define output_row(b)  (b) + 20         ; JDIMENSION output_row
shun-iwasawa 82a8f5
%define num_rows(b)    (b) + 24         ; int num_rows
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%define original_ebp   ebp + 0
shun-iwasawa 82a8f5
%define wk(i)          ebp - (WK_NUM - (i)) * SIZEOF_YMMWORD
shun-iwasawa 82a8f5
                                        ; ymmword wk[WK_NUM]
shun-iwasawa 82a8f5
%define WK_NUM         8
shun-iwasawa 82a8f5
%define gotptr         wk(0) - SIZEOF_POINTER  ; void * gotptr
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    align       32
shun-iwasawa 82a8f5
    GLOBAL_FUNCTION(jsimd_rgb_ycc_convert_avx2)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTN(jsimd_rgb_ycc_convert_avx2):
shun-iwasawa 82a8f5
    push        ebp
shun-iwasawa 82a8f5
    mov         eax, esp                     ; eax = original ebp
shun-iwasawa 82a8f5
    sub         esp, byte 4
shun-iwasawa 82a8f5
    and         esp, byte (-SIZEOF_YMMWORD)  ; align to 256 bits
shun-iwasawa 82a8f5
    mov         [esp], eax
shun-iwasawa 82a8f5
    mov         ebp, esp                     ; ebp = aligned ebp
shun-iwasawa 82a8f5
    lea         esp, [wk(0)]
shun-iwasawa 82a8f5
    pushpic     eax                     ; make a room for GOT address
shun-iwasawa 82a8f5
    push        ebx
shun-iwasawa 82a8f5
;   push        ecx                     ; need not be preserved
shun-iwasawa 82a8f5
;   push        edx                     ; need not be preserved
shun-iwasawa 82a8f5
    push        esi
shun-iwasawa 82a8f5
    push        edi
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    get_GOT     ebx                     ; get GOT address
shun-iwasawa 82a8f5
    movpic      POINTER [gotptr], ebx   ; save GOT address
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    mov         ecx, JDIMENSION [img_width(eax)]
shun-iwasawa 82a8f5
    test        ecx, ecx
shun-iwasawa 82a8f5
    jz          near .return
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    push        ecx
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    mov         esi, JSAMPIMAGE [output_buf(eax)]
shun-iwasawa 82a8f5
    mov         ecx, JDIMENSION [output_row(eax)]
shun-iwasawa 82a8f5
    mov         edi, JSAMPARRAY [esi+0*SIZEOF_JSAMPARRAY]
shun-iwasawa 82a8f5
    mov         ebx, JSAMPARRAY [esi+1*SIZEOF_JSAMPARRAY]
shun-iwasawa 82a8f5
    mov         edx, JSAMPARRAY [esi+2*SIZEOF_JSAMPARRAY]
shun-iwasawa 82a8f5
    lea         edi, [edi+ecx*SIZEOF_JSAMPROW]
shun-iwasawa 82a8f5
    lea         ebx, [ebx+ecx*SIZEOF_JSAMPROW]
shun-iwasawa 82a8f5
    lea         edx, [edx+ecx*SIZEOF_JSAMPROW]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pop         ecx
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    mov         esi, JSAMPARRAY [input_buf(eax)]
shun-iwasawa 82a8f5
    mov         eax, INT [num_rows(eax)]
shun-iwasawa 82a8f5
    test        eax, eax
shun-iwasawa 82a8f5
    jle         near .return
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
.rowloop:
shun-iwasawa 82a8f5
    pushpic     eax
shun-iwasawa 82a8f5
    push        edx
shun-iwasawa 82a8f5
    push        ebx
shun-iwasawa 82a8f5
    push        edi
shun-iwasawa 82a8f5
    push        esi
shun-iwasawa 82a8f5
    push        ecx                     ; col
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    mov         esi, JSAMPROW [esi]     ; inptr
shun-iwasawa 82a8f5
    mov         edi, JSAMPROW [edi]     ; outptr0
shun-iwasawa 82a8f5
    mov         ebx, JSAMPROW [ebx]     ; outptr1
shun-iwasawa 82a8f5
    mov         edx, JSAMPROW [edx]     ; outptr2
shun-iwasawa 82a8f5
    movpic      eax, POINTER [gotptr]   ; load GOT address (eax)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_YMMWORD
shun-iwasawa 82a8f5
    jae         near .columnloop
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%if RGB_PIXELSIZE == 3  ; ---------------
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.column_ld1:
shun-iwasawa 82a8f5
    push        eax
shun-iwasawa 82a8f5
    push        edx
shun-iwasawa 82a8f5
    lea         ecx, [ecx+ecx*2]        ; imul ecx,RGB_PIXELSIZE
shun-iwasawa 82a8f5
    test        cl, SIZEOF_BYTE
shun-iwasawa 82a8f5
    jz          short .column_ld2
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_BYTE
shun-iwasawa 82a8f5
    movzx       eax, byte [esi+ecx]
shun-iwasawa 82a8f5
.column_ld2:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_WORD
shun-iwasawa 82a8f5
    jz          short .column_ld4
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_WORD
shun-iwasawa 82a8f5
    movzx       edx, word [esi+ecx]
shun-iwasawa 82a8f5
    shl         eax, WORD_BIT
shun-iwasawa 82a8f5
    or          eax, edx
shun-iwasawa 82a8f5
.column_ld4:
shun-iwasawa 82a8f5
    vmovd       xmmA, eax
shun-iwasawa 82a8f5
    pop         edx
shun-iwasawa 82a8f5
    pop         eax
shun-iwasawa 82a8f5
    test        cl, SIZEOF_DWORD
shun-iwasawa 82a8f5
    jz          short .column_ld8
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_DWORD
shun-iwasawa 82a8f5
    vmovd       xmmF, XMM_DWORD [esi+ecx]
shun-iwasawa 82a8f5
    vpslldq     xmmA, xmmA, SIZEOF_DWORD
shun-iwasawa 82a8f5
    vpor        xmmA, xmmA, xmmF
shun-iwasawa 82a8f5
.column_ld8:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_MMWORD
shun-iwasawa 82a8f5
    jz          short .column_ld16
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_MMWORD
shun-iwasawa 82a8f5
    vmovq       xmmB, XMM_MMWORD [esi+ecx]
shun-iwasawa 82a8f5
    vpslldq     xmmA, xmmA, SIZEOF_MMWORD
shun-iwasawa 82a8f5
    vpor        xmmA, xmmA, xmmB
shun-iwasawa 82a8f5
.column_ld16:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jz          short .column_ld32
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    vmovdqu     xmmB, XMM_MMWORD [esi+ecx]
shun-iwasawa 82a8f5
    vperm2i128  ymmA, ymmA, ymmA, 1
shun-iwasawa 82a8f5
    vpor        ymmA, ymmB
shun-iwasawa 82a8f5
.column_ld32:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_YMMWORD
shun-iwasawa 82a8f5
    jz          short .column_ld64
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_YMMWORD
shun-iwasawa 82a8f5
    vmovdqa     ymmF, ymmA
shun-iwasawa 82a8f5
    vmovdqu     ymmA, YMMWORD [esi+0*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
.column_ld64:
shun-iwasawa 82a8f5
    test        cl, 2*SIZEOF_YMMWORD
shun-iwasawa 82a8f5
    mov         ecx, SIZEOF_YMMWORD
shun-iwasawa 82a8f5
    jz          short .rgb_ycc_cnv
shun-iwasawa 82a8f5
    vmovdqa     ymmB, ymmA
shun-iwasawa 82a8f5
    vmovdqu     ymmA, YMMWORD [esi+0*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
    vmovdqu     ymmF, YMMWORD [esi+1*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
    jmp         short .rgb_ycc_cnv
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.columnloop:
shun-iwasawa 82a8f5
    vmovdqu     ymmA, YMMWORD [esi+0*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
    vmovdqu     ymmF, YMMWORD [esi+1*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
    vmovdqu     ymmB, YMMWORD [esi+2*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.rgb_ycc_cnv:
shun-iwasawa 82a8f5
    ; ymmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05
shun-iwasawa 82a8f5
    ;       15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
shun-iwasawa 82a8f5
    ; ymmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F
shun-iwasawa 82a8f5
    ;       0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L)
shun-iwasawa 82a8f5
    ; ymmB=(1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q
shun-iwasawa 82a8f5
    ;       2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqu     ymmC, ymmA
shun-iwasawa 82a8f5
    vinserti128 ymmA, ymmF, xmmA, 0  ; ymmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05
shun-iwasawa 82a8f5
                                     ;       0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L)
shun-iwasawa 82a8f5
    vinserti128 ymmC, ymmC, xmmB, 0  ; ymmC=(1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q
shun-iwasawa 82a8f5
                                     ;       15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
shun-iwasawa 82a8f5
    vinserti128 ymmB, ymmB, xmmF, 0  ; ymmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F
shun-iwasawa 82a8f5
                                     ;       2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V)
shun-iwasawa 82a8f5
    vperm2i128  ymmF, ymmC, ymmC, 1  ; ymmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A
shun-iwasawa 82a8f5
                                     ;       1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmG, ymmA
shun-iwasawa 82a8f5
    vpslldq     ymmA, ymmA, 8     ; ymmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12
shun-iwasawa 82a8f5
                                  ;       22 03 13 23 04 14 24 05 0G 1G 2G 0H 1H 2H 0I 1I)
shun-iwasawa 82a8f5
    vpsrldq     ymmG, ymmG, 8     ; ymmG=(22 03 13 23 04 14 24 05 0G 1G 2G 0H 1H 2H 0I 1I
shun-iwasawa 82a8f5
                                  ;       2I 0J 1J 2J 0K 1K 2K 0L -- -- -- -- -- -- -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpunpckhbw  ymmA, ymmA, ymmF  ; ymmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A
shun-iwasawa 82a8f5
                                  ;       0G 0O 1G 1O 2G 2O 0H 0P 1H 1P 2H 2P 0I 0Q 1I 1Q)
shun-iwasawa 82a8f5
    vpslldq     ymmF, ymmF, 8     ; ymmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27
shun-iwasawa 82a8f5
                                  ;       08 18 28 09 19 29 0A 1A 1L 2L 0M 1M 2M 0N 1N 2N)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpunpcklbw  ymmG, ymmG, ymmB  ; ymmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D
shun-iwasawa 82a8f5
                                  ;       2I 2Q 0J 0R 1J 1R 2J 2R 0K 0S 1K 1S 2K 2S 0L 0T)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmF, ymmF, ymmB  ; ymmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F
shun-iwasawa 82a8f5
                                  ;       1L 1T 2L 2T 0M 0U 1M 1U 2M 2U 0N 0V 1N 1V 2N 2V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmD, ymmA
shun-iwasawa 82a8f5
    vpslldq     ymmA, ymmA, 8     ; ymmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09
shun-iwasawa 82a8f5
                                  ;       11 19 21 29 02 0A 12 1A 0G 0O 1G 1O 2G 2O 0H 0P)
shun-iwasawa 82a8f5
    vpsrldq     ymmD, ymmD, 8     ; ymmD=(11 19 21 29 02 0A 12 1A 0G 0O 1G 1O 2G 2O 0H 0P
shun-iwasawa 82a8f5
                                  ;       1H 1P 2H 2P 0I 0Q 1I 1Q -- -- -- -- -- -- -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpunpckhbw  ymmA, ymmA, ymmG  ; ymmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D
shun-iwasawa 82a8f5
                                  ;       0G 0K 0O 0S 1G 1K 1O 1S 2G 2K 2O 2S 0H 0L 0P 0T)
shun-iwasawa 82a8f5
    vpslldq     ymmG, ymmG, 8     ; ymmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B
shun-iwasawa 82a8f5
                                  ;       04 0C 14 1C 24 2C 05 0D 2I 2Q 0J 0R 1J 1R 2J 2R)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpunpcklbw  ymmD, ymmD, ymmF  ; ymmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E
shun-iwasawa 82a8f5
                                  ;       1H 1L 1P 1T 2H 2L 2P 2T 0I 0M 0Q 0U 1I 1M 1Q 1U)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmG, ymmG, ymmF  ; ymmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F
shun-iwasawa 82a8f5
                                  ;       2I 2M 2Q 2U 0J 0N 0R 0V 1J 1N 1R 1V 2J 2N 2R 2V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmE, ymmA
shun-iwasawa 82a8f5
    vpslldq     ymmA, ymmA, 8     ; ymmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C
shun-iwasawa 82a8f5
                                  ;       20 24 28 2C 01 05 09 0D 0G 0K 0O 0S 1G 1K 1O 1S)
shun-iwasawa 82a8f5
    vpsrldq     ymmE, ymmE, 8     ; ymmE=(20 24 28 2C 01 05 09 0D 0G 0K 0O 0S 1G 1K 1O 1S
shun-iwasawa 82a8f5
                                  ;       2G 2K 2O 2S 0H 0L 0P 0T -- -- -- -- -- -- -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpunpckhbw  ymmA, ymmA, ymmD  ; ymmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E
shun-iwasawa 82a8f5
                                  ;       0G 0I 0K 0M 0O 0Q 0S 0U 1G 1I 1K 1M 1O 1Q 1S 1U)
shun-iwasawa 82a8f5
    vpslldq     ymmD, ymmD, 8     ; ymmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D
shun-iwasawa 82a8f5
                                  ;       02 06 0A 0E 12 16 1A 1E 1H 1L 1P 1T 2H 2L 2P 2T)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpunpcklbw  ymmE, ymmE, ymmG  ; ymmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F
shun-iwasawa 82a8f5
                                  ;       2G 2I 2K 2M 2O 2Q 2S 2U 0H 0J 0L 0N 0P 0R 0T 0V)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmD, ymmD, ymmG  ; ymmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F
shun-iwasawa 82a8f5
                                  ;       1H 1J 1L 1N 1P 1R 1T 1V 2H 2J 2L 2N 2P 2R 2T 2V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpxor       ymmH, ymmH, ymmH
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmC, ymmA
shun-iwasawa 82a8f5
    vpunpcklbw  ymmA, ymmA, ymmH  ; ymmA=(00 02 04 06 08 0A 0C 0E 0G 0I 0K 0M 0O 0Q 0S 0U)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmC, ymmC, ymmH  ; ymmC=(10 12 14 16 18 1A 1C 1E 1G 1I 1K 1M 1O 1Q 1S 1U)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmB, ymmE
shun-iwasawa 82a8f5
    vpunpcklbw  ymmE, ymmE, ymmH  ; ymmE=(20 22 24 26 28 2A 2C 2E 2G 2I 2K 2M 2O 2Q 2S 2U)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmB, ymmB, ymmH  ; ymmB=(01 03 05 07 09 0B 0D 0F 0H 0J 0L 0N 0P 0R 0T 0V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmF, ymmD
shun-iwasawa 82a8f5
    vpunpcklbw  ymmD, ymmD, ymmH  ; ymmD=(11 13 15 17 19 1B 1D 1F 1H 1J 1L 1N 1P 1R 1T 1V)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmF, ymmF, ymmH  ; ymmF=(21 23 25 27 29 2B 2D 2F 2H 2J 2L 2N 2P 2R 2T 2V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%else  ; RGB_PIXELSIZE == 4 ; -----------
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.column_ld1:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_XMMWORD/16
shun-iwasawa 82a8f5
    jz          short .column_ld2
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD/16
shun-iwasawa 82a8f5
    vmovd       xmmA, XMM_DWORD [esi+ecx*RGB_PIXELSIZE]
shun-iwasawa 82a8f5
.column_ld2:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_XMMWORD/8
shun-iwasawa 82a8f5
    jz          short .column_ld4
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD/8
shun-iwasawa 82a8f5
    vmovq       xmmF, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE]
shun-iwasawa 82a8f5
    vpslldq     xmmA, xmmA, SIZEOF_MMWORD
shun-iwasawa 82a8f5
    vpor        xmmA, xmmA, xmmF
shun-iwasawa 82a8f5
.column_ld4:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_XMMWORD/4
shun-iwasawa 82a8f5
    jz          short .column_ld8
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD/4
shun-iwasawa 82a8f5
    vmovdqa     xmmF, xmmA
shun-iwasawa 82a8f5
    vperm2i128  ymmF, ymmF, ymmF, 1
shun-iwasawa 82a8f5
    vmovdqu     xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE]
shun-iwasawa 82a8f5
    vpor        ymmA, ymmA, ymmF
shun-iwasawa 82a8f5
.column_ld8:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_XMMWORD/2
shun-iwasawa 82a8f5
    jz          short .column_ld16
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD/2
shun-iwasawa 82a8f5
    vmovdqa     ymmF, ymmA
shun-iwasawa 82a8f5
    vmovdqu     ymmA, YMMWORD [esi+ecx*RGB_PIXELSIZE]
shun-iwasawa 82a8f5
.column_ld16:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    mov         ecx, SIZEOF_YMMWORD
shun-iwasawa 82a8f5
    jz          short .rgb_ycc_cnv
shun-iwasawa 82a8f5
    vmovdqa     ymmE, ymmA
shun-iwasawa 82a8f5
    vmovdqa     ymmH, ymmF
shun-iwasawa 82a8f5
    vmovdqu     ymmA, YMMWORD [esi+0*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
    vmovdqu     ymmF, YMMWORD [esi+1*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
    jmp         short .rgb_ycc_cnv
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.columnloop:
shun-iwasawa 82a8f5
    vmovdqu     ymmA, YMMWORD [esi+0*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
    vmovdqu     ymmF, YMMWORD [esi+1*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
    vmovdqu     ymmE, YMMWORD [esi+2*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
    vmovdqu     ymmH, YMMWORD [esi+3*SIZEOF_YMMWORD]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.rgb_ycc_cnv:
shun-iwasawa 82a8f5
    ; ymmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
shun-iwasawa 82a8f5
    ;       04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
shun-iwasawa 82a8f5
    ; ymmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B
shun-iwasawa 82a8f5
    ;       0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
shun-iwasawa 82a8f5
    ; ymmE=(0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J
shun-iwasawa 82a8f5
    ;       0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N)
shun-iwasawa 82a8f5
    ; ymmH=(0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R
shun-iwasawa 82a8f5
    ;       0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmB, ymmA
shun-iwasawa 82a8f5
    vinserti128 ymmA, ymmA, xmmE, 1     ; ymmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
shun-iwasawa 82a8f5
                                        ;       0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J)
shun-iwasawa 82a8f5
    vperm2i128  ymmE, ymmB, ymmE, 0x31  ; ymmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37
shun-iwasawa 82a8f5
                                        ;       0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmB, ymmF
shun-iwasawa 82a8f5
    vinserti128 ymmF, ymmF, xmmH, 1     ; ymmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B
shun-iwasawa 82a8f5
                                        ;       0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R)
shun-iwasawa 82a8f5
    vperm2i128  ymmH, ymmB, ymmH, 0x31  ; ymmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F
shun-iwasawa 82a8f5
                                        ;       0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmD, ymmA
shun-iwasawa 82a8f5
    vpunpcklbw  ymmA, ymmA, ymmE      ; ymmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35
shun-iwasawa 82a8f5
                                      ;       0G 0K 1G 1K 2G 2K 3G 3K 0H 0L 1H 1L 2H 2L 3H 3L)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmD, ymmD, ymmE      ; ymmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37
shun-iwasawa 82a8f5
                                      ;       0I 0M 1I 1M 2I 2M 3I 3M 0J 0N 1J 1N 2J 2N 3J 3N)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmC, ymmF
shun-iwasawa 82a8f5
    vpunpcklbw  ymmF, ymmF, ymmH      ; ymmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D
shun-iwasawa 82a8f5
                                      ;       0O 0S 1O 1S 2O 2S 3O 3S 0P 0T 1P 1T 2P 2T 3P 3T)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmC, ymmC, ymmH      ; ymmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F
shun-iwasawa 82a8f5
                                      ;       0Q 0U 1Q 1U 2Q 2U 3Q 3U 0R 0V 1R 1V 2R 2V 3R 3V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmB, ymmA
shun-iwasawa 82a8f5
    vpunpcklwd  ymmA, ymmA, ymmF      ; ymmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C
shun-iwasawa 82a8f5
                                      ;       0G 0K 0O 0S 1G 1K 1O 1S 2G 2K 2O 2S 3G 3K 3O 3S)
shun-iwasawa 82a8f5
    vpunpckhwd  ymmB, ymmB, ymmF      ; ymmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D
shun-iwasawa 82a8f5
                                      ;       0H 0L 0P 0T 1H 1L 1P 1T 2H 2L 2P 2T 3H 3L 3P 3T)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmG, ymmD
shun-iwasawa 82a8f5
    vpunpcklwd  ymmD, ymmD, ymmC      ; ymmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E
shun-iwasawa 82a8f5
                                      ;       0I 0M 0Q 0U 1I 1M 1Q 1U 2I 2M 2Q 2U 3I 3M 3Q 3U)
shun-iwasawa 82a8f5
    vpunpckhwd  ymmG, ymmG, ymmC      ; ymmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F
shun-iwasawa 82a8f5
                                      ;       0J 0N 0R 0V 1J 1N 1R 1V 2J 2N 2R 2V 3J 3N 3R 3V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmE, ymmA
shun-iwasawa 82a8f5
    vpunpcklbw  ymmA, ymmA, ymmD      ; ymmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E
shun-iwasawa 82a8f5
                                      ;       0G 0I 0K 0M 0O 0Q 0S 0U 1G 1I 1K 1M 1O 1Q 1S 1U)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmE, ymmE, ymmD      ; ymmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E
shun-iwasawa 82a8f5
                                      ;       2G 2I 2K 2M 2O 2Q 2S 2U 3G 3I 3K 3M 3O 3Q 3S 3U)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmH, ymmB
shun-iwasawa 82a8f5
    vpunpcklbw  ymmB, ymmB, ymmG      ; ymmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F
shun-iwasawa 82a8f5
                                      ;       0H 0J 0L 0N 0P 0R 0T 0V 1H 1J 1L 1N 1P 1R 1T 1V)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmH, ymmH, ymmG      ; ymmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F
shun-iwasawa 82a8f5
                                      ;       2H 2J 2L 2N 2P 2R 2T 2V 3H 3J 3L 3N 3P 3R 3T 3V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpxor       ymmF, ymmF, ymmF
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmC, ymmA
shun-iwasawa 82a8f5
    vpunpcklbw  ymmA, ymmA, ymmF      ; ymmA=(00 02 04 06 08 0A 0C 0E 0G 0I 0K 0M 0O 0Q 0S 0U)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmC, ymmC, ymmF      ; ymmC=(10 12 14 16 18 1A 1C 1E 1G 1I 1K 1M 1O 1Q 1S 1U)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmD, ymmB
shun-iwasawa 82a8f5
    vpunpcklbw  ymmB, ymmB, ymmF      ; ymmB=(01 03 05 07 09 0B 0D 0F 0H 0J 0L 0N 0P 0R 0T 0V)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmD, ymmD, ymmF      ; ymmD=(11 13 15 17 19 1B 1D 1F 1H 1J 1L 1N 1P 1R 1T 1V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymmG, ymmE
shun-iwasawa 82a8f5
    vpunpcklbw  ymmE, ymmE, ymmF      ; ymmE=(20 22 24 26 28 2A 2C 2E 2G 2I 2K 2M 2O 2Q 2S 2U)
shun-iwasawa 82a8f5
    vpunpckhbw  ymmG, ymmG, ymmF      ; ymmG=(30 32 34 36 38 3A 3C 3E 3G 3I 3K 3M 3O 3Q 3S 3U)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpunpcklbw  ymmF, ymmF, ymmH
shun-iwasawa 82a8f5
    vpunpckhbw  ymmH, ymmH, ymmH
shun-iwasawa 82a8f5
    vpsrlw      ymmF, ymmF, BYTE_BIT  ; ymmF=(21 23 25 27 29 2B 2D 2F 2H 2J 2L 2N 2P 2R 2T 2V)
shun-iwasawa 82a8f5
    vpsrlw      ymmH, ymmH, BYTE_BIT  ; ymmH=(31 33 35 37 39 3B 3D 3F 3H 3J 3L 3N 3P 3R 3T 3V)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%endif  ; RGB_PIXELSIZE ; ---------------
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    ; ymm0=R(02468ACEGIKMOQSU)=RE, ymm2=G(02468ACEGIKMOQSU)=GE, ymm4=B(02468ACEGIKMOQSU)=BE
shun-iwasawa 82a8f5
    ; ymm1=R(13579BDFHJLNPRTV)=RO, ymm3=G(13579BDFHJLNPRTV)=GO, ymm5=B(13579BDFHJLNPRTV)=BO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    ; (Original)
shun-iwasawa 82a8f5
    ; Y  =  0.29900 * R + 0.58700 * G + 0.11400 * B
shun-iwasawa 82a8f5
    ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
shun-iwasawa 82a8f5
    ; Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
shun-iwasawa 82a8f5
    ;
shun-iwasawa 82a8f5
    ; (This implementation)
shun-iwasawa 82a8f5
    ; Y  =  0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
shun-iwasawa 82a8f5
    ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
shun-iwasawa 82a8f5
    ; Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     YMMWORD [wk(0)], ymm0   ; wk(0)=RE
shun-iwasawa 82a8f5
    vmovdqa     YMMWORD [wk(1)], ymm1   ; wk(1)=RO
shun-iwasawa 82a8f5
    vmovdqa     YMMWORD [wk(2)], ymm4   ; wk(2)=BE
shun-iwasawa 82a8f5
    vmovdqa     YMMWORD [wk(3)], ymm5   ; wk(3)=BO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm6, ymm1
shun-iwasawa 82a8f5
    vpunpcklwd  ymm1, ymm1, ymm3
shun-iwasawa 82a8f5
    vpunpckhwd  ymm6, ymm6, ymm3
shun-iwasawa 82a8f5
    vmovdqa     ymm7, ymm1
shun-iwasawa 82a8f5
    vmovdqa     ymm4, ymm6
shun-iwasawa 82a8f5
    vpmaddwd    ymm1, ymm1, [GOTOFF(eax,PW_F0299_F0337)]  ; ymm1=ROL*FIX(0.299)+GOL*FIX(0.337)
shun-iwasawa 82a8f5
    vpmaddwd    ymm6, ymm6, [GOTOFF(eax,PW_F0299_F0337)]  ; ymm6=ROH*FIX(0.299)+GOH*FIX(0.337)
shun-iwasawa 82a8f5
    vpmaddwd    ymm7, ymm7, [GOTOFF(eax,PW_MF016_MF033)]  ; ymm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
shun-iwasawa 82a8f5
    vpmaddwd    ymm4, ymm4, [GOTOFF(eax,PW_MF016_MF033)]  ; ymm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     YMMWORD [wk(4)], ymm1   ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
shun-iwasawa 82a8f5
    vmovdqa     YMMWORD [wk(5)], ymm6   ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpxor       ymm1, ymm1, ymm1
shun-iwasawa 82a8f5
    vpxor       ymm6, ymm6, ymm6
shun-iwasawa 82a8f5
    vpunpcklwd  ymm1, ymm1, ymm5        ; ymm1=BOL
shun-iwasawa 82a8f5
    vpunpckhwd  ymm6, ymm6, ymm5        ; ymm6=BOH
shun-iwasawa 82a8f5
    vpsrld      ymm1, ymm1, 1           ; ymm1=BOL*FIX(0.500)
shun-iwasawa 82a8f5
    vpsrld      ymm6, ymm6, 1           ; ymm6=BOH*FIX(0.500)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm5, [GOTOFF(eax,PD_ONEHALFM1_CJ)]  ; ymm5=[PD_ONEHALFM1_CJ]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpaddd      ymm7, ymm7, ymm1
shun-iwasawa 82a8f5
    vpaddd      ymm4, ymm4, ymm6
shun-iwasawa 82a8f5
    vpaddd      ymm7, ymm7, ymm5
shun-iwasawa 82a8f5
    vpaddd      ymm4, ymm4, ymm5
shun-iwasawa 82a8f5
    vpsrld      ymm7, ymm7, SCALEBITS   ; ymm7=CbOL
shun-iwasawa 82a8f5
    vpsrld      ymm4, ymm4, SCALEBITS   ; ymm4=CbOH
shun-iwasawa 82a8f5
    vpackssdw   ymm7, ymm7, ymm4        ; ymm7=CbO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm1, YMMWORD [wk(2)]   ; ymm1=BE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm6, ymm0
shun-iwasawa 82a8f5
    vpunpcklwd  ymm0, ymm0, ymm2
shun-iwasawa 82a8f5
    vpunpckhwd  ymm6, ymm6, ymm2
shun-iwasawa 82a8f5
    vmovdqa     ymm5, ymm0
shun-iwasawa 82a8f5
    vmovdqa     ymm4, ymm6
shun-iwasawa 82a8f5
    vpmaddwd    ymm0, ymm0, [GOTOFF(eax,PW_F0299_F0337)]  ; ymm0=REL*FIX(0.299)+GEL*FIX(0.337)
shun-iwasawa 82a8f5
    vpmaddwd    ymm6, ymm6, [GOTOFF(eax,PW_F0299_F0337)]  ; ymm6=REH*FIX(0.299)+GEH*FIX(0.337)
shun-iwasawa 82a8f5
    vpmaddwd    ymm5, ymm5, [GOTOFF(eax,PW_MF016_MF033)]  ; ymm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
shun-iwasawa 82a8f5
    vpmaddwd    ymm4, ymm4, [GOTOFF(eax,PW_MF016_MF033)]  ; ymm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     YMMWORD [wk(6)], ymm0   ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
shun-iwasawa 82a8f5
    vmovdqa     YMMWORD [wk(7)], ymm6   ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpxor       ymm0, ymm0, ymm0
shun-iwasawa 82a8f5
    vpxor       ymm6, ymm6, ymm6
shun-iwasawa 82a8f5
    vpunpcklwd  ymm0, ymm0, ymm1        ; ymm0=BEL
shun-iwasawa 82a8f5
    vpunpckhwd  ymm6, ymm6, ymm1        ; ymm6=BEH
shun-iwasawa 82a8f5
    vpsrld      ymm0, ymm0, 1           ; ymm0=BEL*FIX(0.500)
shun-iwasawa 82a8f5
    vpsrld      ymm6, ymm6, 1           ; ymm6=BEH*FIX(0.500)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm1, [GOTOFF(eax,PD_ONEHALFM1_CJ)]  ; ymm1=[PD_ONEHALFM1_CJ]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpaddd      ymm5, ymm5, ymm0
shun-iwasawa 82a8f5
    vpaddd      ymm4, ymm4, ymm6
shun-iwasawa 82a8f5
    vpaddd      ymm5, ymm5, ymm1
shun-iwasawa 82a8f5
    vpaddd      ymm4, ymm4, ymm1
shun-iwasawa 82a8f5
    vpsrld      ymm5, ymm5, SCALEBITS   ; ymm5=CbEL
shun-iwasawa 82a8f5
    vpsrld      ymm4, ymm4, SCALEBITS   ; ymm4=CbEH
shun-iwasawa 82a8f5
    vpackssdw   ymm5, ymm5, ymm4        ; ymm5=CbE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpsllw      ymm7, ymm7, BYTE_BIT
shun-iwasawa 82a8f5
    vpor        ymm5, ymm5, ymm7        ; ymm5=Cb
shun-iwasawa 82a8f5
    vmovdqu     YMMWORD [ebx], ymm5     ; Save Cb
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm0, YMMWORD [wk(3)]   ; ymm0=BO
shun-iwasawa 82a8f5
    vmovdqa     ymm6, YMMWORD [wk(2)]   ; ymm6=BE
shun-iwasawa 82a8f5
    vmovdqa     ymm1, YMMWORD [wk(1)]   ; ymm1=RO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm4, ymm0
shun-iwasawa 82a8f5
    vpunpcklwd  ymm0, ymm0, ymm3
shun-iwasawa 82a8f5
    vpunpckhwd  ymm4, ymm4, ymm3
shun-iwasawa 82a8f5
    vmovdqa     ymm7, ymm0
shun-iwasawa 82a8f5
    vmovdqa     ymm5, ymm4
shun-iwasawa 82a8f5
    vpmaddwd    ymm0, ymm0, [GOTOFF(eax,PW_F0114_F0250)]  ; ymm0=BOL*FIX(0.114)+GOL*FIX(0.250)
shun-iwasawa 82a8f5
    vpmaddwd    ymm4, ymm4, [GOTOFF(eax,PW_F0114_F0250)]  ; ymm4=BOH*FIX(0.114)+GOH*FIX(0.250)
shun-iwasawa 82a8f5
    vpmaddwd    ymm7, ymm7, [GOTOFF(eax,PW_MF008_MF041)]  ; ymm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
shun-iwasawa 82a8f5
    vpmaddwd    ymm5, ymm5, [GOTOFF(eax,PW_MF008_MF041)]  ; ymm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm3, [GOTOFF(eax,PD_ONEHALF)]            ; ymm3=[PD_ONEHALF]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpaddd      ymm0, ymm0, YMMWORD [wk(4)]
shun-iwasawa 82a8f5
    vpaddd      ymm4, ymm4, YMMWORD [wk(5)]
shun-iwasawa 82a8f5
    vpaddd      ymm0, ymm0, ymm3
shun-iwasawa 82a8f5
    vpaddd      ymm4, ymm4, ymm3
shun-iwasawa 82a8f5
    vpsrld      ymm0, ymm0, SCALEBITS   ; ymm0=YOL
shun-iwasawa 82a8f5
    vpsrld      ymm4, ymm4, SCALEBITS   ; ymm4=YOH
shun-iwasawa 82a8f5
    vpackssdw   ymm0, ymm0, ymm4        ; ymm0=YO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpxor       ymm3, ymm3, ymm3
shun-iwasawa 82a8f5
    vpxor       ymm4, ymm4, ymm4
shun-iwasawa 82a8f5
    vpunpcklwd  ymm3, ymm3, ymm1        ; ymm3=ROL
shun-iwasawa 82a8f5
    vpunpckhwd  ymm4, ymm4, ymm1        ; ymm4=ROH
shun-iwasawa 82a8f5
    vpsrld      ymm3, ymm3, 1           ; ymm3=ROL*FIX(0.500)
shun-iwasawa 82a8f5
    vpsrld      ymm4, ymm4, 1           ; ymm4=ROH*FIX(0.500)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm1, [GOTOFF(eax,PD_ONEHALFM1_CJ)]  ; ymm1=[PD_ONEHALFM1_CJ]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpaddd      ymm7, ymm7, ymm3
shun-iwasawa 82a8f5
    vpaddd      ymm5, ymm5, ymm4
shun-iwasawa 82a8f5
    vpaddd      ymm7, ymm7, ymm1
shun-iwasawa 82a8f5
    vpaddd      ymm5, ymm5, ymm1
shun-iwasawa 82a8f5
    vpsrld      ymm7, ymm7, SCALEBITS   ; ymm7=CrOL
shun-iwasawa 82a8f5
    vpsrld      ymm5, ymm5, SCALEBITS   ; ymm5=CrOH
shun-iwasawa 82a8f5
    vpackssdw   ymm7, ymm7, ymm5        ; ymm7=CrO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm3, YMMWORD [wk(0)]   ; ymm3=RE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm4, ymm6
shun-iwasawa 82a8f5
    vpunpcklwd  ymm6, ymm6, ymm2
shun-iwasawa 82a8f5
    vpunpckhwd  ymm4, ymm4, ymm2
shun-iwasawa 82a8f5
    vmovdqa     ymm1, ymm6
shun-iwasawa 82a8f5
    vmovdqa     ymm5, ymm4
shun-iwasawa 82a8f5
    vpmaddwd    ymm6, ymm6, [GOTOFF(eax,PW_F0114_F0250)]  ; ymm6=BEL*FIX(0.114)+GEL*FIX(0.250)
shun-iwasawa 82a8f5
    vpmaddwd    ymm4, ymm4, [GOTOFF(eax,PW_F0114_F0250)]  ; ymm4=BEH*FIX(0.114)+GEH*FIX(0.250)
shun-iwasawa 82a8f5
    vpmaddwd    ymm1, ymm1, [GOTOFF(eax,PW_MF008_MF041)]  ; ymm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
shun-iwasawa 82a8f5
    vpmaddwd    ymm5, ymm5, [GOTOFF(eax,PW_MF008_MF041)]  ; ymm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm2, [GOTOFF(eax,PD_ONEHALF)]            ; ymm2=[PD_ONEHALF]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpaddd      ymm6, ymm6, YMMWORD [wk(6)]
shun-iwasawa 82a8f5
    vpaddd      ymm4, ymm4, YMMWORD [wk(7)]
shun-iwasawa 82a8f5
    vpaddd      ymm6, ymm6, ymm2
shun-iwasawa 82a8f5
    vpaddd      ymm4, ymm4, ymm2
shun-iwasawa 82a8f5
    vpsrld      ymm6, ymm6, SCALEBITS   ; ymm6=YEL
shun-iwasawa 82a8f5
    vpsrld      ymm4, ymm4, SCALEBITS   ; ymm4=YEH
shun-iwasawa 82a8f5
    vpackssdw   ymm6, ymm6, ymm4        ; ymm6=YE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpsllw      ymm0, ymm0, BYTE_BIT
shun-iwasawa 82a8f5
    vpor        ymm6, ymm6, ymm0        ; ymm6=Y
shun-iwasawa 82a8f5
    vmovdqu     YMMWORD [edi], ymm6     ; Save Y
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpxor       ymm2, ymm2, ymm2
shun-iwasawa 82a8f5
    vpxor       ymm4, ymm4, ymm4
shun-iwasawa 82a8f5
    vpunpcklwd  ymm2, ymm2, ymm3        ; ymm2=REL
shun-iwasawa 82a8f5
    vpunpckhwd  ymm4, ymm4, ymm3        ; ymm4=REH
shun-iwasawa 82a8f5
    vpsrld      ymm2, ymm2, 1           ; ymm2=REL*FIX(0.500)
shun-iwasawa 82a8f5
    vpsrld      ymm4, ymm4, 1           ; ymm4=REH*FIX(0.500)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vmovdqa     ymm0, [GOTOFF(eax,PD_ONEHALFM1_CJ)]  ; ymm0=[PD_ONEHALFM1_CJ]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpaddd      ymm1, ymm1, ymm2
shun-iwasawa 82a8f5
    vpaddd      ymm5, ymm5, ymm4
shun-iwasawa 82a8f5
    vpaddd      ymm1, ymm1, ymm0
shun-iwasawa 82a8f5
    vpaddd      ymm5, ymm5, ymm0
shun-iwasawa 82a8f5
    vpsrld      ymm1, ymm1, SCALEBITS   ; ymm1=CrEL
shun-iwasawa 82a8f5
    vpsrld      ymm5, ymm5, SCALEBITS   ; ymm5=CrEH
shun-iwasawa 82a8f5
    vpackssdw   ymm1, ymm1, ymm5        ; ymm1=CrE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    vpsllw      ymm7, ymm7, BYTE_BIT
shun-iwasawa 82a8f5
    vpor        ymm1, ymm1, ymm7        ; ymm1=Cr
shun-iwasawa 82a8f5
    vmovdqu     YMMWORD [edx], ymm1     ; Save Cr
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_YMMWORD
shun-iwasawa 82a8f5
    add         esi, RGB_PIXELSIZE*SIZEOF_YMMWORD  ; inptr
shun-iwasawa 82a8f5
    add         edi, byte SIZEOF_YMMWORD           ; outptr0
shun-iwasawa 82a8f5
    add         ebx, byte SIZEOF_YMMWORD           ; outptr1
shun-iwasawa 82a8f5
    add         edx, byte SIZEOF_YMMWORD           ; outptr2
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_YMMWORD
shun-iwasawa 82a8f5
    jae         near .columnloop
shun-iwasawa 82a8f5
    test        ecx, ecx
shun-iwasawa 82a8f5
    jnz         near .column_ld1
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pop         ecx                     ; col
shun-iwasawa 82a8f5
    pop         esi
shun-iwasawa 82a8f5
    pop         edi
shun-iwasawa 82a8f5
    pop         ebx
shun-iwasawa 82a8f5
    pop         edx
shun-iwasawa 82a8f5
    poppic      eax
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    add         esi, byte SIZEOF_JSAMPROW  ; input_buf
shun-iwasawa 82a8f5
    add         edi, byte SIZEOF_JSAMPROW
shun-iwasawa 82a8f5
    add         ebx, byte SIZEOF_JSAMPROW
shun-iwasawa 82a8f5
    add         edx, byte SIZEOF_JSAMPROW
shun-iwasawa 82a8f5
    dec         eax                        ; num_rows
shun-iwasawa 82a8f5
    jg          near .rowloop
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.return:
shun-iwasawa 82a8f5
    vzeroupper
shun-iwasawa 82a8f5
    pop         edi
shun-iwasawa 82a8f5
    pop         esi
shun-iwasawa 82a8f5
;   pop         edx                     ; need not be preserved
shun-iwasawa 82a8f5
;   pop         ecx                     ; need not be preserved
shun-iwasawa 82a8f5
    pop         ebx
shun-iwasawa 82a8f5
    mov         esp, ebp                ; esp <- aligned ebp
shun-iwasawa 82a8f5
    pop         esp                     ; esp <- original ebp
shun-iwasawa 82a8f5
    pop         ebp
shun-iwasawa 82a8f5
    ret
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
; For some reason, the OS X linker does not honor the request to align the
shun-iwasawa 82a8f5
; segment unless we do this.
shun-iwasawa 82a8f5
    align       32