shun-iwasawa 82a8f5
;
shun-iwasawa 82a8f5
; jquantf.asm - sample data conversion and quantization (SSE & SSE2)
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_sse2(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_sse2)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTN(jsimd_convsamp_float_sse2):
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     xmm7, xmm7
shun-iwasawa 82a8f5
    psllw       xmm7, 7
shun-iwasawa 82a8f5
    packsswb    xmm7, xmm7              ; xmm7 = 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        xmm0, XMM_MMWORD [ebx+eax*SIZEOF_JSAMPLE]
shun-iwasawa 82a8f5
    movq        xmm1, XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE]
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    psubb       xmm0, xmm7              ; xmm0=(01234567)
shun-iwasawa 82a8f5
    psubb       xmm1, xmm7              ; xmm1=(89ABCDEF)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklbw   xmm0, xmm0              ; xmm0=(*0*1*2*3*4*5*6*7)
shun-iwasawa 82a8f5
    punpcklbw   xmm1, xmm1              ; xmm1=(*8*9*A*B*C*D*E*F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    punpcklwd   xmm2, xmm0              ; xmm2=(***0***1***2***3)
shun-iwasawa 82a8f5
    punpckhwd   xmm0, xmm0              ; xmm0=(***4***5***6***7)
shun-iwasawa 82a8f5
    punpcklwd   xmm3, xmm1              ; xmm3=(***8***9***A***B)
shun-iwasawa 82a8f5
    punpckhwd   xmm1, xmm1              ; xmm1=(***C***D***E***F)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    psrad       xmm2, (DWORD_BIT-BYTE_BIT)  ; xmm2=(0123)
shun-iwasawa 82a8f5
    psrad       xmm0, (DWORD_BIT-BYTE_BIT)  ; xmm0=(4567)
shun-iwasawa 82a8f5
    cvtdq2ps    xmm2, xmm2                  ; xmm2=(0123)
shun-iwasawa 82a8f5
    cvtdq2ps    xmm0, xmm0                  ; xmm0=(4567)
shun-iwasawa 82a8f5
    psrad       xmm3, (DWORD_BIT-BYTE_BIT)  ; xmm3=(89AB)
shun-iwasawa 82a8f5
    psrad       xmm1, (DWORD_BIT-BYTE_BIT)  ; xmm1=(CDEF)
shun-iwasawa 82a8f5
    cvtdq2ps    xmm3, xmm3                  ; xmm3=(89AB)
shun-iwasawa 82a8f5
    cvtdq2ps    xmm1, xmm1                  ; xmm1=(CDEF)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movaps      XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_FAST_FLOAT)], xmm2
shun-iwasawa 82a8f5
    movaps      XMMWORD [XMMBLOCK(0,1,edi,SIZEOF_FAST_FLOAT)], xmm0
shun-iwasawa 82a8f5
    movaps      XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_FAST_FLOAT)], xmm3
shun-iwasawa 82a8f5
    movaps      XMMWORD [XMMBLOCK(1,1,edi,SIZEOF_FAST_FLOAT)], xmm1
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         short .convloop
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_sse2(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_sse2)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTN(jsimd_quantize_float_sse2):
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
    cvtps2dq    xmm0, xmm0
shun-iwasawa 82a8f5
    cvtps2dq    xmm1, xmm1
shun-iwasawa 82a8f5
    cvtps2dq    xmm2, xmm2
shun-iwasawa 82a8f5
    cvtps2dq    xmm3, xmm3
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    packssdw    xmm0, xmm1
shun-iwasawa 82a8f5
    packssdw    xmm2, xmm3
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
    movdqa      XMMWORD [XMMBLOCK(0,0,edi,SIZEOF_JCOEF)], xmm0
shun-iwasawa 82a8f5
    movdqa      XMMWORD [XMMBLOCK(1,0,edi,SIZEOF_JCOEF)], xmm2
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
    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