]> git.sesse.net Git - x264/blob - common/x86/bitstream-a.asm
Optimize x86 intra_sa8d_x3_8x8
[x264] / common / x86 / bitstream-a.asm
1 ;*****************************************************************************
2 ;* bitstream-a.asm: x86 bitstream functions
3 ;*****************************************************************************
4 ;* Copyright (C) 2010-2011 x264 project
5 ;*
6 ;* Authors: Fiona Glaser <fiona@x264.com>
7 ;*          Henrik Gramner <hengar-6@student.ltu.se>
8 ;*
9 ;* This program is free software; you can redistribute it and/or modify
10 ;* it under the terms of the GNU General Public License as published by
11 ;* the Free Software Foundation; either version 2 of the License, or
12 ;* (at your option) any later version.
13 ;*
14 ;* This program is distributed in the hope that it will be useful,
15 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;* GNU General Public License for more details.
18 ;*
19 ;* You should have received a copy of the GNU General Public License
20 ;* along with this program; if not, write to the Free Software
21 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
22 ;*
23 ;* This program is also available under a commercial proprietary license.
24 ;* For more information, contact us at licensing@x264.com.
25 ;*****************************************************************************
26
27 %include "x86inc.asm"
28 %include "x86util.asm"
29
30 SECTION .text
31
32 ;-----------------------------------------------------------------------------
33 ; uint8_t *x264_nal_escape( uint8_t *dst, uint8_t *src, uint8_t *end )
34 ;-----------------------------------------------------------------------------
35
36 %macro NAL_LOOP 2
37 %1_escape:
38     ; Detect false positive to avoid unneccessary escape loop
39     xor      r3d, r3d
40     cmp byte [r0+r1-1], 0
41     setnz    r3b
42     xor      r3d, r4d
43     jnz .escape
44     jmp %1_continue
45 ALIGN 16
46 %1:
47     pcmpeqb   m3, m1, m4
48     pcmpeqb   m2, m0, m4
49     pmovmskb r3d, m3
50     %2   [r0+r1], m0
51     pmovmskb r4d, m2
52     shl      r3d, mmsize
53     mova      m0, [r1+r2+2*mmsize]
54     or       r4d, r3d
55     %2 [r0+r1+mmsize], m1
56     lea      r3d, [r4+r4+1]
57     mova      m1, [r1+r2+3*mmsize]
58     and      r4d, r3d
59     jnz %1_escape
60 %1_continue:
61     add       r1, 2*mmsize
62     jl %1
63 %endmacro
64
65 %macro NAL_ESCAPE 0
66
67 cglobal nal_escape, 3,5
68     mov      r3w, [r1]
69     sub       r1, r2 ; r1 = offset of current src pointer from end of src
70     pxor      m4, m4
71     sub       r0, r1 ; r0 = projected end of dst, assuming no more escapes
72     mov  [r0+r1], r3w
73     add       r1, 2
74     jge .ret
75
76     ; Start off by jumping into the escape loop in
77     ; case there's an escape at the start.
78     ; And do a few more in scalar until src is aligned again.
79     jmp .first_escape
80
81     NAL_LOOP .loop_aligned, mova
82 %if mmsize==16
83     jmp .ret
84     NAL_LOOP .loop_unaligned, movu
85 %endif
86 .ret:
87     movifnidn rax, r0
88     RET
89
90 ALIGN 16
91 .escape:
92     ; Skip bytes that are known to be valid
93     and      r4d, r3d
94     bsf      r3d, r4d
95     add       r1, r3
96 .escape_loop:
97     inc       r1
98     jge .ret
99 .first_escape:
100     movzx    r3d, byte [r1+r2]
101     lea       r4, [r1+r2]
102     cmp      r3d, 3
103     jna .escape_check
104 .no_escape:
105     mov  [r0+r1], r3b
106     test     r4d, mmsize-1 ; Do SIMD when src is aligned
107     jnz .escape_loop
108     mova      m0, [r4]
109     mova      m1, [r4+mmsize]
110 %if mmsize==16
111     lea      r4d, [r0+r1]
112     test     r4d, mmsize-1
113     jnz .loop_unaligned
114 %endif
115     jmp .loop_aligned
116
117 ALIGN 16
118 .escape_check:
119     cmp word [r0+r1-2], 0
120     jnz .no_escape
121     mov byte [r0+r1], 3
122     inc      r0
123     jmp .no_escape
124 %endmacro
125
126 INIT_MMX mmx2
127 NAL_ESCAPE
128 INIT_XMM sse2
129 NAL_ESCAPE
130 INIT_XMM avx
131 NAL_ESCAPE