Path: blob/master/3rdparty/libwebp/src/dsp/lossless_neon.c
16348 views
// Copyright 2014 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// NEON variant of methods for lossless decoder10//11// Author: Skal ([email protected])1213#include "src/dsp/dsp.h"1415#if defined(WEBP_USE_NEON)1617#include <arm_neon.h>1819#include "src/dsp/lossless.h"20#include "src/dsp/neon.h"2122//------------------------------------------------------------------------------23// Colorspace conversion functions2425#if !defined(WORK_AROUND_GCC)26// gcc 4.6.0 had some trouble (NDK-r9) with this code. We only use it for27// gcc-4.8.x at least.28static void ConvertBGRAToRGBA_NEON(const uint32_t* src,29int num_pixels, uint8_t* dst) {30const uint32_t* const end = src + (num_pixels & ~15);31for (; src < end; src += 16) {32uint8x16x4_t pixel = vld4q_u8((uint8_t*)src);33// swap B and R. (VSWP d0,d2 has no intrinsics equivalent!)34const uint8x16_t tmp = pixel.val[0];35pixel.val[0] = pixel.val[2];36pixel.val[2] = tmp;37vst4q_u8(dst, pixel);38dst += 64;39}40VP8LConvertBGRAToRGBA_C(src, num_pixels & 15, dst); // left-overs41}4243static void ConvertBGRAToBGR_NEON(const uint32_t* src,44int num_pixels, uint8_t* dst) {45const uint32_t* const end = src + (num_pixels & ~15);46for (; src < end; src += 16) {47const uint8x16x4_t pixel = vld4q_u8((uint8_t*)src);48const uint8x16x3_t tmp = { { pixel.val[0], pixel.val[1], pixel.val[2] } };49vst3q_u8(dst, tmp);50dst += 48;51}52VP8LConvertBGRAToBGR_C(src, num_pixels & 15, dst); // left-overs53}5455static void ConvertBGRAToRGB_NEON(const uint32_t* src,56int num_pixels, uint8_t* dst) {57const uint32_t* const end = src + (num_pixels & ~15);58for (; src < end; src += 16) {59const uint8x16x4_t pixel = vld4q_u8((uint8_t*)src);60const uint8x16x3_t tmp = { { pixel.val[2], pixel.val[1], pixel.val[0] } };61vst3q_u8(dst, tmp);62dst += 48;63}64VP8LConvertBGRAToRGB_C(src, num_pixels & 15, dst); // left-overs65}6667#else // WORK_AROUND_GCC6869// gcc-4.6.0 fallback7071static const uint8_t kRGBAShuffle[8] = { 2, 1, 0, 3, 6, 5, 4, 7 };7273static void ConvertBGRAToRGBA_NEON(const uint32_t* src,74int num_pixels, uint8_t* dst) {75const uint32_t* const end = src + (num_pixels & ~1);76const uint8x8_t shuffle = vld1_u8(kRGBAShuffle);77for (; src < end; src += 2) {78const uint8x8_t pixels = vld1_u8((uint8_t*)src);79vst1_u8(dst, vtbl1_u8(pixels, shuffle));80dst += 8;81}82VP8LConvertBGRAToRGBA_C(src, num_pixels & 1, dst); // left-overs83}8485static const uint8_t kBGRShuffle[3][8] = {86{ 0, 1, 2, 4, 5, 6, 8, 9 },87{ 10, 12, 13, 14, 16, 17, 18, 20 },88{ 21, 22, 24, 25, 26, 28, 29, 30 }89};9091static void ConvertBGRAToBGR_NEON(const uint32_t* src,92int num_pixels, uint8_t* dst) {93const uint32_t* const end = src + (num_pixels & ~7);94const uint8x8_t shuffle0 = vld1_u8(kBGRShuffle[0]);95const uint8x8_t shuffle1 = vld1_u8(kBGRShuffle[1]);96const uint8x8_t shuffle2 = vld1_u8(kBGRShuffle[2]);97for (; src < end; src += 8) {98uint8x8x4_t pixels;99INIT_VECTOR4(pixels,100vld1_u8((const uint8_t*)(src + 0)),101vld1_u8((const uint8_t*)(src + 2)),102vld1_u8((const uint8_t*)(src + 4)),103vld1_u8((const uint8_t*)(src + 6)));104vst1_u8(dst + 0, vtbl4_u8(pixels, shuffle0));105vst1_u8(dst + 8, vtbl4_u8(pixels, shuffle1));106vst1_u8(dst + 16, vtbl4_u8(pixels, shuffle2));107dst += 8 * 3;108}109VP8LConvertBGRAToBGR_C(src, num_pixels & 7, dst); // left-overs110}111112static const uint8_t kRGBShuffle[3][8] = {113{ 2, 1, 0, 6, 5, 4, 10, 9 },114{ 8, 14, 13, 12, 18, 17, 16, 22 },115{ 21, 20, 26, 25, 24, 30, 29, 28 }116};117118static void ConvertBGRAToRGB_NEON(const uint32_t* src,119int num_pixels, uint8_t* dst) {120const uint32_t* const end = src + (num_pixels & ~7);121const uint8x8_t shuffle0 = vld1_u8(kRGBShuffle[0]);122const uint8x8_t shuffle1 = vld1_u8(kRGBShuffle[1]);123const uint8x8_t shuffle2 = vld1_u8(kRGBShuffle[2]);124for (; src < end; src += 8) {125uint8x8x4_t pixels;126INIT_VECTOR4(pixels,127vld1_u8((const uint8_t*)(src + 0)),128vld1_u8((const uint8_t*)(src + 2)),129vld1_u8((const uint8_t*)(src + 4)),130vld1_u8((const uint8_t*)(src + 6)));131vst1_u8(dst + 0, vtbl4_u8(pixels, shuffle0));132vst1_u8(dst + 8, vtbl4_u8(pixels, shuffle1));133vst1_u8(dst + 16, vtbl4_u8(pixels, shuffle2));134dst += 8 * 3;135}136VP8LConvertBGRAToRGB_C(src, num_pixels & 7, dst); // left-overs137}138139#endif // !WORK_AROUND_GCC140141//------------------------------------------------------------------------------142// Predictor Transform143144#define LOAD_U32_AS_U8(IN) vreinterpret_u8_u32(vdup_n_u32((IN)))145#define LOAD_U32P_AS_U8(IN) vreinterpret_u8_u32(vld1_u32((IN)))146#define LOADQ_U32_AS_U8(IN) vreinterpretq_u8_u32(vdupq_n_u32((IN)))147#define LOADQ_U32P_AS_U8(IN) vreinterpretq_u8_u32(vld1q_u32((IN)))148#define GET_U8_AS_U32(IN) vget_lane_u32(vreinterpret_u32_u8((IN)), 0);149#define GETQ_U8_AS_U32(IN) vgetq_lane_u32(vreinterpretq_u32_u8((IN)), 0);150#define STOREQ_U8_AS_U32P(OUT, IN) vst1q_u32((OUT), vreinterpretq_u32_u8((IN)));151#define ROTATE32_LEFT(L) vextq_u8((L), (L), 12) // D|C|B|A -> C|B|A|D152153static WEBP_INLINE uint8x8_t Average2_u8_NEON(uint32_t a0, uint32_t a1) {154const uint8x8_t A0 = LOAD_U32_AS_U8(a0);155const uint8x8_t A1 = LOAD_U32_AS_U8(a1);156return vhadd_u8(A0, A1);157}158159static WEBP_INLINE uint32_t ClampedAddSubtractHalf_NEON(uint32_t c0,160uint32_t c1,161uint32_t c2) {162const uint8x8_t avg = Average2_u8_NEON(c0, c1);163// Remove one to c2 when bigger than avg.164const uint8x8_t C2 = LOAD_U32_AS_U8(c2);165const uint8x8_t cmp = vcgt_u8(C2, avg);166const uint8x8_t C2_1 = vadd_u8(C2, cmp);167// Compute half of the difference between avg and c2.168const int8x8_t diff_avg = vreinterpret_s8_u8(vhsub_u8(avg, C2_1));169// Compute the sum with avg and saturate.170const int16x8_t avg_16 = vreinterpretq_s16_u16(vmovl_u8(avg));171const uint8x8_t res = vqmovun_s16(vaddw_s8(avg_16, diff_avg));172const uint32_t output = GET_U8_AS_U32(res);173return output;174}175176static WEBP_INLINE uint32_t Average2_NEON(uint32_t a0, uint32_t a1) {177const uint8x8_t avg_u8x8 = Average2_u8_NEON(a0, a1);178const uint32_t avg = GET_U8_AS_U32(avg_u8x8);179return avg;180}181182static WEBP_INLINE uint32_t Average3_NEON(uint32_t a0, uint32_t a1,183uint32_t a2) {184const uint8x8_t avg0 = Average2_u8_NEON(a0, a2);185const uint8x8_t A1 = LOAD_U32_AS_U8(a1);186const uint32_t avg = GET_U8_AS_U32(vhadd_u8(avg0, A1));187return avg;188}189190static uint32_t Predictor5_NEON(uint32_t left, const uint32_t* const top) {191return Average3_NEON(left, top[0], top[1]);192}193static uint32_t Predictor6_NEON(uint32_t left, const uint32_t* const top) {194return Average2_NEON(left, top[-1]);195}196static uint32_t Predictor7_NEON(uint32_t left, const uint32_t* const top) {197return Average2_NEON(left, top[0]);198}199static uint32_t Predictor13_NEON(uint32_t left, const uint32_t* const top) {200return ClampedAddSubtractHalf_NEON(left, top[0], top[-1]);201}202203// Batch versions of those functions.204205// Predictor0: ARGB_BLACK.206static void PredictorAdd0_NEON(const uint32_t* in, const uint32_t* upper,207int num_pixels, uint32_t* out) {208int i;209const uint8x16_t black = vreinterpretq_u8_u32(vdupq_n_u32(ARGB_BLACK));210for (i = 0; i + 4 <= num_pixels; i += 4) {211const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]);212const uint8x16_t res = vaddq_u8(src, black);213STOREQ_U8_AS_U32P(&out[i], res);214}215VP8LPredictorsAdd_C[0](in + i, upper + i, num_pixels - i, out + i);216}217218// Predictor1: left.219static void PredictorAdd1_NEON(const uint32_t* in, const uint32_t* upper,220int num_pixels, uint32_t* out) {221int i;222const uint8x16_t zero = LOADQ_U32_AS_U8(0);223for (i = 0; i + 4 <= num_pixels; i += 4) {224// a | b | c | d225const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]);226// 0 | a | b | c227const uint8x16_t shift0 = vextq_u8(zero, src, 12);228// a | a + b | b + c | c + d229const uint8x16_t sum0 = vaddq_u8(src, shift0);230// 0 | 0 | a | a + b231const uint8x16_t shift1 = vextq_u8(zero, sum0, 8);232// a | a + b | a + b + c | a + b + c + d233const uint8x16_t sum1 = vaddq_u8(sum0, shift1);234const uint8x16_t prev = LOADQ_U32_AS_U8(out[i - 1]);235const uint8x16_t res = vaddq_u8(sum1, prev);236STOREQ_U8_AS_U32P(&out[i], res);237}238VP8LPredictorsAdd_C[1](in + i, upper + i, num_pixels - i, out + i);239}240241// Macro that adds 32-bit integers from IN using mod 256 arithmetic242// per 8 bit channel.243#define GENERATE_PREDICTOR_1(X, IN) \244static void PredictorAdd##X##_NEON(const uint32_t* in, \245const uint32_t* upper, int num_pixels, \246uint32_t* out) { \247int i; \248for (i = 0; i + 4 <= num_pixels; i += 4) { \249const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]); \250const uint8x16_t other = LOADQ_U32P_AS_U8(&(IN)); \251const uint8x16_t res = vaddq_u8(src, other); \252STOREQ_U8_AS_U32P(&out[i], res); \253} \254VP8LPredictorsAdd_C[(X)](in + i, upper + i, num_pixels - i, out + i); \255}256// Predictor2: Top.257GENERATE_PREDICTOR_1(2, upper[i])258// Predictor3: Top-right.259GENERATE_PREDICTOR_1(3, upper[i + 1])260// Predictor4: Top-left.261GENERATE_PREDICTOR_1(4, upper[i - 1])262#undef GENERATE_PREDICTOR_1263264// Predictor5: average(average(left, TR), T)265#define DO_PRED5(LANE) do { \266const uint8x16_t avgLTR = vhaddq_u8(L, TR); \267const uint8x16_t avg = vhaddq_u8(avgLTR, T); \268const uint8x16_t res = vaddq_u8(avg, src); \269vst1q_lane_u32(&out[i + (LANE)], vreinterpretq_u32_u8(res), (LANE)); \270L = ROTATE32_LEFT(res); \271} while (0)272273static void PredictorAdd5_NEON(const uint32_t* in, const uint32_t* upper,274int num_pixels, uint32_t* out) {275int i;276uint8x16_t L = LOADQ_U32_AS_U8(out[-1]);277for (i = 0; i + 4 <= num_pixels; i += 4) {278const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]);279const uint8x16_t T = LOADQ_U32P_AS_U8(&upper[i + 0]);280const uint8x16_t TR = LOADQ_U32P_AS_U8(&upper[i + 1]);281DO_PRED5(0);282DO_PRED5(1);283DO_PRED5(2);284DO_PRED5(3);285}286VP8LPredictorsAdd_C[5](in + i, upper + i, num_pixels - i, out + i);287}288#undef DO_PRED5289290#define DO_PRED67(LANE) do { \291const uint8x16_t avg = vhaddq_u8(L, top); \292const uint8x16_t res = vaddq_u8(avg, src); \293vst1q_lane_u32(&out[i + (LANE)], vreinterpretq_u32_u8(res), (LANE)); \294L = ROTATE32_LEFT(res); \295} while (0)296297// Predictor6: average(left, TL)298static void PredictorAdd6_NEON(const uint32_t* in, const uint32_t* upper,299int num_pixels, uint32_t* out) {300int i;301uint8x16_t L = LOADQ_U32_AS_U8(out[-1]);302for (i = 0; i + 4 <= num_pixels; i += 4) {303const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]);304const uint8x16_t top = LOADQ_U32P_AS_U8(&upper[i - 1]);305DO_PRED67(0);306DO_PRED67(1);307DO_PRED67(2);308DO_PRED67(3);309}310VP8LPredictorsAdd_C[6](in + i, upper + i, num_pixels - i, out + i);311}312313// Predictor7: average(left, T)314static void PredictorAdd7_NEON(const uint32_t* in, const uint32_t* upper,315int num_pixels, uint32_t* out) {316int i;317uint8x16_t L = LOADQ_U32_AS_U8(out[-1]);318for (i = 0; i + 4 <= num_pixels; i += 4) {319const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]);320const uint8x16_t top = LOADQ_U32P_AS_U8(&upper[i]);321DO_PRED67(0);322DO_PRED67(1);323DO_PRED67(2);324DO_PRED67(3);325}326VP8LPredictorsAdd_C[7](in + i, upper + i, num_pixels - i, out + i);327}328#undef DO_PRED67329330#define GENERATE_PREDICTOR_2(X, IN) \331static void PredictorAdd##X##_NEON(const uint32_t* in, \332const uint32_t* upper, int num_pixels, \333uint32_t* out) { \334int i; \335for (i = 0; i + 4 <= num_pixels; i += 4) { \336const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]); \337const uint8x16_t Tother = LOADQ_U32P_AS_U8(&(IN)); \338const uint8x16_t T = LOADQ_U32P_AS_U8(&upper[i]); \339const uint8x16_t avg = vhaddq_u8(T, Tother); \340const uint8x16_t res = vaddq_u8(avg, src); \341STOREQ_U8_AS_U32P(&out[i], res); \342} \343VP8LPredictorsAdd_C[(X)](in + i, upper + i, num_pixels - i, out + i); \344}345// Predictor8: average TL T.346GENERATE_PREDICTOR_2(8, upper[i - 1])347// Predictor9: average T TR.348GENERATE_PREDICTOR_2(9, upper[i + 1])349#undef GENERATE_PREDICTOR_2350351// Predictor10: average of (average of (L,TL), average of (T, TR)).352#define DO_PRED10(LANE) do { \353const uint8x16_t avgLTL = vhaddq_u8(L, TL); \354const uint8x16_t avg = vhaddq_u8(avgTTR, avgLTL); \355const uint8x16_t res = vaddq_u8(avg, src); \356vst1q_lane_u32(&out[i + (LANE)], vreinterpretq_u32_u8(res), (LANE)); \357L = ROTATE32_LEFT(res); \358} while (0)359360static void PredictorAdd10_NEON(const uint32_t* in, const uint32_t* upper,361int num_pixels, uint32_t* out) {362int i;363uint8x16_t L = LOADQ_U32_AS_U8(out[-1]);364for (i = 0; i + 4 <= num_pixels; i += 4) {365const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]);366const uint8x16_t TL = LOADQ_U32P_AS_U8(&upper[i - 1]);367const uint8x16_t T = LOADQ_U32P_AS_U8(&upper[i]);368const uint8x16_t TR = LOADQ_U32P_AS_U8(&upper[i + 1]);369const uint8x16_t avgTTR = vhaddq_u8(T, TR);370DO_PRED10(0);371DO_PRED10(1);372DO_PRED10(2);373DO_PRED10(3);374}375VP8LPredictorsAdd_C[10](in + i, upper + i, num_pixels - i, out + i);376}377#undef DO_PRED10378379// Predictor11: select.380#define DO_PRED11(LANE) do { \381const uint8x16_t sumLin = vaddq_u8(L, src); /* in + L */ \382const uint8x16_t pLTL = vabdq_u8(L, TL); /* |L - TL| */ \383const uint16x8_t sum_LTL = vpaddlq_u8(pLTL); \384const uint32x4_t pa = vpaddlq_u16(sum_LTL); \385const uint32x4_t mask = vcleq_u32(pa, pb); \386const uint8x16_t res = vbslq_u8(vreinterpretq_u8_u32(mask), sumTin, sumLin); \387vst1q_lane_u32(&out[i + (LANE)], vreinterpretq_u32_u8(res), (LANE)); \388L = ROTATE32_LEFT(res); \389} while (0)390391static void PredictorAdd11_NEON(const uint32_t* in, const uint32_t* upper,392int num_pixels, uint32_t* out) {393int i;394uint8x16_t L = LOADQ_U32_AS_U8(out[-1]);395for (i = 0; i + 4 <= num_pixels; i += 4) {396const uint8x16_t T = LOADQ_U32P_AS_U8(&upper[i]);397const uint8x16_t TL = LOADQ_U32P_AS_U8(&upper[i - 1]);398const uint8x16_t pTTL = vabdq_u8(T, TL); // |T - TL|399const uint16x8_t sum_TTL = vpaddlq_u8(pTTL);400const uint32x4_t pb = vpaddlq_u16(sum_TTL);401const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]);402const uint8x16_t sumTin = vaddq_u8(T, src); // in + T403DO_PRED11(0);404DO_PRED11(1);405DO_PRED11(2);406DO_PRED11(3);407}408VP8LPredictorsAdd_C[11](in + i, upper + i, num_pixels - i, out + i);409}410#undef DO_PRED11411412// Predictor12: ClampedAddSubtractFull.413#define DO_PRED12(DIFF, LANE) do { \414const uint8x8_t pred = \415vqmovun_s16(vaddq_s16(vreinterpretq_s16_u16(L), (DIFF))); \416const uint8x8_t res = \417vadd_u8(pred, (LANE <= 1) ? vget_low_u8(src) : vget_high_u8(src)); \418const uint16x8_t res16 = vmovl_u8(res); \419vst1_lane_u32(&out[i + (LANE)], vreinterpret_u32_u8(res), (LANE) & 1); \420/* rotate in the left predictor for next iteration */ \421L = vextq_u16(res16, res16, 4); \422} while (0)423424static void PredictorAdd12_NEON(const uint32_t* in, const uint32_t* upper,425int num_pixels, uint32_t* out) {426int i;427uint16x8_t L = vmovl_u8(LOAD_U32_AS_U8(out[-1]));428for (i = 0; i + 4 <= num_pixels; i += 4) {429// load four pixels of source430const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]);431// precompute the difference T - TL once for all, stored as s16432const uint8x16_t TL = LOADQ_U32P_AS_U8(&upper[i - 1]);433const uint8x16_t T = LOADQ_U32P_AS_U8(&upper[i]);434const int16x8_t diff_lo =435vreinterpretq_s16_u16(vsubl_u8(vget_low_u8(T), vget_low_u8(TL)));436const int16x8_t diff_hi =437vreinterpretq_s16_u16(vsubl_u8(vget_high_u8(T), vget_high_u8(TL)));438// loop over the four reconstructed pixels439DO_PRED12(diff_lo, 0);440DO_PRED12(diff_lo, 1);441DO_PRED12(diff_hi, 2);442DO_PRED12(diff_hi, 3);443}444VP8LPredictorsAdd_C[12](in + i, upper + i, num_pixels - i, out + i);445}446#undef DO_PRED12447448// Predictor13: ClampedAddSubtractHalf449#define DO_PRED13(LANE, LOW_OR_HI) do { \450const uint8x16_t avg = vhaddq_u8(L, T); \451const uint8x16_t cmp = vcgtq_u8(TL, avg); \452const uint8x16_t TL_1 = vaddq_u8(TL, cmp); \453/* Compute half of the difference between avg and TL'. */ \454const int8x8_t diff_avg = \455vreinterpret_s8_u8(LOW_OR_HI(vhsubq_u8(avg, TL_1))); \456/* Compute the sum with avg and saturate. */ \457const int16x8_t avg_16 = vreinterpretq_s16_u16(vmovl_u8(LOW_OR_HI(avg))); \458const uint8x8_t delta = vqmovun_s16(vaddw_s8(avg_16, diff_avg)); \459const uint8x8_t res = vadd_u8(LOW_OR_HI(src), delta); \460const uint8x16_t res2 = vcombine_u8(res, res); \461vst1_lane_u32(&out[i + (LANE)], vreinterpret_u32_u8(res), (LANE) & 1); \462L = ROTATE32_LEFT(res2); \463} while (0)464465static void PredictorAdd13_NEON(const uint32_t* in, const uint32_t* upper,466int num_pixels, uint32_t* out) {467int i;468uint8x16_t L = LOADQ_U32_AS_U8(out[-1]);469for (i = 0; i + 4 <= num_pixels; i += 4) {470const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]);471const uint8x16_t T = LOADQ_U32P_AS_U8(&upper[i]);472const uint8x16_t TL = LOADQ_U32P_AS_U8(&upper[i - 1]);473DO_PRED13(0, vget_low_u8);474DO_PRED13(1, vget_low_u8);475DO_PRED13(2, vget_high_u8);476DO_PRED13(3, vget_high_u8);477}478VP8LPredictorsAdd_C[13](in + i, upper + i, num_pixels - i, out + i);479}480#undef DO_PRED13481482#undef LOAD_U32_AS_U8483#undef LOAD_U32P_AS_U8484#undef LOADQ_U32_AS_U8485#undef LOADQ_U32P_AS_U8486#undef GET_U8_AS_U32487#undef GETQ_U8_AS_U32488#undef STOREQ_U8_AS_U32P489#undef ROTATE32_LEFT490491//------------------------------------------------------------------------------492// Subtract-Green Transform493494// vtbl?_u8 are marked unavailable for iOS arm64 with Xcode < 6.3, use495// non-standard versions there.496#if defined(__APPLE__) && defined(__aarch64__) && \497defined(__apple_build_version__) && (__apple_build_version__< 6020037)498#define USE_VTBLQ499#endif500501#ifdef USE_VTBLQ502// 255 = byte will be zeroed503static const uint8_t kGreenShuffle[16] = {5041, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13, 255505};506507static WEBP_INLINE uint8x16_t DoGreenShuffle_NEON(const uint8x16_t argb,508const uint8x16_t shuffle) {509return vcombine_u8(vtbl1q_u8(argb, vget_low_u8(shuffle)),510vtbl1q_u8(argb, vget_high_u8(shuffle)));511}512#else // !USE_VTBLQ513// 255 = byte will be zeroed514static const uint8_t kGreenShuffle[8] = { 1, 255, 1, 255, 5, 255, 5, 255 };515516static WEBP_INLINE uint8x16_t DoGreenShuffle_NEON(const uint8x16_t argb,517const uint8x8_t shuffle) {518return vcombine_u8(vtbl1_u8(vget_low_u8(argb), shuffle),519vtbl1_u8(vget_high_u8(argb), shuffle));520}521#endif // USE_VTBLQ522523static void AddGreenToBlueAndRed_NEON(const uint32_t* src, int num_pixels,524uint32_t* dst) {525const uint32_t* const end = src + (num_pixels & ~3);526#ifdef USE_VTBLQ527const uint8x16_t shuffle = vld1q_u8(kGreenShuffle);528#else529const uint8x8_t shuffle = vld1_u8(kGreenShuffle);530#endif531for (; src < end; src += 4, dst += 4) {532const uint8x16_t argb = vld1q_u8((const uint8_t*)src);533const uint8x16_t greens = DoGreenShuffle_NEON(argb, shuffle);534vst1q_u8((uint8_t*)dst, vaddq_u8(argb, greens));535}536// fallthrough and finish off with plain-C537VP8LAddGreenToBlueAndRed_C(src, num_pixels & 3, dst);538}539540//------------------------------------------------------------------------------541// Color Transform542543static void TransformColorInverse_NEON(const VP8LMultipliers* const m,544const uint32_t* const src,545int num_pixels, uint32_t* dst) {546// sign-extended multiplying constants, pre-shifted by 6.547#define CST(X) (((int16_t)(m->X << 8)) >> 6)548const int16_t rb[8] = {549CST(green_to_blue_), CST(green_to_red_),550CST(green_to_blue_), CST(green_to_red_),551CST(green_to_blue_), CST(green_to_red_),552CST(green_to_blue_), CST(green_to_red_)553};554const int16x8_t mults_rb = vld1q_s16(rb);555const int16_t b2[8] = {5560, CST(red_to_blue_), 0, CST(red_to_blue_),5570, CST(red_to_blue_), 0, CST(red_to_blue_),558};559const int16x8_t mults_b2 = vld1q_s16(b2);560#undef CST561#ifdef USE_VTBLQ562static const uint8_t kg0g0[16] = {563255, 1, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13564};565const uint8x16_t shuffle = vld1q_u8(kg0g0);566#else567static const uint8_t k0g0g[8] = { 255, 1, 255, 1, 255, 5, 255, 5 };568const uint8x8_t shuffle = vld1_u8(k0g0g);569#endif570const uint32x4_t mask_ag = vdupq_n_u32(0xff00ff00u);571int i;572for (i = 0; i + 4 <= num_pixels; i += 4) {573const uint8x16_t in = vld1q_u8((const uint8_t*)(src + i));574const uint32x4_t a0g0 = vandq_u32(vreinterpretq_u32_u8(in), mask_ag);575// 0 g 0 g576const uint8x16_t greens = DoGreenShuffle_NEON(in, shuffle);577// x dr x db1578const int16x8_t A = vqdmulhq_s16(vreinterpretq_s16_u8(greens), mults_rb);579// x r' x b'580const int8x16_t B = vaddq_s8(vreinterpretq_s8_u8(in),581vreinterpretq_s8_s16(A));582// r' 0 b' 0583const int16x8_t C = vshlq_n_s16(vreinterpretq_s16_s8(B), 8);584// x db2 0 0585const int16x8_t D = vqdmulhq_s16(C, mults_b2);586// 0 x db2 0587const uint32x4_t E = vshrq_n_u32(vreinterpretq_u32_s16(D), 8);588// r' x b'' 0589const int8x16_t F = vaddq_s8(vreinterpretq_s8_u32(E),590vreinterpretq_s8_s16(C));591// 0 r' 0 b''592const uint16x8_t G = vshrq_n_u16(vreinterpretq_u16_s8(F), 8);593const uint32x4_t out = vorrq_u32(vreinterpretq_u32_u16(G), a0g0);594vst1q_u32(dst + i, out);595}596// Fall-back to C-version for left-overs.597VP8LTransformColorInverse_C(m, src + i, num_pixels - i, dst + i);598}599600#undef USE_VTBLQ601602//------------------------------------------------------------------------------603// Entry point604605extern void VP8LDspInitNEON(void);606607WEBP_TSAN_IGNORE_FUNCTION void VP8LDspInitNEON(void) {608VP8LPredictors[5] = Predictor5_NEON;609VP8LPredictors[6] = Predictor6_NEON;610VP8LPredictors[7] = Predictor7_NEON;611VP8LPredictors[13] = Predictor13_NEON;612613VP8LPredictorsAdd[0] = PredictorAdd0_NEON;614VP8LPredictorsAdd[1] = PredictorAdd1_NEON;615VP8LPredictorsAdd[2] = PredictorAdd2_NEON;616VP8LPredictorsAdd[3] = PredictorAdd3_NEON;617VP8LPredictorsAdd[4] = PredictorAdd4_NEON;618VP8LPredictorsAdd[5] = PredictorAdd5_NEON;619VP8LPredictorsAdd[6] = PredictorAdd6_NEON;620VP8LPredictorsAdd[7] = PredictorAdd7_NEON;621VP8LPredictorsAdd[8] = PredictorAdd8_NEON;622VP8LPredictorsAdd[9] = PredictorAdd9_NEON;623VP8LPredictorsAdd[10] = PredictorAdd10_NEON;624VP8LPredictorsAdd[11] = PredictorAdd11_NEON;625VP8LPredictorsAdd[12] = PredictorAdd12_NEON;626VP8LPredictorsAdd[13] = PredictorAdd13_NEON;627628VP8LConvertBGRAToRGBA = ConvertBGRAToRGBA_NEON;629VP8LConvertBGRAToBGR = ConvertBGRAToBGR_NEON;630VP8LConvertBGRAToRGB = ConvertBGRAToRGB_NEON;631632VP8LAddGreenToBlueAndRed = AddGreenToBlueAndRed_NEON;633VP8LTransformColorInverse = TransformColorInverse_NEON;634}635636#else // !WEBP_USE_NEON637638WEBP_DSP_INIT_STUB(VP8LDspInitNEON)639640#endif // WEBP_USE_NEON641642643