aldanor / fast-float-rust

Super-fast float parser in Rust (now part of Rust core)
https://docs.rs/fast-float
Apache License 2.0
275 stars 20 forks source link

Update `try_add_digit` for more efficient ASM generation. #31

Closed Alexhuszagh closed 3 years ago

Alexhuszagh commented 3 years ago

This generates more efficient assembly, and also makes justifying trim easier to rationalize from a cursory glance at the code.

Original

example::Decimal::try_add_digit:
        mov     rax, qword ptr [rdi]
        cmp     rax, 767
        ja      .LBB0_2
        mov     byte ptr [rdi + rax + 14], sil
        mov     rax, qword ptr [rdi]
.LBB0_2:
        add     rax, 1
        mov     qword ptr [rdi], rax
        ret

New

example::Decimal::try_add_digit:
        mov     rax, qword ptr [rdi]
        cmp     rax, 767
        ja      .LBB0_2
        mov     byte ptr [rdi + rax + 14], sil
        add     qword ptr [rdi], 1
.LBB0_2:
        ret