Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; /*
  2. ; * Provide SSE luma mc functions for HEVC decoding
  3. ; * Copyright (c) 2013 Pierre-Edouard LEPERE
  4. ; *
  5. ; * This file is part of FFmpeg.
  6. ; *
  7. ; * FFmpeg is free software; you can redistribute it and/or
  8. ; * modify it under the terms of the GNU Lesser General Public
  9. ; * License as published by the Free Software Foundation; either
  10. ; * version 2.1 of the License, or (at your option) any later version.
  11. ; *
  12. ; * FFmpeg is distributed in the hope that it will be useful,
  13. ; * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. ; * Lesser General Public License for more details.
  16. ; *
  17. ; * You should have received a copy of the GNU Lesser General Public
  18. ; * License along with FFmpeg; if not, write to the Free Software
  19. ; * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. ; */
  21. %include "libavutil/x86/x86util.asm"
  22. %if ARCH_X86_64
  23. SECTION_RODATA
  24. cextern hevc_epel_filters
  25.  
  26. epel_extra_before: DB 1    ;corresponds to EPEL_EXTRA_BEFORE in hevc.h
  27. max_pb_size:        DB 64   ;corresponds to MAX_PB_SIZE in hevc.h
  28.  
  29. epel_h_shuffle1_m:   DB 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6
  30.  
  31. epel_h_shuffle2_m:   DB 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9, 7, 8, 9, 10
  32.  
  33.  
  34. %ifdef PIC
  35. %define epel_h_shuffle1 picregq
  36. %define epel_h_shuffle2 picregq
  37. %define npicregs 1
  38. %else
  39. %define epel_h_shuffle1 epel_h_shuffle1_m
  40. %define epel_h_shuffle2 epel_h_shuffle2_m
  41. %define npicregs 0
  42. %endif
  43.  
  44.  
  45. SECTION .text
  46.  
  47.  
  48. INIT_XMM sse4        ; adds ff_ and _sse4 to function name
  49.  
  50. ; ******************************
  51. ; void put_hevc_mc_pixels_8(int16_t *dst, ptrdiff_t dststride,
  52. ;                                       uint8_t *_src, ptrdiff_t _srcstride,
  53. ;                                       int width, int height, int mx, int my,
  54. ;                                       int16_t* mcbuffer)
  55. ;
  56. ;        r0 : *dst
  57. ;        r1 : dststride
  58. ;        r2 : *src
  59. ;         r3 : srcstride
  60. ;        r4 : width
  61. ;        r5 : height
  62. ;
  63. ; ******************************
  64.  
  65. ; 1 by 1. Can be done on any processor
  66. cglobal put_hevc_mc_pixels_2_8, 9, 12, 0 , dst, dststride, src, srcstride, width, height
  67.                   mov          r6,0                        ; height
  68. mc_pixels_2_h:        ; for height
  69.                   mov          r7, 0                       ; width
  70.  
  71. mc_pixels_2_w:        ; for width
  72.                   mov          r9,0
  73.                   mov          r9b,[srcq+r7]               ; get byte
  74.                   shl          r9,6                        ; shift
  75.                   mov          [dstq+2*r7],r9w             ; store
  76.                   inc          r7
  77.                   cmp          r7, widthq                  ; cmp width
  78.                   jl           mc_pixels_2_w               ; width loop
  79.                   lea          dstq,[dstq+2*dststrideq]    ; dst += dststride
  80.                   lea          srcq,[srcq+srcstrideq]      ; src += srcstride
  81.                   add          r6,1
  82.                   cmp          r6,heightq                  ; cmp height
  83.                   jl           mc_pixels_2_h               ; height loop
  84.                   RET
  85. ; 4 by 4
  86. cglobal put_hevc_mc_pixels_4_8, 9, 12, 0 , dst, dststride, src, srcstride,width,height
  87.                   pxor         m0,m0                       ; set register at zero
  88.                   mov          r6,0                        ; height
  89.                   mov          r9,0
  90.  
  91.         ; 8 by 8
  92. mc_pixels_4_h:        ; for height
  93.                   mov          r7,0                        ; width
  94.  
  95. mc_pixels_4_w:        ; for width
  96.                   pxor         m1,m1
  97.                   movq         m1,[srcq+r7]                ; load 64 bits
  98.                   punpcklbw    m2,m1,m0                    ; unpack to 16 bits
  99.                   psllw        m2,6                        ; shift left 6 bits (14 - bit depth) each 16bit element
  100.                   movq         [dstq+2*r7],m2              ; store 64 bits
  101.                   add          r7,4                        ; add 4 for width loop
  102.                   cmp          r7, widthq                  ; cmp width
  103.                   jl           mc_pixels_4_w               ; width loop
  104.                   lea          dstq,[dstq+2*dststrideq]    ; dst += dststride
  105.                   lea          srcq,[srcq+srcstrideq]      ; src += srcstride
  106.                   add          r6,1
  107.                   cmp          r6,heightq                  ; cmp height
  108.                   jl           mc_pixels_4_h               ; height loop
  109.                   RET
  110.  
  111. ; 8 by 8
  112. cglobal put_hevc_mc_pixels_8_8, 9, 12, 0 , dst, dststride, src, srcstride,width,height
  113.                   pxor         m0,m0                       ; set register at zero
  114.                   mov          r6,0                        ; height
  115.                   mov          r9,0
  116.  
  117.         ; 8 by 8
  118. mc_pixels_8_h:        ; for height
  119.                   mov          r7,0                        ; width
  120.  
  121. mc_pixels_8_w:        ; for width
  122.  
  123.                   pxor         m1,m1
  124.                   movq         m1,[srcq+r7]                ; load 64 bits
  125.                   punpcklbw    m2,m1,m0                    ; unpack to 16 bits
  126.                   psllw        m2,6                        ; shift left 6 bits (14 - bit depth) each 16bit element
  127.                   movdqu       [dstq+2*r7],m2              ; store 128 bits
  128.                   add          r7,8                        ; add 8 for width loop
  129.                   cmp          r7, r4                      ; cmp width
  130.                   cmp          r7, widthq                  ; cmp width
  131.                   jl           mc_pixels_8_w               ; width loop
  132.                   lea          dstq,[dstq+2*dststrideq]    ; dst += dststride
  133.                   lea          srcq,[srcq+srcstrideq]      ; src += srcstride
  134.                   add          r6,1
  135.                   cmp          r6,heightq                  ; cmp height
  136.                   jl           mc_pixels_8_h               ; height loop
  137.                   RET
  138.  
  139. ; 16 by 16
  140. cglobal put_hevc_mc_pixels_16_8, 9, 12, 0 , dst, dststride, src, srcstride,width,height
  141.                   pxor         m0,m0                   ; set register at zero
  142.                   mov          r6,0                        ; height
  143.                   mov          r9,0
  144.  
  145.         ; 8 by 8
  146. mc_pixels_16_h:        ; for height
  147.                   mov          r7,0                        ; width
  148.  
  149. mc_pixels_16_w:        ; for width
  150.  
  151.                   pxor         m1,m1
  152.                   movdqu       m1,[srcq+r7]                ; load 128 bits
  153.                   punpcklbw    m2,m1,m0                    ; unpack low to 16 bits
  154.                   punpckhbw    m3,m1,m0                    ; unpack high to 16 bits
  155.                   psllw        m2,6                        ; shift left 6 bits (14 - bit depth) each 16bit element
  156.                   psllw        m3,6                        ; shift left 6 bits (14 - bit depth) each 16bit element
  157.                   movdqu       [dstq+2*r7],m2              ; store 128 bits
  158.                   movdqu       [dstq+2*r7+16],m3           ; store 128 bits
  159.                   add          r7,16                       ; add 16 for width loop
  160.                   cmp          r7, widthq                  ; cmp width
  161.                   jl           mc_pixels_16_w              ; width loop
  162.                   lea          dstq,[dstq+2*dststrideq]    ; dst += dststride
  163.                   lea          srcq,[srcq+srcstrideq]      ; src += srcstride
  164.                   add          r6,1
  165.                   cmp          r6,heightq                  ; cmp height
  166.                   jl           mc_pixels_16_h              ; height loop
  167.                   RET
  168.  
  169. ;function to call other mc_pixels functions according to width value
  170. cglobal put_hevc_mc_pixels_master_8, 9, 12, 0 , dst, dststride, src, srcstride,width,height
  171. cmp  r4,8
  172. je  goto_mc_pixels_8_8
  173. cmp  r4,16
  174. je  goto_mc_pixels_16_8
  175. cmp  r4,4
  176. je  goto_mc_pixels_4_8
  177. cmp  r4,32
  178. je  goto_mc_pixels_16_8
  179. cmp  r4,12
  180. je  goto_mc_pixels_4_8
  181. cmp  r4,24
  182. je  goto_mc_pixels_8_8
  183. cmp  r4,6
  184. je  goto_mc_pixels_2_8
  185. cmp  r4,64
  186. je  goto_mc_pixels_16_8
  187. cmp  r4,2
  188. je  goto_mc_pixels_2_8
  189.  
  190. jmp  goto_mc_pixels_2_8
  191.  
  192. goto_mc_pixels_2_8:
  193. call put_hevc_mc_pixels_2_8
  194. RET
  195.  
  196. goto_mc_pixels_4_8:
  197. call put_hevc_mc_pixels_4_8
  198. RET
  199.  
  200. goto_mc_pixels_8_8:
  201. call put_hevc_mc_pixels_8_8
  202. RET
  203.  
  204. goto_mc_pixels_16_8:
  205. call put_hevc_mc_pixels_16_8
  206. RET
  207.  
  208.  
  209.  
  210. ; ******************************
  211. ; void put_hevc_epel_h_8(int16_t *dst, ptrdiff_t dststride,
  212. ;                                       uint8_t *_src, ptrdiff_t _srcstride,
  213. ;                                       int width, int height, int mx, int my,
  214. ;                                       int16_t* mcbuffer)
  215. ;
  216. ;        r0 : *dst
  217. ;        r1 : dststride
  218. ;        r2 : *src
  219. ;        r3 : srcstride
  220. ;        r4 : width
  221. ;        r5 : height
  222. ;
  223. ; ******************************
  224.  
  225. ;8 by 8
  226. cglobal put_hevc_epel_h_8_8, 7, 12+ npicregs, 0 , dst, dststride, src, srcstride,width,height,mx,my,picreg
  227.  
  228. %ifdef PIC
  229.     lea  picregq, [epel_h_shuffle2_m]
  230. %endif
  231.     movdqu  m4,[epel_h_shuffle2]
  232. epel_h_8_h:
  233.     mov r8,0                            ; width counter
  234. epel_h_8_w:
  235.     movdqu   m2,[srcq+r8-1]             ; load data from source
  236.     pshufb  m5,m4,m0                    ; shuffle2
  237.     pshufb  m2,m2,m0                    ; shuffle
  238.     pmaddubsw   m2,m1                   ; maddubs (see SSE instruction set for details)
  239.     pmaddubsw   m5,m1                   ; maddubs (see SSE instruction set for details)
  240.     phaddw  m2,m5                       ; horizontal add
  241.     movdqu    [dstq+2*r8],m2              ; store data to dst
  242.     add     r8,4
  243.     cmp     r8,widthq                   ;
  244.     jl      epel_h_4_w
  245.     lea     dstq,[dstq+2*dststrideq]    ; dst += dststride
  246.     lea     srcq,[srcq+srcstrideq]      ; src += srcstride
  247.     add     r9,1
  248.     cmp     r9,heightq                  ; cmp height
  249.     jl      epel_h_4_h                  ; height loop
  250.  
  251. RET
  252.  
  253. ;4 by 4
  254. cglobal put_hevc_epel_h_4_8, 9, 12, 0 , dst, dststride, src, srcstride,width,height,mx,my
  255.  
  256. epel_h_4_h:
  257.     mov r8,0                            ; width counter
  258. epel_h_4_w:
  259.     movdqu   m2,[srcq+r8-1]             ; load data from source
  260.     pshufb  m2,m2,m0                    ; shuffle
  261.     pmaddubsw   m2,m1                   ; maddubs (see SSE instruction set for details)
  262.     phaddw  m2,m3                       ; horizontal add
  263.     movq    [dstq+2*r8],m2              ; store data to dst
  264.     add     r8,4
  265.     cmp     r8,widthq                   ;
  266.     jl      epel_h_8_w
  267.     lea     dstq,[dstq+2*dststrideq]    ; dst += dststride
  268.     lea     srcq,[srcq+srcstrideq]      ; src += srcstride
  269.     add     r9,1
  270.     cmp     r9,heightq                  ; cmp height
  271.     jl      epel_h_8_h                  ; height loop
  272.  
  273. RET
  274.  
  275. cglobal put_hevc_epel_h_master_8, 9, 12, 0 , dst, dststride, src, srcstride,width,height,mx,my,picreg
  276.  
  277. %ifdef PIC
  278.     lea  picregq, [epel_h_shuffle1_m]
  279. %endif
  280.  
  281.     movsxd   mxq,mxd                    ; extend sign
  282.     pxor     m3,m3                      ; set zero
  283.  
  284.     lea     r10,[hevc_epel_filters]
  285.     sub     mxq,1
  286.     shl     mxq,4                       ; multiply by 16
  287.     movq    m0,[r10+mxq]                ; get 4 first values of filters
  288.     pshufd  m1,m0,0                     ; cast 32 bit on all register.
  289.     movdqu   m0,[epel_h_shuffle1]       ; register containing shuffle
  290.     mov     r9,0                        ; height counter
  291.  
  292. cmp     widthq,2
  293. je      goto_epel_h_4_8
  294. cmp     widthq,4
  295. je      goto_epel_h_4_8
  296. cmp     widthq,6
  297. je      goto_epel_h_4_8
  298. cmp     widthq,8
  299. je      goto_epel_h_8_8
  300. cmp     widthq,12
  301. je      goto_epel_h_4_8
  302. cmp     widthq,16
  303. je      goto_epel_h_8_8
  304. cmp     widthq,24
  305. je      goto_epel_h_8_8
  306. cmp     widthq,32
  307. je      goto_epel_h_8_8
  308. cmp     widthq,64
  309. je      goto_epel_h_8_8
  310.  
  311. jmp     goto_epel_h_4_8
  312.  
  313. RET
  314. goto_epel_h_4_8:
  315. call put_hevc_epel_h_4_8
  316. RET
  317.  
  318. goto_epel_h_8_8:
  319. call put_hevc_epel_h_8_8
  320. RET
  321.  
  322. ;TODO : epel_h_2
  323.  
  324. ; ******************************
  325. ; void put_hevc_epel_v_8(int16_t *dst, ptrdiff_t dststride,
  326. ;                                       uint8_t *_src, ptrdiff_t _srcstride,
  327. ;                                       int width, int height, int mx, int my,
  328. ;                                       int16_t* mcbuffer)
  329. ;
  330. ;        r0 : *dst
  331. ;        r1 : dststride
  332. ;        r2 : *src
  333. ;        r3 : srcstride
  334. ;        r4 : width
  335. ;        r5 : height
  336. ;
  337. ; ******************************
  338.  
  339. cglobal put_hevc_epel_v_16_8, 8, 12, 0 , dst, dststride, src, srcstride, width, height, mx, my
  340. ;filters and initialization is done in master
  341. epel_v_16_h:
  342.     mov r9,0                                ;set width counter
  343. epel_v_16_v:
  344.     lea  r10,[srcq+r9]
  345.     mov  r11,r10
  346.     sub  r11,srcstrideq
  347.     movdqu m5,[r11]           ;load 64bit of x-stride
  348.     movdqu m6,[r10]                       ;load 64bit of x
  349.     movdqu m7,[r10+srcstrideq]            ;load 64bit of x+stride
  350.     movdqu m8,[r10+2*srcstrideq]          ;load 64bit of x+2*stride
  351.  
  352.     punpckhbw m9,m5,m0                         ;unpack 8bit to 16bit
  353.     punpckhbw m10,m6,m0                         ;unpack 8bit to 16bit
  354.     punpckhbw m11,m7,m0                         ;unpack 8bit to 16bit
  355.     punpckhbw m12,m8,m0                         ;unpack 8bit to 16bit
  356.  
  357.     punpcklbw m5,m0                         ;unpack 8bit to 16bit
  358.     punpcklbw m6,m0                         ;unpack 8bit to 16bit
  359.     punpcklbw m7,m0                         ;unpack 8bit to 16bit
  360.     punpcklbw m8,m0                         ;unpack 8bit to 16bit
  361.  
  362.  
  363.     pmullw  m9,m1                           ;multiply values with filter
  364.     pmullw  m10,m2
  365.     pmullw  m11,m3
  366.     pmullw  m12,m4
  367.  
  368.     pmullw  m5,m1                           ;multiply values with filter
  369.     pmullw  m6,m2
  370.     pmullw  m7,m3
  371.     pmullw  m8,m4
  372.  
  373.     paddsw  m9,m10                           ;add the different values
  374.     paddsw  m11,m12
  375.     paddsw  m9,m11
  376.  
  377.     paddsw  m5,m6                           ;add the different values
  378.     paddsw  m7,m8
  379.     paddsw  m5,m7
  380.  
  381.     movdqu    [dstq+2*r9],m5              ;store 128bit to dst
  382.     movdqu    [dstq+2*r9+16],m9           ;store 128bit to dst
  383.  
  384.     add     r9,16                        ; add 16 for width loop
  385.     cmp     r9, widthq                  ; cmp width
  386.     jl      epel_v_16_v                  ; width loop
  387.     lea     dstq,[dstq+2*dststrideq]    ; dst += dststride
  388.     lea     srcq,[srcq+srcstrideq]      ; src += srcstride
  389.     add     r8,1
  390.     cmp     r8,heightq                  ; cmp height
  391.     jl      epel_v_16_h                  ; height loop
  392.  
  393. RET
  394.  
  395.  
  396. cglobal put_hevc_epel_v_8_8, 8, 12, 0 , dst, dststride, src, srcstride,width,height,mx,my
  397. ;filters and initialization is done in master
  398. epel_v_8_h:
  399.     mov r9,0                                ;set width counter
  400. epel_v_8_v:
  401.     lea  r10,[srcq+r9]
  402.     mov  r11,r10
  403.     sub  r11,srcstrideq
  404.     movq m5,[r11]           ;load 64bit of x-stride
  405.     movq m6,[r10]                       ;load 64bit of x
  406.     movq m7,[r10+srcstrideq]            ;load 64bit of x+stride
  407.     movq m8,[r10+2*srcstrideq]          ;load 64bit of x+2*stride
  408.  
  409.     punpcklbw m5,m0                         ;unpack 8bit to 16bit
  410.     punpcklbw m6,m0                         ;unpack 8bit to 16bit
  411.     punpcklbw m7,m0                         ;unpack 8bit to 16bit
  412.     punpcklbw m8,m0                         ;unpack 8bit to 16bit
  413.  
  414.     pmullw  m5,m1                           ;multiply values with filter
  415.     pmullw  m6,m2
  416.     pmullw  m7,m3
  417.     pmullw  m8,m4
  418.  
  419.     paddsw  m5,m6                           ;add the different values
  420.     paddsw  m7,m8
  421.     paddsw  m5,m7
  422.  
  423.     movdqu    [dstq+2*r9],m5              ;store 64bit to dst
  424.     add     r9,8                        ; add 4 for width loop
  425.     cmp     r9, widthq                  ; cmp width
  426.     jl      epel_v_8_v                  ; width loop
  427.     lea     dstq,[dstq+2*dststrideq]    ; dst += dststride
  428.     lea     srcq,[srcq+srcstrideq]      ; src += srcstride
  429.     add     r8,1
  430.     cmp     r8,heightq                  ; cmp height
  431.     jl      epel_v_8_h                  ; height loop
  432.  
  433. RET
  434.  
  435. cglobal put_hevc_epel_v_4_8, 8, 12, 0, dst, dststride, src, srcstride, width, height, mx, my
  436.  
  437. epel_v_4_h:
  438.     mov r9,0                             ;set width counter
  439. epel_v_4_v:
  440.     lea     r10,[srcq+r9]
  441.     mov     r11,r10
  442.     sub     r11,srcstrideq
  443.     movq m5,[r11]                        ;load 64bit of x-stride
  444.     movq m6,[r10]                        ;load 64bit of x
  445.     movq m7,[r10+srcstrideq]             ;load 64bit of x+stride
  446.     movq m8,[r10+2*srcstrideq]           ;load 64bit of x+2*stride
  447.  
  448.     punpcklbw m5,m0                      ;unpack 8bit to 16bit
  449.     punpcklbw m6,m0                      ;unpack 8bit to 16bit
  450.     punpcklbw m7,m0                      ;unpack 8bit to 16bit
  451.     punpcklbw m8,m0                      ;unpack 8bit to 16bit
  452.  
  453.     pmullw    m5,m1                      ;multiply values with filter
  454.     pmullw    m6,m2
  455.     pmullw    m7,m3
  456.     pmullw    m8,m4
  457.  
  458.     paddsw    m5,m6                      ;add the different values
  459.     paddsw    m7,m8
  460.     paddsw    m5,m7
  461.  
  462.     movq    [dstq+2*r9],m5               ;store 64bit to dst
  463.     add     r9,4                         ; add 4 for width loop
  464.     cmp     r9, widthq                   ; cmp width
  465.     jl      epel_v_4_v                   ; width loop
  466.     lea     dstq,[dstq+2*dststrideq]     ; dst += dststride
  467.     lea     srcq,[srcq+srcstrideq]       ; src += srcstride
  468.     add     r8,1
  469.     cmp     r8,heightq                   ; cmp height
  470.     jl      epel_v_4_h                   ; height loop
  471.  
  472. RET
  473.  
  474. ;function to call other epel_v functions according to width value
  475. cglobal put_hevc_epel_v_master_8, 8, 12, 0 , dst, dststride, src, srcstride,width,height,mx,my
  476.  
  477.     pxor    m1,m1                               ;set zero
  478.     movsxd   myq,myd                           ;extend sign
  479.     sub    myq,1                                ;my-1
  480.     shl    myq,4                                ;multiply by 16
  481.     lea     r10,[hevc_epel_filters]
  482.     movq    m0,[r10+myq]                ;filters
  483.  
  484.     punpcklbw   m1,m0                   ;unpack to 16 bit
  485.     psraw       m1,8                    ;shift for bit-sign
  486.     punpcklwd   m1,m1                   ;put double values to 32bit.
  487.     psrldq      m2,m1,4                 ;filter 1
  488.     psrldq      m3,m1,8                 ;filter 2
  489.     psrldq      m4,m1,12                ;filter 3
  490.     pshufd      m1,m1,0                 ;extend 32bit to whole register
  491.     pshufd      m2,m2,0
  492.     pshufd      m3,m3,0
  493.     pshufd      m4,m4,0
  494.  
  495.     pxor m0,m0                          ;set zero
  496.  
  497.     mov r8,0                                ;set height counter
  498.  
  499.  
  500. cmp  r4,8
  501. je  goto_epel_v_8_8
  502. cmp  r4,16
  503. je  goto_epel_v_16_8
  504. cmp  r4,4
  505. je  goto_epel_v_4_8
  506. cmp  r4,32
  507. je  goto_epel_v_16_8
  508. cmp  r4,12
  509. je  goto_epel_v_4_8
  510. cmp  r4,24
  511. je  goto_epel_v_8_8
  512. cmp  r4,6
  513. je  goto_epel_v_2_8
  514. cmp  r4,64
  515. je  goto_epel_v_16_8
  516. cmp  r4,2
  517. je  goto_epel_v_2_8
  518.  
  519. jmp  goto_epel_v_2_8
  520. RET
  521.  
  522. goto_epel_v_4_8:
  523. call put_hevc_epel_v_4_8
  524. RET
  525.  
  526. goto_epel_v_8_8:
  527. call put_hevc_epel_v_8_8
  528. RET
  529.  
  530. goto_epel_v_16_8:
  531. call put_hevc_epel_v_16_8
  532. RET
  533.  
  534. goto_epel_v_2_8:
  535. call put_hevc_epel_v_4_8
  536. RET
  537.  
  538. ;TODO : put_hevc_epel_v_2_8.
  539.  
  540.  
  541. ; ******************************
  542. ; void put_hevc_epel_hv_8(int16_t *dst, ptrdiff_t dststride,
  543. ;                                       uint8_t *_src, ptrdiff_t _srcstride,
  544. ;                                       int width, int height, int mx, int my,
  545. ;                                       int16_t* mcbuffer)
  546. ;
  547. ;        r0 : *dst
  548. ;        r1 : dststride
  549. ;        r2 : *src
  550. ;        r3 : srcstride
  551. ;        r4 : width
  552. ;        r5 : height
  553. ;        r6 : mx
  554. ;        r7 : my
  555. ;        r8 : mcbuffer
  556. ;
  557. ; ******************************
  558.  
  559. cglobal put_hevc_epel_hv_4_8, 9, 12, 0 , dst, dststride, src, srcstride, width, height, mx, my, mcbuffer,picreg
  560. %ifdef PIC
  561.     lea  picregq, [epel_h_shuffle1_m]
  562. %endif
  563.  
  564.     movsxd   mxq,mxd                    ; extend sign
  565.     movsxd   myq,myd                    ; extend sign
  566.     movsxd   srcstrideq,srcstrided      ; extend sign
  567.     movsxd   dststrideq,dststrided      ; extend sign
  568.     movsxd   widthq,widthd              ; extend sign
  569.     movsxd   heightq,heightd            ; extend sign
  570.  
  571.     pxor     m3,m3                      ; set zero
  572.  
  573.     lea     r10,[hevc_epel_filters]
  574.     sub     mxq,1
  575.     shl     mxq,4                       ; multiply by 16
  576.     movq    m0,[r10+mxq]                ; get 4 first values of filters
  577.     pshufd  m1,m0,0                     ; cast 32 bit on all register.
  578.     movdqu  m0,[epel_h_shuffle1]        ; register containing shuffle1
  579.  
  580.     mov     r15, srcstrideq
  581.     imul    r15, epel_extra_before
  582. ;    sub     srcq,srcstrideq                    ; src -= EPEL_EXTRA_BEFORE * srcstride
  583.     mov     r14,max_pb_size
  584.     shl     r14,2                       ;double because it's used for 16bit adressing
  585.     lea     r13,[mcbufferq]
  586.  
  587.     mov     r9,0                        ; height counter
  588.  
  589. epel_hv_4_h_h:
  590.     xor r10,r10                            ; width counter
  591. epel_hv_4_h_w:
  592.     movdqu   m2,[srcq+r10]            ; load data from source
  593.     pshufb  m2,m2,m0                    ; shuffle
  594.     pmaddubsw   m2,m1                   ; maddubs (see SSE instruction set for details)
  595.     phaddw  m2,m3                       ; horizontal add
  596.    movq    [r13+2*r10],m2            ; store data to dst
  597.     add     r10,4
  598.     cmp     r10,widthq                  ;
  599.     jl      epel_hv_4_h_w
  600.     lea     dstq,[r13+r14]              ; dst += dststride
  601.     lea     srcq,[srcq+srcstrideq]      ; src += srcstride
  602.     add     r9,1
  603.     cmp     r9,heightq                  ; cmp height
  604.     jl      epel_hv_4_h_h                  ; height loop
  605.  
  606. ;end H treatment
  607. ;    imul    r14,r15;
  608.     add     mcbufferq,r14               ; mcbuffer+= EPEL_EXTRA_BEFORE * MAX_PB_SIZE
  609.  
  610.  
  611.     pxor    m1,m1                               ;set zero
  612.     movsxd   myq,myd                           ;extend sign
  613.     sub    myq,1                                ;my-1
  614.     shl    myq,4                                ;multiply by 16
  615.     lea     r10,[hevc_epel_filters]
  616.     movq    m0,[r10+myq]                ;filters
  617.  
  618.     punpcklbw   m1,m0                   ;unpack to 16 bit
  619.     psraw       m1,8                    ;shift for bit-sign
  620.     punpcklwd   m1,m1                   ;put double values to 32bit.
  621.     psrldq      m2,m1,4                 ;filter 1
  622.     psrldq      m3,m1,8                 ;filter 2
  623.     psrldq      m4,m1,12                ;filter 3
  624.     pshufd      m1,m1,0                 ;extend 32bit to whole register
  625.     pshufd      m2,m2,0
  626.     pshufd      m3,m3,0
  627.     pshufd      m4,m4,0
  628.  
  629.     pxor m0,m0                          ;set zero
  630.     mov r8,0                            ;set height counter
  631.  
  632. epel_hv_4_v_h:
  633.     mov r9,0                            ;set width counter
  634. epel_hv_4_v_w:
  635.     lea  r10,[mcbufferq+r9]
  636.     mov  r11,r10
  637.     sub  r11,srcstrideq
  638. ;    movq m5,[r11]                       ;load 64bit of x-stride
  639. ;    movq m6,[r10]                       ;load 64bit of x
  640. ;    movq m7,[r10+srcstrideq]            ;load 64bit of x+stride
  641. ;    movq m8,[r10+2*srcstrideq]          ;load 64bit of x+2*stride
  642.  
  643.  
  644.     punpcklbw   m5,m0                   ;unpack to 16 bit
  645.     psraw       m5,16                   ;shift for bit-sign
  646.     punpcklbw   m6,m0                   ;unpack to 16 bit
  647.     psraw       m6,16                   ;shift for bit-sign
  648.     punpcklbw   m7,m0                   ;unpack to 16 bit
  649.     psraw       m7,16                   ;shift for bit-sign
  650.     punpcklbw   m8,m0                   ;unpack to 16 bit
  651.     psraw       m8,16                   ;shift for bit-sign
  652.  
  653.  
  654.     pmulld    m5,m1                      ;multiply values with filter - SSE4.2 function
  655.     pmulld    m6,m2
  656.     pmulld    m7,m3
  657.     pmulld    m8,m4
  658.  
  659.     paddd    m5,m6                      ;add the different values
  660.     paddd    m7,m8
  661.     paddd    m5,m7
  662.  
  663.     psrld   m5,2                        ; >> BIT_DEPTH-2
  664.     packssdw    m5,m0                   ;back to 16bit
  665.     pxor    m5,m5
  666.  
  667. ;    movdqu    [dstq+2*r9],m5              ;store 128bit to dst
  668.     add     r9,4                        ; add 4 for width loop
  669.     cmp     r9, widthq                  ; cmp width
  670.     jl      epel_hv_4_v_w                  ; width loop
  671.     lea     dstq,[dstq+2*dststrideq]    ; dst += dststride
  672.     lea     srcq,[mcbufferq+r15]      ; src += srcstride
  673.     add     r8,1
  674.     cmp     r8,heightq                  ; cmp height
  675.     jl      epel_hv_4_v_h                  ; height loop
  676.  
  677. RET
  678.  
  679. %endif ; ARCH_X86_64
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement