⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idct_mmx.asm

📁 MPEG-4编解码的实现(包括MPEG4视音频编解码)
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	psrad mm4, SHIFT_INV_ROW 		; y6=a1-b1 y7=a0-b0

	psubd mm7, mm2 			; 2 	; a3-b3 a2-b2
	psrad mm0, SHIFT_INV_ROW 		; y3=a3+b3 y2=a2+b2

	psrad mm7, SHIFT_INV_ROW 		; y4=a3-b3 y5=a2-b2

	packssdw mm3, mm0 		; 0 	; y3 y2 y1 y0

	packssdw mm7, mm4 		; 4 	; y6 y7 y4 y5

        movq [%2], mm3            ; 3     ; save y3 y2 y1 y0
	pshufw mm7, mm7, 10110001b 		; y7 y6 y5 y4

        movq [%2+8], mm7          ; 7     ; save y7 y6 y5 y4

%endmacro


;=============================================================================
;
;=============================================================================

;=============================================================================
;
; The first stage DCT 8x8 - forward DCTs of columns
;
; The %2puts are multiplied
; for rows 0,4 - on cos_4_16,
; for rows 1,7 - on cos_1_16,
; for rows 2,6 - on cos_2_16,
; for rows 3,5 - on cos_3_16
; and are shifted to the left for rise of accuracy
;
;-----------------------------------------------------------------------------
;
; The 8-point scaled forward DCT algorithm (26a8m)
;
;-----------------------------------------------------------------------------
;
; #define DCT_8_FRW_COL(x, y)
;{
; short t0, t1, t2, t3, t4, t5, t6, t7;
; short tp03, tm03, tp12, tm12, tp65, tm65;
; short tp465, tm465, tp765, tm765;
;
; t0 = LEFT_SHIFT ( x[0] + x[7] );
; t1 = LEFT_SHIFT ( x[1] + x[6] );
; t2 = LEFT_SHIFT ( x[2] + x[5] );
; t3 = LEFT_SHIFT ( x[3] + x[4] );
; t4 = LEFT_SHIFT ( x[3] - x[4] );
; t5 = LEFT_SHIFT ( x[2] - x[5] );
; t6 = LEFT_SHIFT ( x[1] - x[6] );
; t7 = LEFT_SHIFT ( x[0] - x[7] );
;
; tp03 = t0 + t3;
; tm03 = t0 - t3;
; tp12 = t1 + t2;
; tm12 = t1 - t2;
;
; y[0] = tp03 + tp12;
; y[4] = tp03 - tp12;
;
; y[2] = tm03 + tm12 * tg_2_16;
; y[6] = tm03 * tg_2_16 - tm12;
;
; tp65 =(t6 +t5 )*cos_4_16;
; tm65 =(t6 -t5 )*cos_4_16;
;
; tp765 = t7 + tp65;
; tm765 = t7 - tp65;
; tp465 = t4 + tm65;
; tm465 = t4 - tm65;
;
; y[1] = tp765 + tp465 * tg_1_16;
; y[7] = tp765 * tg_1_16 - tp465;
; y[5] = tm765 * tg_3_16 + tm465;
; y[3] = tm765 - tm465 * tg_3_16;
;}
;
;=============================================================================


;
; DCT_8_FRW_COL_4      INP, OUT
;

%macro DCT_8_FRW_COL_4          2

        LOCAL x0, x1, x2, x3, x4, x5, x6, x7
        LOCAL y0, y1, y2, y3, y4, y5, y6, y7
        x0 equ [%1 + 0*16]
        x1 equ [%1 + 1*16]
        x2 equ [%1 + 2*16]
        x3 equ [%1 + 3*16]
        x4 equ [%1 + 4*16]
        x5 equ [%1 + 5*16]
        x6 equ [%1 + 6*16]
        x7 equ [%1 + 7*16]
        y0 equ [%2 + 0*16]
        y1 equ [%2 + 1*16]
        y2 equ [%2 + 2*16]
        y3 equ [%2 + 3*16]
        y4 equ [%2 + 4*16]
        y5 equ [%2 + 5*16]
        y6 equ [%2 + 6*16]
        y7 equ [%2 + 7*16]
        movq mm0, x1 ; 0 ; x1
        movq mm1, x6 ; 1 ; x6
        movq mm2, mm0 ; 2 ; x1
        movq mm3, x2 ; 3 ; x2
        paddsw mm0, mm1 ; t1 = x[1] + x[6]
        movq mm4, x5 ; 4 ; x5
        psllw mm0, SHIFT_FRW_COL ; t1
        movq mm5, x0 ; 5 ; x0
        paddsw mm4, mm3 ; t2 = x[2] + x[5]
        paddsw mm5, x7 ; t0 = x[0] + x[7]
        psllw mm4, SHIFT_FRW_COL ; t2
        movq mm6, mm0 ; 6 ; t1
        psubsw mm2, mm1 ; 1 ; t6 = x[1] - x[6]
        movq mm1, [tg_2_16] ; 1 ; tg_2_16
        psubsw mm0, mm4 ; tm12 = t1 - t2
        movq mm7, x3 ; 7 ; x3
        pmulhw mm1, mm0 ; tm12*tg_2_16
        paddsw mm7, x4 ; t3 = x[3] + x[4]
        psllw mm5, SHIFT_FRW_COL ; t0
        paddsw mm6, mm4 ; 4 ; tp12 = t1 + t2
        psllw mm7, SHIFT_FRW_COL ; t3
        movq mm4, mm5 ; 4 ; t0
        psubsw mm5, mm7 ; tm03 = t0 - t3
        paddsw mm1, mm5 ; y2 = tm03 + tm12*tg_2_16
        paddsw mm4, mm7 ; 7 ; tp03 = t0 + t3
        por mm1, [one_corr] ; correction y2 +0.5
        psllw mm2, SHIFT_FRW_COL+1 ; t6
        pmulhw mm5, [tg_2_16] ; tm03*tg_2_16
        movq mm7, mm4 ; 7 ; tp03
        psubsw mm3, x5 ; t5 = x[2] - x[5]
        psubsw mm4, mm6 ; y4 = tp03 - tp12
        movq y2, mm1 ; 1 ; save y2
        paddsw mm7, mm6 ; 6 ; y0 = tp03 + tp12
        movq mm1, x3 ; 1 ; x3
        psllw mm3, SHIFT_FRW_COL+1 ; t5
        psubsw mm1, x4 ; t4 = x[3] - x[4]
        movq mm6, mm2 ; 6 ; t6
        movq y4, mm4 ; 4 ; save y4
        paddsw mm2, mm3 ; t6 + t5
        pmulhw mm2, [ocos_4_16] ; tp65 = (t6 + t5)*cos_4_16
        psubsw mm6, mm3 ; 3 ; t6 - t5
        pmulhw mm6, [ocos_4_16] ; tm65 = (t6 - t5)*cos_4_16
        psubsw mm5, mm0 ; 0 ; y6 = tm03*tg_2_16 - tm12
        por mm5, [one_corr] ; correction y6 +0.5
        psllw mm1, SHIFT_FRW_COL ; t4
        por mm2, [one_corr] ; correction tp65 +0.5
        movq mm4, mm1 ; 4 ; t4
        movq mm3, x0 ; 3 ; x0
        paddsw mm1, mm6 ; tp465 = t4 + tm65
        psubsw mm3, x7 ; t7 = x[0] - x[7]
        psubsw mm4, mm6 ; 6 ; tm465 = t4 - tm65
        movq mm0, [tg_1_16] ; 0 ; tg_1_16
        psllw mm3, SHIFT_FRW_COL ; t7
        movq mm6, [tg_3_16] ; 6 ; tg_3_16
        pmulhw mm0, mm1 ; tp465*tg_1_16
        movq y0, mm7 ; 7 ; save y0
        pmulhw mm6, mm4 ; tm465*tg_3_16
        movq y6, mm5 ; 5 ; save y6
        movq mm7, mm3 ; 7 ; t7
        movq mm5, [tg_3_16] ; 5 ; tg_3_16
        psubsw mm7, mm2 ; tm765 = t7 - tp65
        paddsw mm3, mm2 ; 2 ; tp765 = t7 + tp65
        pmulhw mm5, mm7 ; tm765*tg_3_16
        paddsw mm0, mm3 ; y1 = tp765 + tp465*tg_1_16
        paddsw mm6, mm4 ; tm465*tg_3_16
        pmulhw mm3, [tg_1_16] ; tp765*tg_1_16
        por mm0, [one_corr] ; correction y1 +0.5
        paddsw mm5, mm7 ; tm765*tg_3_16
        psubsw mm7, mm6 ; 6 ; y3 = tm765 - tm465*tg_3_16
        movq y1, mm0 ; 0 ; save y1
        paddsw mm5, mm4 ; 4 ; y5 = tm765*tg_3_16 + tm465
        movq y3, mm7 ; 7 ; save y3
        psubsw mm3, mm1 ; 1 ; y7 = tp765*tg_1_16 - tp465
        movq y5, mm5 ; 5 ; save y5
        movq y7, mm3 ; 3 ; save y7
%endmacro


;
; DCT_8_INV_COL_4  INP,OUT
;

%macro DCT_8_INV_COL_4          2
        movq    mm0, [tg_3_16]

        movq    mm3, [%1+16*3]
	movq	mm1, mm0			; tg_3_16

        movq    mm5, [%1+16*5]
	pmulhw	mm0, mm3			; x3*(tg_3_16-1)

        movq    mm4, [tg_1_16]
	pmulhw	mm1, mm5			; x5*(tg_3_16-1)

        movq    mm7, [%1+16*7]
	movq	mm2, mm4			; tg_1_16

        movq    mm6, [%1+16*1]
	pmulhw	mm4, mm7			; x7*tg_1_16

	paddsw	mm0, mm3			; x3*tg_3_16
	pmulhw	mm2, mm6			; x1*tg_1_16

	paddsw	mm1, mm3			; x3+x5*(tg_3_16-1)
	psubsw	mm0, mm5			; x3*tg_3_16-x5 = tm35

        movq    mm3, [ocos_4_16]
	paddsw	mm1, mm5			; x3+x5*tg_3_16 = tp35

	paddsw	mm4, mm6			; x1+tg_1_16*x7 = tp17
	psubsw	mm2, mm7			; x1*tg_1_16-x7 = tm17

	movq	mm5, mm4			; tp17
	movq	mm6, mm2			; tm17

	paddsw	mm5, mm1			; tp17+tp35 = b0
	psubsw	mm6, mm0			; tm17-tm35 = b3

	psubsw	mm4, mm1			; tp17-tp35 = t1
	paddsw	mm2, mm0			; tm17+tm35 = t2

        movq    mm7, [tg_2_16]
	movq	mm1, mm4			; t1

;       movq    [SCRATCH+0], mm5     ; save b0
        movq    [%2+3*16], mm5      ; save b0
	paddsw	mm1, mm2			; t1+t2

;       movq    [SCRATCH+8], mm6     ; save b3
        movq    [%2+5*16], mm6      ; save b3
	psubsw	mm4, mm2			; t1-t2

        movq    mm5, [%1+2*16]
	movq	mm0, mm7			; tg_2_16

        movq    mm6, [%1+6*16]
	pmulhw	mm0, mm5			; x2*tg_2_16

	pmulhw	mm7, mm6			; x6*tg_2_16
; slot
	pmulhw	mm1, mm3			; ocos_4_16*(t1+t2) = b1/2
; slot
        movq    mm2, [%1+0*16]
	pmulhw	mm4, mm3			; ocos_4_16*(t1-t2) = b2/2

	psubsw	mm0, mm6			; t2*tg_2_16-x6 = tm26
	movq	mm3, mm2			; x0

        movq    mm6, [%1+4*16]
	paddsw	mm7, mm5			; x2+x6*tg_2_16 = tp26

	paddsw	mm2, mm6			; x0+x4 = tp04
	psubsw	mm3, mm6			; x0-x4 = tm04

	movq	mm5, mm2			; tp04
	movq	mm6, mm3			; tm04

	psubsw	mm2, mm7			; tp04-tp26 = a3
	paddsw	mm3, mm0			; tm04+tm26 = a1

	paddsw mm1, mm1				; b1
	paddsw mm4, mm4				; b2

	paddsw	mm5, mm7			; tp04+tp26 = a0
	psubsw	mm6, mm0			; tm04-tm26 = a2

	movq	mm7, mm3			; a1
	movq	mm0, mm6			; a2

	paddsw	mm3, mm1			; a1+b1
	paddsw	mm6, mm4			; a2+b2

	psraw	mm3, SHIFT_INV_COL		; dst1
	psubsw	mm7, mm1			; a1-b1

	psraw	mm6, SHIFT_INV_COL		; dst2
	psubsw	mm0, mm4			; a2-b2

;       movq    mm1, [SCRATCH+0]     ; load b0
        movq    mm1, [%2+3*16]      ; load b0
	psraw	mm7, SHIFT_INV_COL		; dst6

	movq	mm4, mm5			; a0
	psraw	mm0, SHIFT_INV_COL		; dst5

        movq    [%2+1*16], mm3
	paddsw	mm5, mm1			; a0+b0

        movq    [%2+2*16], mm6
	psubsw	mm4, mm1			; a0-b0

;       movq    mm3, [SCRATCH+8]     ; load b3
        movq    mm3, [%2+5*16]      ; load b3
	psraw	mm5, SHIFT_INV_COL		; dst0

	movq	mm6, mm2			; a3
	psraw	mm4, SHIFT_INV_COL		; dst7

        movq    [%2+5*16], mm0
	paddsw	mm2, mm3			; a3+b3

        movq    [%2+6*16], mm7
	psubsw	mm6, mm3			; a3-b3

        movq    [%2+0*16], mm5
	psraw	mm2, SHIFT_INV_COL		; dst3

        movq    [%2+7*16], mm4
	psraw	mm6, SHIFT_INV_COL		; dst4

        movq    [%2+3*16], mm2

        movq    [%2+4*16], mm6
%endmacro



section .text

;=============================================================================
;
; void idct_mmx (short * const src_result);
;
;=============================================================================

align 16
cglobal idct_mmx
idct_mmx
        mov eax, dword [esp + 4]

        DCT_8_INV_ROW_1 eax+0, eax+0, tab_i_04, rounder_0
        DCT_8_INV_ROW_1 eax+16, eax+16, tab_i_17, rounder_1
        DCT_8_INV_ROW_1 eax+32, eax+32, tab_i_26, rounder_2
        DCT_8_INV_ROW_1 eax+48, eax+48, tab_i_35, rounder_3
        DCT_8_INV_ROW_1 eax+64, eax+64, tab_i_04, rounder_4
        DCT_8_INV_ROW_1 eax+80, eax+80, tab_i_35, rounder_5
        DCT_8_INV_ROW_1 eax+96, eax+96, tab_i_26, rounder_6
        DCT_8_INV_ROW_1 eax+112, eax+112, tab_i_17, rounder_7

        DCT_8_INV_COL_4 eax+0,eax+0
        DCT_8_INV_COL_4 eax+8,eax+8

        ret    



;=============================================================================
;
; void idct_sse (short * const src_result);
;
;=============================================================================

align 16
cglobal idct_xmm
idct_xmm
        mov eax, dword [esp + 4]

        DCT_8_INV_ROW_1_sse eax+0, eax+0, tab_i_04_sse, rounder_0
        DCT_8_INV_ROW_1_sse eax+16, eax+16, tab_i_17_sse, rounder_1
        DCT_8_INV_ROW_1_sse eax+32, eax+32, tab_i_26_sse, rounder_2
        DCT_8_INV_ROW_1_sse eax+48, eax+48, tab_i_35_sse, rounder_3
        DCT_8_INV_ROW_1_sse eax+64, eax+64, tab_i_04_sse, rounder_4
        DCT_8_INV_ROW_1_sse eax+80, eax+80, tab_i_35_sse, rounder_5
        DCT_8_INV_ROW_1_sse eax+96, eax+96, tab_i_26_sse, rounder_6
        DCT_8_INV_ROW_1_sse eax+112, eax+112, tab_i_17_sse, rounder_7

        DCT_8_INV_COL_4 eax+0, eax+0
        DCT_8_INV_COL_4 eax+8, eax+8

        ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -