mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
alpha_processing*: use WEBP_RESTRICT qualifier
this helps both auto-vectorization in the C code and the optimized code generation Change-Id: Ide570d6be45125ffef7248bdc40e9eb08f00e832
This commit is contained in:
parent
a2e18f10eb
commit
a1e5dae0f0
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "src/dsp/dsp.h"
|
#include "src/dsp/dsp.h"
|
||||||
|
#include "src/utils/utils.h"
|
||||||
|
|
||||||
// Tables can be faster on some platform but incur some extra binary size (~2k).
|
// Tables can be faster on some platform but incur some extra binary size (~2k).
|
||||||
#if !defined(USE_TABLES_FOR_ALPHA_MULT)
|
#if !defined(USE_TABLES_FOR_ALPHA_MULT)
|
||||||
@ -157,7 +158,8 @@ void WebPMultARGBRow_C(uint32_t* const ptr, int width, int inverse) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPMultRow_C(uint8_t* const ptr, const uint8_t* const alpha,
|
void WebPMultRow_C(uint8_t* WEBP_RESTRICT const ptr,
|
||||||
|
const uint8_t* WEBP_RESTRICT const alpha,
|
||||||
int width, int inverse) {
|
int width, int inverse) {
|
||||||
int x;
|
int x;
|
||||||
for (x = 0; x < width; ++x) {
|
for (x = 0; x < width; ++x) {
|
||||||
@ -193,8 +195,8 @@ void WebPMultARGBRows(uint8_t* ptr, int stride, int width, int num_rows,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPMultRows(uint8_t* ptr, int stride,
|
void WebPMultRows(uint8_t* WEBP_RESTRICT ptr, int stride,
|
||||||
const uint8_t* alpha, int alpha_stride,
|
const uint8_t* WEBP_RESTRICT alpha, int alpha_stride,
|
||||||
int width, int num_rows, int inverse) {
|
int width, int num_rows, int inverse) {
|
||||||
int n;
|
int n;
|
||||||
for (n = 0; n < num_rows; ++n) {
|
for (n = 0; n < num_rows; ++n) {
|
||||||
@ -290,9 +292,9 @@ static void ApplyAlphaMultiply_16b_C(uint8_t* rgba4444,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !WEBP_NEON_OMIT_C_CODE
|
#if !WEBP_NEON_OMIT_C_CODE
|
||||||
static int DispatchAlpha_C(const uint8_t* alpha, int alpha_stride,
|
static int DispatchAlpha_C(const uint8_t* WEBP_RESTRICT alpha, int alpha_stride,
|
||||||
int width, int height,
|
int width, int height,
|
||||||
uint8_t* dst, int dst_stride) {
|
uint8_t* WEBP_RESTRICT dst, int dst_stride) {
|
||||||
uint32_t alpha_mask = 0xff;
|
uint32_t alpha_mask = 0xff;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@ -309,9 +311,10 @@ static int DispatchAlpha_C(const uint8_t* alpha, int alpha_stride,
|
|||||||
return (alpha_mask != 0xff);
|
return (alpha_mask != 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DispatchAlphaToGreen_C(const uint8_t* alpha, int alpha_stride,
|
static void DispatchAlphaToGreen_C(const uint8_t* WEBP_RESTRICT alpha,
|
||||||
int width, int height,
|
int alpha_stride, int width, int height,
|
||||||
uint32_t* dst, int dst_stride) {
|
uint32_t* WEBP_RESTRICT dst,
|
||||||
|
int dst_stride) {
|
||||||
int i, j;
|
int i, j;
|
||||||
for (j = 0; j < height; ++j) {
|
for (j = 0; j < height; ++j) {
|
||||||
for (i = 0; i < width; ++i) {
|
for (i = 0; i < width; ++i) {
|
||||||
@ -322,9 +325,9 @@ static void DispatchAlphaToGreen_C(const uint8_t* alpha, int alpha_stride,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ExtractAlpha_C(const uint8_t* argb, int argb_stride,
|
static int ExtractAlpha_C(const uint8_t* WEBP_RESTRICT argb, int argb_stride,
|
||||||
int width, int height,
|
int width, int height,
|
||||||
uint8_t* alpha, int alpha_stride) {
|
uint8_t* WEBP_RESTRICT alpha, int alpha_stride) {
|
||||||
uint8_t alpha_mask = 0xff;
|
uint8_t alpha_mask = 0xff;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@ -340,7 +343,8 @@ static int ExtractAlpha_C(const uint8_t* argb, int argb_stride,
|
|||||||
return (alpha_mask == 0xff);
|
return (alpha_mask == 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ExtractGreen_C(const uint32_t* argb, uint8_t* alpha, int size) {
|
static void ExtractGreen_C(const uint32_t* WEBP_RESTRICT argb,
|
||||||
|
uint8_t* WEBP_RESTRICT alpha, int size) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < size; ++i) alpha[i] = argb[i] >> 8;
|
for (i = 0; i < size; ++i) alpha[i] = argb[i] >> 8;
|
||||||
}
|
}
|
||||||
@ -372,8 +376,11 @@ static WEBP_INLINE uint32_t MakeARGB32(int a, int r, int g, int b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
static void PackARGB_C(const uint8_t* a, const uint8_t* r, const uint8_t* g,
|
static void PackARGB_C(const uint8_t* WEBP_RESTRICT a,
|
||||||
const uint8_t* b, int len, uint32_t* out) {
|
const uint8_t* WEBP_RESTRICT r,
|
||||||
|
const uint8_t* WEBP_RESTRICT g,
|
||||||
|
const uint8_t* WEBP_RESTRICT b,
|
||||||
|
int len, uint32_t* WEBP_RESTRICT out) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
out[i] = MakeARGB32(a[4 * i], r[4 * i], g[4 * i], b[4 * i]);
|
out[i] = MakeARGB32(a[4 * i], r[4 * i], g[4 * i], b[4 * i]);
|
||||||
@ -381,8 +388,10 @@ static void PackARGB_C(const uint8_t* a, const uint8_t* r, const uint8_t* g,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void PackRGB_C(const uint8_t* r, const uint8_t* g, const uint8_t* b,
|
static void PackRGB_C(const uint8_t* WEBP_RESTRICT r,
|
||||||
int len, int step, uint32_t* out) {
|
const uint8_t* WEBP_RESTRICT g,
|
||||||
|
const uint8_t* WEBP_RESTRICT b,
|
||||||
|
int len, int step, uint32_t* WEBP_RESTRICT out) {
|
||||||
int i, offset = 0;
|
int i, offset = 0;
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
out[i] = MakeARGB32(0xff, r[offset], g[offset], b[offset]);
|
out[i] = MakeARGB32(0xff, r[offset], g[offset], b[offset]);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#if defined(WEBP_USE_NEON)
|
#if defined(WEBP_USE_NEON)
|
||||||
|
|
||||||
#include "src/dsp/neon.h"
|
#include "src/dsp/neon.h"
|
||||||
|
#include "src/utils/utils.h"
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -80,9 +81,9 @@ static void ApplyAlphaMultiply_NEON(uint8_t* rgba, int alpha_first,
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
static int DispatchAlpha_NEON(const uint8_t* alpha, int alpha_stride,
|
static int DispatchAlpha_NEON(const uint8_t* WEBP_RESTRICT alpha,
|
||||||
int width, int height,
|
int alpha_stride, int width, int height,
|
||||||
uint8_t* dst, int dst_stride) {
|
uint8_t* WEBP_RESTRICT dst, int dst_stride) {
|
||||||
uint32_t alpha_mask = 0xffffffffu;
|
uint32_t alpha_mask = 0xffffffffu;
|
||||||
uint8x8_t mask8 = vdup_n_u8(0xff);
|
uint8x8_t mask8 = vdup_n_u8(0xff);
|
||||||
uint32_t tmp[2];
|
uint32_t tmp[2];
|
||||||
@ -112,9 +113,10 @@ static int DispatchAlpha_NEON(const uint8_t* alpha, int alpha_stride,
|
|||||||
return (alpha_mask != 0xffffffffu);
|
return (alpha_mask != 0xffffffffu);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DispatchAlphaToGreen_NEON(const uint8_t* alpha, int alpha_stride,
|
static void DispatchAlphaToGreen_NEON(const uint8_t* WEBP_RESTRICT alpha,
|
||||||
int width, int height,
|
int alpha_stride, int width, int height,
|
||||||
uint32_t* dst, int dst_stride) {
|
uint32_t* WEBP_RESTRICT dst,
|
||||||
|
int dst_stride) {
|
||||||
int i, j;
|
int i, j;
|
||||||
uint8x8x4_t greens; // leave A/R/B channels zero'd.
|
uint8x8x4_t greens; // leave A/R/B channels zero'd.
|
||||||
greens.val[0] = vdup_n_u8(0);
|
greens.val[0] = vdup_n_u8(0);
|
||||||
@ -131,9 +133,9 @@ static void DispatchAlphaToGreen_NEON(const uint8_t* alpha, int alpha_stride,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ExtractAlpha_NEON(const uint8_t* argb, int argb_stride,
|
static int ExtractAlpha_NEON(const uint8_t* WEBP_RESTRICT argb, int argb_stride,
|
||||||
int width, int height,
|
int width, int height,
|
||||||
uint8_t* alpha, int alpha_stride) {
|
uint8_t* WEBP_RESTRICT alpha, int alpha_stride) {
|
||||||
uint32_t alpha_mask = 0xffffffffu;
|
uint32_t alpha_mask = 0xffffffffu;
|
||||||
uint8x8_t mask8 = vdup_n_u8(0xff);
|
uint8x8_t mask8 = vdup_n_u8(0xff);
|
||||||
uint32_t tmp[2];
|
uint32_t tmp[2];
|
||||||
@ -161,8 +163,8 @@ static int ExtractAlpha_NEON(const uint8_t* argb, int argb_stride,
|
|||||||
return (alpha_mask == 0xffffffffu);
|
return (alpha_mask == 0xffffffffu);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ExtractGreen_NEON(const uint32_t* argb,
|
static void ExtractGreen_NEON(const uint32_t* WEBP_RESTRICT argb,
|
||||||
uint8_t* alpha, int size) {
|
uint8_t* WEBP_RESTRICT alpha, int size) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i + 16 <= size; i += 16) {
|
for (i = 0; i + 16 <= size; i += 16) {
|
||||||
const uint8x16x4_t rgbX = vld4q_u8((const uint8_t*)(argb + i));
|
const uint8x16x4_t rgbX = vld4q_u8((const uint8_t*)(argb + i));
|
||||||
|
@ -16,11 +16,13 @@
|
|||||||
#if defined(WEBP_USE_SSE2)
|
#if defined(WEBP_USE_SSE2)
|
||||||
#include <emmintrin.h>
|
#include <emmintrin.h>
|
||||||
|
|
||||||
|
#include "src/utils/utils.h"
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
static int DispatchAlpha_SSE2(const uint8_t* alpha, int alpha_stride,
|
static int DispatchAlpha_SSE2(const uint8_t* WEBP_RESTRICT alpha,
|
||||||
int width, int height,
|
int alpha_stride, int width, int height,
|
||||||
uint8_t* dst, int dst_stride) {
|
uint8_t* WEBP_RESTRICT dst, int dst_stride) {
|
||||||
// alpha_and stores an 'and' operation of all the alpha[] values. The final
|
// alpha_and stores an 'and' operation of all the alpha[] values. The final
|
||||||
// value is not 0xff if any of the alpha[] is not equal to 0xff.
|
// value is not 0xff if any of the alpha[] is not equal to 0xff.
|
||||||
uint32_t alpha_and = 0xff;
|
uint32_t alpha_and = 0xff;
|
||||||
@ -72,9 +74,10 @@ static int DispatchAlpha_SSE2(const uint8_t* alpha, int alpha_stride,
|
|||||||
return (alpha_and != 0xff);
|
return (alpha_and != 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DispatchAlphaToGreen_SSE2(const uint8_t* alpha, int alpha_stride,
|
static void DispatchAlphaToGreen_SSE2(const uint8_t* WEBP_RESTRICT alpha,
|
||||||
int width, int height,
|
int alpha_stride, int width, int height,
|
||||||
uint32_t* dst, int dst_stride) {
|
uint32_t* WEBP_RESTRICT dst,
|
||||||
|
int dst_stride) {
|
||||||
int i, j;
|
int i, j;
|
||||||
const __m128i zero = _mm_setzero_si128();
|
const __m128i zero = _mm_setzero_si128();
|
||||||
const int limit = width & ~15;
|
const int limit = width & ~15;
|
||||||
@ -98,9 +101,9 @@ static void DispatchAlphaToGreen_SSE2(const uint8_t* alpha, int alpha_stride,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ExtractAlpha_SSE2(const uint8_t* argb, int argb_stride,
|
static int ExtractAlpha_SSE2(const uint8_t* WEBP_RESTRICT argb, int argb_stride,
|
||||||
int width, int height,
|
int width, int height,
|
||||||
uint8_t* alpha, int alpha_stride) {
|
uint8_t* WEBP_RESTRICT alpha, int alpha_stride) {
|
||||||
// alpha_and stores an 'and' operation of all the alpha[] values. The final
|
// alpha_and stores an 'and' operation of all the alpha[] values. The final
|
||||||
// value is not 0xff if any of the alpha[] is not equal to 0xff.
|
// value is not 0xff if any of the alpha[] is not equal to 0xff.
|
||||||
uint32_t alpha_and = 0xff;
|
uint32_t alpha_and = 0xff;
|
||||||
@ -317,7 +320,8 @@ static void MultARGBRow_SSE2(uint32_t* const ptr, int width, int inverse) {
|
|||||||
if (width > 0) WebPMultARGBRow_C(ptr + x, width, inverse);
|
if (width > 0) WebPMultARGBRow_C(ptr + x, width, inverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MultRow_SSE2(uint8_t* const ptr, const uint8_t* const alpha,
|
static void MultRow_SSE2(uint8_t* WEBP_RESTRICT const ptr,
|
||||||
|
const uint8_t* WEBP_RESTRICT const alpha,
|
||||||
int width, int inverse) {
|
int width, int inverse) {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
if (!inverse) {
|
if (!inverse) {
|
||||||
|
@ -17,11 +17,13 @@
|
|||||||
|
|
||||||
#include <smmintrin.h>
|
#include <smmintrin.h>
|
||||||
|
|
||||||
|
#include "src/utils/utils.h"
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
static int ExtractAlpha_SSE41(const uint8_t* argb, int argb_stride,
|
static int ExtractAlpha_SSE41(const uint8_t* WEBP_RESTRICT argb,
|
||||||
int width, int height,
|
int argb_stride, int width, int height,
|
||||||
uint8_t* alpha, int alpha_stride) {
|
uint8_t* WEBP_RESTRICT alpha, int alpha_stride) {
|
||||||
// alpha_and stores an 'and' operation of all the alpha[] values. The final
|
// alpha_and stores an 'and' operation of all the alpha[] values. The final
|
||||||
// value is not 0xff if any of the alpha[] is not equal to 0xff.
|
// value is not 0xff if any of the alpha[] is not equal to 0xff.
|
||||||
uint32_t alpha_and = 0xff;
|
uint32_t alpha_and = 0xff;
|
||||||
|
Loading…
Reference in New Issue
Block a user