Blame thirdparty/libjpeg-turbo/libjpeg-turbo-2.0.6/simd/i386/jquant-sse.asm

shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; jquant.asm - sample data conversion and quantization (SSE & MMX)
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB</ossman@cendio.se>
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 "jsimdext.inc"
shun-iwasawa 82a8f5
%include "jdct.inc"
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
; --------------------------------------------------------------------------
shun-iwasawa 82a8f5
    SECTION     SEG_TEXT
shun-iwasawa 82a8f5
    BITS        32
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; Load data into workspace, applying unsigned->signed conversion
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; GLOBAL(void)
shun-iwasawa 82a8f5
; jsimd_convsamp_float_sse(JSAMPARRAY sample_data, JDIMENSION start_col,
shun-iwasawa 82a8f5
;                          FAST_FLOAT *workspace);
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%define sample_data  ebp + 8            ; JSAMPARRAY sample_data
shun-iwasawa 82a8f5
%define start_col    ebp + 12           ; JDIMENSION start_col
shun-iwasawa 82a8f5
%define workspace    ebp + 16           ; FAST_FLOAT *workspace
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    align       32
shun-iwasawa 82a8f5
    GLOBAL_FUNCTION(jsimd_convsamp_float_sse)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTN(jsimd_convsamp_float_sse):
shun-iwasawa 82a8f5
    push        ebp
shun-iwasawa 82a8f5
    mov         ebp, esp
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
    pcmpeqw     mm7, mm7
shun-iwasawa 82a8f5
    psllw       mm7, 7
shun-iwasawa 82a8f5
    packsswb    mm7, mm7                ; mm7 = PB_CENTERJSAMPLE (0x808080..)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    mov         esi, JSAMPARRAY [sample_data]  ; (JSAMPROW *)
shun-iwasawa 82a8f5
    mov         eax, JDIMENSION [start_col]
shun-iwasawa 82a8f5
    mov         edi, POINTER [workspace]       ; (DCTELEM *)
shun-iwasawa 82a8f5
    mov         ecx, DCTSIZE/2
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
.convloop:
shun-iwasawa 82a8f5
    mov         ebx, JSAMPROW [esi+0*SIZEOF_JSAMPROW]  ; (JSAMPLE *)
shun-iwasawa 82a8f5
    mov         edx, JSAMPROW [esi+1*SIZEOF_JSAMPROW]  ; (JSAMPLE *)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movq        mm0, MMWORD [ebx+eax*SIZEOF_JSAMPLE]
shun-iwasawa 82a8f5
    movq        mm1, MMWORD [edx+eax*SIZEOF_JSAMPLE]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    psubb       mm0, mm7                ; mm0=(01234567)
shun-iwasawa 82a8f5
    psubb       mm1, mm7                ; mm1=(89ABCDEF)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklbw   mm2, mm0                ; mm2=(*0*1*2*3)
shun-iwasawa 82a8f5
    punpckhbw   mm0, mm0                ; mm0=(*4*5*6*7)
shun-iwasawa 82a8f5
    punpcklbw   mm3, mm1                ; mm3=(*8*9*A*B)
shun-iwasawa 82a8f5
    punpckhbw   mm1, mm1                ; mm1=(*C*D*E*F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklwd   mm4, mm2                ; mm4=(***0***1)
shun-iwasawa 82a8f5
    punpckhwd   mm2, mm2                ; mm2=(***2***3)
shun-iwasawa 82a8f5
    punpcklwd   mm5, mm0                ; mm5=(***4***5)
shun-iwasawa 82a8f5
    punpckhwd   mm0, mm0                ; mm0=(***6***7)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    psrad       mm4, (DWORD_BIT-BYTE_BIT)  ; mm4=(01)
shun-iwasawa 82a8f5
    psrad       mm2, (DWORD_BIT-BYTE_BIT)  ; mm2=(23)
shun-iwasawa 82a8f5
    cvtpi2ps    xmm0, mm4                  ; xmm0=(01**)
shun-iwasawa 82a8f5
    cvtpi2ps    xmm1, mm2                  ; xmm1=(23**)
shun-iwasawa 82a8f5
    psrad       mm5, (DWORD_BIT-BYTE_BIT)  ; mm5=(45)
shun-iwasawa 82a8f5
    psrad       mm0, (DWORD_BIT-BYTE_BIT)  ; mm0=(67)
shun-iwasawa 82a8f5
    cvtpi2ps    xmm2, mm5                  ; xmm2=(45**)
shun-iwasawa 82a8f5
    cvtpi2ps    xmm3, mm0                  ; xmm3=(67**)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklwd   mm6, mm3                ; mm6=(***8***9)
shun-iwasawa 82a8f5
    punpckhwd   mm3, mm3                ; mm3=(***A***B)
shun-iwasawa 82a8f5
    punpcklwd   mm4, mm1                ; mm4=(***C***D)
shun-iwasawa 82a8f5
    punpckhwd   mm1, mm1                ; mm1=(***E***F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    psrad       mm6, (DWORD_BIT-BYTE_BIT)  ; mm6=(89)
shun-iwasawa 82a8f5
    psrad       mm3, (DWORD_BIT-BYTE_BIT)  ; mm3=(AB)
shun-iwasawa 82a8f5
    cvtpi2ps    xmm4, mm6                  ; xmm4=(89**)
shun-iwasawa 82a8f5
    cvtpi2ps    xmm5, mm3                  ; xmm5=(AB**)
shun-iwasawa 82a8f5
    psrad       mm4, (DWORD_BIT-BYTE_BIT)  ; mm4=(CD)
shun-iwasawa 82a8f5
    psrad       mm1, (DWORD_BIT-BYTE_BIT)  ; mm1=(EF)
shun-iwasawa 82a8f5
    cvtpi2ps    xmm6, mm4                  ; xmm6=(CD**)
shun-iwasawa 82a8f5
    cvtpi2ps    xmm7, mm1                  ; xmm7=(EF**)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movlhps     xmm0, xmm1              ; xmm0=(0123)
shun-iwasawa 82a8f5
    movlhps     xmm2, xmm3              ; xmm2=(4567)
shun-iwasawa 82a8f5
    movlhps     xmm4, xmm5              ; xmm4=(89AB)
shun-iwasawa 82a8f5
    movlhps     xmm6, xmm7              ; xmm6=(CDEF)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movaps      XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm0
shun-iwasawa 82a8f5
    movaps      XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm2
shun-iwasawa 82a8f5
    movaps      XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm4
shun-iwasawa 82a8f5
    movaps      XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm6
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    add         esi, byte 2*SIZEOF_JSAMPROW
shun-iwasawa 82a8f5
    add         edi, byte 2*DCTSIZE*SIZEOF_FAST_FLOAT
shun-iwasawa 82a8f5
    dec         ecx
shun-iwasawa 82a8f5
    jnz         near .convloop
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    emms                                ; empty MMX state
shun-iwasawa 82a8f5
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
    pop         ebp
shun-iwasawa 82a8f5
    ret
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
; --------------------------------------------------------------------------
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; Quantize/descale the coefficients, and store into coef_block
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; GLOBAL(void)
shun-iwasawa 82a8f5
; jsimd_quantize_float_sse(JCOEFPTR coef_block, FAST_FLOAT *divisors,
shun-iwasawa 82a8f5
;                          FAST_FLOAT *workspace);
shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
%define coef_block  ebp + 8             ; JCOEFPTR coef_block
shun-iwasawa 82a8f5
%define divisors    ebp + 12            ; FAST_FLOAT *divisors
shun-iwasawa 82a8f5
%define workspace   ebp + 16            ; FAST_FLOAT *workspace
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    align       32
shun-iwasawa 82a8f5
    GLOBAL_FUNCTION(jsimd_quantize_float_sse)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTN(jsimd_quantize_float_sse):
shun-iwasawa 82a8f5
    push        ebp
shun-iwasawa 82a8f5
    mov         ebp, esp
shun-iwasawa 82a8f5
;   push        ebx                     ; unused
shun-iwasawa 82a8f5
;   push        ecx                     ; unused
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
    mov         esi, POINTER [workspace]
shun-iwasawa 82a8f5
    mov         edx, POINTER [divisors]
shun-iwasawa 82a8f5
    mov         edi, JCOEFPTR [coef_block]
shun-iwasawa 82a8f5
    mov         eax, DCTSIZE2/16
shun-iwasawa 82a8f5
    alignx      16, 7
shun-iwasawa 82a8f5
.quantloop:
shun-iwasawa 82a8f5
    movaps      xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_FAST_FLOAT)]
shun-iwasawa 82a8f5
    movaps      xmm1, XMMWORD [XMMBLOCK(0,1,esi,SIZEOF_FAST_FLOAT)]
shun-iwasawa 82a8f5
    mulps       xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_FAST_FLOAT)]
shun-iwasawa 82a8f5
    mulps       xmm1, XMMWORD [XMMBLOCK(0,1,edx,SIZEOF_FAST_FLOAT)]
shun-iwasawa 82a8f5
    movaps      xmm2, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_FAST_FLOAT)]
shun-iwasawa 82a8f5
    movaps      xmm3, XMMWORD [XMMBLOCK(1,1,esi,SIZEOF_FAST_FLOAT)]
shun-iwasawa 82a8f5
    mulps       xmm2, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_FAST_FLOAT)]
shun-iwasawa 82a8f5
    mulps       xmm3, XMMWORD [XMMBLOCK(1,1,edx,SIZEOF_FAST_FLOAT)]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movhlps     xmm4, xmm0
shun-iwasawa 82a8f5
    movhlps     xmm5, xmm1
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    cvtps2pi    mm0, xmm0
shun-iwasawa 82a8f5
    cvtps2pi    mm1, xmm1
shun-iwasawa 82a8f5
    cvtps2pi    mm4, xmm4
shun-iwasawa 82a8f5
    cvtps2pi    mm5, xmm5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movhlps     xmm6, xmm2
shun-iwasawa 82a8f5
    movhlps     xmm7, xmm3
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    cvtps2pi    mm2, xmm2
shun-iwasawa 82a8f5
    cvtps2pi    mm3, xmm3
shun-iwasawa 82a8f5
    cvtps2pi    mm6, xmm6
shun-iwasawa 82a8f5
    cvtps2pi    mm7, xmm7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    packssdw    mm0, mm4
shun-iwasawa 82a8f5
    packssdw    mm1, mm5
shun-iwasawa 82a8f5
    packssdw    mm2, mm6
shun-iwasawa 82a8f5
    packssdw    mm3, mm7
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movq        MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0
shun-iwasawa 82a8f5
    movq        MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm1
shun-iwasawa 82a8f5
    movq        MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm2
shun-iwasawa 82a8f5
    movq        MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm3
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    add         esi, byte 16*SIZEOF_FAST_FLOAT
shun-iwasawa 82a8f5
    add         edx, byte 16*SIZEOF_FAST_FLOAT
shun-iwasawa 82a8f5
    add         edi, byte 16*SIZEOF_JCOEF
shun-iwasawa 82a8f5
    dec         eax
shun-iwasawa 82a8f5
    jnz         short .quantloop
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    emms                                ; empty MMX state
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    pop         edi
shun-iwasawa 82a8f5
    pop         esi
shun-iwasawa 82a8f5
;   pop         edx                     ; need not be preserved
shun-iwasawa 82a8f5
;   pop         ecx                     ; unused
shun-iwasawa 82a8f5
;   pop         ebx                     ; unused
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