/* * Copyright (c) 2017, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/ #include <arm_neon.h>
// Load half of a vector and duplicated in other half staticinline uint8x8_t vldh_dup_u8(const uint8_t *ptr) { return vreinterpret_u8_u32(vld1_dup_u32((const uint32_t *)ptr));
}
// Store half of a vector. staticinlinevoid vsth_u16(uint16_t *ptr, uint16x4_t val) {
vst1_lane_u32((uint32_t *)ptr, vreinterpret_u32_u16(val), 0);
}
// Store half of a vector. staticinlinevoid vsth_u8(uint8_t *ptr, uint8x8_t val) {
vst1_lane_u32((uint32_t *)ptr, vreinterpret_u32_u8(val), 0);
}
staticvoid cfl_luma_subsampling_420_lbd_neon(const uint8_t *input, int input_stride,
uint16_t *pred_buf_q3, int width, int height) { const uint16_t *end = pred_buf_q3 + (height >> 1) * CFL_BUF_LINE; constint luma_stride = input_stride << 1; do { if (width == 4) { const uint16x4_t top = vpaddl_u8(vldh_dup_u8(input)); const uint16x4_t sum = vpadal_u8(top, vldh_dup_u8(input + input_stride));
vsth_u16(pred_buf_q3, vshl_n_u16(sum, 1));
} elseif (width == 8) { const uint16x4_t top = vpaddl_u8(vld1_u8(input)); const uint16x4_t sum = vpadal_u8(top, vld1_u8(input + input_stride));
vst1_u16(pred_buf_q3, vshl_n_u16(sum, 1));
} elseif (width == 16) { const uint16x8_t top = vpaddlq_u8(vld1q_u8(input)); const uint16x8_t sum = vpadalq_u8(top, vld1q_u8(input + input_stride));
vst1q_u16(pred_buf_q3, vshlq_n_u16(sum, 1));
} else { const uint8x8x4_t top = vld4_u8(input); const uint8x8x4_t bot = vld4_u8(input + input_stride); // equivalent to a vpaddlq_u8 (because vld4q interleaves) const uint16x8_t top_0 = vaddl_u8(top.val[0], top.val[1]); // equivalent to a vpaddlq_u8 (because vld4q interleaves) const uint16x8_t bot_0 = vaddl_u8(bot.val[0], bot.val[1]); // equivalent to a vpaddlq_u8 (because vld4q interleaves) const uint16x8_t top_1 = vaddl_u8(top.val[2], top.val[3]); // equivalent to a vpaddlq_u8 (because vld4q interleaves) const uint16x8_t bot_1 = vaddl_u8(bot.val[2], bot.val[3]);
uint16x8x2_t sum;
sum.val[0] = vshlq_n_u16(vaddq_u16(top_0, bot_0), 1);
sum.val[1] = vshlq_n_u16(vaddq_u16(top_1, bot_1), 1);
vst2q_u16(pred_buf_q3, sum);
}
input += luma_stride;
} while ((pred_buf_q3 += CFL_BUF_LINE) < end);
}
staticvoid cfl_luma_subsampling_422_lbd_neon(const uint8_t *input, int input_stride,
uint16_t *pred_buf_q3, int width, int height) { const uint16_t *end = pred_buf_q3 + height * CFL_BUF_LINE; do { if (width == 4) { const uint16x4_t top = vpaddl_u8(vldh_dup_u8(input));
vsth_u16(pred_buf_q3, vshl_n_u16(top, 2));
} elseif (width == 8) { const uint16x4_t top = vpaddl_u8(vld1_u8(input));
vst1_u16(pred_buf_q3, vshl_n_u16(top, 2));
} elseif (width == 16) { const uint16x8_t top = vpaddlq_u8(vld1q_u8(input));
vst1q_u16(pred_buf_q3, vshlq_n_u16(top, 2));
} else { const uint8x8x4_t top = vld4_u8(input);
uint16x8x2_t sum; // vaddl_u8 is equivalent to a vpaddlq_u8 (because vld4q interleaves)
sum.val[0] = vshlq_n_u16(vaddl_u8(top.val[0], top.val[1]), 2);
sum.val[1] = vshlq_n_u16(vaddl_u8(top.val[2], top.val[3]), 2);
vst2q_u16(pred_buf_q3, sum);
}
input += input_stride;
} while ((pred_buf_q3 += CFL_BUF_LINE) < end);
}
// Permute and add in such a way that each lane contains the block sum. // [A+C+B+D, B+D+A+C, C+A+D+B, D+B+C+A] #if AOM_ARCH_AARCH64
sum_32x4 = vpaddq_u32(sum_32x4, sum_32x4);
sum_32x4 = vpaddq_u32(sum_32x4, sum_32x4); #else
uint32x4_t flip =
vcombine_u32(vget_high_u32(sum_32x4), vget_low_u32(sum_32x4));
sum_32x4 = vaddq_u32(sum_32x4, flip);
sum_32x4 = vaddq_u32(sum_32x4, vrev64q_u32(sum_32x4)); #endif
// Computing the average could be done using scalars, but getting off the NEON // engine introduces latency, so we use vqrshrn.
int16x4_t avg_16x4; // Constant propagation makes for some ugly code. switch (num_pel_log2) { case 4: avg_16x4 = vreinterpret_s16_u16(vqrshrn_n_u32(sum_32x4, 4)); break; case 5: avg_16x4 = vreinterpret_s16_u16(vqrshrn_n_u32(sum_32x4, 5)); break; case 6: avg_16x4 = vreinterpret_s16_u16(vqrshrn_n_u32(sum_32x4, 6)); break; case 7: avg_16x4 = vreinterpret_s16_u16(vqrshrn_n_u32(sum_32x4, 7)); break; case 8: avg_16x4 = vreinterpret_s16_u16(vqrshrn_n_u32(sum_32x4, 8)); break; case 9: avg_16x4 = vreinterpret_s16_u16(vqrshrn_n_u32(sum_32x4, 9)); break; case 10:
avg_16x4 = vreinterpret_s16_u16(vqrshrn_n_u32(sum_32x4, 10)); break; default: assert(0);
}
// Saturating negate 16-bit integers in a when the corresponding signed 16-bit // integer in b is negative. // Notes: // * Negating INT16_MIN results in INT16_MIN. However, this cannot occur in // practice, as scaled_luma is the multiplication of two absolute values. // * In the Intel equivalent, elements in a are zeroed out when the // corresponding elements in b are zero. Because vsign is used twice in a // row, with b in the first call becoming a in the second call, there's no // impact from not zeroing out. static int16x4_t vsign_s16(int16x4_t a, int16x4_t b) { const int16x4_t mask = vshr_n_s16(b, 15); return veor_s16(vadd_s16(a, mask), mask);
}
// Saturating negate 16-bit integers in a when the corresponding signed 16-bit // integer in b is negative. // Notes: // * Negating INT16_MIN results in INT16_MIN. However, this cannot occur in // practice, as scaled_luma is the multiplication of two absolute values. // * In the Intel equivalent, elements in a are zeroed out when the // corresponding elements in b are zero. Because vsignq is used twice in a // row, with b in the first call becoming a in the second call, there's no // impact from not zeroing out. static int16x8_t vsignq_s16(int16x8_t a, int16x8_t b) { const int16x8_t mask = vshrq_n_s16(b, 15); return veorq_s16(vaddq_s16(a, mask), mask);
}
staticinline int16x8x2_t predict_w16(const int16_t *pred_buf_q3,
int16x8_t alpha_sign, int abs_alpha_q12,
int16x8_t dc) { // vld2q_s16 interleaves, which is not useful for prediction. vst1q_s16_x2 // does not interleave, but is not currently available in the compilier used // by the AOM build system. const int16x8x2_t ac_q3 = vld2q_s16(pred_buf_q3); const int16x8_t ac_sign_0 = veorq_s16(alpha_sign, ac_q3.val[0]); const int16x8_t ac_sign_1 = veorq_s16(alpha_sign, ac_q3.val[1]); const int16x8_t scaled_luma_0 =
vqrdmulhq_n_s16(vabsq_s16(ac_q3.val[0]), abs_alpha_q12); const int16x8_t scaled_luma_1 =
vqrdmulhq_n_s16(vabsq_s16(ac_q3.val[1]), abs_alpha_q12);
int16x8x2_t result;
result.val[0] = vaddq_s16(vsignq_s16(scaled_luma_0, ac_sign_0), dc);
result.val[1] = vaddq_s16(vsignq_s16(scaled_luma_1, ac_sign_1), dc); return result;
}
staticinline int16x8x4_t predict_w32(const int16_t *pred_buf_q3,
int16x8_t alpha_sign, int abs_alpha_q12,
int16x8_t dc) { // vld4q_s16 interleaves, which is not useful for prediction. vst1q_s16_x4 // does not interleave, but is not currently available in the compilier used // by the AOM build system. const int16x8x4_t ac_q3 = vld4q_s16(pred_buf_q3); const int16x8_t ac_sign_0 = veorq_s16(alpha_sign, ac_q3.val[0]); const int16x8_t ac_sign_1 = veorq_s16(alpha_sign, ac_q3.val[1]); const int16x8_t ac_sign_2 = veorq_s16(alpha_sign, ac_q3.val[2]); const int16x8_t ac_sign_3 = veorq_s16(alpha_sign, ac_q3.val[3]); const int16x8_t scaled_luma_0 =
vqrdmulhq_n_s16(vabsq_s16(ac_q3.val[0]), abs_alpha_q12); const int16x8_t scaled_luma_1 =
vqrdmulhq_n_s16(vabsq_s16(ac_q3.val[1]), abs_alpha_q12); const int16x8_t scaled_luma_2 =
vqrdmulhq_n_s16(vabsq_s16(ac_q3.val[2]), abs_alpha_q12); const int16x8_t scaled_luma_3 =
vqrdmulhq_n_s16(vabsq_s16(ac_q3.val[3]), abs_alpha_q12);
int16x8x4_t result;
result.val[0] = vaddq_s16(vsignq_s16(scaled_luma_0, ac_sign_0), dc);
result.val[1] = vaddq_s16(vsignq_s16(scaled_luma_1, ac_sign_1), dc);
result.val[2] = vaddq_s16(vsignq_s16(scaled_luma_2, ac_sign_2), dc);
result.val[3] = vaddq_s16(vsignq_s16(scaled_luma_3, ac_sign_3), dc); return result;
}
staticinlinevoid cfl_predict_lbd_neon(const int16_t *pred_buf_q3,
uint8_t *dst, int dst_stride, int alpha_q3, int width, int height) { const int16_t abs_alpha_q12 = abs(alpha_q3) << 9; const int16_t *const end = pred_buf_q3 + height * CFL_BUF_LINE; if (width == 4) { const int16x4_t alpha_sign = vdup_n_s16(alpha_q3); const int16x4_t dc = vdup_n_s16(*dst); do { const int16x4_t pred =
predict_w4(pred_buf_q3, alpha_sign, abs_alpha_q12, dc);
vsth_u8(dst, vqmovun_s16(vcombine_s16(pred, pred)));
dst += dst_stride;
} while ((pred_buf_q3 += CFL_BUF_LINE) < end);
} else { const int16x8_t alpha_sign = vdupq_n_s16(alpha_q3); const int16x8_t dc = vdupq_n_s16(*dst); do { if (width == 8) {
vst1_u8(dst, vqmovun_s16(predict_w8(pred_buf_q3, alpha_sign,
abs_alpha_q12, dc)));
} elseif (width == 16) { const int16x8x2_t pred =
predict_w16(pred_buf_q3, alpha_sign, abs_alpha_q12, dc); const uint8x8x2_t predun = { { vqmovun_s16(pred.val[0]),
vqmovun_s16(pred.val[1]) } };
vst2_u8(dst, predun);
} else { const int16x8x4_t pred =
predict_w32(pred_buf_q3, alpha_sign, abs_alpha_q12, dc); const uint8x8x4_t predun = {
{ vqmovun_s16(pred.val[0]), vqmovun_s16(pred.val[1]),
vqmovun_s16(pred.val[2]), vqmovun_s16(pred.val[3]) }
};
vst4_u8(dst, predun);
}
dst += dst_stride;
} while ((pred_buf_q3 += CFL_BUF_LINE) < end);
}
}
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.