Path: blob/master/thirdparty/libwebp/src/dsp/alpha_processing_sse41.c
21091 views
// Copyright 2015 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Utilities for processing transparent channel, SSE4.1 variant.10//11// Author: Skal ([email protected])1213#include "src/dsp/cpu.h"14#include "src/webp/types.h"15#include "src/dsp/dsp.h"1617#if defined(WEBP_USE_SSE41)18#include <emmintrin.h>19#include <smmintrin.h>2021//------------------------------------------------------------------------------2223static int ExtractAlpha_SSE41(const uint8_t* WEBP_RESTRICT argb,24int argb_stride, int width, int height,25uint8_t* WEBP_RESTRICT alpha, int alpha_stride) {26// alpha_and stores an 'and' operation of all the alpha[] values. The final27// value is not 0xff if any of the alpha[] is not equal to 0xff.28uint32_t alpha_and = 0xff;29int i, j;30const __m128i all_0xff = _mm_set1_epi32(~0);31__m128i all_alphas = all_0xff;3233// We must be able to access 3 extra bytes after the last written byte34// 'src[4 * width - 4]', because we don't know if alpha is the first or the35// last byte of the quadruplet.36const int limit = (width - 1) & ~15;37const __m128i kCstAlpha0 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1,38-1, -1, -1, -1, 12, 8, 4, 0);39const __m128i kCstAlpha1 = _mm_set_epi8(-1, -1, -1, -1, -1, -1, -1, -1,4012, 8, 4, 0, -1, -1, -1, -1);41const __m128i kCstAlpha2 = _mm_set_epi8(-1, -1, -1, -1, 12, 8, 4, 0,42-1, -1, -1, -1, -1, -1, -1, -1);43const __m128i kCstAlpha3 = _mm_set_epi8(12, 8, 4, 0, -1, -1, -1, -1,44-1, -1, -1, -1, -1, -1, -1, -1);45for (j = 0; j < height; ++j) {46const __m128i* src = (const __m128i*)argb;47for (i = 0; i < limit; i += 16) {48// load 64 argb bytes49const __m128i a0 = _mm_loadu_si128(src + 0);50const __m128i a1 = _mm_loadu_si128(src + 1);51const __m128i a2 = _mm_loadu_si128(src + 2);52const __m128i a3 = _mm_loadu_si128(src + 3);53const __m128i b0 = _mm_shuffle_epi8(a0, kCstAlpha0);54const __m128i b1 = _mm_shuffle_epi8(a1, kCstAlpha1);55const __m128i b2 = _mm_shuffle_epi8(a2, kCstAlpha2);56const __m128i b3 = _mm_shuffle_epi8(a3, kCstAlpha3);57const __m128i c0 = _mm_or_si128(b0, b1);58const __m128i c1 = _mm_or_si128(b2, b3);59const __m128i d0 = _mm_or_si128(c0, c1);60// store61_mm_storeu_si128((__m128i*)&alpha[i], d0);62// accumulate sixteen alpha 'and' in parallel63all_alphas = _mm_and_si128(all_alphas, d0);64src += 4;65}66for (; i < width; ++i) {67const uint32_t alpha_value = argb[4 * i];68alpha[i] = alpha_value;69alpha_and &= alpha_value;70}71argb += argb_stride;72alpha += alpha_stride;73}74// Combine the sixteen alpha 'and' into an 8-bit mask.75alpha_and |= 0xff00u; // pretend the upper bits [8..15] were tested ok.76alpha_and &= _mm_movemask_epi8(_mm_cmpeq_epi8(all_alphas, all_0xff));77return (alpha_and == 0xffffu);78}7980//------------------------------------------------------------------------------81// Entry point8283extern void WebPInitAlphaProcessingSSE41(void);8485WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessingSSE41(void) {86WebPExtractAlpha = ExtractAlpha_SSE41;87}8889#else // !WEBP_USE_SSE419091WEBP_DSP_INIT_STUB(WebPInitAlphaProcessingSSE41)9293#endif // WEBP_USE_SSE41949596