| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * SIMD-optimized motion estimation | ||
| 3 | * Copyright (c) 2000, 2001 Fabrice Bellard | ||
| 4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
| 5 | * | ||
| 6 | * MMX optimization by Nick Kurshev <nickols_k@mail.ru> | ||
| 7 | * | ||
| 8 | * This file is part of FFmpeg. | ||
| 9 | * | ||
| 10 | * FFmpeg is free software; you can redistribute it and/or | ||
| 11 | * modify it under the terms of the GNU Lesser General Public | ||
| 12 | * License as published by the Free Software Foundation; either | ||
| 13 | * version 2.1 of the License, or (at your option) any later version. | ||
| 14 | * | ||
| 15 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 18 | * Lesser General Public License for more details. | ||
| 19 | * | ||
| 20 | * You should have received a copy of the GNU Lesser General Public | ||
| 21 | * License along with FFmpeg; if not, write to the Free Software | ||
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include "libavutil/attributes.h" | ||
| 26 | #include "libavutil/cpu.h" | ||
| 27 | #include "libavutil/x86/cpu.h" | ||
| 28 | #include "libavcodec/me_cmp.h" | ||
| 29 | #include "libavcodec/mpegvideoenc.h" | ||
| 30 | |||
| 31 | int ff_sum_abs_dctelem_sse2(const int16_t *block); | ||
| 32 | int ff_sum_abs_dctelem_ssse3(const int16_t *block); | ||
| 33 | int ff_sse8_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 34 | ptrdiff_t stride, int h); | ||
| 35 | int ff_sse16_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 36 | ptrdiff_t stride, int h); | ||
| 37 | int ff_hf_noise8_ssse3(const uint8_t *pix1, ptrdiff_t stride, int h); | ||
| 38 | int ff_hf_noise16_ssse3(const uint8_t *pix1, ptrdiff_t stride, int h); | ||
| 39 | int ff_sad8_mmxext(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 40 | ptrdiff_t stride, int h); | ||
| 41 | int ff_sad16_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 42 | ptrdiff_t stride, int h); | ||
| 43 | int ff_sad16u_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 44 | ptrdiff_t stride, int h); | ||
| 45 | int ff_sad8_x2_mmxext(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 46 | ptrdiff_t stride, int h); | ||
| 47 | int ff_sad16_x2_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 48 | ptrdiff_t stride, int h); | ||
| 49 | int ff_sad8_y2_mmxext(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 50 | ptrdiff_t stride, int h); | ||
| 51 | int ff_sad16_y2_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 52 | ptrdiff_t stride, int h); | ||
| 53 | int ff_sad8_approx_xy2_mmxext(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 54 | ptrdiff_t stride, int h); | ||
| 55 | int ff_sad8_xy2_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 56 | ptrdiff_t stride, int h); | ||
| 57 | int ff_sad16_approx_xy2_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 58 | ptrdiff_t stride, int h); | ||
| 59 | int ff_sad16_xy2_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 60 | ptrdiff_t stride, int h); | ||
| 61 | int ff_vsad_intra8_mmxext(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 62 | ptrdiff_t stride, int h); | ||
| 63 | int ff_vsad_intra16_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 64 | ptrdiff_t stride, int h); | ||
| 65 | int ff_vsad_intra16u_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 66 | ptrdiff_t stride, int h); | ||
| 67 | int ff_vsad8_approx_mmxext(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 68 | ptrdiff_t stride, int h); | ||
| 69 | int ff_vsad16_approx_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 70 | ptrdiff_t stride, int h); | ||
| 71 | int ff_vsad16u_approx_sse2(MPVEncContext *v, const uint8_t *pix1, const uint8_t *pix2, | ||
| 72 | ptrdiff_t stride, int h); | ||
| 73 | |||
| 74 | #define hadamard_func(cpu) \ | ||
| 75 | int ff_hadamard8_diff_ ## cpu(MPVEncContext *s, const uint8_t *src1, \ | ||
| 76 | const uint8_t *src2, ptrdiff_t stride, int h); \ | ||
| 77 | int ff_hadamard8_diff16_ ## cpu(MPVEncContext *s, const uint8_t *src1, \ | ||
| 78 | const uint8_t *src2, ptrdiff_t stride, int h); | ||
| 79 | |||
| 80 | hadamard_func(sse2) | ||
| 81 | hadamard_func(ssse3) | ||
| 82 | |||
| 83 | #if HAVE_X86ASM | ||
| 84 | 16 | static int nsse16_ssse3(MPVEncContext *c, const uint8_t *pix1, const uint8_t *pix2, | |
| 85 | ptrdiff_t stride, int h) | ||
| 86 | { | ||
| 87 | 16 | int score1 = ff_sse16_sse2(c, pix1, pix2, stride, h); | |
| 88 | 16 | int score2 = ff_hf_noise16_ssse3(pix1, stride, h) - | |
| 89 | 16 | ff_hf_noise16_ssse3(pix2, stride, h); | |
| 90 | |||
| 91 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (c) |
| 92 | ✗ | return score1 + FFABS(score2) * c->c.avctx->nsse_weight; | |
| 93 | else | ||
| 94 | 16 | return score1 + FFABS(score2) * 8; | |
| 95 | } | ||
| 96 | |||
| 97 | 16 | static int nsse8_ssse3(MPVEncContext *c, const uint8_t *pix1, const uint8_t *pix2, | |
| 98 | ptrdiff_t stride, int h) | ||
| 99 | { | ||
| 100 | 16 | int score1 = ff_sse8_sse2(c, pix1, pix2, stride, h); | |
| 101 | 16 | int score2 = ff_hf_noise8_ssse3(pix1, stride, h) - | |
| 102 | 16 | ff_hf_noise8_ssse3(pix2, stride, h); | |
| 103 | |||
| 104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (c) |
| 105 | ✗ | return score1 + FFABS(score2) * c->c.avctx->nsse_weight; | |
| 106 | else | ||
| 107 | 16 | return score1 + FFABS(score2) * 8; | |
| 108 | } | ||
| 109 | |||
| 110 | #endif /* HAVE_X86ASM */ | ||
| 111 | |||
| 112 | 1069 | av_cold void ff_me_cmp_init_x86(MECmpContext *c, AVCodecContext *avctx) | |
| 113 | { | ||
| 114 | #if HAVE_X86ASM | ||
| 115 | 1069 | int cpu_flags = av_get_cpu_flags(); | |
| 116 | |||
| 117 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 1000 times.
|
1069 | if (EXTERNAL_MMXEXT(cpu_flags)) { |
| 118 | 69 | c->sad[1] = ff_sad8_mmxext; | |
| 119 | |||
| 120 | 69 | c->pix_abs[1][0] = ff_sad8_mmxext; | |
| 121 | 69 | c->pix_abs[1][1] = ff_sad8_x2_mmxext; | |
| 122 | 69 | c->pix_abs[1][2] = ff_sad8_y2_mmxext; | |
| 123 | |||
| 124 | 69 | c->vsad[5] = ff_vsad_intra8_mmxext; | |
| 125 | |||
| 126 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 13 times.
|
69 | if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT)) { |
| 127 | 56 | c->pix_abs[1][3] = ff_sad8_approx_xy2_mmxext; | |
| 128 | |||
| 129 | 56 | c->vsad[1] = ff_vsad8_approx_mmxext; | |
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 1002 times.
|
1069 | if (EXTERNAL_SSE2(cpu_flags)) { |
| 134 | 67 | c->sse[0] = ff_sse16_sse2; | |
| 135 | 67 | c->sse[1] = ff_sse8_sse2; | |
| 136 | 67 | c->sum_abs_dctelem = ff_sum_abs_dctelem_sse2; | |
| 137 | |||
| 138 | 67 | c->pix_abs[0][0] = ff_sad16_sse2; | |
| 139 | 67 | c->pix_abs[0][1] = ff_sad16_x2_sse2; | |
| 140 | 67 | c->pix_abs[0][2] = ff_sad16_y2_sse2; | |
| 141 | 67 | c->pix_abs[0][3] = ff_sad16_xy2_sse2; | |
| 142 | |||
| 143 | 67 | c->hadamard8_diff[0] = ff_hadamard8_diff16_sse2; | |
| 144 | 67 | c->hadamard8_diff[1] = ff_hadamard8_diff_sse2; | |
| 145 |
1/2✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
|
67 | if (avctx->codec_id != AV_CODEC_ID_SNOW) { |
| 146 | 67 | c->sad[0] = ff_sad16_sse2; | |
| 147 | |||
| 148 | 67 | c->vsad[4] = ff_vsad_intra16_sse2; | |
| 149 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
|
67 | if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT)) { |
| 150 | 56 | c->vsad[0] = ff_vsad16_approx_sse2; | |
| 151 | } | ||
| 152 | } else { | ||
| 153 | // Snow does not abide by the alignment requirements | ||
| 154 | // of blk1, so we use special versions without them for it. | ||
| 155 | ✗ | c->sad[0] = ff_sad16u_sse2; | |
| 156 | |||
| 157 | ✗ | c->vsad[4] = ff_vsad_intra16u_sse2; | |
| 158 | ✗ | if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT)) { | |
| 159 | ✗ | c->vsad[0] = ff_vsad16u_approx_sse2; | |
| 160 | } | ||
| 161 | } | ||
| 162 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 56 times.
|
67 | if (avctx->flags & AV_CODEC_FLAG_BITEXACT) { |
| 163 | 11 | c->pix_abs[1][3] = ff_sad8_xy2_sse2; | |
| 164 | } else { | ||
| 165 | 56 | c->pix_abs[0][3] = ff_sad16_approx_xy2_sse2; | |
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 |
2/2✓ Branch 0 taken 65 times.
✓ Branch 1 taken 1004 times.
|
1069 | if (EXTERNAL_SSSE3(cpu_flags)) { |
| 170 | 65 | c->nsse[0] = nsse16_ssse3; | |
| 171 | 65 | c->nsse[1] = nsse8_ssse3; | |
| 172 | |||
| 173 | 65 | c->sum_abs_dctelem = ff_sum_abs_dctelem_ssse3; | |
| 174 | 65 | c->hadamard8_diff[0] = ff_hadamard8_diff16_ssse3; | |
| 175 | 65 | c->hadamard8_diff[1] = ff_hadamard8_diff_ssse3; | |
| 176 | } | ||
| 177 | #endif | ||
| 178 | 1069 | } | |
| 179 |