On 11/26/26 17:53, Peder Bergan via B4 Relay wrote:
From: Peder Bergan <[email protected]>

Reed-Solomon error correction reduces the sum of two GF(256) exponents
modulo 255 for each generator coefficient. Both exponents are below
255, so the sum needs at most one subtraction.

Use a conditional subtraction for the reduction. In the x86-64
userspace benchmark, this replaces a multiply-and-shift sequence with
a comparison and conditional moves. On top of the first two patches,
the change saved about 32 us per version-40 encode with raw input and
31 us with a URL.

Thanks for your contribution.
This code is executed only once when a panic occurs, so optimizations are clearly not a priority.
But this series looks good, and keep the code simple.

Reviewed-by: Jocelyn Falempe <[email protected]>

Signed-off-by: Peder Bergan <[email protected]>
---
  drivers/gpu/drm/drm_panic_helper_qr.rs | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_panic_helper_qr.rs 
b/drivers/gpu/drm/drm_panic_helper_qr.rs
index 1d96ae855052a..4ba2e3de5a6b6 100644
--- a/drivers/gpu/drm/drm_panic_helper_qr.rs
+++ b/drivers/gpu/drm/drm_panic_helper_qr.rs
@@ -569,7 +569,10 @@ fn error_code_for_blocks(&mut self, offset: usize, size: 
usize, ec_offset: usize
              }
              let log_lead_coeff = usize::from(LOG_TABLE[lead_coeff]);
              for (u, &v) in tmp[i + 1..].iter_mut().zip(self.poly.iter()) {
-                *u ^= EXP_TABLE[(usize::from(v) + log_lead_coeff) % 255];
+                // Both exponents are below 255, so at most one subtraction is 
needed.
+                let sum = usize::from(v) + log_lead_coeff;
+                let index = if sum >= 255 { sum - 255 } else { sum };
+                *u ^= EXP_TABLE[index];
              }
          }
          self.data[ec_offset..ec_offset + self.ec_size]


Reply via email to