Skip to content

Conversation

@paolobarbolini
Copy link
Member

No description provided.

Compiler Explorer comparison URL: https://rust.godbolt.org/z/9aE9dG8xx

```asm
example::U31::checked_add::h0a14bb76814034a2:
        add     edi, esi
        setb    al
        test    edi, edi
        setns   cl
        not     al
        and     al, cl
        movzx   eax, al
        mov     edx, edi
        ret

example::U31::saturating_add::h42559bf8f3c4f4ba:
        lea     eax, [rdi + rsi]
        add     edi, esi
        jb      .LBB1_1
        shr     eax, 31
        test    al, al
        mov     eax, 2147483647
        cmove   eax, edi
        ret
.LBB1_1:
        mov     al, 1
        test    al, al
        mov     eax, 2147483647
        cmove   eax, edi
        ret

example::U31::checked_mul::h6bb2dd85cef4eaf5:
        mov     eax, edi
        mul     esi
        mov     edx, eax
        setno   al
        test    edx, edx
        setns   cl
        and     cl, al
        movzx   eax, cl
        ret

example::U31::saturating_mul::h836028ce939d6d0b:
        mov     eax, edi
        mul     esi
        seto    cl
        cmp     eax, 2147483647
        mov     edx, 2147483647
        cmovae  eax, edx
        test    cl, cl
        cmovne  eax, edx
        ret

example::U31::checked_div::h07829b35455c103f:
        test    esi, esi
        je      .LBB4_1
        mov     eax, edi
        xor     edx, edx
        div     esi
        mov     edx, eax
        mov     eax, 1
        ret
.LBB4_1:
        xor     eax, eax
        ret
```

```asm
example::U31::checked_add::h0a14bb76814034a2:
        xor     eax, eax
        add     edi, esi
        setno   al
        mov     edx, edi
        ret

example::U31::saturating_add::h42559bf8f3c4f4ba:
        add     edi, esi
        mov     eax, 2147483647
        cmovno  eax, edi
        ret

example::U31::checked_mul::h6bb2dd85cef4eaf5:
        xor     eax, eax
        imul    edi, esi
        setno   al
        mov     edx, edi
        ret

example::U31::saturating_mul::h836028ce939d6d0b:
        imul    edi, esi
        mov     eax, 2147483647
        cmovno  eax, edi
        ret

example::U31::checked_div::h07829b35455c103f:
        test    esi, esi
        je      .LBB4_1
        mov     eax, edi
        xor     edx, edx
        div     esi
        mov     edx, eax
        mov     eax, 1
        ret
.LBB4_1:
        xor     eax, eax
        ret
```
@paolobarbolini
Copy link
Member Author

Cc @dodomorandi

Copy link
Contributor

@manuelpelloni manuelpelloni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@paolobarbolini paolobarbolini merged commit fda2e4a into main Jun 11, 2025
14 checks passed
@paolobarbolini paolobarbolini deleted the improvements branch June 11, 2025 08:51
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.

3 participants