2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include <emmintrin.h>
12 #include "vpx_ports/mem.h"
15 unsigned int vp9_avg_8x8_sse2(const uint8_t *s, int p) {
18 u0 = _mm_setzero_si128();
19 s0 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(s)), u0);
20 s1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(s + p)), u0);
21 s0 = _mm_adds_epu16(s0, s1);
22 s1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(s + 2 * p)), u0);
23 s0 = _mm_adds_epu16(s0, s1);
24 s1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(s + 3 * p)), u0);
25 s0 = _mm_adds_epu16(s0, s1);
26 s1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(s + 4 * p)), u0);
27 s0 = _mm_adds_epu16(s0, s1);
28 s1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(s + 5 * p)), u0);
29 s0 = _mm_adds_epu16(s0, s1);
30 s1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(s + 6 * p)), u0);
31 s0 = _mm_adds_epu16(s0, s1);
32 s1 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i *)(s + 7 * p)), u0);
33 s0 = _mm_adds_epu16(s0, s1);
35 s0 = _mm_adds_epu16(s0, _mm_srli_si128(s0, 8));
36 s0 = _mm_adds_epu16(s0, _mm_srli_epi64(s0, 32));
37 s0 = _mm_adds_epu16(s0, _mm_srli_epi64(s0, 16));
38 avg = _mm_extract_epi16(s0, 0);
39 return (avg + 32) >> 6;