From 27a529f48ebe346fdfb2ce4c38159a465c3594cf Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Mon, 31 Mar 2025 16:26:55 +0200
Subject: [PATCH 03/12] postproc/postprocess_template: Use immediate instead of
 memory load

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libpostproc/postprocess.c                  | 5 ++---
 libpostproc/postprocess_altivec_template.c | 2 +-
 libpostproc/postprocess_template.c         | 6 +++---
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/libpostproc/postprocess.c b/libpostproc/postprocess.c
index fd74f5c72c..0223bab548 100644
--- a/libpostproc/postprocess.c
+++ b/libpostproc/postprocess.c
@@ -95,6 +95,8 @@ try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks
 #define TEMP_STRIDE 8
 //#define NUM_BLOCKS_AT_ONCE 16 //not used yet
 
+#define DERING_THRESHOLD 20
+
 #if ARCH_X86 && HAVE_INLINE_ASM
 DECLARE_ASM_CONST(8, uint64_t, w05)= 0x0005000500050005LL;
 DECLARE_ASM_CONST(8, uint64_t, w04)= 0x0004000400040004LL;
@@ -105,9 +107,6 @@ DECLARE_ASM_CONST(8, uint64_t, b08)= 0x0808080808080808LL;
 DECLARE_ASM_CONST(8, uint64_t, b80)= 0x8080808080808080LL;
 #endif
 
-DECLARE_ASM_CONST(8, int, deringThreshold)= 20;
-
-
 static const struct PPFilter filters[]=
 {
     {"hb", "hdeblock",              1, 1, 3, H_DEBLOCK},
diff --git a/libpostproc/postprocess_altivec_template.c b/libpostproc/postprocess_altivec_template.c
index a9d4cd29a3..827d6300e5 100644
--- a/libpostproc/postprocess_altivec_template.c
+++ b/libpostproc/postprocess_altivec_template.c
@@ -573,7 +573,7 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) {
     src & stride :-(
     */
     uint8_t *srcCopy = src;
-    DECLARE_ALIGNED(16, uint8_t, dt)[16] = { deringThreshold };
+    DECLARE_ALIGNED(16, uint8_t, dt)[16] = { DERING_THRESHOLD };
     const vector signed int zero = vec_splat_s32(0);
     vector unsigned char v_dt = vec_splat(vec_ld(0, dt), 0);
 
diff --git a/libpostproc/postprocess_template.c b/libpostproc/postprocess_template.c
index 1fa4123896..f0e3c50d88 100644
--- a/libpostproc/postprocess_template.c
+++ b/libpostproc/postprocess_template.c
@@ -888,7 +888,7 @@ FIND_MIN_MAX((%0, %1, 8))
         "psubb %%mm7, %%mm6                     \n\t" // max - min
         "push %%"FF_REG_a"                      \n\t"
         "movd %%mm6, %%eax                      \n\t"
-        "cmpb "MANGLE(deringThreshold)", %%al   \n\t"
+        "cmpb $"AV_STRINGIFY(DERING_THRESHOLD)", %%al   \n\t"
         "pop %%"FF_REG_a"                       \n\t"
         " jb 1f                                 \n\t"
         PAVGB(%%mm0, %%mm7)                           // a=(max + min)/2
@@ -1017,7 +1017,7 @@ DERING_CORE((%0, %1, 8)       ,(%%FF_REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,
 
         "1:                        \n\t"
         : : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb), "m"(c->pQPb2), "q"(tmp)
-          NAMED_CONSTRAINTS_ADD(deringThreshold,b00,b08)
+          NAMED_CONSTRAINTS_ADD(b00,b08)
         : "%"FF_REG_a, "%"FF_REG_d
     );
 #else // HAVE_7REGS && TEMPLATE_PP_MMXEXT
@@ -1041,7 +1041,7 @@ DERING_CORE((%0, %1, 8)       ,(%%FF_REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,
     }
     avg= (min + max + 1)>>1;
 
-    if(max - min <deringThreshold) return;
+    if (max - min < DERING_THRESHOLD) return;
 
     for(y=0; y<10; y++){
         int t = 0;
-- 
2.45.2