Skip to content

Comments

Change decimal digits lookup table from static to const#54

Merged
dtolnay merged 1 commit intomasterfrom
lut
Nov 20, 2024
Merged

Change decimal digits lookup table from static to const#54
dtolnay merged 1 commit intomasterfrom
lut

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
@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