Skip to contentSkip to conversation

drm/panic: reconsider manual div_by_10 implementation in drm_panic_qr.rs

RFC max graey 1 participant 1 message Apr 5 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 814c998c-e63e-4a33-b152-4f3b8ed6dae2@Spark

max graey

author
#1 lore raw

Hi,

while looking at drivers/gpu/drm/drm_panic_qr.rs, I noticed that div10() uses special manual implementation for 32-bit ARM. As far as I understand, this was introduced due to older LLVM behavior, where 64-bit division on 32-bit targets could lower into a call to __aeabi_uldivmod, which in this context could lead to a panic.

Reference:
https://github.com/MatthewCroughan/linux/commit/33429daec773809c01be492b46a6210ab1473851

However, starting from rustc 1.70.0 (and corresponding LLVM versions), this no longer seems to be an issue. The compiler now lowers constant division by 10 into a multiplication + shift sequence, avoiding runtime helper calls.
Additionally, the generated code appears to be at least as efficient, if not better, than the current manual implementation.

Godbolt proof:
https://godbolt.org/z/fonv1MEhT

Given this, I was wondering whether it makes sense to remove the platform-specific  manual division path, and rely on the compiler for optimal code generation.

Thanks!