|
shun-iwasawa |
82a8f5 |
;
|
|
shun-iwasawa |
82a8f5 |
; jcgryext.asm - grayscale colorspace conversion (64-bit SSE2)
|
|
shun-iwasawa |
82a8f5 |
;
|
|
shun-iwasawa |
82a8f5 |
; Copyright (C) 2011, 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_gray_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 |
; r10d = JDIMENSION img_width
|
|
shun-iwasawa |
82a8f5 |
; r11 = JSAMPARRAY input_buf
|
|
shun-iwasawa |
82a8f5 |
; r12 = JSAMPIMAGE output_buf
|
|
shun-iwasawa |
82a8f5 |
; r13d = JDIMENSION output_row
|
|
shun-iwasawa |
82a8f5 |
; r14d = int num_rows
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
%define wk(i) rbp - (WK_NUM - (i)) * SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
|
|
shun-iwasawa |
82a8f5 |
%define WK_NUM 2
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
align 32
|
|
shun-iwasawa |
82a8f5 |
GLOBAL_FUNCTION(jsimd_rgb_gray_convert_sse2)
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
EXTN(jsimd_rgb_gray_convert_sse2):
|
|
shun-iwasawa |
82a8f5 |
push rbp
|
|
shun-iwasawa |
82a8f5 |
mov rax, rsp ; rax = original rbp
|
|
shun-iwasawa |
82a8f5 |
sub rsp, byte 4
|
|
shun-iwasawa |
82a8f5 |
and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
|
|
shun-iwasawa |
82a8f5 |
mov [rsp], rax
|
|
shun-iwasawa |
82a8f5 |
mov rbp, rsp ; rbp = aligned rbp
|
|
shun-iwasawa |
82a8f5 |
lea rsp, [wk(0)]
|
|
shun-iwasawa |
82a8f5 |
collect_args 5
|
|
shun-iwasawa |
82a8f5 |
push rbx
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
mov ecx, r10d
|
|
shun-iwasawa |
82a8f5 |
test rcx, rcx
|
|
shun-iwasawa |
82a8f5 |
jz near .return
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
push rcx
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
mov rsi, r12
|
|
shun-iwasawa |
82a8f5 |
mov ecx, r13d
|
|
shun-iwasawa |
82a8f5 |
mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
|
|
shun-iwasawa |
82a8f5 |
lea rdi, [rdi+rcx*SIZEOF_JSAMPROW]
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
pop rcx
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
mov rsi, r11
|
|
shun-iwasawa |
82a8f5 |
mov eax, r14d
|
|
shun-iwasawa |
82a8f5 |
test rax, rax
|
|
shun-iwasawa |
82a8f5 |
jle near .return
|
|
shun-iwasawa |
82a8f5 |
.rowloop:
|
|
shun-iwasawa |
82a8f5 |
push rdi
|
|
shun-iwasawa |
82a8f5 |
push rsi
|
|
shun-iwasawa |
82a8f5 |
push rcx ; col
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
mov rsi, JSAMPROW [rsi] ; inptr
|
|
shun-iwasawa |
82a8f5 |
mov rdi, JSAMPROW [rdi] ; outptr0
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
cmp rcx, byte SIZEOF_XMMWORD
|
|
shun-iwasawa |
82a8f5 |
jae near .columnloop
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
%if RGB_PIXELSIZE == 3 ; ---------------
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
.column_ld1:
|
|
shun-iwasawa |
82a8f5 |
push rax
|
|
shun-iwasawa |
82a8f5 |
push rdx
|
|
shun-iwasawa |
82a8f5 |
lea rcx, [rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE
|
|
shun-iwasawa |
82a8f5 |
test cl, SIZEOF_BYTE
|
|
shun-iwasawa |
82a8f5 |
jz short .column_ld2
|
|
shun-iwasawa |
82a8f5 |
sub rcx, byte SIZEOF_BYTE
|
|
shun-iwasawa |
82a8f5 |
movzx rax, byte [rsi+rcx]
|
|
shun-iwasawa |
82a8f5 |
.column_ld2:
|
|
shun-iwasawa |
82a8f5 |
test cl, SIZEOF_WORD
|
|
shun-iwasawa |
82a8f5 |
jz short .column_ld4
|
|
shun-iwasawa |
82a8f5 |
sub rcx, byte SIZEOF_WORD
|
|
shun-iwasawa |
82a8f5 |
movzx rdx, word [rsi+rcx]
|
|
shun-iwasawa |
82a8f5 |
shl rax, WORD_BIT
|
|
shun-iwasawa |
82a8f5 |
or rax, rdx
|
|
shun-iwasawa |
82a8f5 |
.column_ld4:
|
|
shun-iwasawa |
82a8f5 |
movd xmmA, eax
|
|
shun-iwasawa |
82a8f5 |
pop rdx
|
|
shun-iwasawa |
82a8f5 |
pop rax
|
|
shun-iwasawa |
82a8f5 |
test cl, SIZEOF_DWORD
|
|
shun-iwasawa |
82a8f5 |
jz short .column_ld8
|
|
shun-iwasawa |
82a8f5 |
sub rcx, byte SIZEOF_DWORD
|
|
shun-iwasawa |
82a8f5 |
movd xmmF, XMM_DWORD [rsi+rcx]
|
|
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 rcx, byte SIZEOF_MMWORD
|
|
shun-iwasawa |
82a8f5 |
movq xmmB, XMM_MMWORD [rsi+rcx]
|
|
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 [rsi+0*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
mov rcx, SIZEOF_XMMWORD
|
|
shun-iwasawa |
82a8f5 |
jmp short .rgb_gray_cnv
|
|
shun-iwasawa |
82a8f5 |
.column_ld32:
|
|
shun-iwasawa |
82a8f5 |
test cl, 2*SIZEOF_XMMWORD
|
|
shun-iwasawa |
82a8f5 |
mov rcx, SIZEOF_XMMWORD
|
|
shun-iwasawa |
82a8f5 |
jz short .rgb_gray_cnv
|
|
shun-iwasawa |
82a8f5 |
movdqa xmmB, xmmA
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
jmp short .rgb_gray_cnv
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
.columnloop:
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
.rgb_gray_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 rcx, byte SIZEOF_XMMWORD/16
|
|
shun-iwasawa |
82a8f5 |
movd xmmA, XMM_DWORD [rsi+rcx*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 rcx, byte SIZEOF_XMMWORD/8
|
|
shun-iwasawa |
82a8f5 |
movq xmmE, XMM_MMWORD [rsi+rcx*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 rcx, byte SIZEOF_XMMWORD/4
|
|
shun-iwasawa |
82a8f5 |
movdqa xmmE, xmmA
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
|
|
shun-iwasawa |
82a8f5 |
.column_ld8:
|
|
shun-iwasawa |
82a8f5 |
test cl, SIZEOF_XMMWORD/2
|
|
shun-iwasawa |
82a8f5 |
mov rcx, SIZEOF_XMMWORD
|
|
shun-iwasawa |
82a8f5 |
jz short .rgb_gray_cnv
|
|
shun-iwasawa |
82a8f5 |
movdqa xmmF, xmmA
|
|
shun-iwasawa |
82a8f5 |
movdqa xmmH, xmmE
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
jmp short .rgb_gray_cnv
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
.columnloop:
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD]
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
.rgb_gray_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 |
;
|
|
shun-iwasawa |
82a8f5 |
; (This implementation)
|
|
shun-iwasawa |
82a8f5 |
; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
movdqa xmm6, xmm1
|
|
shun-iwasawa |
82a8f5 |
punpcklwd xmm1, xmm3
|
|
shun-iwasawa |
82a8f5 |
punpckhwd xmm6, xmm3
|
|
shun-iwasawa |
82a8f5 |
pmaddwd xmm1, [rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
|
|
shun-iwasawa |
82a8f5 |
pmaddwd xmm6, [rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
movdqa xmm7, xmm6 ; xmm7=ROH*FIX(0.299)+GOH*FIX(0.337)
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
movdqa xmm6, xmm0
|
|
shun-iwasawa |
82a8f5 |
punpcklwd xmm0, xmm2
|
|
shun-iwasawa |
82a8f5 |
punpckhwd xmm6, xmm2
|
|
shun-iwasawa |
82a8f5 |
pmaddwd xmm0, [rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
|
|
shun-iwasawa |
82a8f5 |
pmaddwd xmm6, [rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=REL*FIX(0.299)+GEL*FIX(0.337)
|
|
shun-iwasawa |
82a8f5 |
movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=REH*FIX(0.299)+GEH*FIX(0.337)
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
movdqa xmm0, xmm5 ; xmm0=BO
|
|
shun-iwasawa |
82a8f5 |
movdqa xmm6, xmm4 ; xmm6=BE
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
movdqa xmm4, xmm0
|
|
shun-iwasawa |
82a8f5 |
punpcklwd xmm0, xmm3
|
|
shun-iwasawa |
82a8f5 |
punpckhwd xmm4, xmm3
|
|
shun-iwasawa |
82a8f5 |
pmaddwd xmm0, [rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
|
|
shun-iwasawa |
82a8f5 |
pmaddwd xmm4, [rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
movdqa xmm3, [rel PD_ONEHALF] ; xmm3=[PD_ONEHALF]
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
paddd xmm0, xmm1
|
|
shun-iwasawa |
82a8f5 |
paddd xmm4, xmm7
|
|
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 |
movdqa xmm4, xmm6
|
|
shun-iwasawa |
82a8f5 |
punpcklwd xmm6, xmm2
|
|
shun-iwasawa |
82a8f5 |
punpckhwd xmm4, xmm2
|
|
shun-iwasawa |
82a8f5 |
pmaddwd xmm6, [rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
|
|
shun-iwasawa |
82a8f5 |
pmaddwd xmm4, [rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
movdqa xmm2, [rel PD_ONEHALF] ; xmm2=[PD_ONEHALF]
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
paddd xmm6, XMMWORD [wk(0)]
|
|
shun-iwasawa |
82a8f5 |
paddd xmm4, XMMWORD [wk(1)]
|
|
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 [rdi], xmm6 ; Save Y
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
sub rcx, byte SIZEOF_XMMWORD
|
|
shun-iwasawa |
82a8f5 |
add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
|
|
shun-iwasawa |
82a8f5 |
add rdi, byte SIZEOF_XMMWORD ; outptr0
|
|
shun-iwasawa |
82a8f5 |
cmp rcx, byte SIZEOF_XMMWORD
|
|
shun-iwasawa |
82a8f5 |
jae near .columnloop
|
|
shun-iwasawa |
82a8f5 |
test rcx, rcx
|
|
shun-iwasawa |
82a8f5 |
jnz near .column_ld1
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
pop rcx ; col
|
|
shun-iwasawa |
82a8f5 |
pop rsi
|
|
shun-iwasawa |
82a8f5 |
pop rdi
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
add rsi, byte SIZEOF_JSAMPROW ; input_buf
|
|
shun-iwasawa |
82a8f5 |
add rdi, byte SIZEOF_JSAMPROW
|
|
shun-iwasawa |
82a8f5 |
dec rax ; num_rows
|
|
shun-iwasawa |
82a8f5 |
jg near .rowloop
|
|
shun-iwasawa |
82a8f5 |
|
|
shun-iwasawa |
82a8f5 |
.return:
|
|
shun-iwasawa |
82a8f5 |
pop rbx
|
|
shun-iwasawa |
82a8f5 |
uncollect_args 5
|
|
shun-iwasawa |
82a8f5 |
mov rsp, rbp ; rsp <- aligned rbp
|
|
shun-iwasawa |
82a8f5 |
pop rsp ; rsp <- original rbp
|
|
shun-iwasawa |
82a8f5 |
pop rbp
|
|
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
|