// Copyright 2014 Google Inc. All Rights Reserved. // // Use of this source code is governed by a BSD-style license // that can be found in the COPYING file in the root of the source // tree. An additional intellectual property rights grant can be found // in the file PATENTS. All contributing project authors may // be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // NEON variant of methods for lossless decoder // // Author: Skal (pascal.massimino@gmail.com)
// Predictor0: ARGB_BLACK. staticvoid PredictorAdd0_NEON(const uint32_t* in, const uint32_t* upper, int num_pixels, uint32_t* WEBP_RESTRICT out) { int i; const uint8x16_t black = vreinterpretq_u8_u32(vdupq_n_u32(ARGB_BLACK)); for (i = 0; i + 4 <= num_pixels; i += 4) { const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]); const uint8x16_t res = vaddq_u8(src, black);
STOREQ_U8_AS_U32P(&out[i], res);
}
VP8LPredictorsAdd_C[0](in + i, upper + i, num_pixels - i, out + i);
}
// Predictor1: left. staticvoid PredictorAdd1_NEON(const uint32_t* in, const uint32_t* upper, int num_pixels, uint32_t* WEBP_RESTRICT out) { int i; const uint8x16_t zero = LOADQ_U32_AS_U8(0); for (i = 0; i + 4 <= num_pixels; i += 4) { // a | b | c | d const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]); // 0 | a | b | c const uint8x16_t shift0 = vextq_u8(zero, src, 12); // a | a + b | b + c | c + d const uint8x16_t sum0 = vaddq_u8(src, shift0); // 0 | 0 | a | a + b const uint8x16_t shift1 = vextq_u8(zero, sum0, 8); // a | a + b | a + b + c | a + b + c + d const uint8x16_t sum1 = vaddq_u8(sum0, shift1); const uint8x16_t prev = LOADQ_U32_AS_U8(out[i - 1]); const uint8x16_t res = vaddq_u8(sum1, prev);
STOREQ_U8_AS_U32P(&out[i], res);
}
VP8LPredictorsAdd_C[1](in + i, upper + i, num_pixels - i, out + i);
}
// Macro that adds 32-bit integers from IN using mod 256 arithmetic // per 8 bit channel. #define GENERATE_PREDICTOR_1(X, IN) \ staticvoid PredictorAdd##X##_NEON(const uint32_t* in, \ const uint32_t* upper, int num_pixels, \
uint32_t* WEBP_RESTRICT out) { \ int i; \ for (i = 0; i + 4 <= num_pixels; i += 4) { \ const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]); \ const uint8x16_t other = LOADQ_U32P_AS_U8(&(IN)); \ const uint8x16_t res = vaddq_u8(src, other); \
STOREQ_U8_AS_U32P(&out[i], res); \
} \
VP8LPredictorsAdd_C[(X)](in + i, upper + i, num_pixels - i, out + i); \
} // Predictor2: Top.
GENERATE_PREDICTOR_1(2, upper[i]) // Predictor3: Top-right.
GENERATE_PREDICTOR_1(3, upper[i + 1]) // Predictor4: Top-left.
GENERATE_PREDICTOR_1(4, upper[i - 1]) #undef GENERATE_PREDICTOR_1
staticvoid PredictorAdd11_NEON(const uint32_t* in, const uint32_t* upper, int num_pixels, uint32_t* WEBP_RESTRICT out) { int i;
uint8x16_t L = LOADQ_U32_AS_U8(out[-1]); for (i = 0; i + 4 <= num_pixels; i += 4) { const uint8x16_t T = LOADQ_U32P_AS_U8(&upper[i]); const uint8x16_t TL = LOADQ_U32P_AS_U8(&upper[i - 1]); const uint8x16_t pTTL = vabdq_u8(T, TL); // |T - TL| const uint16x8_t sum_TTL = vpaddlq_u8(pTTL); const uint32x4_t pb = vpaddlq_u16(sum_TTL); const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]); const uint8x16_t sumTin = vaddq_u8(T, src); // in + T
DO_PRED11(0);
DO_PRED11(1);
DO_PRED11(2);
DO_PRED11(3);
}
VP8LPredictorsAdd_C[11](in + i, upper + i, num_pixels - i, out + i);
} #undef DO_PRED11
// Predictor12: ClampedAddSubtractFull. #define DO_PRED12(DIFF, LANE) do { \ const uint8x8_t pred = \
vqmovun_s16(vaddq_s16(vreinterpretq_s16_u16(L), (DIFF))); \ const uint8x8_t res = \
vadd_u8(pred, (LANE <= 1) ? vget_low_u8(src) : vget_high_u8(src)); \ const uint16x8_t res16 = vmovl_u8(res); \
vst1_lane_u32(&out[i + (LANE)], vreinterpret_u32_u8(res), (LANE) & 1); \ /* rotate in the left predictor for next iteration */ \
L = vextq_u16(res16, res16, 4); \
} while (0)
staticvoid PredictorAdd12_NEON(const uint32_t* in, const uint32_t* upper, int num_pixels, uint32_t* WEBP_RESTRICT out) { int i;
uint16x8_t L = vmovl_u8(LOAD_U32_AS_U8(out[-1])); for (i = 0; i + 4 <= num_pixels; i += 4) { // load four pixels of source const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]); // precompute the difference T - TL once for all, stored as s16 const uint8x16_t TL = LOADQ_U32P_AS_U8(&upper[i - 1]); const uint8x16_t T = LOADQ_U32P_AS_U8(&upper[i]); const int16x8_t diff_lo =
vreinterpretq_s16_u16(vsubl_u8(vget_low_u8(T), vget_low_u8(TL))); const int16x8_t diff_hi =
vreinterpretq_s16_u16(vsubl_u8(vget_high_u8(T), vget_high_u8(TL))); // loop over the four reconstructed pixels
DO_PRED12(diff_lo, 0);
DO_PRED12(diff_lo, 1);
DO_PRED12(diff_hi, 2);
DO_PRED12(diff_hi, 3);
}
VP8LPredictorsAdd_C[12](in + i, upper + i, num_pixels - i, out + i);
} #undef DO_PRED12
// Predictor13: ClampedAddSubtractHalf #define DO_PRED13(LANE, LOW_OR_HI) do { \ const uint8x16_t avg = vhaddq_u8(L, T); \ const uint8x16_t cmp = vcgtq_u8(TL, avg); \ const uint8x16_t TL_1 = vaddq_u8(TL, cmp); \ /* Compute half of the difference between avg and TL'. */ \ const int8x8_t diff_avg = \
vreinterpret_s8_u8(LOW_OR_HI(vhsubq_u8(avg, TL_1))); \ /* Compute the sum with avg and saturate. */ \ const int16x8_t avg_16 = vreinterpretq_s16_u16(vmovl_u8(LOW_OR_HI(avg))); \ const uint8x8_t delta = vqmovun_s16(vaddw_s8(avg_16, diff_avg)); \ const uint8x8_t res = vadd_u8(LOW_OR_HI(src), delta); \ const uint8x16_t res2 = vcombine_u8(res, res); \
vst1_lane_u32(&out[i + (LANE)], vreinterpret_u32_u8(res), (LANE) & 1); \
L = ROTATE32_LEFT(res2); \
} while (0)
staticvoid PredictorAdd13_NEON(const uint32_t* in, const uint32_t* upper, int num_pixels, uint32_t* WEBP_RESTRICT out) { int i;
uint8x16_t L = LOADQ_U32_AS_U8(out[-1]); for (i = 0; i + 4 <= num_pixels; i += 4) { const uint8x16_t src = LOADQ_U32P_AS_U8(&in[i]); const uint8x16_t T = LOADQ_U32P_AS_U8(&upper[i]); const uint8x16_t TL = LOADQ_U32P_AS_U8(&upper[i - 1]);
DO_PRED13(0, vget_low_u8);
DO_PRED13(1, vget_low_u8);
DO_PRED13(2, vget_high_u8);
DO_PRED13(3, vget_high_u8);
}
VP8LPredictorsAdd_C[13](in + i, upper + i, num_pixels - i, out + i);
} #undef DO_PRED13
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.