2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
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>
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
++) {
19 dst
[2] = src
[i
] >> 16;
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.
37 __m128i rgba
= _mm_loadu_si128((const __m128i
*) src
);
39 __m128i rgb
= _mm_shuffle_epi8(rgba
, pack
);
42 _mm_storeu_si128((__m128i
*) dst
, rgb
);
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
);
56 __m128i rgba
= _mm_loadu_si128((const __m128i
*) src
);
58 __m128i rgb
= _mm_shuffle_epi8(rgba
, pack
);
61 *((uint32_t*)dst
) = _mm_cvtsi128_si32(rgb
);
67 RGB1_to_R_portable(dst
, src
, count
);
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
);