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

shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; jccolext.asm - colorspace conversion (SSE2)
shun-iwasawa 82a8f5
;
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_sse2(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_XMMWORD
shun-iwasawa 82a8f5
                                        ; xmmword 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_sse2)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTN(jsimd_rgb_ycc_convert_sse2):
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_XMMWORD)  ; align to 128 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_XMMWORD
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
    movd        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
    movd        xmmF, XMM_DWORD [esi+ecx]
shun-iwasawa 82a8f5
    pslldq      xmmA, SIZEOF_DWORD
shun-iwasawa 82a8f5
    por         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
    movq        xmmB, XMM_MMWORD [esi+ecx]
shun-iwasawa 82a8f5
    pslldq      xmmA, SIZEOF_MMWORD
shun-iwasawa 82a8f5
    por         xmmA, xmmB
shun-iwasawa 82a8f5
.column_ld16:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jz          short .column_ld32
shun-iwasawa 82a8f5
    movdqa      xmmF, xmmA
shun-iwasawa 82a8f5
    movdqu      xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
    mov         ecx, SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jmp         short .rgb_ycc_cnv
shun-iwasawa 82a8f5
.column_ld32:
shun-iwasawa 82a8f5
    test        cl, 2*SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    mov         ecx, SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jz          short .rgb_ycc_cnv
shun-iwasawa 82a8f5
    movdqa      xmmB, xmmA
shun-iwasawa 82a8f5
    movdqu      xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
    movdqu      xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
    jmp         short .rgb_ycc_cnv
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.columnloop:
shun-iwasawa 82a8f5
    movdqu      xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
    movdqu      xmmF, XMMWORD [esi+1*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
    movdqu      xmmB, XMMWORD [esi+2*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.rgb_ycc_cnv:
shun-iwasawa 82a8f5
    ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
shun-iwasawa 82a8f5
    ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
shun-iwasawa 82a8f5
    ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmG, xmmA
shun-iwasawa 82a8f5
    pslldq      xmmA, 8     ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
shun-iwasawa 82a8f5
    psrldq      xmmG, 8     ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpckhbw   xmmA, xmmF  ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
shun-iwasawa 82a8f5
    pslldq      xmmF, 8     ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklbw   xmmG, xmmB  ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
shun-iwasawa 82a8f5
    punpckhbw   xmmF, xmmB  ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmD, xmmA
shun-iwasawa 82a8f5
    pslldq      xmmA, 8     ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
shun-iwasawa 82a8f5
    psrldq      xmmD, 8     ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpckhbw   xmmA, xmmG  ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
shun-iwasawa 82a8f5
    pslldq      xmmG, 8     ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklbw   xmmD, xmmF  ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
shun-iwasawa 82a8f5
    punpckhbw   xmmG, xmmF  ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmE, xmmA
shun-iwasawa 82a8f5
    pslldq      xmmA, 8     ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
shun-iwasawa 82a8f5
    psrldq      xmmE, 8     ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpckhbw   xmmA, xmmD  ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
shun-iwasawa 82a8f5
    pslldq      xmmD, 8     ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklbw   xmmE, xmmG  ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
shun-iwasawa 82a8f5
    punpckhbw   xmmD, xmmG  ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pxor        xmmH, xmmH
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmC, xmmA
shun-iwasawa 82a8f5
    punpcklbw   xmmA, xmmH  ; xmmA=(00 02 04 06 08 0A 0C 0E)
shun-iwasawa 82a8f5
    punpckhbw   xmmC, xmmH  ; xmmC=(10 12 14 16 18 1A 1C 1E)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmB, xmmE
shun-iwasawa 82a8f5
    punpcklbw   xmmE, xmmH  ; xmmE=(20 22 24 26 28 2A 2C 2E)
shun-iwasawa 82a8f5
    punpckhbw   xmmB, xmmH  ; xmmB=(01 03 05 07 09 0B 0D 0F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmF, xmmD
shun-iwasawa 82a8f5
    punpcklbw   xmmD, xmmH  ; xmmD=(11 13 15 17 19 1B 1D 1F)
shun-iwasawa 82a8f5
    punpckhbw   xmmF, xmmH  ; xmmF=(21 23 25 27 29 2B 2D 2F)
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
    movd        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
    movq        xmmE, XMM_MMWORD [esi+ecx*RGB_PIXELSIZE]
shun-iwasawa 82a8f5
    pslldq      xmmA, SIZEOF_MMWORD
shun-iwasawa 82a8f5
    por         xmmA, xmmE
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
    movdqa      xmmE, xmmA
shun-iwasawa 82a8f5
    movdqu      xmmA, XMMWORD [esi+ecx*RGB_PIXELSIZE]
shun-iwasawa 82a8f5
.column_ld8:
shun-iwasawa 82a8f5
    test        cl, SIZEOF_XMMWORD/2
shun-iwasawa 82a8f5
    mov         ecx, SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    jz          short .rgb_ycc_cnv
shun-iwasawa 82a8f5
    movdqa      xmmF, xmmA
shun-iwasawa 82a8f5
    movdqa      xmmH, xmmE
shun-iwasawa 82a8f5
    movdqu      xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
    movdqu      xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
    jmp         short .rgb_ycc_cnv
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.columnloop:
shun-iwasawa 82a8f5
    movdqu      xmmA, XMMWORD [esi+0*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
    movdqu      xmmE, XMMWORD [esi+1*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
    movdqu      xmmF, XMMWORD [esi+2*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
    movdqu      xmmH, XMMWORD [esi+3*SIZEOF_XMMWORD]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
.rgb_ycc_cnv:
shun-iwasawa 82a8f5
    ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
shun-iwasawa 82a8f5
    ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
shun-iwasawa 82a8f5
    ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
shun-iwasawa 82a8f5
    ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmD, xmmA
shun-iwasawa 82a8f5
    punpcklbw   xmmA, xmmE      ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
shun-iwasawa 82a8f5
    punpckhbw   xmmD, xmmE      ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmC, xmmF
shun-iwasawa 82a8f5
    punpcklbw   xmmF, xmmH      ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
shun-iwasawa 82a8f5
    punpckhbw   xmmC, xmmH      ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmB, xmmA
shun-iwasawa 82a8f5
    punpcklwd   xmmA, xmmF      ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
shun-iwasawa 82a8f5
    punpckhwd   xmmB, xmmF      ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmG, xmmD
shun-iwasawa 82a8f5
    punpcklwd   xmmD, xmmC      ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
shun-iwasawa 82a8f5
    punpckhwd   xmmG, xmmC      ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmE, xmmA
shun-iwasawa 82a8f5
    punpcklbw   xmmA, xmmD      ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
shun-iwasawa 82a8f5
    punpckhbw   xmmE, xmmD      ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmH, xmmB
shun-iwasawa 82a8f5
    punpcklbw   xmmB, xmmG      ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
shun-iwasawa 82a8f5
    punpckhbw   xmmH, xmmG      ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pxor        xmmF, xmmF
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmC, xmmA
shun-iwasawa 82a8f5
    punpcklbw   xmmA, xmmF      ; xmmA=(00 02 04 06 08 0A 0C 0E)
shun-iwasawa 82a8f5
    punpckhbw   xmmC, xmmF      ; xmmC=(10 12 14 16 18 1A 1C 1E)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmD, xmmB
shun-iwasawa 82a8f5
    punpcklbw   xmmB, xmmF      ; xmmB=(01 03 05 07 09 0B 0D 0F)
shun-iwasawa 82a8f5
    punpckhbw   xmmD, xmmF      ; xmmD=(11 13 15 17 19 1B 1D 1F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmmG, xmmE
shun-iwasawa 82a8f5
    punpcklbw   xmmE, xmmF      ; xmmE=(20 22 24 26 28 2A 2C 2E)
shun-iwasawa 82a8f5
    punpckhbw   xmmG, xmmF      ; xmmG=(30 32 34 36 38 3A 3C 3E)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklbw   xmmF, xmmH
shun-iwasawa 82a8f5
    punpckhbw   xmmH, xmmH
shun-iwasawa 82a8f5
    psrlw       xmmF, BYTE_BIT  ; xmmF=(21 23 25 27 29 2B 2D 2F)
shun-iwasawa 82a8f5
    psrlw       xmmH, BYTE_BIT  ; xmmH=(31 33 35 37 39 3B 3D 3F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%endif  ; RGB_PIXELSIZE ; ---------------
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
shun-iwasawa 82a8f5
    ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=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
    movdqa      XMMWORD [wk(0)], xmm0   ; wk(0)=RE
shun-iwasawa 82a8f5
    movdqa      XMMWORD [wk(1)], xmm1   ; wk(1)=RO
shun-iwasawa 82a8f5
    movdqa      XMMWORD [wk(2)], xmm4   ; wk(2)=BE
shun-iwasawa 82a8f5
    movdqa      XMMWORD [wk(3)], xmm5   ; wk(3)=BO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm6, xmm1
shun-iwasawa 82a8f5
    punpcklwd   xmm1, xmm3
shun-iwasawa 82a8f5
    punpckhwd   xmm6, xmm3
shun-iwasawa 82a8f5
    movdqa      xmm7, xmm1
shun-iwasawa 82a8f5
    movdqa      xmm4, xmm6
shun-iwasawa 82a8f5
    pmaddwd     xmm1, [GOTOFF(eax,PW_F0299_F0337)]  ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
shun-iwasawa 82a8f5
    pmaddwd     xmm6, [GOTOFF(eax,PW_F0299_F0337)]  ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
shun-iwasawa 82a8f5
    pmaddwd     xmm7, [GOTOFF(eax,PW_MF016_MF033)]  ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
shun-iwasawa 82a8f5
    pmaddwd     xmm4, [GOTOFF(eax,PW_MF016_MF033)]  ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      XMMWORD [wk(4)], xmm1   ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
shun-iwasawa 82a8f5
    movdqa      XMMWORD [wk(5)], xmm6   ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pxor        xmm1, xmm1
shun-iwasawa 82a8f5
    pxor        xmm6, xmm6
shun-iwasawa 82a8f5
    punpcklwd   xmm1, xmm5              ; xmm1=BOL
shun-iwasawa 82a8f5
    punpckhwd   xmm6, xmm5              ; xmm6=BOH
shun-iwasawa 82a8f5
    psrld       xmm1, 1                 ; xmm1=BOL*FIX(0.500)
shun-iwasawa 82a8f5
    psrld       xmm6, 1                 ; xmm6=BOH*FIX(0.500)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm5, [GOTOFF(eax,PD_ONEHALFM1_CJ)]  ; xmm5=[PD_ONEHALFM1_CJ]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddd       xmm7, xmm1
shun-iwasawa 82a8f5
    paddd       xmm4, xmm6
shun-iwasawa 82a8f5
    paddd       xmm7, xmm5
shun-iwasawa 82a8f5
    paddd       xmm4, xmm5
shun-iwasawa 82a8f5
    psrld       xmm7, SCALEBITS         ; xmm7=CbOL
shun-iwasawa 82a8f5
    psrld       xmm4, SCALEBITS         ; xmm4=CbOH
shun-iwasawa 82a8f5
    packssdw    xmm7, xmm4              ; xmm7=CbO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm1, XMMWORD [wk(2)]   ; xmm1=BE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm6, xmm0
shun-iwasawa 82a8f5
    punpcklwd   xmm0, xmm2
shun-iwasawa 82a8f5
    punpckhwd   xmm6, xmm2
shun-iwasawa 82a8f5
    movdqa      xmm5, xmm0
shun-iwasawa 82a8f5
    movdqa      xmm4, xmm6
shun-iwasawa 82a8f5
    pmaddwd     xmm0, [GOTOFF(eax,PW_F0299_F0337)]  ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
shun-iwasawa 82a8f5
    pmaddwd     xmm6, [GOTOFF(eax,PW_F0299_F0337)]  ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
shun-iwasawa 82a8f5
    pmaddwd     xmm5, [GOTOFF(eax,PW_MF016_MF033)]  ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
shun-iwasawa 82a8f5
    pmaddwd     xmm4, [GOTOFF(eax,PW_MF016_MF033)]  ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      XMMWORD [wk(6)], xmm0   ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
shun-iwasawa 82a8f5
    movdqa      XMMWORD [wk(7)], xmm6   ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pxor        xmm0, xmm0
shun-iwasawa 82a8f5
    pxor        xmm6, xmm6
shun-iwasawa 82a8f5
    punpcklwd   xmm0, xmm1              ; xmm0=BEL
shun-iwasawa 82a8f5
    punpckhwd   xmm6, xmm1              ; xmm6=BEH
shun-iwasawa 82a8f5
    psrld       xmm0, 1                 ; xmm0=BEL*FIX(0.500)
shun-iwasawa 82a8f5
    psrld       xmm6, 1                 ; xmm6=BEH*FIX(0.500)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm1, [GOTOFF(eax,PD_ONEHALFM1_CJ)]  ; xmm1=[PD_ONEHALFM1_CJ]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddd       xmm5, xmm0
shun-iwasawa 82a8f5
    paddd       xmm4, xmm6
shun-iwasawa 82a8f5
    paddd       xmm5, xmm1
shun-iwasawa 82a8f5
    paddd       xmm4, xmm1
shun-iwasawa 82a8f5
    psrld       xmm5, SCALEBITS         ; xmm5=CbEL
shun-iwasawa 82a8f5
    psrld       xmm4, SCALEBITS         ; xmm4=CbEH
shun-iwasawa 82a8f5
    packssdw    xmm5, xmm4              ; xmm5=CbE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    psllw       xmm7, BYTE_BIT
shun-iwasawa 82a8f5
    por         xmm5, xmm7              ; xmm5=Cb
shun-iwasawa 82a8f5
    movdqa      XMMWORD [ebx], xmm5     ; Save Cb
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm0, XMMWORD [wk(3)]   ; xmm0=BO
shun-iwasawa 82a8f5
    movdqa      xmm6, XMMWORD [wk(2)]   ; xmm6=BE
shun-iwasawa 82a8f5
    movdqa      xmm1, XMMWORD [wk(1)]   ; xmm1=RO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm4, xmm0
shun-iwasawa 82a8f5
    punpcklwd   xmm0, xmm3
shun-iwasawa 82a8f5
    punpckhwd   xmm4, xmm3
shun-iwasawa 82a8f5
    movdqa      xmm7, xmm0
shun-iwasawa 82a8f5
    movdqa      xmm5, xmm4
shun-iwasawa 82a8f5
    pmaddwd     xmm0, [GOTOFF(eax,PW_F0114_F0250)]  ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
shun-iwasawa 82a8f5
    pmaddwd     xmm4, [GOTOFF(eax,PW_F0114_F0250)]  ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
shun-iwasawa 82a8f5
    pmaddwd     xmm7, [GOTOFF(eax,PW_MF008_MF041)]  ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
shun-iwasawa 82a8f5
    pmaddwd     xmm5, [GOTOFF(eax,PW_MF008_MF041)]  ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm3, [GOTOFF(eax,PD_ONEHALF)]  ; xmm3=[PD_ONEHALF]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddd       xmm0, XMMWORD [wk(4)]
shun-iwasawa 82a8f5
    paddd       xmm4, XMMWORD [wk(5)]
shun-iwasawa 82a8f5
    paddd       xmm0, xmm3
shun-iwasawa 82a8f5
    paddd       xmm4, xmm3
shun-iwasawa 82a8f5
    psrld       xmm0, SCALEBITS         ; xmm0=YOL
shun-iwasawa 82a8f5
    psrld       xmm4, SCALEBITS         ; xmm4=YOH
shun-iwasawa 82a8f5
    packssdw    xmm0, xmm4              ; xmm0=YO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pxor        xmm3, xmm3
shun-iwasawa 82a8f5
    pxor        xmm4, xmm4
shun-iwasawa 82a8f5
    punpcklwd   xmm3, xmm1              ; xmm3=ROL
shun-iwasawa 82a8f5
    punpckhwd   xmm4, xmm1              ; xmm4=ROH
shun-iwasawa 82a8f5
    psrld       xmm3, 1                 ; xmm3=ROL*FIX(0.500)
shun-iwasawa 82a8f5
    psrld       xmm4, 1                 ; xmm4=ROH*FIX(0.500)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm1, [GOTOFF(eax,PD_ONEHALFM1_CJ)]  ; xmm1=[PD_ONEHALFM1_CJ]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddd       xmm7, xmm3
shun-iwasawa 82a8f5
    paddd       xmm5, xmm4
shun-iwasawa 82a8f5
    paddd       xmm7, xmm1
shun-iwasawa 82a8f5
    paddd       xmm5, xmm1
shun-iwasawa 82a8f5
    psrld       xmm7, SCALEBITS         ; xmm7=CrOL
shun-iwasawa 82a8f5
    psrld       xmm5, SCALEBITS         ; xmm5=CrOH
shun-iwasawa 82a8f5
    packssdw    xmm7, xmm5              ; xmm7=CrO
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm3, XMMWORD [wk(0)]   ; xmm3=RE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm4, xmm6
shun-iwasawa 82a8f5
    punpcklwd   xmm6, xmm2
shun-iwasawa 82a8f5
    punpckhwd   xmm4, xmm2
shun-iwasawa 82a8f5
    movdqa      xmm1, xmm6
shun-iwasawa 82a8f5
    movdqa      xmm5, xmm4
shun-iwasawa 82a8f5
    pmaddwd     xmm6, [GOTOFF(eax,PW_F0114_F0250)]  ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
shun-iwasawa 82a8f5
    pmaddwd     xmm4, [GOTOFF(eax,PW_F0114_F0250)]  ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
shun-iwasawa 82a8f5
    pmaddwd     xmm1, [GOTOFF(eax,PW_MF008_MF041)]  ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
shun-iwasawa 82a8f5
    pmaddwd     xmm5, [GOTOFF(eax,PW_MF008_MF041)]  ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm2, [GOTOFF(eax,PD_ONEHALF)]      ; xmm2=[PD_ONEHALF]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddd       xmm6, XMMWORD [wk(6)]
shun-iwasawa 82a8f5
    paddd       xmm4, XMMWORD [wk(7)]
shun-iwasawa 82a8f5
    paddd       xmm6, xmm2
shun-iwasawa 82a8f5
    paddd       xmm4, xmm2
shun-iwasawa 82a8f5
    psrld       xmm6, SCALEBITS         ; xmm6=YEL
shun-iwasawa 82a8f5
    psrld       xmm4, SCALEBITS         ; xmm4=YEH
shun-iwasawa 82a8f5
    packssdw    xmm6, xmm4              ; xmm6=YE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    psllw       xmm0, BYTE_BIT
shun-iwasawa 82a8f5
    por         xmm6, xmm0              ; xmm6=Y
shun-iwasawa 82a8f5
    movdqa      XMMWORD [edi], xmm6     ; Save Y
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pxor        xmm2, xmm2
shun-iwasawa 82a8f5
    pxor        xmm4, xmm4
shun-iwasawa 82a8f5
    punpcklwd   xmm2, xmm3              ; xmm2=REL
shun-iwasawa 82a8f5
    punpckhwd   xmm4, xmm3              ; xmm4=REH
shun-iwasawa 82a8f5
    psrld       xmm2, 1                 ; xmm2=REL*FIX(0.500)
shun-iwasawa 82a8f5
    psrld       xmm4, 1                 ; xmm4=REH*FIX(0.500)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      xmm0, [GOTOFF(eax,PD_ONEHALFM1_CJ)]  ; xmm0=[PD_ONEHALFM1_CJ]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    paddd       xmm1, xmm2
shun-iwasawa 82a8f5
    paddd       xmm5, xmm4
shun-iwasawa 82a8f5
    paddd       xmm1, xmm0
shun-iwasawa 82a8f5
    paddd       xmm5, xmm0
shun-iwasawa 82a8f5
    psrld       xmm1, SCALEBITS         ; xmm1=CrEL
shun-iwasawa 82a8f5
    psrld       xmm5, SCALEBITS         ; xmm5=CrEH
shun-iwasawa 82a8f5
    packssdw    xmm1, xmm5              ; xmm1=CrE
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    psllw       xmm7, BYTE_BIT
shun-iwasawa 82a8f5
    por         xmm1, xmm7              ; xmm1=Cr
shun-iwasawa 82a8f5
    movdqa      XMMWORD [edx], xmm1     ; Save Cr
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    sub         ecx, byte SIZEOF_XMMWORD
shun-iwasawa 82a8f5
    add         esi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD  ; inptr
shun-iwasawa 82a8f5
    add         edi, byte SIZEOF_XMMWORD                ; outptr0
shun-iwasawa 82a8f5
    add         ebx, byte SIZEOF_XMMWORD                ; outptr1
shun-iwasawa 82a8f5
    add         edx, byte SIZEOF_XMMWORD                ; outptr2
shun-iwasawa 82a8f5
    cmp         ecx, byte SIZEOF_XMMWORD
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
    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