1 /*****************************************************************************
2 * mc.h: h264 encoder library
3 *****************************************************************************
4 * Copyright (C) 2008 x264 Project
6 * Authors: Fiona Glaser <fiona@x264.com>
7 * Loren Merritt <lorenm@u.washington.edu>
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.
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.
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 *****************************************************************************/
24 #ifndef X264_X86_UTIL_H
25 #define X264_X86_UTIL_H
30 #include <xmmintrin.h>
33 #define x264_median_mv x264_median_mv_mmxext
34 static ALWAYS_INLINE void x264_median_mv_mmxext( int16_t *dst, int16_t *a, int16_t *b, int16_t *c )
39 "movq %%mm0, %%mm3 \n"
41 "pmaxsw %%mm1, %%mm0 \n"
42 "pminsw %%mm3, %%mm1 \n"
43 "pminsw %%mm2, %%mm0 \n"
44 "pmaxsw %%mm1, %%mm0 \n"
46 :"=m"(*(x264_union32_t*)dst)
47 :"m"(M32( a )), "m"(M32( b )), "m"(M32( c ))
51 #define x264_predictor_difference x264_predictor_difference_mmxext
52 static ALWAYS_INLINE int x264_predictor_difference_mmxext( int16_t (*mvc)[2], intptr_t i_mvc )
55 static const uint64_t pw_1 = 0x0001000100010001ULL;
58 "pxor %%mm4, %%mm4 \n"
61 "movd -8(%2,%1,4), %%mm0 \n"
62 "movd -4(%2,%1,4), %%mm3 \n"
63 "psubw %%mm3, %%mm0 \n"
68 "movq -8(%2,%1,4), %%mm0 \n"
69 "psubw -4(%2,%1,4), %%mm0 \n"
72 "pxor %%mm2, %%mm2 \n"
73 "psubw %%mm0, %%mm2 \n"
74 "pmaxsw %%mm2, %%mm0 \n"
75 "paddusw %%mm0, %%mm4 \n"
77 "pmaddwd %4, %%mm4 \n"
78 "pshufw $14, %%mm4, %%mm0 \n"
79 "paddd %%mm0, %%mm4 \n"
81 :"=r"(sum), "+r"(i_mvc)
82 :"r"(mvc), "m"(M64( mvc )), "m"(pw_1)
87 #define x264_cabac_mvd_sum x264_cabac_mvd_sum_mmxext
88 static ALWAYS_INLINE uint16_t x264_cabac_mvd_sum_mmxext(uint8_t *mvdleft, uint8_t *mvdtop)
90 static const uint64_t pb_2 = 0x0202020202020202ULL;
91 static const uint64_t pb_32 = 0x2020202020202020ULL;
96 "paddb %%mm1, %%mm0 \n"
97 "pxor %%mm2, %%mm2 \n"
98 "movq %%mm0, %%mm1 \n"
99 "pcmpgtb %3, %%mm0 \n"
100 "pcmpgtb %4, %%mm1 \n"
101 "psubb %%mm0, %%mm2 \n"
102 "psubb %%mm1, %%mm2 \n"
105 :"m"(M16( mvdleft )),"m"(M16( mvdtop )),
111 #define x264_predictor_roundclip x264_predictor_roundclip_mmxext
112 static void ALWAYS_INLINE x264_predictor_roundclip_mmxext( int16_t (*dst)[2], int16_t (*mvc)[2], int i_mvc, int mv_x_min, int mv_x_max, int mv_y_min, int mv_y_max )
114 uint32_t mv_min = pack16to32_mask( mv_x_min, mv_y_min );
115 uint32_t mv_max = pack16to32_mask( mv_x_max, mv_y_max );
116 static const uint64_t pw_2 = 0x0002000200020002ULL;
122 "punpckldq %%mm5, %%mm5 \n"
123 "punpckldq %%mm6, %%mm6 \n"
126 "movd -4(%6,%0,4), %%mm0 \n"
127 "paddw %%mm7, %%mm0 \n"
129 "pmaxsw %%mm5, %%mm0 \n"
130 "pminsw %%mm6, %%mm0 \n"
131 "movd %%mm0, -4(%5,%0,4) \n"
135 "movq -8(%6,%0,4), %%mm0 \n"
136 "paddw %%mm7, %%mm0 \n"
138 "pmaxsw %%mm5, %%mm0 \n"
139 "pminsw %%mm6, %%mm0 \n"
140 "movq %%mm0, -8(%5,%0,4) \n"
144 :"+r"(i), "=m"(M64( dst ))
145 :"g"(mv_min), "g"(mv_max), "m"(pw_2), "r"(dst), "r"(mvc), "m"(M64( mvc ))
151 #define M128_ZERO ((__m128){0,0,0,0})
152 #define x264_union128_t x264_union128_sse_t
153 typedef union { __m128 i; uint64_t a[2]; uint32_t b[4]; uint16_t c[8]; uint8_t d[16]; } MAY_ALIAS x264_union128_sse_t;