[llvm] [NFC][ADT] add NumDigitsBase10 to MathExtra and update some current users (PR #165479)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 29 04:28:07 PDT 2025


Ralender wrote:

Yeah its a bit more complex, but if we are sharing the implementations in LLVM, we might as well use an implementation that is fast.

All the complexity in this implementation is buiding the table at complie-time, once that done on x86-64 you get
```asm
    20b0:	f3 48 0f bd c7       	lzcnt  %rdi,%rax
    20b5:	48 8d 0d 94 e9 ff ff 	lea    -0x166c(%rip),%rcx
    20bc:	0f b6 04 08          	movzbl (%rax,%rcx,1),%eax
    20c0:	48 3b 7c c1 48       	cmp    0x48(%rcx,%rax,8),%rdi
    20c5:	83 d8 ff             	sbb    $0xffffffff,%eax
```

But I could replace `getNumDisplayWidth` by `NumDigitsBase10`

https://github.com/llvm/llvm-project/pull/165479


More information about the llvm-commits mailing list