fix build
[LibreOffice.git] / external / skia / source / skia_opts_internal.hxx
blob0ca6a04351d2cb2ef3afb87633063d78dfe5e664
1 /*
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
6 #ifndef SKIA_OPTS_INTERNAL_H
7 #define SKIA_OPTS_INTERNAL_H
9 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
10 #include <immintrin.h>
11 #endif
13 namespace SK_OPTS_NS {
15 static void RGB1_to_RGB_portable(uint8_t dst[], const uint32_t* src, int count) {
16 for (int i = 0; i < count; i++) {
17 dst[0] = src[i] >> 0;
18 dst[1] = src[i] >> 8;
19 dst[2] = src[i] >> 16;
20 dst += 3;
23 static void RGB1_to_R_portable(uint8_t dst[], const uint32_t* src, int count) {
24 for (int i = 0; i < count; i++) {
25 dst[i] = src[i] & 0xFF;
29 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
30 inline void RGB1_to_RGB(uint8_t dst[], const uint32_t* src, int count) {
31 const uint8_t X = 0xFF; // Used a placeholder. The value of X is irrelevant.
32 __m128i pack = _mm_setr_epi8(0,1,2, 4,5,6, 8,9,10, 12,13,14, X,X,X,X);
34 // Storing 4 pixels should store 12 bytes, but here it stores 16, so test count >= 6
35 // in order to not overrun the output buffer.
36 while (count >= 6) {
37 __m128i rgba = _mm_loadu_si128((const __m128i*) src);
39 __m128i rgb = _mm_shuffle_epi8(rgba, pack);
41 // Store 4 pixels.
42 _mm_storeu_si128((__m128i*) dst, rgb);
44 src += 4;
45 dst += 4*3;
46 count -= 4;
48 RGB1_to_RGB_portable(dst, src, count);
51 inline void RGB1_to_R(uint8_t dst[], const uint32_t* src, int count) {
52 const uint8_t X = 0xFF; // Used a placeholder. The value of X is irrelevant.
53 __m128i pack = _mm_setr_epi8(0,4,8,12, X,X,X,X,X,X,X,X,X,X,X,X);
55 while (count >= 4) {
56 __m128i rgba = _mm_loadu_si128((const __m128i*) src);
58 __m128i rgb = _mm_shuffle_epi8(rgba, pack);
60 // Store 4 pixels.
61 *((uint32_t*)dst) = _mm_cvtsi128_si32(rgb);
63 src += 4;
64 dst += 4;
65 count -= 4;
67 RGB1_to_R_portable(dst, src, count);
70 #else
71 inline void RGB1_to_RGB(uint8_t dst[], const uint32_t* src, int count) {
72 RGB1_to_RGB_portable(dst, src, count);
74 inline void RGB1_to_R(uint8_t dst[], const uint32_t* src, int count) {
75 RGB1_to_R_portable(dst, src, count);
77 #endif
79 } // namespace
81 #endif