2
0

avg_pred_sse2.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2017 The WebM project authors. All Rights Reserved.
  3. *
  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.
  9. */
  10. #include <assert.h>
  11. #include <emmintrin.h>
  12. #include "./vpx_dsp_rtcd.h"
  13. #include "vpx/vpx_integer.h"
  14. void vpx_comp_avg_pred_sse2(uint8_t *comp, const uint8_t *pred, int width,
  15. int height, const uint8_t *ref, int ref_stride) {
  16. /* comp and pred must be 16 byte aligned. */
  17. assert(((intptr_t)comp & 0xf) == 0);
  18. assert(((intptr_t)pred & 0xf) == 0);
  19. if (width > 8) {
  20. int x, y;
  21. for (y = 0; y < height; ++y) {
  22. for (x = 0; x < width; x += 16) {
  23. const __m128i p = _mm_load_si128((const __m128i *)(pred + x));
  24. const __m128i r = _mm_loadu_si128((const __m128i *)(ref + x));
  25. const __m128i avg = _mm_avg_epu8(p, r);
  26. _mm_store_si128((__m128i *)(comp + x), avg);
  27. }
  28. comp += width;
  29. pred += width;
  30. ref += ref_stride;
  31. }
  32. } else { // width must be 4 or 8.
  33. int i;
  34. // Process 16 elements at a time. comp and pred have width == stride and
  35. // therefore live in contigious memory. 4*4, 4*8, 8*4, 8*8, and 8*16 are all
  36. // divisible by 16 so just ref needs to be massaged when loading.
  37. for (i = 0; i < width * height; i += 16) {
  38. const __m128i p = _mm_load_si128((const __m128i *)pred);
  39. __m128i r;
  40. __m128i avg;
  41. if (width == ref_stride) {
  42. r = _mm_loadu_si128((const __m128i *)ref);
  43. ref += 16;
  44. } else if (width == 4) {
  45. r = _mm_set_epi32(*(const uint32_t *)(ref + 3 * ref_stride),
  46. *(const uint32_t *)(ref + 2 * ref_stride),
  47. *(const uint32_t *)(ref + ref_stride),
  48. *(const uint32_t *)(ref));
  49. ref += 4 * ref_stride;
  50. } else {
  51. const __m128i r_0 = _mm_loadl_epi64((const __m128i *)ref);
  52. assert(width == 8);
  53. r = _mm_castps_si128(_mm_loadh_pi(_mm_castsi128_ps(r_0),
  54. (const __m64 *)(ref + ref_stride)));
  55. ref += 2 * ref_stride;
  56. }
  57. avg = _mm_avg_epu8(p, r);
  58. _mm_store_si128((__m128i *)comp, avg);
  59. pred += 16;
  60. comp += 16;
  61. }
  62. }
  63. }