mirror of https://git.ffmpeg.org/ffmpeg.git
lavc/audiodsp: properly unroll vector_clipf
Given that source and destination can alias, the compiler was forced to perform each read-modify-write sequentially. We cannot use the `restrict` qualifier to avoid this here because the AC-3 encoder uses the function in-place. Instead this commit provides an explicit guarantee to the compiler that batches of 8 elements will not overlap, so that it can interleave calculations. In practice contemporary optimising compilers are able to unroll and keep the temporary array in FPU registers (without spilling). On SiFive-U74, this speeds the same signs branch by 4x, and the opposite signs branch 1.5x.
This commit is contained in:
parent
d527d23872
commit
d86b6767ce
|
@ -38,41 +38,35 @@ static inline float clipf_c_one(float a, uint32_t mini,
|
||||||
static void vector_clipf_c_opposite_sign(float *dst, const float *src,
|
static void vector_clipf_c_opposite_sign(float *dst, const float *src,
|
||||||
float min, float max, int len)
|
float min, float max, int len)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
uint32_t mini = av_float2int(min);
|
uint32_t mini = av_float2int(min);
|
||||||
uint32_t maxi = av_float2int(max);
|
uint32_t maxi = av_float2int(max);
|
||||||
uint32_t maxisign = maxi ^ (1U << 31);
|
uint32_t maxisign = maxi ^ (1U << 31);
|
||||||
|
|
||||||
for (i = 0; i < len; i += 8) {
|
for (int i = 0; i < len; i += 8) {
|
||||||
dst[i + 0] = clipf_c_one(src[i + 0], mini, maxi, maxisign);
|
float tmp[8];
|
||||||
dst[i + 1] = clipf_c_one(src[i + 1], mini, maxi, maxisign);
|
|
||||||
dst[i + 2] = clipf_c_one(src[i + 2], mini, maxi, maxisign);
|
for (int j = 0; j < 8; j++)
|
||||||
dst[i + 3] = clipf_c_one(src[i + 3], mini, maxi, maxisign);
|
tmp[j]= clipf_c_one(src[i + j], mini, maxi, maxisign);
|
||||||
dst[i + 4] = clipf_c_one(src[i + 4], mini, maxi, maxisign);
|
for (int j = 0; j < 8; j++)
|
||||||
dst[i + 5] = clipf_c_one(src[i + 5], mini, maxi, maxisign);
|
dst[i + j] = tmp[j];
|
||||||
dst[i + 6] = clipf_c_one(src[i + 6], mini, maxi, maxisign);
|
|
||||||
dst[i + 7] = clipf_c_one(src[i + 7], mini, maxi, maxisign);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vector_clipf_c(float *dst, const float *src, int len,
|
static void vector_clipf_c(float *dst, const float *src, int len,
|
||||||
float min, float max)
|
float min, float max)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
if (min < 0 && max > 0) {
|
if (min < 0 && max > 0) {
|
||||||
vector_clipf_c_opposite_sign(dst, src, min, max, len);
|
vector_clipf_c_opposite_sign(dst, src, min, max, len);
|
||||||
} else {
|
return;
|
||||||
for (i = 0; i < len; i += 8) {
|
}
|
||||||
dst[i] = av_clipf(src[i], min, max);
|
|
||||||
dst[i + 1] = av_clipf(src[i + 1], min, max);
|
for (int i = 0; i < len; i += 8) {
|
||||||
dst[i + 2] = av_clipf(src[i + 2], min, max);
|
float tmp[8];
|
||||||
dst[i + 3] = av_clipf(src[i + 3], min, max);
|
|
||||||
dst[i + 4] = av_clipf(src[i + 4], min, max);
|
for (int j = 0; j < 8; j++)
|
||||||
dst[i + 5] = av_clipf(src[i + 5], min, max);
|
tmp[j]= av_clipf(src[i + j], min, max);
|
||||||
dst[i + 6] = av_clipf(src[i + 6], min, max);
|
for (int j = 0; j < 8; j++)
|
||||||
dst[i + 7] = av_clipf(src[i + 7], min, max);
|
dst[i + j] = tmp[j];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue