jcsample-mmi.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Loongson MMI optimizations for libjpeg-turbo
  3. *
  4. * Copyright (C) 2015, 2018, D. R. Commander. All Rights Reserved.
  5. * Copyright (C) 2016-2017, Loongson Technology Corporation Limited, BeiJing.
  6. * All Rights Reserved.
  7. * Authors: ZhuChen <zhuchen@loongson.cn>
  8. * CaiWanwei <caiwanwei@loongson.cn>
  9. * SunZhangzhi <sunzhangzhi-cq@loongson.cn>
  10. *
  11. * Based on the x86 SIMD extension for IJG JPEG library
  12. * Copyright (C) 1999-2006, MIYASAKA Masaru.
  13. *
  14. * This software is provided 'as-is', without any express or implied
  15. * warranty. In no event will the authors be held liable for any damages
  16. * arising from the use of this software.
  17. *
  18. * Permission is granted to anyone to use this software for any purpose,
  19. * including commercial applications, and to alter it and redistribute it
  20. * freely, subject to the following restrictions:
  21. *
  22. * 1. The origin of this software must not be misrepresented; you must not
  23. * claim that you wrote the original software. If you use this software
  24. * in a product, an acknowledgment in the product documentation would be
  25. * appreciated but is not required.
  26. * 2. Altered source versions must be plainly marked as such, and must not be
  27. * misrepresented as being the original software.
  28. * 3. This notice may not be removed or altered from any source distribution.
  29. */
  30. /* CHROMA DOWNSAMPLING */
  31. #include "jsimd_mmi.h"
  32. #include "jcsample.h"
  33. void jsimd_h2v2_downsample_mmi(JDIMENSION image_width, int max_v_samp_factor,
  34. JDIMENSION v_samp_factor,
  35. JDIMENSION width_in_blocks,
  36. JSAMPARRAY input_data, JSAMPARRAY output_data)
  37. {
  38. int inrow, outrow, outcol, bias;
  39. JDIMENSION output_cols = width_in_blocks * DCTSIZE;
  40. JSAMPROW inptr0, inptr1, outptr;
  41. __m64 mm0, mm1, mm2, mm3, mm4, mm5, mm6 = 0.0, mm7;
  42. expand_right_edge(input_data, max_v_samp_factor, image_width,
  43. output_cols * 2);
  44. bias = (1 << 17) + 1; /* 0x00020001 (bias pattern) */
  45. mm7 = _mm_set1_pi32(bias); /* mm7={1, 2, 1, 2} */
  46. mm6 = _mm_cmpeq_pi16(mm6, mm6);
  47. mm6 = _mm_srli_pi16(mm6, BYTE_BIT); /* mm6={0xFF 0x00 0xFF 0x00 ..} */
  48. for (inrow = 0, outrow = 0; outrow < v_samp_factor;
  49. inrow += 2, outrow++) {
  50. inptr0 = input_data[inrow];
  51. inptr1 = input_data[inrow + 1];
  52. outptr = output_data[outrow];
  53. for (outcol = output_cols; outcol > 0;
  54. outcol -= 8, inptr0 += 16, inptr1 += 16, outptr += 8) {
  55. mm0 = _mm_load_si64((__m64 *)&inptr0[0]);
  56. mm1 = _mm_load_si64((__m64 *)&inptr1[0]);
  57. mm2 = _mm_load_si64((__m64 *)&inptr0[8]);
  58. mm3 = _mm_load_si64((__m64 *)&inptr1[8]);
  59. mm4 = mm0;
  60. mm5 = mm1;
  61. mm0 = _mm_and_si64(mm0, mm6);
  62. mm4 = _mm_srli_pi16(mm4, BYTE_BIT);
  63. mm1 = _mm_and_si64(mm1, mm6);
  64. mm5 = _mm_srli_pi16(mm5, BYTE_BIT);
  65. mm0 = _mm_add_pi16(mm0, mm4);
  66. mm1 = _mm_add_pi16(mm1, mm5);
  67. mm4 = mm2;
  68. mm5 = mm3;
  69. mm2 = _mm_and_si64(mm2, mm6);
  70. mm4 = _mm_srli_pi16(mm4, BYTE_BIT);
  71. mm3 = _mm_and_si64(mm3, mm6);
  72. mm5 = _mm_srli_pi16(mm5, BYTE_BIT);
  73. mm2 = _mm_add_pi16(mm2, mm4);
  74. mm3 = _mm_add_pi16(mm3, mm5);
  75. mm0 = _mm_add_pi16(mm0, mm1);
  76. mm2 = _mm_add_pi16(mm2, mm3);
  77. mm0 = _mm_add_pi16(mm0, mm7);
  78. mm2 = _mm_add_pi16(mm2, mm7);
  79. mm0 = _mm_srli_pi16(mm0, 2);
  80. mm2 = _mm_srli_pi16(mm2, 2);
  81. mm0 = _mm_packs_pu16(mm0, mm2);
  82. _mm_store_si64((__m64 *)&outptr[0], mm0);
  83. }
  84. }
  85. }