* [FFmpeg-devel] [PATCH] lavc/aacpsdsp: precompute constant factors
@ 2022-09-20 17:42 remi
0 siblings, 0 replies; only message in thread
From: remi @ 2022-09-20 17:42 UTC (permalink / raw)
To: ffmpeg-devel
From: Rémi Denis-Courmont <remi@remlab.net>
The input complex factors are constant for each iterations. This
substitudes 4 loads, 2 additions and 2 subtractions per iteration of
the inner-loop with another 4 loads. Thus effectively 4 arithmetic
operations per iteration of the inner loop are avoided, i.e. 24
operations per iteration of the outer loop, or 24 * (n - 1) operations
in total.
If the inner loop is not unrolled by the compiler, this also might
also save some pointer arithmetic as most instruction sets do not
have addressing modes with negated register offsets (12 - j). Unless
the compiler is optimising for code size, this is unlikely though.
---
libavcodec/aacpsdsp_template.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/libavcodec/aacpsdsp_template.c b/libavcodec/aacpsdsp_template.c
index 31ff718420..c063788b89 100644
--- a/libavcodec/aacpsdsp_template.c
+++ b/libavcodec/aacpsdsp_template.c
@@ -47,21 +47,24 @@ static void ps_hybrid_analysis_c(INTFLOAT (*out)[2], INTFLOAT (*in)[2],
const INTFLOAT (*filter)[8][2],
ptrdiff_t stride, int n)
{
- int i, j;
+ INT64FLOAT inre0[6], inre1[6], inim0[6], inim1[6];
- for (i = 0; i < n; i++) {
+ for (int j = 0; j < 6; j++) {
+ inre0[j] = in[j][0] + in[12 - j][0];
+ inre1[j] = in[j][1] - in[12 - j][1];
+ inim0[j] = in[j][1] + in[12 - j][1];
+ inim1[j] = in[j][0] - in[12 - j][0];
+ }
+
+ for (int i = 0; i < n; i++) {
INT64FLOAT sum_re = (INT64FLOAT)filter[i][6][0] * in[6][0];
INT64FLOAT sum_im = (INT64FLOAT)filter[i][6][0] * in[6][1];
- for (j = 0; j < 6; j++) {
- INT64FLOAT in0_re = in[j][0];
- INT64FLOAT in0_im = in[j][1];
- INT64FLOAT in1_re = in[12-j][0];
- INT64FLOAT in1_im = in[12-j][1];
- sum_re += (INT64FLOAT)filter[i][j][0] * (in0_re + in1_re) -
- (INT64FLOAT)filter[i][j][1] * (in0_im - in1_im);
- sum_im += (INT64FLOAT)filter[i][j][0] * (in0_im + in1_im) +
- (INT64FLOAT)filter[i][j][1] * (in0_re - in1_re);
+ for (int j = 0; j < 6; j++) {
+ sum_re += (INT64FLOAT)filter[i][j][0] * inre0[j] -
+ (INT64FLOAT)filter[i][j][1] * inre1[j];
+ sum_im += (INT64FLOAT)filter[i][j][0] * inim0[j] +
+ (INT64FLOAT)filter[i][j][1] * inim1[j];
}
#if USE_FIXED
out[i * stride][0] = (int)((sum_re + 0x40000000) >> 31);
--
2.37.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-09-20 17:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20 17:42 [FFmpeg-devel] [PATCH] lavc/aacpsdsp: precompute constant factors remi
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git