Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: remi@remlab.net
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] lavc/aacpsdsp: precompute constant factors
Date: Tue, 20 Sep 2022 20:42:13 +0300
Message-ID: <20220920174213.35055-1-remi@remlab.net> (raw)

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".

                 reply	other threads:[~2022-09-20 17:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220920174213.35055-1-remi@remlab.net \
    --to=remi@remlab.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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