1 ;******************************************************************************
2 ;* x86 optimized dithering format conversion
3 ;* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
5 ;* This file is part of FFmpeg.
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.
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.
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 ;******************************************************************************
22 %include "libavutil/x86/x86util.asm"
26 ; 1.0f / (2.0f * INT32_MAX)
27 pf_dither_scale: times 8 dd 2.32830643762e-10
29 pf_s16_scale: times 4 dd 32753.0
33 ;------------------------------------------------------------------------------
34 ; void ff_quantize(int16_t *dst, float *src, float *dither, int len);
35 ;------------------------------------------------------------------------------
38 cglobal quantize, 4,4,3, dst, src, dither, len
41 lea srcq, [srcq+2*lenq]
42 lea ditherq, [ditherq+2*lenq]
44 mova m2, [pf_s16_scale]
46 mulps m0, m2, [srcq+2*lenq]
47 mulps m1, m2, [srcq+2*lenq+mmsize]
48 addps m0, [ditherq+2*lenq]
49 addps m1, [ditherq+2*lenq+mmsize]
58 ;------------------------------------------------------------------------------
59 ; void ff_dither_int_to_float_rectangular(float *dst, int *src, int len)
60 ;------------------------------------------------------------------------------
62 %macro DITHER_INT_TO_FLOAT_RECTANGULAR 0
63 cglobal dither_int_to_float_rectangular, 3,3,3, dst, src, len
68 mova m0, [pf_dither_scale]
70 cvtdq2ps m1, [srcq+lenq]
71 cvtdq2ps m2, [srcq+lenq+mmsize]
75 mova [dstq+lenq+mmsize], m2
82 DITHER_INT_TO_FLOAT_RECTANGULAR
84 DITHER_INT_TO_FLOAT_RECTANGULAR
86 ;------------------------------------------------------------------------------
87 ; void ff_dither_int_to_float_triangular(float *dst, int *src0, int len)
88 ;------------------------------------------------------------------------------
90 %macro DITHER_INT_TO_FLOAT_TRIANGULAR 0
91 cglobal dither_int_to_float_triangular, 3,4,5, dst, src0, len, src1
93 lea src1q, [src0q+2*lenq]
97 mova m0, [pf_dither_scale]
99 cvtdq2ps m1, [src0q+lenq]
100 cvtdq2ps m2, [src0q+lenq+mmsize]
101 cvtdq2ps m3, [src1q+lenq]
102 cvtdq2ps m4, [src1q+lenq+mmsize]
108 mova [dstq+lenq+mmsize], m2
115 DITHER_INT_TO_FLOAT_TRIANGULAR
117 DITHER_INT_TO_FLOAT_TRIANGULAR