home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Meia / source / a_predict_scalar.asm < prev    next >
Encoding:
Assembly Source File  |  2009-09-14  |  19.7 KB  |  1,068 lines

  1. ;    VirtualDub - Video processing and capture application
  2. ;    Copyright (C) 1998-2001 Avery Lee
  3. ;
  4. ;    This program is free software; you can redistribute it and/or modify
  5. ;    it under the terms of the GNU General Public License as published by
  6. ;    the Free Software Foundation; either version 2 of the License, or
  7. ;    (at your option) any later version.
  8. ;
  9. ;    This program is distributed in the hope that it will be useful,
  10. ;    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;    GNU General Public License for more details.
  13. ;
  14. ;    You should have received a copy of the GNU General Public License
  15. ;    along with this program; if not, write to the Free Software
  16. ;    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. ;****************************************************
  19. ;
  20. ; This module now uses a new algorithm that was suggested to me in email:
  21. ;
  22. ;    result = (((x^y) & 0xfefefefe)>>1) + (x&y);
  23. ;
  24. ; The formula rounds down, but it can be reversed to round according to
  25. ; MPEG:
  26. ;
  27. ;    result = (x|y) - (((x^y) & 0xfefefefe)>>1);
  28. ;
  29. ;****************************************************
  30.  
  31.     segment    .rdata, align=16
  32.  
  33.     align 16
  34.  
  35.     global    _g_VDMPEGPredict_scalar
  36.  
  37. _g_VDMPEGPredict_scalar    dd    predict_Y_normal
  38.             dd    predict_Y_halfpelX
  39.             dd    predict_Y_halfpelY
  40.             dd    predict_Y_quadpel
  41.             dd    predict_C_normal
  42.             dd    predict_C_halfpelX
  43.             dd    predict_C_halfpelY
  44.             dd    predict_C_quadpel
  45.             dd    predict_add_Y_normal
  46.             dd    predict_add_Y_halfpelX
  47.             dd    predict_add_Y_halfpelY
  48.             dd    predict_add_Y_quadpel
  49.             dd    predict_add_C_normal
  50.             dd    predict_add_C_halfpelX
  51.             dd    predict_add_C_halfpelY
  52.             dd    predict_add_C_quadpel
  53.  
  54. %macro PREDICT_START 0
  55.         push    ebp
  56.         push    edi
  57.         push    esi
  58.         push    ebx
  59.         mov    edx,[esp+4+16]
  60.         mov    ecx,[esp+8+16]
  61.         mov    esi,[esp+12+16]    
  62. %endmacro
  63.  
  64. %macro PREDICT_END 0
  65.         pop    ebx
  66.         pop    esi
  67.         pop    edi
  68.         pop    ebp
  69. %endmacro
  70.  
  71.  
  72.     segment    .text
  73.  
  74. ;*********************************************************
  75. ;*
  76. ;*    Luminance - quadpel
  77. ;*
  78. ;*********************************************************
  79.  
  80.     align    16
  81. predict_Y_quadpel:
  82.     PREDICT_START
  83.     push    16
  84. loop_Y1_quadpel:
  85.  
  86. ;    [A][B][C][D][E][F][G][H]
  87. ;    [I][J][K][L][M][N][O][P]
  88.  
  89. %macro quadpel_move 1
  90.     mov    edi,[ecx+%1]
  91.     mov    ebp,0fcfcfcfch
  92.  
  93.     and    ebp,edi
  94.     and    edi,03030303h
  95.  
  96.     shr    ebp,2
  97.     mov    eax,[ecx+esi+%1]
  98.  
  99.     mov    ebx,0fcfcfcfch
  100.     and    ebx,eax
  101.  
  102.     and    eax,03030303h
  103.     add    edi,eax
  104.  
  105.     shr    ebx,2
  106.     mov    eax,[ecx+1+%1]
  107.  
  108.     add    ebp,ebx
  109.     mov    ebx,0fcfcfcfch
  110.  
  111.     and    ebx,eax
  112.     and    eax,03030303h
  113.  
  114.     shr    ebx,2
  115.     add    edi,eax
  116.  
  117.     add    ebp,ebx
  118.     mov    eax,[ecx+esi+1+%1]
  119.  
  120.     add    edi,02020202h
  121.     mov    ebx,0fcfcfcfch
  122.  
  123.     and    ebx,eax
  124.     and    eax,03030303h
  125.  
  126.     shr    ebx,2
  127.     add    edi,eax
  128.  
  129.     shr    edi,2
  130.     add    ebp,ebx
  131.  
  132.     and    edi,03030303h
  133.     add    ebp,edi
  134.  
  135.     mov    [edx+%1],ebp
  136. %endmacro
  137.  
  138.     quadpel_move    0
  139.     quadpel_move    4
  140.     quadpel_move    8
  141.     quadpel_move    12
  142.  
  143.     mov    eax,[esp]
  144.     lea    ecx,[ecx+esi]
  145.     dec    eax
  146.     lea    edx,[edx+esi]
  147.     mov    [esp],eax
  148.     jne    loop_Y1_quadpel
  149.     pop    eax
  150.     PREDICT_END
  151.     ret
  152.  
  153.  
  154. ;*********************************************************
  155. ;*
  156. ;*    Luminance - half-pel Y
  157. ;*
  158. ;*********************************************************
  159.  
  160.     align    16
  161. predict_Y_halfpelY:
  162.     PREDICT_START
  163.     mov    ebp,16
  164. loop_Y1_halfpelV:
  165.     mov    edi,[ecx+0]        ;[1]
  166.     mov    ebx,[ecx+esi+0]        ;[1]
  167.     mov    eax,ebx            ;[1]
  168.     xor    ebx,edi            ;[1]
  169.     shr    ebx,1            ;[1]
  170.     or    eax,edi            ;[1]
  171.     and    ebx,7f7f7f7fh        ;[1]
  172.     mov    edi,[ecx+4]        ;[2]
  173.     sub    eax,ebx            ;[1]
  174.     mov    ebx,[ecx+esi+4]        ;[2]
  175.     mov    [edx+0],eax        ;[1]
  176.     mov    eax,ebx            ;[2]
  177.     xor    ebx,edi            ;[2]
  178.     shr    ebx,1            ;[2]
  179.     or    eax,edi            ;[2]
  180.     and    ebx,7f7f7f7fh        ;[2]
  181.     mov    edi,[ecx+8]        ;[3]
  182.     sub    eax,ebx            ;[2]
  183.     mov    ebx,[ecx+esi+8]        ;[3]
  184.     mov    [edx+4],eax        ;[2]
  185.     mov    eax,ebx            ;[3]
  186.     xor    ebx,edi            ;[3]
  187.     shr    ebx,1            ;[3]
  188.     or    eax,edi            ;[3]
  189.     and    ebx,7f7f7f7fh        ;[3]
  190.     mov    edi,[ecx+12]        ;[4]
  191.     sub    eax,ebx            ;[3]
  192.     mov    ebx,[ecx+esi+12]    ;[4]
  193.     mov    [edx+8],eax        ;[3]
  194.     mov    eax,ebx            ;[4]
  195.     xor    ebx,edi            ;[4]
  196.     shr    ebx,1            ;[4]
  197.     or    eax,edi            ;[4]
  198.     and    ebx,7f7f7f7fh        ;[4]
  199.     add    ecx,esi
  200.     sub    eax,ebx            ;[4]
  201.     dec    ebp
  202.     mov    [edx+12],eax        ;[4]
  203.     lea    edx,[edx+esi]
  204.     jne    loop_Y1_halfpelV
  205.  
  206.     PREDICT_END
  207.     ret
  208.  
  209. ;*********************************************************
  210. ;*
  211. ;*    Luminance - half-pel X
  212. ;*
  213. ;*********************************************************
  214.  
  215.     align    16
  216. predict_Y_halfpelX:
  217.     PREDICT_START
  218.     mov    ebp,16
  219. loop_Y1_halfpelX:
  220.     mov    edi,[ecx+0]        ;[1]
  221.     mov    ebx,[ecx+1]        ;[1]
  222.     mov    eax,ebx            ;[1]
  223.     xor    ebx,edi            ;[1]
  224.     shr    ebx,1            ;[1]
  225.     or    eax,edi            ;[1]
  226.     and    ebx,7f7f7f7fh        ;[1]
  227.     mov    edi,[ecx+4]        ;[2]
  228.     sub    eax,ebx            ;[1]
  229.     mov    ebx,[ecx+5]        ;[2]
  230.     mov    [edx+0],eax        ;[1]
  231.     mov    eax,ebx            ;[2]
  232.     xor    ebx,edi            ;[2]
  233.     shr    ebx,1            ;[2]
  234.     or    eax,edi            ;[2]
  235.     and    ebx,7f7f7f7fh        ;[2]
  236.     mov    edi,[ecx+8]        ;[3]
  237.     sub    eax,ebx            ;[2]
  238.     mov    ebx,[ecx+9]        ;[3]
  239.     mov    [edx+4],eax        ;[2]
  240.     mov    eax,ebx            ;[3]
  241.     xor    ebx,edi            ;[3]
  242.     shr    ebx,1            ;[3]
  243.     or    eax,edi            ;[3]
  244.     and    ebx,7f7f7f7fh        ;[3]
  245.     mov    edi,[ecx+12]        ;[4]
  246.     sub    eax,ebx            ;[3]
  247.     mov    ebx,[ecx+13]        ;[4]
  248.     mov    [edx+8],eax        ;[3]
  249.     mov    eax,ebx            ;[4]
  250.     xor    ebx,edi            ;[4]
  251.     shr    ebx,1            ;[4]
  252.     or    eax,edi            ;[4]
  253.     and    ebx,7f7f7f7fh        ;[4]
  254.     add    ecx,esi
  255.     sub    eax,ebx            ;[4]
  256.     dec    ebp
  257.     mov    [edx+12],eax        ;[4]
  258.     lea    edx,[edx+esi]
  259.     jne    loop_Y1_halfpelX
  260.  
  261.     PREDICT_END
  262.     ret
  263.  
  264.  
  265. ;*********************************************************
  266. ;*
  267. ;*    Luminance - normal
  268. ;*
  269. ;*********************************************************
  270.  
  271.     align    16
  272. predict_Y_normal:
  273.     PREDICT_START
  274.     mov    edi,8
  275. loop_Y:
  276.     mov    eax,[ecx]
  277.     mov    ebx,[ecx+4]
  278.     mov    [edx],eax
  279.     mov    [edx+4],ebx
  280.     mov    eax,[ecx+8]
  281.     mov    ebx,[ecx+12]
  282.     mov    [edx+8],eax
  283.     mov    [edx+12],ebx
  284.     mov    eax,[ecx+esi]
  285.     mov    ebx,[ecx+esi+4]
  286.     mov    [edx+esi],eax
  287.     mov    [edx+esi+4],ebx
  288.     mov    eax,[ecx+esi+8]
  289.     mov    ebx,[ecx+esi+12]
  290.     mov    [edx+esi+8],eax
  291.     mov    [edx+esi+12],ebx
  292.     lea    ecx,[ecx+esi*2]
  293.     lea    edx,[edx+esi*2]
  294.     dec    edi
  295.     jne    loop_Y
  296.  
  297.     PREDICT_END
  298.     ret
  299.  
  300.  
  301.  
  302.  
  303. ;**************************************************************************
  304. ;*
  305. ;*
  306. ;*
  307. ;*  Addition predictors
  308. ;*
  309. ;*
  310. ;*
  311. ;**************************************************************************
  312.  
  313. ;*********************************************************
  314. ;*
  315. ;*    Luminance - quadpel
  316. ;*
  317. ;*********************************************************
  318.  
  319.     align    16
  320. predict_add_Y_quadpel:
  321.     PREDICT_START
  322.     push    16
  323. add_loop_Y1_quadpel:
  324.  
  325. ;    [A][B][C][D][E][F][G][H]
  326. ;    [I][J][K][L][M][N][O][P]
  327.  
  328. %macro quadpel_add 1
  329.     mov    edi,[ecx+%1]
  330.     mov    ebp,0f8f8f8f8h
  331.  
  332.     and    ebp,edi
  333.     and    edi,07070707h
  334.  
  335.     shr    ebp,3
  336.     mov    eax,[ecx+esi+%1]
  337.  
  338.     mov    ebx,0f8f8f8f8h
  339.     and    ebx,eax
  340.  
  341.     and    eax,07070707h
  342.     add    edi,eax
  343.  
  344.     shr    ebx,3
  345.     mov    eax,[ecx+1+%1]
  346.  
  347.     add    ebp,ebx
  348.     mov    ebx,0f8f8f8f8h
  349.  
  350.     and    ebx,eax
  351.     and    eax,07070707h
  352.  
  353.     shr    ebx,3
  354.     add    edi,eax
  355.  
  356.     add    ebp,ebx
  357.     mov    eax,[ecx+esi+1+%1]
  358.  
  359.     add    edi,04040404h
  360.     mov    ebx,0f8f8f8f8h
  361.  
  362.     and    ebx,eax
  363.     and    eax,07070707h
  364.  
  365.     shr    ebx,3
  366.     add    edi,eax
  367.  
  368.     mov    eax,[edx+%1]
  369.     add    ebp,ebx
  370.  
  371.     mov    ebx,eax
  372.     and    eax,0fefefefeh
  373.  
  374.     shr    eax,1
  375.     and    ebx,01010101h
  376.  
  377.     shl    ebx,2
  378.     add    ebp,eax
  379.  
  380.     add    edi,ebx
  381.     shr    edi,3
  382.     and    edi,07070707h
  383.     add    ebp,edi
  384.  
  385.     mov    [edx+%1],ebp
  386. %endmacro
  387.  
  388.     quadpel_add    0
  389.     quadpel_add    4
  390.     quadpel_add    8
  391.     quadpel_add    12
  392.  
  393.     mov    eax,[esp]
  394.     lea    ecx,[ecx+esi]
  395.     dec    eax
  396.     lea    edx,[edx+esi]
  397.     mov    [esp],eax
  398.     jne    add_loop_Y1_quadpel
  399.     pop    eax
  400.     PREDICT_END
  401.     ret
  402.  
  403. ;*********************************************************
  404. ;*
  405. ;*    Luminance - half-pel Y
  406. ;*
  407. ;*********************************************************
  408.  
  409.     align    16
  410. predict_add_Y_halfpelY:
  411.     PREDICT_START
  412.     mov    ebp,16
  413. add_loop_Y1_halfpelV:
  414.     mov    edi,[ecx]        ;[1]
  415.     mov    ebx,[ecx+esi]        ;[1]
  416.     mov    eax,ebx            ;[1]
  417.     xor    ebx,edi            ;[1]
  418.     shr    ebx,1            ;[1]
  419.     or    edi,eax            ;[1]
  420.     and    ebx,7f7f7f7fh        ;[1]
  421.     mov    eax,[edx]        ;[1]
  422.     sub    edi,ebx            ;[1]
  423.     mov    ebx,eax            ;[1]
  424.     xor    ebx,edi            ;[1]
  425.     shr    ebx,1            ;[1]
  426.     or    eax,edi            ;[1]
  427.     and    ebx,7f7f7f7fh        ;[1]
  428.     mov    edi,[ecx+4]        ;[2]
  429.     sub    eax,ebx            ;[1]
  430.     mov    ebx,[ecx+esi+4]        ;[2]
  431.     mov    [edx],eax        ;[1]
  432.     mov    eax,ebx            ;[2]
  433.     xor    ebx,edi            ;[2]
  434.     shr    ebx,1            ;[2]
  435.     or    edi,eax            ;[2]
  436.     and    ebx,7f7f7f7fh        ;[2]
  437.     mov    eax,[edx+4]        ;[2]
  438.     sub    edi,ebx            ;[2]
  439.     mov    ebx,eax            ;[2]
  440.     xor    ebx,edi            ;[2]
  441.     shr    ebx,1            ;[2]
  442.     or    eax,edi            ;[2]
  443.     and    ebx,7f7f7f7fh        ;[2]
  444.     mov    edi,[ecx+8]        ;[3]
  445.     sub    eax,ebx            ;[2]
  446.     mov    ebx,[ecx+esi+8]        ;[3]
  447.     mov    [edx+4],eax        ;[2]
  448.     mov    eax,ebx            ;[3]
  449.     xor    ebx,edi            ;[3]
  450.     shr    ebx,1            ;[3]
  451.     or    edi,eax            ;[3]
  452.     and    ebx,7f7f7f7fh        ;[3]
  453.     mov    eax,[edx+8]        ;[3]
  454.     sub    edi,ebx            ;[3]
  455.     mov    ebx,eax            ;[3]
  456.     xor    ebx,edi            ;[3]
  457.     shr    ebx,1            ;[3]
  458.     or    eax,edi            ;[3]
  459.     and    ebx,7f7f7f7fh        ;[3]
  460.     mov    edi,[ecx+12]        ;[4]
  461.     sub    eax,ebx            ;[3]
  462.     mov    ebx,[ecx+esi+12]    ;[4]
  463.     mov    [edx+8],eax        ;[3]
  464.     mov    eax,ebx            ;[4]
  465.     xor    ebx,edi            ;[4]
  466.     shr    ebx,1            ;[4]
  467.     or    edi,eax            ;[4]
  468.     and    ebx,7f7f7f7fh        ;[4]
  469.     mov    eax,[edx+12]        ;[4]
  470.     sub    edi,ebx            ;[4]
  471.     mov    ebx,eax            ;[4]
  472.     xor    ebx,edi            ;[4]
  473.     shr    ebx,1            ;[4]
  474.     or    eax,edi            ;[4]
  475.     and    ebx,7f7f7f7fh        ;[4]
  476.     add    ecx,esi
  477.     sub    eax,ebx            ;[4]
  478.     dec    ebp
  479.     mov    [edx+12],eax        ;[4]
  480.     lea    edx,[edx+esi]
  481.     jne    add_loop_Y1_halfpelV
  482.     PREDICT_END
  483.     ret
  484.  
  485.  
  486. ;*********************************************************
  487. ;*
  488. ;*    Luminance - half-pel X
  489. ;*
  490. ;*********************************************************
  491.  
  492.     align    16
  493. predict_add_Y_halfpelX:
  494.     PREDICT_START
  495.     mov    ebp,16
  496. add_loop_Y1_halfpelX:
  497.     mov    edi,[ecx]        ;[1]
  498.     mov    ebx,[ecx+1]        ;[1]
  499.     mov    eax,ebx            ;[1]
  500.     xor    ebx,edi            ;[1]
  501.     shr    ebx,1            ;[1]
  502.     or    edi,eax            ;[1]
  503.     and    ebx,7f7f7f7fh        ;[1]
  504.     mov    eax,[edx]        ;[1]
  505.     sub    edi,ebx            ;[1]
  506.     mov    ebx,eax            ;[1]
  507.     xor    ebx,edi            ;[1]
  508.     shr    ebx,1            ;[1]
  509.     or    eax,edi            ;[1]
  510.     and    ebx,7f7f7f7fh        ;[1]
  511.     mov    edi,[ecx+4]        ;[2]
  512.     sub    eax,ebx            ;[1]
  513.     mov    ebx,[ecx+5]        ;[2]
  514.     mov    [edx],eax        ;[1]
  515.     mov    eax,ebx            ;[2]
  516.     xor    ebx,edi            ;[2]
  517.     shr    ebx,1            ;[2]
  518.     or    edi,eax            ;[2]
  519.     and    ebx,7f7f7f7fh        ;[2]
  520.     mov    eax,[edx+4]        ;[2]
  521.     sub    edi,ebx            ;[2]
  522.     mov    ebx,eax            ;[2]
  523.     xor    ebx,edi            ;[2]
  524.     shr    ebx,1            ;[2]
  525.     or    eax,edi            ;[2]
  526.     and    ebx,7f7f7f7fh        ;[2]
  527.     mov    edi,[ecx+8]        ;[3]
  528.     sub    eax,ebx            ;[2]
  529.     mov    ebx,[ecx+9]        ;[3]
  530.     mov    [edx+4],eax        ;[2]
  531.     mov    eax,ebx            ;[3]
  532.     xor    ebx,edi            ;[3]
  533.     shr    ebx,1            ;[3]
  534.     or    edi,eax            ;[3]
  535.     and    ebx,7f7f7f7fh        ;[3]
  536.     mov    eax,[edx+8]        ;[3]
  537.     sub    edi,ebx            ;[3]
  538.     mov    ebx,eax            ;[3]
  539.     xor    ebx,edi            ;[3]
  540.     shr    ebx,1            ;[3]
  541.     or    eax,edi            ;[3]
  542.     and    ebx,7f7f7f7fh        ;[3]
  543.     mov    edi,[ecx+12]        ;[4]
  544.     sub    eax,ebx            ;[3]
  545.     mov    ebx,[ecx+13]        ;[4]
  546.     mov    [edx+8],eax        ;[3]
  547.     mov    eax,ebx            ;[4]
  548.     xor    ebx,edi            ;[4]
  549.     shr    ebx,1            ;[4]
  550.     or    edi,eax            ;[4]
  551.     and    ebx,7f7f7f7fh        ;[4]
  552.     mov    eax,[edx+12]        ;[4]
  553.     sub    edi,ebx            ;[4]
  554.     mov    ebx,eax            ;[4]
  555.     xor    ebx,edi            ;[4]
  556.     shr    ebx,1            ;[4]
  557.     or    eax,edi            ;[4]
  558.     and    ebx,7f7f7f7fh        ;[4]
  559.     add    ecx,esi
  560.     sub    eax,ebx            ;[4]
  561.     dec    ebp
  562.     mov    [edx+12],eax        ;[4]
  563.     lea    edx,[edx+esi]
  564.     jne    add_loop_Y1_halfpelX
  565.     PREDICT_END
  566.     ret
  567.  
  568.  
  569.  
  570.  
  571.  
  572. ;*********************************************************
  573. ;*
  574. ;*    Luminance - normal
  575. ;*
  576. ;*    See note at top, or this will be unreadable.
  577. ;*
  578. ;*********************************************************
  579.  
  580.     align    16
  581. predict_add_Y_normal:
  582.     PREDICT_START
  583.     mov    ebp, 16
  584. add_loop_Y1_normal:
  585.     mov    edi,[ecx]        ;[1]
  586.     mov    ebx,[edx]        ;[1]
  587.     mov    eax,ebx            ;[1]
  588.     xor    ebx,edi            ;[1]
  589.     shr    ebx,1            ;[1]
  590.     or    eax,edi            ;[1]
  591.     and    ebx,7f7f7f7fh        ;[1]
  592.     mov    edi,[ecx+4]        ;[2]
  593.     sub    eax,ebx            ;[1]
  594.     mov    ebx,[edx+4]        ;[2]
  595.     mov    [edx],eax        ;[1]
  596.     mov    eax,ebx            ;[2]
  597.     xor    ebx,edi            ;[2]
  598.     shr    ebx,1            ;[2]
  599.     or    eax,edi            ;[2]
  600.     and    ebx,7f7f7f7fh        ;[2]
  601.     mov    edi,[ecx+8]        ;[3]
  602.     sub    eax,ebx            ;[2]
  603.     mov    ebx,[edx+8]        ;[3]
  604.     mov    [edx+4],eax        ;[2]
  605.     mov    eax,ebx            ;[3]
  606.     xor    ebx,edi            ;[3]
  607.     shr    ebx,1            ;[3]
  608.     or    eax,edi            ;[3]
  609.     and    ebx,7f7f7f7fh        ;[3]
  610.     mov    edi,[ecx+12]        ;[4]
  611.     sub    eax,ebx            ;[3]
  612.     mov    ebx,[edx+12]        ;[4]
  613.     mov    [edx+8],eax        ;[3]
  614.     mov    eax,ebx            ;[4]
  615.     xor    ebx,edi            ;[4]
  616.     shr    ebx,1            ;[4]
  617.     or    eax,edi            ;[4]
  618.     and    ebx,7f7f7f7fh        ;[4]
  619.     sub    eax,ebx            ;[4]
  620.     add    ecx,esi
  621.     mov    [edx+12],eax        ;[4]
  622.     add    edx,esi
  623.     dec    ebp
  624.     jne    add_loop_Y1_normal
  625.  
  626.     PREDICT_END
  627.     ret
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637. ;**************************************************************************
  638. ;*
  639. ;*
  640. ;*    Chrominance predictors
  641. ;*
  642. ;*
  643. ;**************************************************************************
  644.  
  645. ;*********************************************************
  646. ;*
  647. ;*    Luminance - quadpel
  648. ;*
  649. ;*********************************************************
  650.  
  651.     align    16
  652. predict_C_quadpel:
  653.     PREDICT_START
  654.     push    8
  655. loop_C1_quadpel:
  656.  
  657. ;    [A][B][C][D][E][F][G][H]
  658. ;    [I][J][K][L][M][N][O][P]
  659.  
  660. %macro quadpel_move_y 1
  661.     mov    eax,[ecx+%1]        ;EAX = [D][C][B][A] (#1)
  662.     mov    ebx,[ecx+1+%1]        ;EBX = [E][D][C][B] (#2)
  663.     mov    edi,eax            ;EDI = [D][C][B][A] (#1)
  664.     mov    ebp,ebx            ;EBP = [E][D][C][B] (#2)
  665.     shr    edi,8            ;EDI = [0][D][C][B] (#1>>8)
  666.     and    eax,00ff00ffh        ;EAX = [ C ][ A ] (#1 even)
  667.     shr    ebp,8            ;EBP = [0][E][D][C] (#2>>8)
  668.     and    ebx,00ff00ffh        ;EBX = [ D ][ B ] (#2 even)
  669.     and    edi,00ff00ffh        ;EDI = [ D ][ B ] (#1 odd)
  670.     and    ebp,00ff00ffh        ;EBP = [ E ][ C ] (#2 odd)
  671.     add    eax,ebx            ;EAX = [C+D][A+B]
  672.     add    edi,ebp            ;EDI = [D+E][B+C]
  673.  
  674.     mov    ebx,[ecx+esi+%1]    ;EBX = [L][K][J][I]
  675.     add    eax,00020002h        ;EAX = [C+D+4][A+B+4]
  676.  
  677.     mov    ebp,ebx            ;EBP = [L][K][J][I]
  678.     and    ebx,00ff00ffh        ;EBX = [ K ][ I ]
  679.     shr    ebp,8            ;EBP = [0][L][K][J]
  680.     add    eax,ebx            ;EAX = [C+D+K+4][A+B+I+4]
  681.     and    ebp,00ff00ffh        ;EBP = [ L ][ J ]
  682.     mov    ebx,[ecx+esi+1+%1]    ;EBX = [M][L][K][J]
  683.     add    edi,ebp            ;EDI = [D+E+L][B+C+J]
  684.     mov    ebp,ebx            ;EBP = [M][L][K][J]
  685.     
  686.     shr    ebp,8            ;EBP = [0][M][L][K]
  687.     add    edi,00020002h
  688.  
  689.     and    ebx,00ff00ffh        ;EBX = [ L ][ J ]
  690.     and    ebp,00ff00ffh        ;EBP = [ M ][ K ]
  691.  
  692.     add    edi,ebp            ;EDI = [D+E+L+M][B+C+J+K]
  693.     add    eax,ebx            ;EAX = [C+D+K+L+4][A+B+I+J+4]
  694.     
  695.     shl    edi,6
  696.     and    eax,03fc03fch
  697.  
  698.     shr    eax,2
  699.     and    edi,0ff00ff00h
  700.  
  701.     or    eax,edi
  702.     mov    [edx+%1],eax
  703. %endmacro
  704.  
  705.     quadpel_move_y    0
  706.     quadpel_move_y    4
  707.  
  708.     mov    eax,[esp]
  709.     lea    ecx,[ecx+esi]
  710.     dec    eax
  711.     lea    edx,[edx+esi]
  712.     mov    [esp],eax
  713.     jne    loop_C1_quadpel
  714.     pop    eax
  715.     PREDICT_END
  716.     ret
  717.  
  718.  
  719.  
  720.  
  721. ;*********************************************************
  722. ;*
  723. ;*    Luminance - half-pel Y
  724. ;*
  725. ;*********************************************************
  726.  
  727.     align    16
  728. predict_C_halfpelY:
  729.     PREDICT_START
  730.     mov    ebp,8
  731. loop_C1_halfpelV:
  732.     mov    edi,[ecx]        ;[1]
  733.     mov    ebx,[ecx+esi]        ;[1]
  734.     mov    eax,ebx            ;[1]
  735.     xor    ebx,edi            ;[1]
  736.     shr    ebx,1            ;[1]
  737.     or    eax,edi            ;[1]
  738.     and    ebx,7f7f7f7fh        ;[1]
  739.     mov    edi,[ecx+4]        ;[2]
  740.     sub    eax,ebx            ;[1]
  741.     mov    ebx,[ecx+esi+4]        ;[2]
  742.     mov    [edx],eax        ;[1]
  743.     mov    eax,ebx            ;[2]
  744.     xor    ebx,edi            ;[2]
  745.     shr    ebx,1            ;[2]
  746.     or    eax,edi            ;[2]
  747.     and    ebx,7f7f7f7fh        ;[2]
  748.     add    ecx,esi
  749.     sub    eax,ebx            ;[2]
  750.     dec    ebp
  751.     mov    [edx+4],eax        ;[2]
  752.     lea    edx,[edx+esi]
  753.     jne    loop_C1_halfpelV
  754.  
  755.     PREDICT_END
  756.     ret
  757.  
  758.  
  759. ;*********************************************************
  760. ;*
  761. ;*    Luminance - half-pel X
  762. ;*
  763. ;*********************************************************
  764.  
  765.     align    16
  766. predict_C_halfpelX:
  767.     PREDICT_START
  768.     mov    ebp,8
  769. loop_C1_halfpelX:
  770.     mov    edi,[ecx]        ;[1]
  771.     mov    ebx,[ecx+1]        ;[1]
  772.     mov    eax,ebx            ;[1]
  773.     xor    ebx,edi            ;[1]
  774.     shr    ebx,1            ;[1]
  775.     or    eax,edi            ;[1]
  776.     and    ebx,7f7f7f7fh        ;[1]
  777.     mov    edi,[ecx+4]        ;[2]
  778.     sub    eax,ebx            ;[1]
  779.     mov    ebx,[ecx+5]        ;[2]
  780.     mov    [edx],eax        ;[1]
  781.     mov    eax,ebx            ;[2]
  782.     xor    ebx,edi            ;[2]
  783.     shr    ebx,1            ;[2]
  784.     or    eax,edi            ;[2]
  785.     and    ebx,7f7f7f7fh        ;[2]
  786.     add    ecx,esi
  787.     sub    eax,ebx            ;[2]
  788.     dec    ebp
  789.     mov    [edx+4],eax        ;[2]
  790.     lea    edx,[edx+esi]
  791.     jne    loop_C1_halfpelX
  792.     PREDICT_END
  793.     ret
  794.  
  795.  
  796. ;*********************************************************
  797. ;*
  798. ;*    Luminance - normal
  799. ;*
  800. ;*********************************************************
  801.  
  802.     align    16
  803. predict_C_normal:
  804.     PREDICT_START
  805.     mov    edi,4
  806. loop_C:
  807.     mov    eax,[ecx]
  808.     mov    ebx,[ecx+4]
  809.     mov    [edx],eax
  810.     mov    [edx+4],ebx
  811.     mov    eax,[ecx+esi]
  812.     mov    ebx,[ecx+esi+4]
  813.     mov    [edx+esi],eax
  814.     mov    [edx+esi+4],ebx
  815.     lea    ecx,[ecx+esi*2]
  816.     lea    edx,[edx+esi*2]
  817.     dec    edi
  818.     jne    loop_C
  819.     PREDICT_END
  820.     ret
  821.  
  822.  
  823.  
  824.  
  825.  
  826. ;**************************************************************************
  827. ;*
  828. ;*
  829. ;*
  830. ;*  Addition predictors
  831. ;*
  832. ;*
  833. ;*
  834. ;**************************************************************************
  835.  
  836.  
  837. ;*********************************************************
  838. ;*
  839. ;*    Luminance - quadpel
  840. ;*
  841. ;*********************************************************
  842.  
  843.     align    16
  844. predict_add_C_quadpel:
  845.     PREDICT_START
  846.     push    8
  847. add_loop_C1_quadpel:
  848.  
  849. ;    [A][B][C][D][E][F][G][H]
  850. ;    [I][J][K][L][M][N][O][P]
  851.  
  852. %macro quadpel_add_y    1
  853.     mov    edi,[ecx+%1]
  854.     mov    ebp,0f8f8f8f8h
  855.  
  856.     and    ebp,edi
  857.     and    edi,07070707h
  858.  
  859.     shr    ebp,3
  860.     mov    eax,[ecx+esi+%1]
  861.  
  862.     mov    ebx,0f8f8f8f8h
  863.     and    ebx,eax
  864.  
  865.     and    eax,07070707h
  866.     add    edi,eax
  867.  
  868.     shr    ebx,3
  869.     mov    eax,[ecx+1+%1]
  870.  
  871.     add    ebp,ebx
  872.     mov    ebx,0f8f8f8f8h
  873.  
  874.     and    ebx,eax
  875.     and    eax,07070707h
  876.  
  877.     shr    ebx,3
  878.     add    edi,eax
  879.  
  880.     add    ebp,ebx
  881.     mov    eax,[ecx+esi+1+%1]
  882.  
  883.     add    edi,04040404h
  884.     mov    ebx,0f8f8f8f8h
  885.  
  886.     and    ebx,eax
  887.     and    eax,07070707h
  888.  
  889.     shr    ebx,3
  890.     add    edi,eax
  891.  
  892.     mov    eax,[edx+%1]
  893.     add    ebp,ebx
  894.  
  895.     mov    ebx,eax
  896.     and    eax,0fefefefeh
  897.  
  898.     shr    eax,1
  899.     and    ebx,01010101h
  900.  
  901.     shl    ebx,2
  902.     add    ebp,eax
  903.  
  904.     add    edi,ebx
  905.     shr    edi,3
  906.     and    edi,07070707h
  907.     add    ebp,edi
  908.  
  909.     mov    [edx+%1],ebp
  910. %endmacro
  911.  
  912.     quadpel_add_y    0
  913.     quadpel_add_y    4
  914.  
  915.     mov    eax,[esp]
  916.     lea    ecx,[ecx+esi]
  917.     dec    eax
  918.     lea    edx,[edx+esi]
  919.     mov    [esp],eax
  920.     jne    add_loop_C1_quadpel
  921.     pop    eax
  922.     PREDICT_END
  923.     ret
  924.  
  925.  
  926. ;*********************************************************
  927. ;*
  928. ;*    Luminance - half-pel Y
  929. ;*
  930. ;*********************************************************
  931.  
  932.     align    16
  933. predict_add_C_halfpelY:
  934.     PREDICT_START
  935.     mov    ebp,8
  936. add_loop_C1_halfpelV:
  937.     mov    edi,[ecx]        ;[1]
  938.     mov    ebx,[ecx+esi]        ;[1]
  939.     mov    eax,ebx            ;[1]
  940.     xor    ebx,edi            ;[1]
  941.     shr    ebx,1            ;[1]
  942.     or    edi,eax            ;[1]
  943.     and    ebx,7f7f7f7fh        ;[1]
  944.     mov    eax,[edx]        ;[1]
  945.     sub    edi,ebx            ;[1]
  946.     mov    ebx,eax            ;[1]
  947.     xor    ebx,edi            ;[1]
  948.     shr    ebx,1            ;[1]
  949.     or    eax,edi            ;[1]
  950.     and    ebx,7f7f7f7fh        ;[1]
  951.     mov    edi,[ecx+4]        ;[2]
  952.     sub    eax,ebx            ;[1]
  953.     mov    ebx,[ecx+esi+4]        ;[2]
  954.     mov    [edx],eax        ;[1]
  955.     mov    eax,ebx            ;[2]
  956.     xor    ebx,edi            ;[2]
  957.     shr    ebx,1            ;[2]
  958.     or    edi,eax            ;[2]
  959.     and    ebx,7f7f7f7fh        ;[2]
  960.     mov    eax,[edx+4]        ;[2]
  961.     sub    edi,ebx            ;[2]
  962.     mov    ebx,eax            ;[2]
  963.     xor    ebx,edi            ;[2]
  964.     shr    ebx,1            ;[2]
  965.     or    eax,edi            ;[2]
  966.     and    ebx,7f7f7f7fh        ;[2]
  967.     add    ecx,esi
  968.     sub    eax,ebx            ;[2]
  969.     dec    ebp
  970.     mov    [edx+4],eax        ;[2]
  971.     lea    edx,[edx+esi]
  972.     jne    add_loop_C1_halfpelV
  973.     PREDICT_END
  974.     ret
  975.  
  976.  
  977. ;*********************************************************
  978. ;*
  979. ;*    Luminance - half-pel X
  980. ;*
  981. ;*********************************************************
  982.  
  983.     align    16
  984. predict_add_C_halfpelX:
  985.     PREDICT_START
  986.     mov    ebp,8
  987. add_loop_C1_halfpelX:
  988.     mov    edi,[ecx]        ;[1]
  989.     mov    ebx,[ecx+1]        ;[1]
  990.     mov    eax,ebx            ;[1]
  991.     xor    ebx,edi            ;[1]
  992.     shr    ebx,1            ;[1]
  993.     or    edi,eax            ;[1]
  994.     and    ebx,7f7f7f7fh        ;[1]
  995.     mov    eax,[edx]        ;[1]
  996.     sub    edi,ebx            ;[1]
  997.     mov    ebx,eax            ;[1]
  998.     xor    ebx,edi            ;[1]
  999.     shr    ebx,1            ;[1]
  1000.     or    eax,edi            ;[1]
  1001.     and    ebx,7f7f7f7fh        ;[1]
  1002.     mov    edi,[ecx+4]        ;[2]
  1003.     sub    eax,ebx            ;[1]
  1004.     mov    ebx,[ecx+5]        ;[2]
  1005.     mov    [edx],eax        ;[1]
  1006.     mov    eax,ebx            ;[2]
  1007.     xor    ebx,edi            ;[2]
  1008.     shr    ebx,1            ;[2]
  1009.     or    edi,eax            ;[2]
  1010.     and    ebx,7f7f7f7fh        ;[2]
  1011.     mov    eax,[edx+4]        ;[2]
  1012.     sub    edi,ebx            ;[2]
  1013.     mov    ebx,eax            ;[2]
  1014.     xor    ebx,edi            ;[2]
  1015.     shr    ebx,1            ;[2]
  1016.     or    eax,edi            ;[2]
  1017.     and    ebx,7f7f7f7fh        ;[2]
  1018.     add    ecx,esi
  1019.     sub    eax,ebx            ;[2]
  1020.     dec    ebp
  1021.     mov    [edx+4],eax        ;[2]
  1022.     lea    edx,[edx+esi]
  1023.     jne    add_loop_C1_halfpelX
  1024.     PREDICT_END
  1025.     ret
  1026.  
  1027.  
  1028.  
  1029.  
  1030. ;*********************************************************
  1031. ;*
  1032. ;*    Luminance - normal
  1033. ;*
  1034. ;*********************************************************
  1035.  
  1036.     align    16
  1037. predict_add_C_normal:
  1038.     PREDICT_START
  1039.     mov    ebp,8
  1040. add_loop_C1_addX:
  1041.     mov    edi,[ecx]        ;[1]
  1042.     mov    ebx,[edx]        ;[1]
  1043.     mov    eax,ebx            ;[1]
  1044.     xor    ebx,edi            ;[1]
  1045.     shr    ebx,1            ;[1]
  1046.     or    eax,edi            ;[1]
  1047.     and    ebx,7f7f7f7fh        ;[1]
  1048.     mov    edi,[ecx+4]        ;[2]
  1049.     sub    eax,ebx            ;[1]
  1050.     mov    ebx,[edx+4]        ;[2]
  1051.     mov    [edx],eax        ;[1]
  1052.     mov    eax,ebx            ;[2]
  1053.     xor    ebx,edi            ;[2]
  1054.     shr    ebx,1            ;[2]
  1055.     or    eax,edi            ;[2]
  1056.     and    ebx,7f7f7f7fh        ;[2]
  1057.     sub    eax,ebx            ;[2]
  1058.     add    ecx,esi
  1059.     mov    [edx+4],eax        ;[2]
  1060.     add    edx,esi
  1061.     dec    ebp
  1062.     jne    add_loop_C1_addX
  1063.     PREDICT_END
  1064.     ret
  1065.  
  1066.     end
  1067.  
  1068.