Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change decimal digits lookup table from static to const #54

Merged
merged 1 commit into from
Nov 20, 2024
Merged

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Nov 20, 2024

Apparently being a static, even with immutable contents, interferes with constant folding. For example buffer.format(i32::MIN) with a static compiles to:

mov rcx, qword ptr [rip + itoa::DEC_DIGITS_LUT@GOTPCREL]
mov rax, rdi
mov rcx, qword ptr [rcx]
movzx edx, word ptr [rcx + 72]
mov word ptr [rdi + 7], dx
mov edx, dword ptr [rcx + 94]
mov esi, edx
shr esi, 16
mov word ptr [rdi + 9], si
mov dword ptr [rdi + 3], edx
mov edx, 11
movzx ecx, word ptr [rcx + 42]
mov word ptr [rdi + 1], cx
mov byte ptr [rdi], 45
ret

and with const:

mov rax, rdi
mov edx, 11
movabs rcx, 3905527098775974194
mov word ptr [rdi + 9], 14388
mov qword ptr [rdi + 1], rcx
mov byte ptr [rdi], 45
ret

@dtolnay dtolnay merged commit 513debf into master Nov 20, 2024
17 checks passed
@dtolnay dtolnay deleted the lut branch November 20, 2024 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant