[svn] / branches / dev-api-4 / xvidcore / src / quant / x86_asm / quantize_mmx.asm Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/src/quant/x86_asm/quantize_mmx.asm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3, Fri Mar 8 02:46:11 2002 UTC revision 851, Sat Feb 15 15:22:19 2003 UTC
# Line 32  Line 32 
32  ; *  ; *
33  ; *     History:  ; *     History:
34  ; *  ; *
35    ; * 09.08.2002  sse2 dequant funcs revamped
36    ; * 14.06.2002  mmx+xmm dequant_* funcs revamped  -Skal-
37    ; * 24.02.2002  sse2 quant_intra / dequant_intra (have to use movdqu ???)
38    ; * 17.04.2002  sse2 quant_inter / dequant_inter
39  ; * 26.12.2001  minor bug fixes, dequant saturate, further optimization  ; * 26.12.2001  minor bug fixes, dequant saturate, further optimization
40  ; * 19.11.2001  quant_inter_mmx now returns sum of abs. coefficient values  ; * 19.11.2001  quant_inter_mmx now returns sum of abs. coefficient values
41  ; *     04.11.2001      nasm version; (c)2001 peter ross <pross@cs.rmit.edu.au>  ; *     04.11.2001      nasm version; (c)2001 peter ross <pross@cs.rmit.edu.au>
# Line 58  Line 62 
62          %endif          %endif
63  %endmacro  %endmacro
64    
65  plus_one times 4        dw       1  align 16
66    
67    plus_one times 8        dw       1
68    
69  ;===========================================================================  ;===========================================================================
70  ;  ;
# Line 70  Line 76 
76  times 4 dw %1 / 2  times 4 dw %1 / 2
77  %endmacro  %endmacro
78    
79  align ALIGN  align 16
80  mmx_sub  mmx_sub
81                  MMX_SUB 1                  MMX_SUB 1
82                  MMX_SUB 2                  MMX_SUB 2
# Line 120  Line 126 
126  times 4 dw  (1 << 16) / (%1 * 2) + 1  times 4 dw  (1 << 16) / (%1 * 2) + 1
127  %endmacro  %endmacro
128    
129  align ALIGN  align 16
130  mmx_div  mmx_div
131                  MMX_DIV 1                  MMX_DIV 1
132                  MMX_DIV 2                  MMX_DIV 2
# Line 170  Line 176 
176  %endif  %endif
177  %endmacro  %endmacro
178    
179  align ALIGN  align 16
180  mmx_add  mmx_add
181                  MMX_ADD 1                  MMX_ADD 1
182                  MMX_ADD 2                  MMX_ADD 2
# Line 215  Line 221 
221  times 4 dw %1 * 2  times 4 dw %1 * 2
222  %endmacro  %endmacro
223    
224  align ALIGN  align 16
225  mmx_mul  mmx_mul
226                  MMX_MUL 1                  MMX_MUL 1
227                  MMX_MUL 2                  MMX_MUL 2
# Line 256  Line 262 
262  ;  ;
263  ;===========================================================================  ;===========================================================================
264    
265  align ALIGN  align 16
266    sse2_2047       times 8 dw 2047
267    
268    align 16
269    mmx_2047        times 4 dw 2047
270    
271    align 8
272  mmx_32768_minus_2048                            times 4 dw (32768-2048)  mmx_32768_minus_2048                            times 4 dw (32768-2048)
273  mmx_32767_minus_2047                            times 4 dw (32767-2047)  mmx_32767_minus_2047                            times 4 dw (32767-2047)
274    
# Line 371  Line 383 
383    
384  ;===========================================================================  ;===========================================================================
385  ;  ;
386    ; void quant_intra_sse2(int16_t * coeff,
387    ;                                       const int16_t const * data,
388    ;                                       const uint32_t quant,
389    ;                                       const uint32_t dcscalar);
390    ;
391    ;===========================================================================
392    
393    align ALIGN
394    cglobal quant_intra_sse2
395    quant_intra_sse2
396    
397                    push    esi
398                    push    edi
399    
400                    mov             edi, [esp + 8 + 4]                      ; coeff
401                    mov             esi, [esp + 8 + 8]                      ; data
402                    mov             eax, [esp + 8 + 12]                     ; quant
403    
404                    xor             ecx, ecx
405                    cmp             al, 1
406                    jz              near .qas2_q1loop
407    
408    .qas2_not1
409                    movq    mm7, [mmx_div + eax*8 - 8]
410                    movq2dq xmm7, mm7
411                    movlhps xmm7, xmm7
412    
413    align 16
414    .qas2_loop
415                    movdqa  xmm0, [esi + ecx*8]                     ; xmm0 = [1st]
416                    movdqa  xmm3, [esi + ecx*8 + 16]        ; xmm3 = [2nd]
417                    pxor    xmm1, xmm1
418                    pxor    xmm4, xmm4
419                    pcmpgtw xmm1, xmm0
420                    pcmpgtw xmm4, xmm3
421                    pxor    xmm0, xmm1
422                    pxor    xmm3, xmm4
423                    psubw   xmm0, xmm1
424                    psubw   xmm3, xmm4
425                    pmulhw  xmm0, xmm7
426                    pmulhw  xmm3, xmm7
427                    pxor    xmm0, xmm1
428                    pxor    xmm3, xmm4
429                    psubw   xmm0, xmm1
430                    psubw   xmm3, xmm4
431                    movdqa  [edi + ecx*8], xmm0
432                    movdqa  [edi + ecx*8 + 16], xmm3
433    
434                    add             ecx, 4
435                    cmp             ecx, 16
436                    jnz     .qas2_loop
437    
438    .qas2_done
439                    mov     ecx, [esp + 8 + 16]     ; dcscalar
440                    mov     edx, ecx
441                    movsx   eax, word [esi]
442                    shr     edx, 1
443                    cmp             eax, 0
444                    jg              .qas2_gtzero
445    
446                    sub             eax, edx
447                    jmp             short .qas2_mul
448    .qas2_gtzero
449                    add             eax, edx
450    .qas2_mul
451                    cdq
452                    idiv    ecx
453    
454                    mov             [edi], ax
455    
456                    pop             edi
457                    pop             esi
458    
459                    ret
460    
461    align 16
462    .qas2_q1loop
463                    movdqa  xmm0, [esi + ecx*8]                     ; xmm0 = [1st]
464                    movdqa  xmm3, [esi + ecx*8 + 16]        ; xmm3 = [2nd]
465                    pxor    xmm1, xmm1
466                    pxor    xmm4, xmm4
467                    pcmpgtw xmm1, xmm0
468                    pcmpgtw xmm4, xmm3
469                    pxor    xmm0, xmm1
470                    pxor    xmm3, xmm4
471                    psubw   xmm0, xmm1
472                    psubw   xmm3, xmm4
473                    psrlw   xmm0, 1
474                    psrlw   xmm3, 1
475                    pxor    xmm0, xmm1
476                    pxor    xmm3, xmm4
477                    psubw   xmm0, xmm1
478                    psubw   xmm3, xmm4
479                    movdqa  [edi + ecx*8], xmm0
480                    movdqa  [edi + ecx*8 + 16], xmm3
481    
482                    add             ecx, 4
483                    cmp             ecx, 16
484                    jnz             .qas2_q1loop
485                    jmp             near .qas2_done
486    
487    
488    
489    ;===========================================================================
490    ;
491  ; uint32_t quant_inter_mmx(int16_t * coeff,  ; uint32_t quant_inter_mmx(int16_t * coeff,
492  ;                                       const int16_t const * data,  ;                                       const int16_t const * data,
493  ;                                       const uint32_t quant);  ;                                       const uint32_t quant);
# Line 476  Line 593 
593    
594  ;===========================================================================  ;===========================================================================
595  ;  ;
596    ; uint32_t quant_inter_sse2(int16_t * coeff,
597    ;                                       const int16_t const * data,
598    ;                                       const uint32_t quant);
599    ;
600    ;===========================================================================
601    
602    align 16
603    cglobal quant_inter_sse2
604                    quant_inter_sse2
605    
606                    push    esi
607                    push    edi
608    
609                    mov             edi, [esp + 8 + 4]                      ; coeff
610                    mov             esi, [esp + 8 + 8]                      ; data
611                    mov             eax, [esp + 8 + 12]                     ; quant
612    
613                    xor             ecx, ecx
614    
615                    pxor    xmm5, xmm5                                      ; sum
616    
617                    movq    mm0, [mmx_sub + eax*8 - 8]      ; sub
618                    movq2dq xmm6, mm0                                       ; load into low 8 bytes
619                    movlhps xmm6, xmm6                                      ; duplicate into high 8 bytes
620    
621                    cmp             al, 1
622                    jz              near .qes2_q1loop
623    
624    .qes2_not1
625                    movq    mm0, [mmx_div + eax*8 - 8]      ; divider
626                    movq2dq xmm7, mm0
627                    movlhps xmm7, xmm7
628    
629    align 16
630    .qes2_loop
631                    movdqa  xmm0, [esi + ecx*8]                     ; xmm0 = [1st]
632                    movdqa  xmm3, [esi + ecx*8 + 16]        ; xmm3 = [2nd]
633                    pxor    xmm1, xmm1
634                    pxor    xmm4, xmm4
635                    pcmpgtw xmm1, xmm0
636                    pcmpgtw xmm4, xmm3
637                    pxor    xmm0, xmm1
638                    pxor    xmm3, xmm4
639                    psubw   xmm0, xmm1
640                    psubw   xmm3, xmm4
641                    psubusw xmm0, xmm6
642                    psubusw xmm3, xmm6
643                    pmulhw  xmm0, xmm7
644                    pmulhw  xmm3, xmm7
645                    paddw   xmm5, xmm0
646                    pxor    xmm0, xmm1
647                    paddw   xmm5, xmm3
648                    pxor    xmm3, xmm4
649                    psubw   xmm0, xmm1
650                    psubw   xmm3, xmm4
651                    movdqa  [edi + ecx*8], xmm0
652                    movdqa  [edi + ecx*8 + 16], xmm3
653    
654                    add             ecx, 4
655                    cmp             ecx, 16
656                    jnz             .qes2_loop
657    
658    .qes2_done
659                    movdqu  xmm6, [plus_one]
660                    pmaddwd xmm5, xmm6
661                    movhlps xmm6, xmm5
662                    paddd   xmm5, xmm6
663                    movdq2q mm0, xmm5
664    
665                    movq    mm5, mm0
666                    psrlq   mm5, 32
667                    paddd   mm0, mm5
668                    movd    eax, mm0                                        ; return sum
669    
670                    pop             edi
671                    pop             esi
672    
673                    ret
674    
675    align 16
676    .qes2_q1loop
677                    movdqa  xmm0, [esi + ecx*8]                     ; xmm0 = [1st]
678                    movdqa  xmm3, [esi + ecx*8 + 16]        ; xmm3 = [2nd]
679                    pxor    xmm1, xmm1
680                    pxor    xmm4, xmm4
681                    pcmpgtw xmm1, xmm0
682                    pcmpgtw xmm4, xmm3
683                    pxor    xmm0, xmm1
684                    pxor    xmm3, xmm4
685                    psubw   xmm0, xmm1
686                    psubw   xmm3, xmm4
687                    psubusw xmm0, xmm6
688                    psubusw xmm3, xmm6
689                    psrlw   xmm0, 1
690                    psrlw   xmm3, 1
691                    paddw   xmm5, xmm0
692                    pxor    xmm0, xmm1
693                    paddw   xmm5, xmm3
694                    pxor    xmm3, xmm4
695                    psubw   xmm0, xmm1
696                    psubw   xmm3, xmm4
697                    movdqa  [edi + ecx*8], xmm0
698                    movdqa  [edi + ecx*8 + 16], xmm3
699    
700                    add             ecx,4
701                    cmp             ecx,16
702                    jnz             .qes2_q1loop
703                    jmp             .qes2_done
704    
705    
706    ;===========================================================================
707    ;
708  ; void dequant_intra_mmx(int16_t *data,  ; void dequant_intra_mmx(int16_t *data,
709  ;                                       const int16_t const *coeff,  ;                                       const int16_t const *coeff,
710  ;                                       const uint32_t quant,  ;                                       const uint32_t quant,
# Line 483  Line 712 
712  ;  ;
713  ;===========================================================================  ;===========================================================================
714    
715      ; note: we only saturate to +2047 *before* restoring the sign.
716      ; Hence, final clamp really is [-2048,2047]
717    
718  align ALIGN  align ALIGN
719  cglobal dequant_intra_mmx  cglobal dequant_intra_mmx
720  dequant_intra_mmx  dequant_intra_mmx:
   
                 push    esi  
                 push    edi  
   
                 mov     edi, [esp + 8 + 4]              ; data  
                 mov     esi, [esp + 8 + 8]              ; coeff  
                 mov     eax, [esp + 8 + 12]             ; quant  
721    
722                  movq    mm6, [mmx_add + eax * 8 - 8]    mov    edx, [esp+ 4]        ; data
723                  movq    mm7, [mmx_mul + eax * 8 - 8]    mov    ecx, [esp+ 8]        ; coeff
724                  xor eax, eax    mov    eax, [esp+12]        ; quant
725      movq mm6, [mmx_add + eax*8 - 8]  ; quant or quant-1
726      movq mm7, [mmx_mul + eax*8 - 8]  ; 2*quant
727      mov eax, -16
728    
729  align ALIGN  align ALIGN
730  .loop  .loop
731                  movq    mm0, [esi + 8*eax]              ; mm0 = [coeff]    movq mm0, [ecx+8*eax+8*16]      ; c  = coeff[i]
732                  movq    mm3, [esi + 8*eax + 8]  ;    movq mm3, [ecx+8*eax+8*16 + 8]  ; c' = coeff[i+1]
733                  pxor    mm1, mm1                ; mm1 = 0    pxor mm1, mm1
734                  pxor    mm4, mm4                ;    pxor mm4, mm4
735                  pcmpgtw mm1, mm0                ; mm1 = (0 > mm0)    pcmpgtw mm1, mm0  ; sign(c)
736                  pcmpgtw mm4, mm3                ;    pcmpgtw mm4, mm3  ; sign(c')
737                  pxor    mm2, mm2                ; mm2 = 0    pxor mm2, mm2
738                  pxor    mm5, mm5                ;    pxor mm5, mm5
739                  pcmpeqw mm2, mm0                ; mm2 = (0 == mm0)    pcmpeqw mm2, mm0  ; c is zero
740                  pcmpeqw mm5, mm3                ;    pcmpeqw mm5, mm3  ; c' is zero
741                  pandn   mm2, mm6                ; mm2 = (iszero ? 0 : add)    pandn mm2, mm6    ; offset = isZero ? 0 : quant_add
742                  pandn   mm5, mm6                ;    pandn mm5, mm6
743                  pxor    mm0, mm1                ; mm0 = |mm0|    pxor mm0, mm1     ; negate if negative
744                  pxor    mm3, mm4                ;    pxor mm3, mm4     ; negate if negative
745                  psubw   mm0, mm1                ; displace    psubw mm0, mm1
                 psubw   mm3, mm4                ;  
                 pmullw  mm0, mm7                ; mm0 *= 2Q  
                 pmullw  mm3, mm7                ;  
                 paddw   mm0, mm2                ; mm0 += mm2 (add)  
                 paddw   mm3, mm5                ;  
                 pxor    mm0, mm1                ; mm0 *= sign(mm0)  
                 pxor    mm3, mm4                ;  
                 psubw   mm0, mm1                ; undisplace  
746                  psubw   mm3, mm4                  psubw   mm3, mm4
747      pmullw mm0, mm7 ; *= 2Q
748      pmullw mm3, mm7 ; *= 2Q
749      paddw mm0, mm2 ; + offset
750      paddw mm3, mm5 ; + offset
751      paddw mm0, mm1 ; negate back
752      paddw mm3, mm4 ; negate back
753    
754  %ifdef SATURATE      ; saturates to +2047
755                  movq mm2, [mmx_32767_minus_2047]                  movq mm2, [mmx_32767_minus_2047]
756                  movq mm4, [mmx_32768_minus_2048]    add eax, 2
757                  paddsw  mm0, mm2                  paddsw  mm0, mm2
758                  paddsw  mm3, mm2                  paddsw  mm3, mm2
759                  psubsw  mm0, mm2                  psubsw  mm0, mm2
760                  psubsw  mm3, mm2                  psubsw  mm3, mm2
                 psubsw  mm0, mm4  
                 psubsw  mm3, mm4  
                 paddsw  mm0, mm4  
                 paddsw  mm3, mm4  
 %endif  
761    
762                  movq    [edi + 8*eax], mm0              ; [data] = mm0    pxor mm0, mm1
763                  movq    [edi + 8*eax + 8], mm3    pxor mm3, mm4
764      movq [edx + 8*eax + 8*16   - 2*8], mm0
765      movq [edx + 8*eax + 8*16+8 - 2*8], mm3
766      jnz   near .loop
767    
768        ; deal with DC
769    
770      movd mm0, [ecx]
771      pmullw mm0, [esp+16]    ; dcscalar
772      movq mm2, [mmx_32767_minus_2047]
773      paddsw mm0, mm2
774      psubsw mm0, mm2
775      movq mm3, [mmx_32768_minus_2048]
776      psubsw mm0, mm3
777      paddsw mm0, mm3
778      movd eax, mm0
779      mov [edx], ax
780    
781      ret
782    
783    ;===========================================================================
784    ;
785    ; void dequant_intra_xmm(int16_t *data,
786    ;                                       const int16_t const *coeff,
787    ;                                       const uint32_t quant,
788    ;                                       const uint32_t dcscalar);
789    ;
790    ;===========================================================================
791    
792      ; this is the same as dequant_inter_mmx, except that we're
793      ; saturating using 'pminsw' (saves 2 cycles/loop => ~5% faster)
794    
795    align ALIGN
796    cglobal dequant_intra_xmm
797    dequant_intra_xmm:
798    
799      mov    edx, [esp+ 4]        ; data
800      mov    ecx, [esp+ 8]        ; coeff
801      mov    eax, [esp+12]        ; quant
802      movq mm6, [mmx_add + eax*8 - 8]  ; quant or quant-1
803      movq mm7, [mmx_mul + eax*8 - 8]  ; 2*quant
804      mov eax, -16
805    
806    align ALIGN
807    .loop
808      movq mm0, [ecx+8*eax+8*16]      ; c  = coeff[i]
809      movq mm3, [ecx+8*eax+8*16 + 8]  ; c' = coeff[i+1]
810      pxor mm1, mm1
811      pxor mm4, mm4
812      pcmpgtw mm1, mm0  ; sign(c)
813      pcmpgtw mm4, mm3  ; sign(c')
814      pxor mm2, mm2
815      pxor mm5, mm5
816      pcmpeqw mm2, mm0  ; c is zero
817      pcmpeqw mm5, mm3  ; c' is zero
818      pandn mm2, mm6    ; offset = isZero ? 0 : quant_add
819      pandn mm5, mm6
820      pxor mm0, mm1     ; negate if negative
821      pxor mm3, mm4     ; negate if negative
822      psubw mm0, mm1
823      psubw mm3, mm4
824      pmullw mm0, mm7 ; *= 2Q
825      pmullw mm3, mm7 ; *= 2Q
826      paddw mm0, mm2 ; + offset
827      paddw mm3, mm5 ; + offset
828      paddw mm0, mm1 ; negate back
829      paddw mm3, mm4 ; negate back
830    
831        ; saturates to +2047
832      movq mm2, [mmx_2047]
833      pminsw mm0, mm2
834                  add eax, 2                  add eax, 2
835                  cmp eax, 16    pminsw mm3, mm2
836    
837      pxor mm0, mm1
838      pxor mm3, mm4
839      movq [edx + 8*eax + 8*16   - 2*8], mm0
840      movq [edx + 8*eax + 8*16+8 - 2*8], mm3
841                  jnz     near .loop                  jnz     near .loop
842    
843                  mov     ax, [esi]                                       ; ax = data[0]      ; deal with DC
                 imul ax, [esp + 8 + 16]                 ; eax = data[0] * dcscalar  
844    
845  %ifdef SATURATE    movd mm0, [ecx]
846                  cmp ax, -2048    pmullw mm0, [esp+16]    ; dcscalar
847                  jl .set_n2048    movq mm2, [mmx_32767_minus_2047]
848                  cmp ax, 2047    paddsw mm0, mm2
849                  jg .set_2047    psubsw mm0, mm2
850  %endif    movq mm2, [mmx_32768_minus_2048]
851                  mov     [edi], ax    psubsw mm0, mm2
852      paddsw mm0, mm2
853      movd eax, mm0
854      mov [edx], ax
855    
                 pop     edi  
                 pop     esi  
856                  ret                  ret
857    
858  %ifdef SATURATE  
859    ;===========================================================================
860    ;
861    ; void dequant_intra_sse2(int16_t *data,
862    ;                                       const int16_t const *coeff,
863    ;                                       const uint32_t quant,
864    ;                                       const uint32_t dcscalar);
865    ;
866    ;===========================================================================
867  align ALIGN  align ALIGN
868  .set_n2048  cglobal dequant_intra_sse2
869                  mov     word [edi], -2048  dequant_intra_sse2:
870                  pop     edi          mov edx, [esp+ 4]        ; data
871                  pop     esi          mov ecx, [esp+ 8]        ; coeff
872                  ret          mov eax, [esp+12]        ; quant
873            movq mm6, [mmx_add + eax * 8 - 8]
874            movq mm7, [mmx_mul + eax * 8 - 8]
875            movq2dq xmm6, mm6
876            movq2dq xmm7, mm7
877            movlhps xmm6, xmm6
878            movlhps xmm7, xmm7
879            mov eax, -16
880    
881  align ALIGN  align ALIGN
882  .set_2047  .loop
883                  mov     word [edi], 2047          movdqa xmm0, [ecx + 8*16 + 8*eax]      ; c  = coeff[i]
884                  pop     edi          movdqa xmm3, [ecx + 8*16 + 8*eax+ 16]
885                  pop     esi          pxor xmm1, xmm1
886            pxor xmm4, xmm4
887            pcmpgtw xmm1, xmm0  ; sign(c)
888            pcmpgtw xmm4, xmm3
889            pxor xmm2, xmm2
890            pxor xmm5, xmm5
891            pcmpeqw xmm2, xmm0  ; c is zero
892            pcmpeqw xmm5, xmm3
893            pandn xmm2, xmm6    ; offset = isZero ? 0 : quant_add
894            pandn xmm5, xmm6
895            pxor xmm0, xmm1     ; negate if negative
896            pxor xmm3, xmm4
897            psubw xmm0, xmm1
898            psubw xmm3, xmm4
899            pmullw xmm0, xmm7 ; *= 2Q
900            pmullw xmm3, xmm7
901            paddw xmm0, xmm2 ; + offset
902            paddw xmm3, xmm5
903            paddw xmm0, xmm1 ; negate back
904            paddw xmm3, xmm4
905    
906            ; saturates to +2047
907            movdqa xmm2, [sse2_2047]
908            pminsw xmm0, xmm2
909            add eax, 4
910            pminsw xmm3, xmm2
911    
912            pxor xmm0, xmm1
913            pxor xmm3, xmm4
914            movdqa [edx + 8*16 - 8*4 + 8*eax], xmm0
915            movdqa [edx + 8*16 - 8*4 + 8*eax + 16], xmm3
916            jnz     near .loop
917    
918            ; deal with DC
919            movd mm0, [ecx]
920            pmullw mm0, [esp+16]    ; dcscalar
921            movq mm2, [mmx_32767_minus_2047]
922            paddsw mm0, mm2
923            psubsw mm0, mm2
924            movq mm2, [mmx_32768_minus_2048]
925            psubsw mm0, mm2
926            paddsw mm0, mm2
927            movd eax, mm0
928            mov [edx], ax
929    
930                  ret                  ret
931  %endif  
932    
933    
934    
935  ;===========================================================================  ;===========================================================================
936  ;  ;
# Line 586  Line 942 
942    
943  align ALIGN  align ALIGN
944  cglobal dequant_inter_mmx  cglobal dequant_inter_mmx
945  dequant_inter_mmx  dequant_inter_mmx:
946    
947                  push    esi    mov    edx, [esp+ 4]        ; data
948                  push    edi    mov    ecx, [esp+ 8]        ; coeff
949      mov    eax, [esp+12]        ; quant
950                  mov     edi, [esp + 8 + 4]      ; data    movq mm6, [mmx_add + eax*8 - 8]  ; quant or quant-1
951                  mov     esi, [esp + 8 + 8]      ; coeff    movq mm7, [mmx_mul + eax*8 - 8]  ; 2*quant
952                  mov     eax, [esp + 8 + 12]     ; quant    mov eax, -16
                 movq    mm6, [mmx_add + eax * 8 - 8]  
                 movq    mm7, [mmx_mul + eax * 8 - 8]  
   
                 xor eax, eax  
953    
954  align ALIGN  align ALIGN
955  .loop  .loop
956                  movq    mm0, [esi + 8*eax]                      ; mm0 = [coeff]    movq mm0, [ecx+8*eax+8*16]      ; c  = coeff[i]
957                  movq    mm3, [esi + 8*eax + 8]          ;    movq mm3, [ecx+8*eax+8*16 + 8]  ; c' = coeff[i+1]
958                  pxor    mm1, mm1                ; mm1 = 0    pxor mm1, mm1
959                  pxor    mm4, mm4                ;    pxor mm4, mm4
960                  pcmpgtw mm1, mm0                ; mm1 = (0 > mm0)    pcmpgtw mm1, mm0  ; sign(c)
961                  pcmpgtw mm4, mm3                ;    pcmpgtw mm4, mm3  ; sign(c')
962                  pxor    mm2, mm2                ; mm2 = 0    pxor mm2, mm2
963                  pxor    mm5, mm5                ;    pxor mm5, mm5
964                  pcmpeqw mm2, mm0                ; mm2 = (0 == mm0)    pcmpeqw mm2, mm0  ; c is zero
965                  pcmpeqw mm5, mm3                ;    pcmpeqw mm5, mm3  ; c' is zero
966                  pandn   mm2, mm6                ; mm2 = (iszero ? 0 : add)    pandn mm2, mm6    ; offset = isZero ? 0 : quant_add
967                  pandn   mm5, mm6                ;    pandn mm5, mm6
968                  pxor    mm0, mm1                ; mm0 = |mm0|    pxor mm0, mm1     ; negate if negative
969                  pxor    mm3, mm4                ;    pxor mm3, mm4     ; negate if negative
970                  psubw   mm0, mm1                ; displace    psubw mm0, mm1
                 psubw   mm3, mm4                ;  
                 pmullw  mm0, mm7                ; mm0 *= 2Q  
                 pmullw  mm3, mm7                ;  
                 paddw   mm0, mm2                ; mm0 += mm2 (add)  
                 paddw   mm3, mm5                ;  
                 pxor    mm0, mm1                ; mm0 *= sign(mm0)  
                 pxor    mm3, mm4                ;  
                 psubw   mm0, mm1                ; undisplace  
971                  psubw   mm3, mm4                  psubw   mm3, mm4
972      pmullw mm0, mm7 ; *= 2Q
973      pmullw mm3, mm7 ; *= 2Q
974      paddw mm0, mm2 ; + offset
975      paddw mm3, mm5 ; + offset
976      paddw mm0, mm1 ; negate back
977      paddw mm3, mm4 ; negate back
978    
979  %ifdef SATURATE      ; saturates to +2047
980                  movq mm2, [mmx_32767_minus_2047]                  movq mm2, [mmx_32767_minus_2047]
981                  movq mm4, [mmx_32768_minus_2048]    add eax, 2
982                  paddsw  mm0, mm2                  paddsw  mm0, mm2
983                  paddsw  mm3, mm2                  paddsw  mm3, mm2
984                  psubsw  mm0, mm2                  psubsw  mm0, mm2
985                  psubsw  mm3, mm2                  psubsw  mm3, mm2
                 psubsw  mm0, mm4  
                 psubsw  mm3, mm4  
                 paddsw  mm0, mm4  
                 paddsw  mm3, mm4  
 %endif  
986    
987                  movq    [edi + 8*eax], mm0    pxor mm0, mm1
988                  movq    [edi + 8*eax + 8], mm3    pxor mm3, mm4
989      movq [edx + 8*eax + 8*16   - 2*8], mm0
990      movq [edx + 8*eax + 8*16+8 - 2*8], mm3
991      jnz   near .loop
992    
993      ret
994    
995    ;===========================================================================
996    ;
997    ; void dequant_inter_xmm(int16_t * data,
998    ;                                       const int16_t * const coeff,
999    ;                                       const uint32_t quant);
1000    ;
1001    ;===========================================================================
1002    
1003      ; this is the same as dequant_inter_mmx,
1004      ; except that we're saturating using 'pminsw' (saves 2 cycles/loop)
1005    
1006    align ALIGN
1007    cglobal dequant_inter_xmm
1008    dequant_inter_xmm:
1009    
1010      mov    edx, [esp+ 4]        ; data
1011      mov    ecx, [esp+ 8]        ; coeff
1012      mov    eax, [esp+12]        ; quant
1013      movq mm6, [mmx_add + eax*8 - 8]  ; quant or quant-1
1014      movq mm7, [mmx_mul + eax*8 - 8]  ; 2*quant
1015      mov eax, -16
1016    
1017    align ALIGN
1018    .loop
1019      movq mm0, [ecx+8*eax+8*16]      ; c  = coeff[i]
1020      movq mm3, [ecx+8*eax+8*16 + 8]  ; c' = coeff[i+1]
1021      pxor mm1, mm1
1022      pxor mm4, mm4
1023      pcmpgtw mm1, mm0  ; sign(c)
1024      pcmpgtw mm4, mm3  ; sign(c')
1025      pxor mm2, mm2
1026      pxor mm5, mm5
1027      pcmpeqw mm2, mm0  ; c is zero
1028      pcmpeqw mm5, mm3  ; c' is zero
1029      pandn mm2, mm6    ; offset = isZero ? 0 : quant_add
1030      pandn mm5, mm6
1031      pxor mm0, mm1     ; negate if negative
1032      pxor mm3, mm4     ; negate if negative
1033      psubw mm0, mm1
1034      psubw mm3, mm4
1035      pmullw mm0, mm7 ; *= 2Q
1036      pmullw mm3, mm7 ; *= 2Q
1037      paddw mm0, mm2 ; + offset
1038      paddw mm3, mm5 ; + offset
1039      paddw mm0, mm1 ; start restoring sign
1040      paddw mm3, mm4 ; start restoring sign
1041    
1042          ; saturates to +2047
1043      movq mm2, [mmx_2047]
1044      pminsw mm0, mm2
1045                  add eax, 2                  add eax, 2
1046                  cmp eax, 16    pminsw mm3, mm2
1047    
1048      pxor mm0, mm1 ; finish restoring sign
1049      pxor mm3, mm4 ; finish restoring sign
1050      movq [edx + 8*eax + 8*16   - 2*8], mm0
1051      movq [edx + 8*eax + 8*16+8 - 2*8], mm3
1052                  jnz     near .loop                  jnz     near .loop
1053    
1054                  pop     edi    ret
1055                  pop     esi  
1056    ;===========================================================================
1057    ;
1058    ; void dequant_inter_sse2(int16_t * data,
1059    ;                                       const int16_t * const coeff,
1060    ;                                       const uint32_t quant);
1061    ;
1062    ;===========================================================================
1063    align ALIGN
1064    cglobal dequant_inter_sse2
1065    dequant_inter_sse2
1066            mov edx, [esp + 4]      ; data
1067            mov ecx, [esp + 8]      ; coeff
1068            mov eax, [esp + 12]     ; quant
1069            movq mm6, [mmx_add + eax * 8 - 8]
1070            movq mm7, [mmx_mul + eax * 8 - 8]
1071            movq2dq xmm6, mm6
1072            movq2dq xmm7, mm7
1073            movlhps xmm6, xmm6
1074            movlhps xmm7, xmm7
1075            mov eax, -16
1076    
1077    align ALIGN
1078    .loop
1079            movdqa xmm0, [ecx + 8*16 + 8*eax]  ; c  = coeff[i]
1080            movdqa xmm3, [ecx + 8*16 + 8*eax + 16]
1081    
1082            pxor xmm1, xmm1
1083            pxor xmm4, xmm4
1084            pcmpgtw xmm1, xmm0  ; sign(c)
1085            pcmpgtw xmm4, xmm3
1086            pxor xmm2, xmm2
1087            pxor xmm5, xmm5
1088            pcmpeqw xmm2, xmm0  ; c is zero
1089            pcmpeqw xmm5, xmm3
1090            pandn xmm2, xmm6
1091            pandn xmm5, xmm6
1092            pxor xmm0, xmm1  ; negate if negative
1093            pxor xmm3, xmm4
1094            psubw xmm0, xmm1
1095            psubw xmm3, xmm4
1096            pmullw xmm0, xmm7  ; *= 2Q
1097            pmullw xmm3, xmm7
1098            paddw xmm0, xmm2  ; + offset
1099            paddw xmm3, xmm5
1100    
1101            paddw xmm0, xmm1  ; start restoring sign
1102            paddw xmm3, xmm4
1103    
1104            ; saturates to +2047
1105            movdqa xmm2, [sse2_2047]
1106            pminsw xmm0, xmm2
1107            add eax, 4
1108            pminsw xmm3, xmm2
1109    
1110            pxor xmm0, xmm1 ; finish restoring sign
1111            pxor xmm3, xmm4
1112            movdqa [edx + 8*16 - 8*4 + 8*eax], xmm0
1113            movdqa [edx + 8*16 - 8*4 + 8*eax + 16], xmm3
1114            jnz     near .loop
1115    
1116                  ret                  ret

Legend:
Removed from v.3  
changed lines
  Added in v.851

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4