]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/v210enc.asm
Merge commit 'd555bd69e792e42d94bd909b30d9bfef01db4e25'
[ffmpeg] / libavcodec / x86 / v210enc.asm
1 ;******************************************************************************
2 ;* V210 SIMD pack
3 ;* Copyright (c) 2014 Kieran Kunhya <kierank@obe.tv>
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
22 %include "libavutil/x86/x86util.asm"
23
24 SECTION_RODATA
25
26 cextern pw_4
27 %define v210_enc_min_10 pw_4
28 v210_enc_max_10: times 8 dw 0x3fb
29
30 v210_enc_luma_mult_10: dw 4,1,16,4,1,16,0,0
31 v210_enc_luma_shuf_10: db -1,0,1,-1,2,3,4,5,-1,6,7,-1,8,9,10,11
32
33 v210_enc_chroma_mult_10: dw 1,4,16,0,16,1,4,0
34 v210_enc_chroma_shuf_10: db 0,1,8,9,-1,2,3,-1,10,11,4,5,-1,12,13,-1
35
36 cextern pb_1
37 %define v210_enc_min_8 pb_1
38 cextern pb_FE
39 %define v210_enc_max_8 pb_FE
40
41 v210_enc_luma_shuf_8: db 6,-1,7,-1,8,-1,9,-1,10,-1,11,-1,-1,-1,-1,-1
42 v210_enc_luma_mult_8: dw 16,4,64,16,4,64,0,0
43
44 v210_enc_chroma_shuf1_8: db 0,-1,1,-1,2,-1,3,-1,8,-1,9,-1,10,-1,11,-1
45 v210_enc_chroma_shuf2_8: db 3,-1,4,-1,5,-1,7,-1,11,-1,12,-1,13,-1,15,-1
46
47 v210_enc_chroma_mult_8: dw 4,16,64,0,64,4,16,0
48
49 SECTION .text
50
51 %macro v210_planar_pack_10 0
52
53 ; v210_planar_pack_10(const uint16_t *y, const uint16_t *u, const uint16_t *v, uint8_t *dst, ptrdiff_t width)
54 cglobal v210_planar_pack_10, 5, 5, 4, y, u, v, dst, width
55     lea     r0, [yq+2*widthq]
56     add     uq, widthq
57     add     vq, widthq
58     neg     widthq
59
60     mova    m2, [v210_enc_min_10]
61     mova    m3, [v210_enc_max_10]
62
63 .loop:
64     movu    m0, [yq+2*widthq]
65     CLIPW   m0, m2, m3
66
67     movq    m1, [uq+widthq]
68     movhps  m1, [vq+widthq]
69     CLIPW   m1, m2, m3
70
71     pmullw  m0, [v210_enc_luma_mult_10]
72     pshufb  m0, [v210_enc_luma_shuf_10]
73
74     pmullw  m1, [v210_enc_chroma_mult_10]
75     pshufb  m1, [v210_enc_chroma_shuf_10]
76
77     por     m0, m1
78
79     movu    [dstq], m0
80
81     add     dstq, mmsize
82     add     widthq, 6
83     jl .loop
84
85     RET
86 %endmacro
87
88 INIT_XMM ssse3
89 v210_planar_pack_10
90
91 %macro v210_planar_pack_8 0
92
93 ; v210_planar_pack_8(const uint8_t *y, const uint8_t *u, const uint8_t *v, uint8_t *dst, ptrdiff_t width)
94 cglobal v210_planar_pack_8, 5, 5, 7, y, u, v, dst, width
95     add     yq, widthq
96     shr     widthq, 1
97     add     uq, widthq
98     add     vq, widthq
99     neg     widthq
100
101     mova    m4, [v210_enc_min_8]
102     mova    m5, [v210_enc_max_8]
103     pxor    m6, m6
104
105 .loop:
106     movu    m1, [yq+2*widthq]
107     CLIPUB  m1, m4, m5
108
109     punpcklbw m0, m1, m6
110     ; can't unpack high bytes in the same way because we process
111     ; only six bytes at a time
112     pshufb  m1, [v210_enc_luma_shuf_8]
113
114     pmullw  m0, [v210_enc_luma_mult_8]
115     pmullw  m1, [v210_enc_luma_mult_8]
116     pshufb  m0, [v210_enc_luma_shuf_10]
117     pshufb  m1, [v210_enc_luma_shuf_10]
118
119     movq    m3, [uq+widthq]
120     movhps  m3, [vq+widthq]
121     CLIPUB  m3, m4, m5
122
123     ; shuffle and multiply to get the same packing as in 10-bit
124     pshufb  m2, m3, [v210_enc_chroma_shuf1_8]
125     pshufb  m3, [v210_enc_chroma_shuf2_8]
126
127     pmullw  m2, [v210_enc_chroma_mult_8]
128     pmullw  m3, [v210_enc_chroma_mult_8]
129     pshufb  m2, [v210_enc_chroma_shuf_10]
130     pshufb  m3, [v210_enc_chroma_shuf_10]
131
132     por     m0, m2
133     por     m1, m3
134
135     movu    [dstq], m0
136     movu    [dstq+mmsize], m1
137
138     add     dstq, 2*mmsize
139     add     widthq, 6
140     jl .loop
141
142     RET
143 %endmacro
144
145 INIT_XMM ssse3
146 v210_planar_pack_8
147 INIT_XMM avx
148 v210_planar_pack_8