[PATCH 3/3] drm/panic: Simplify QR error correction exponent reduction

From: Peder Bergan via B4 Relay

Date: Thu Nov 26 2026 - 11:53:40 EST


From: Peder Bergan <peder.bergan@xxxxxxxxx>

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.

Signed-off-by: Peder Bergan <peder.bergan@xxxxxxxxx>
---
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]

--
2.56.1