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

fix: optimize MaybeUninit array initialization in keccak256_round_function #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

austinabell
Copy link

What ❔

Optimizes the initialization of an array using [MaybeUninit<_>; _]. This is recommended in std docs and it just simplifies the asm and reduces instructions. I don't believe Rust can optimize away the fact that this would initialize a new array and copy the elements over. I've included the asm of this code in isolation to give an idea.

asm diff
  1,9d0
< <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::size_hint:
<         push    rax
<         mov     rax, rdi
<         mov     qword ptr [rsp], rax
<         call    qword ptr [rip + <core::array::drain::Drain<T> as core::iter::traits::iterator::Iterator>::size_hint@GOTPCREL]
<         mov     rax, qword ptr [rsp]
<         pop     rcx
<         ret
< 
17,19d7
< <core::ops::try_trait::NeverShortCircuit<T> as core::ops::try_trait::FromResidual>::from_residual:
<         ud2
< 
37c25
<         jne     .LBB4_2
---
>         jne     .LBB2_2
39,40c27,28
<         jmp     .LBB4_3
< .LBB4_2:
---
>         jmp     .LBB2_3
> .LBB2_2:
43c31
< .LBB4_3:
---
> .LBB2_3:
50c38
<         jne     .LBB4_5
---
>         jne     .LBB2_5
61,63c49,51
<         jne     .LBB4_7
<         jmp     .LBB4_6
< .LBB4_5:
---
>         jne     .LBB2_7
>         jmp     .LBB2_6
> .LBB2_5:
65,66c53,54
<         jmp     .LBB4_11
< .LBB4_6:
---
>         jmp     .LBB2_11
> .LBB2_6:
78,79c66,67
<         jmp     .LBB4_11
< .LBB4_7:
---
>         jmp     .LBB2_11
> .LBB2_7:
85,86c73,74
<         jmp     .LBB4_10
< .LBB4_8:
---
>         jmp     .LBB2_10
> .LBB2_8:
94,95c82,83
<         jmp     .LBB4_8
< .LBB4_10:
---
>         jmp     .LBB2_8
> .LBB2_10:
97c85
< .LBB4_11:
---
> .LBB2_11:
115,116c103,104
<         jmp     .LBB5_3
< .LBB5_1:
---
>         jmp     .LBB3_3
> .LBB3_1:
124,125c112,113
<         jmp     .LBB5_1
< .LBB5_3:
---
>         jmp     .LBB3_1
> .LBB3_3:
130,131c118,119
<         jmp     .LBB5_4
< .LBB5_4:
---
>         jmp     .LBB3_4
> .LBB3_4:
137,138c125,126
<         jmp     .LBB5_5
< .LBB5_5:
---
>         jmp     .LBB3_5
> .LBB3_5:
162c150
<         jb      .LBB6_2
---
>         jb      .LBB4_2
165,167c153,155
<         jne     .LBB6_4
<         jmp     .LBB6_3
< .LBB6_2:
---
>         jne     .LBB4_4
>         jmp     .LBB4_3
> .LBB4_2:
183,184c171,172
<         jmp     .LBB6_11
< .LBB6_3:
---
>         jmp     .LBB4_11
> .LBB4_3:
186,187c174,175
<         jmp     .LBB6_7
< .LBB6_4:
---
>         jmp     .LBB4_7
> .LBB4_4:
191,193c179,181
<         jb      .LBB6_6
<         jmp     .LBB6_3
< .LBB6_6:
---
>         jb      .LBB4_6
>         jmp     .LBB4_3
> .LBB4_6:
204,206c192,194
< .LBB6_7:
<         jmp     .LBB6_8
< .LBB6_8:
---
> .LBB4_7:
>         jmp     .LBB4_8
> .LBB4_8:
211c199
< .LBB6_9:
---
> .LBB4_9:
219,220c207,208
<         jmp     .LBB6_9
< .LBB6_11:
---
>         jmp     .LBB4_9
> .LBB4_11:
229,271c217
<         jmp     .LBB6_8
< 
< <core::array::drain::Drain<T> as core::iter::traits::unchecked_iterator::UncheckedIterator>::next_unchecked:
<         push    rax
<         call    qword ptr [rip + <core::slice::iter::IterMut<T> as core::iter::traits::unchecked_iterator::UncheckedIterator>::next_unchecked@GOTPCREL]
<         mov     al, byte ptr [rax]
<         pop     rcx
<         ret
< 
< <core::slice::iter::IterMut<T> as core::iter::traits::unchecked_iterator::UncheckedIterator>::next_unchecked:
<         mov     qword ptr [rsp - 24], rdi
<         mov     rax, qword ptr [rdi]
<         mov     qword ptr [rsp - 16], rax
<         xor     eax, eax
<         test    al, 1
<         jne     .LBB8_2
<         mov     rax, qword ptr [rsp - 24]
<         mov     rcx, qword ptr [rax]
<         add     rcx, 1
<         mov     qword ptr [rsp - 8], rcx
<         mov     rcx, qword ptr [rsp - 8]
<         mov     qword ptr [rax], rcx
<         jmp     .LBB8_3
< .LBB8_2:
<         mov     rax, qword ptr [rsp - 24]
<         mov     rcx, qword ptr [rax + 8]
<         sub     rcx, 1
<         mov     qword ptr [rax + 8], rcx
< .LBB8_3:
<         mov     rax, qword ptr [rsp - 16]
<         ret
< 
< <core::iter::adapters::map::Map<I,F> as core::iter::traits::unchecked_iterator::UncheckedIterator>::next_unchecked:
<         sub     rsp, 24
<         mov     qword ptr [rsp + 8], rdi
<         call    qword ptr [rip + <core::array::drain::Drain<T> as core::iter::traits::unchecked_iterator::UncheckedIterator>::next_unchecked@GOTPCREL]
<         mov     rdi, qword ptr [rsp + 8]
<         add     rdi, 16
<         mov     byte ptr [rsp + 23], al
<         movzx   esi, byte ptr [rsp + 23]
<         call    qword ptr [rip + core::ops::try_trait::NeverShortCircuit<T>::wrap_mut_1::{{closure}}@GOTPCREL]
<         add     rsp, 24
<         ret
---
>         jmp     .LBB4_8
278c224
<         jb      .LBB10_2
---
>         jb      .LBB5_2
283,285c229,231
<         je      .LBB10_4
<         jmp     .LBB10_3
< .LBB10_2:
---
>         je      .LBB5_4
>         jmp     .LBB5_3
> .LBB5_2:
287,288c233,234
<         jmp     .LBB10_6
< .LBB10_3:
---
>         jmp     .LBB5_6
> .LBB5_3:
290,291c236,237
<         jmp     .LBB10_5
< .LBB10_4:
---
>         jmp     .LBB5_5
> .LBB5_4:
293,295c239,241
< .LBB10_5:
<         jmp     .LBB10_6
< .LBB10_6:
---
> .LBB5_5:
>         jmp     .LBB5_6
> .LBB5_6:
313,315c259,261
<         jmp     .LBB11_3
< .LBB11_1:
<         jmp     .LBB11_12
---
>         jmp     .LBB6_3
> .LBB6_1:
>         jmp     .LBB6_12
320,321c266,267
<         jmp     .LBB11_1
< .LBB11_3:
---
>         jmp     .LBB6_1
> .LBB6_3:
327,330c273,276
<         jb      .LBB11_5
<         jmp     .LBB11_15
< .LBB11_15:
<         jmp     .LBB11_6
---
>         jb      .LBB6_5
>         jmp     .LBB6_15
> .LBB6_15:
>         jmp     .LBB6_6
332c278
< .LBB11_5:
---
> .LBB6_5:
336,337c282,283
<         jmp     .LBB11_7
< .LBB11_6:
---
>         jmp     .LBB6_7
> .LBB6_6:
341c287
< .LBB11_7:
---
> .LBB6_7:
343,344c289,290
<         jne     .LBB11_9
< .LBB11_8:
---
>         jne     .LBB6_9
> .LBB6_8:
346,350c292,296
<         jne     .LBB11_11
<         jmp     .LBB11_10
< .LBB11_9:
<         jmp     .LBB11_8
< .LBB11_10:
---
>         jne     .LBB6_11
>         jmp     .LBB6_10
> .LBB6_9:
>         jmp     .LBB6_8
> .LBB6_10:
354,356c300,302
< .LBB11_11:
<         jmp     .LBB11_10
< .LBB11_12:
---
> .LBB6_11:
>         jmp     .LBB6_10
> .LBB6_12:
358,359c304,305
<         jne     .LBB11_14
< .LBB11_13:
---
>         jne     .LBB6_14
> .LBB6_13:
363,364c309,310
< .LBB11_14:
<         jmp     .LBB11_13
---
> .LBB6_14:
>         jmp     .LBB6_13
373c319
<         ja      .LBB12_2
---
>         ja      .LBB7_2
390c336
< .LBB12_2:
---
> .LBB7_2:
412,446d357
< core::ops::try_trait::NeverShortCircuit<T>::wrap_mut_1::{{closure}}:
<         push    rax
<         mov     al, sil
<         mov     byte ptr [rsp + 7], al
<         movzx   esi, byte ptr [rsp + 7]
<         call    example::testa::{{closure}}
<         mov     byte ptr [rsp + 6], al
<         mov     al, byte ptr [rsp + 6]
<         pop     rcx
<         ret
< 
< core::ptr::drop_in_place<core::array::drain::Drain<core::mem::maybe_uninit::MaybeUninit<u8>>>:
<         push    rax
<         call    qword ptr [rip + <core::array::drain::Drain<T> as core::ops::drop::Drop>::drop@GOTPCREL]
<         pop     rax
<         ret
< 
< core::ptr::drop_in_place<core::iter::adapters::map::Map<core::array::drain::Drain<core::mem::maybe_uninit::MaybeUninit<u8>>,core::ops::try_trait::NeverShortCircuit<u8>::wrap_mut_1<core::mem::maybe_uninit::MaybeUninit<u8>,example::testa::{{closure}}>::{{closure}}>>:
<         push    rax
<         call    qword ptr [rip + core::ptr::drop_in_place<core::array::drain::Drain<core::mem::maybe_uninit::MaybeUninit<u8>>>@GOTPCREL]
<         pop     rax
<         ret
< 
< core::ptr::drop_in_place<core::array::try_from_trusted_iterator::next<core::ops::try_trait::NeverShortCircuit<u8>,core::iter::adapters::map::Map<core::array::drain::Drain<core::mem::maybe_uninit::MaybeUninit<u8>>,core::ops::try_trait::NeverShortCircuit<u8>::wrap_mut_1<core::mem::maybe_uninit::MaybeUninit<u8>,example::testa::{{closure}}>::{{closure}}>>::{{closure}}>:
<         push    rax
<         call    qword ptr [rip + core::ptr::drop_in_place<core::iter::adapters::map::Map<core::array::drain::Drain<core::mem::maybe_uninit::MaybeUninit<u8>>,core::ops::try_trait::NeverShortCircuit<u8>::wrap_mut_1<core::mem::maybe_uninit::MaybeUninit<u8>,example::testa::{{closure}}>::{{closure}}>>@GOTPCREL]
<         pop     rax
<         ret
< 
< core::ptr::drop_in_place<core::array::Guard<u8>>:
<         push    rax
<         call    qword ptr [rip + <core::array::Guard<T> as core::ops::drop::Drop>::drop@GOTPCREL]
<         pop     rax
<         ret
< 
464,465c375,376
<         jmp     .LBB19_3
< .LBB19_1:
---
>         jmp     .LBB9_3
> .LBB9_1:
467,468c378,379
<         jne     .LBB19_6
<         jmp     .LBB19_5
---
>         jne     .LBB9_6
>         jmp     .LBB9_5
473,474c384,385
<         jmp     .LBB19_1
< .LBB19_3:
---
>         jmp     .LBB9_1
> .LBB9_3:
483,484c394,395
<         jmp     .LBB19_4
< .LBB19_4:
---
>         jmp     .LBB9_4
> .LBB9_4:
488c399
< .LBB19_5:
---
> .LBB9_5:
492,493c403,404
< .LBB19_6:
<         jmp     .LBB19_5
---
> .LBB9_6:
>         jmp     .LBB9_5
522,822d432
<         mov     rax, qword ptr [rsp]
<         add     rsp, 24
<         ret
< 
< core::array::try_from_fn:
<         sub     rsp, 232
<         mov     qword ptr [rsp], rdi
<         mov     qword ptr [rsp + 8], rdi
<         mov     qword ptr [rsp + 16], rsi
<         mov     qword ptr [rsp + 24], rdx
<         movups  xmm0, xmmword ptr [rsp + 144]
<         movups  xmm1, xmmword ptr [rsp + 160]
<         movaps  xmmword ptr [rsp + 192], xmm1
<         movaps  xmmword ptr [rsp + 176], xmm0
<         movaps  xmm0, xmmword ptr [rsp + 176]
<         movaps  xmm1, xmmword ptr [rsp + 192]
<         movaps  xmmword ptr [rsp + 48], xmm1
<         movaps  xmmword ptr [rsp + 32], xmm0
<         mov     rdx, qword ptr [rsp + 16]
<         mov     rcx, qword ptr [rsp + 24]
<         mov     rax, qword ptr [rip + core::array::try_from_fn_erased@GOTPCREL]
<         lea     rdi, [rsp + 32]
<         mov     esi, 32
<         call    rax
<         jmp     .LBB23_3
< .LBB23_1:
<         xor     eax, eax
<         test    al, 1
<         jne     .LBB23_10
<         jmp     .LBB23_9
<         mov     rcx, rax
<         mov     eax, edx
<         mov     qword ptr [rsp + 216], rcx
<         mov     dword ptr [rsp + 224], eax
<         jmp     .LBB23_1
< .LBB23_3:
<         mov     al, 1
<         test    al, 1
<         jne     .LBB23_4
<         jmp     .LBB23_5
< .LBB23_4:
<         mov     rdi, qword ptr [rsp]
<         movaps  xmm0, xmmword ptr [rsp + 32]
<         movaps  xmm1, xmmword ptr [rsp + 48]
<         movaps  xmmword ptr [rsp + 128], xmm1
<         movaps  xmmword ptr [rsp + 112], xmm0
<         movups  xmm0, xmmword ptr [rsp + 112]
<         movups  xmm1, xmmword ptr [rsp + 128]
<         movups  xmmword ptr [rsp + 96], xmm1
<         movups  xmmword ptr [rsp + 80], xmm0
<         mov     rax, qword ptr [rip + <core::ops::try_trait::NeverShortCircuit<T> as core::ops::try_trait::Try>::from_output@GOTPCREL]
<         lea     rsi, [rsp + 80]
<         call    rax
<         jmp     .LBB23_6
< .LBB23_5:
<         mov     rdi, qword ptr [rsp]
<         mov     rax, qword ptr [rip + <core::ops::try_trait::NeverShortCircuit<T> as core::ops::try_trait::FromResidual>::from_residual@GOTPCREL]
<         call    rax
<         jmp     .LBB23_8
< .LBB23_6:
<         jmp     .LBB23_7
< .LBB23_7:
<         mov     rax, qword ptr [rsp + 8]
<         add     rsp, 232
<         ret
< .LBB23_8:
<         jmp     .LBB23_7
< .LBB23_9:
<         mov     rdi, qword ptr [rsp + 216]
<         call    _Unwind_Resume@PLT
<         ud2
< .LBB23_10:
<         mov     rax, qword ptr [rip + core::ptr::drop_in_place<core::array::try_from_trusted_iterator::next<core::ops::try_trait::NeverShortCircuit<u8>,core::iter::adapters::map::Map<core::array::drain::Drain<core::mem::maybe_uninit::MaybeUninit<u8>>,core::ops::try_trait::NeverShortCircuit<u8>::wrap_mut_1<core::mem::maybe_uninit::MaybeUninit<u8>,example::testa::{{closure}}>::{{closure}}>>::{{closure}}>@GOTPCREL]
<         lea     rdi, [rsp + 16]
<         call    rax
<         jmp     .LBB23_9
<         mov     rax, qword ptr [rip + core::panicking::panic_in_cleanup@GOTPCREL]
<         call    rax
<         ud2
< 
< core::array::try_from_fn_erased:
<         sub     rsp, 88
<         mov     qword ptr [rsp + 8], rdx
<         mov     qword ptr [rsp + 16], rcx
<         mov     qword ptr [rsp + 24], rdi
<         mov     qword ptr [rsp + 32], rsi
<         mov     qword ptr [rsp + 40], 0
< .LBB24_1:
<         mov     rax, qword ptr [rsp + 40]
<         cmp     rax, qword ptr [rsp + 32]
<         jb      .LBB24_3
<         lea     rdi, [rsp + 8]
<         call    qword ptr [rip + core::ptr::drop_in_place<core::array::try_from_trusted_iterator::next<core::ops::try_trait::NeverShortCircuit<u8>,core::iter::adapters::map::Map<core::array::drain::Drain<core::mem::maybe_uninit::MaybeUninit<u8>>,core::ops::try_trait::NeverShortCircuit<u8>::wrap_mut_1<core::mem::maybe_uninit::MaybeUninit<u8>,example::testa::{{closure}}>::{{closure}}>>::{{closure}}>@GOTPCREL]
<         jmp     .LBB24_4
< .LBB24_3:
<         mov     rax, qword ptr [rsp + 40]
<         mov     qword ptr [rsp + 56], rax
<         mov     rsi, qword ptr [rsp + 56]
<         mov     rax, qword ptr [rip + core::array::try_from_trusted_iterator::next::{{closure}}@GOTPCREL]
<         lea     rdi, [rsp + 8]
<         call    rax
<         mov     byte ptr [rsp + 7], al
<         jmp     .LBB24_7
< .LBB24_4:
<         add     rsp, 88
<         ret
< .LBB24_5:
<         mov     al, 1
<         test    al, 1
<         jne     .LBB24_17
<         jmp     .LBB24_14
<         mov     rcx, rax
<         mov     eax, edx
<         mov     qword ptr [rsp + 72], rcx
<         mov     dword ptr [rsp + 80], eax
<         jmp     .LBB24_5
< .LBB24_7:
<         mov     al, byte ptr [rsp + 7]
<         movzx   edi, al
<         mov     rax, qword ptr [rip + <core::ops::try_trait::NeverShortCircuit<T> as core::ops::try_trait::Try>::branch@GOTPCREL]
<         call    rax
<         mov     byte ptr [rsp + 6], al
<         jmp     .LBB24_8
< .LBB24_8:
<         mov     al, byte ptr [rsp + 6]
<         mov     byte ptr [rsp + 55], al
<         mov     al, 1
<         test    al, 1
<         jne     .LBB24_9
<         jmp     .LBB24_10
< .LBB24_9:
<         mov     al, byte ptr [rsp + 55]
<         mov     byte ptr [rsp + 54], al
<         jmp     .LBB24_11
< .LBB24_10:
<         ud2
< .LBB24_11:
<         mov     al, 1
<         test    al, 1
<         jne     .LBB24_12
<         jmp     .LBB24_13
< .LBB24_12:
<         mov     dl, byte ptr [rsp + 54]
<         mov     rax, qword ptr [rsp + 24]
<         mov     rcx, qword ptr [rsp + 40]
<         mov     byte ptr [rsp + 71], dl
<         mov     dl, byte ptr [rsp + 71]
<         mov     byte ptr [rsp + 70], dl
<         mov     dl, byte ptr [rsp + 70]
<         mov     byte ptr [rax + rcx], dl
<         mov     rax, qword ptr [rsp + 40]
<         add     rax, 1
<         mov     qword ptr [rsp + 40], rax
<         jmp     .LBB24_1
< .LBB24_13:
<         mov     rax, qword ptr [rip + core::ptr::drop_in_place<core::array::Guard<u8>>@GOTPCREL]
<         lea     rdi, [rsp + 24]
<         call    rax
<         jmp     .LBB24_16
< .LBB24_14:
<         mov     rax, qword ptr [rip + core::ptr::drop_in_place<core::array::try_from_trusted_iterator::next<core::ops::try_trait::NeverShortCircuit<u8>,core::iter::adapters::map::Map<core::array::drain::Drain<core::mem::maybe_uninit::MaybeUninit<u8>>,core::ops::try_trait::NeverShortCircuit<u8>::wrap_mut_1<core::mem::maybe_uninit::MaybeUninit<u8>,example::testa::{{closure}}>::{{closure}}>>::{{closure}}>@GOTPCREL]
<         lea     rdi, [rsp + 8]
<         call    rax
<         jmp     .LBB24_19
<         mov     rcx, rax
<         mov     eax, edx
<         mov     qword ptr [rsp + 72], rcx
<         mov     dword ptr [rsp + 80], eax
<         jmp     .LBB24_14
< .LBB24_16:
<         lea     rdi, [rsp + 8]
<         call    qword ptr [rip + core::ptr::drop_in_place<core::array::try_from_trusted_iterator::next<core::ops::try_trait::NeverShortCircuit<u8>,core::iter::adapters::map::Map<core::array::drain::Drain<core::mem::maybe_uninit::MaybeUninit<u8>>,core::ops::try_trait::NeverShortCircuit<u8>::wrap_mut_1<core::mem::maybe_uninit::MaybeUninit<u8>,example::testa::{{closure}}>::{{closure}}>>::{{closure}}>@GOTPCREL]
<         jmp     .LBB24_4
< .LBB24_17:
<         mov     rax, qword ptr [rip + core::ptr::drop_in_place<core::array::Guard<u8>>@GOTPCREL]
<         lea     rdi, [rsp + 24]
<         call    rax
<         jmp     .LBB24_14
<         mov     rax, qword ptr [rip + core::panicking::panic_in_cleanup@GOTPCREL]
<         call    rax
<         ud2
< .LBB24_19:
<         mov     rdi, qword ptr [rsp + 72]
<         call    _Unwind_Resume@PLT
<         ud2
< 
< core::array::try_from_trusted_iterator:
<         sub     rsp, 104
<         mov     qword ptr [rsp + 8], rdi
<         mov     qword ptr [rsp + 16], rdi
<         mov     qword ptr [rsp + 24], rsi
<         mov     qword ptr [rsp + 32], rdx
<         mov     byte ptr [rsp + 71], 1
<         mov     rax, qword ptr [rip + <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::size_hint@GOTPCREL]
<         lea     rdi, [rsp + 40]
<         lea     rsi, [rsp + 24]
<         call    rax
<         jmp     .LBB25_3
< .LBB25_1:
<         test    byte ptr [rsp + 71], 1
<         jne     .LBB25_9
<         jmp     .LBB25_8
<         mov     rcx, rax
<         mov     eax, edx
<         mov     qword ptr [rsp + 88], rcx
<         mov     dword ptr [rsp + 96], eax
<         jmp     .LBB25_1
< .LBB25_3:
<         cmp     qword ptr [rsp + 40], 32
<         jae     .LBB25_5
<         lea     rdi, [rip + .L__unnamed_5]
<         lea     rdx, [rip + .L__unnamed_6]
<         mov     rax, qword ptr [rip + core::panicking::panic@GOTPCREL]
<         mov     esi, 41
<         call    rax
<         jmp     .LBB25_6
< .LBB25_5:
<         mov     rdi, qword ptr [rsp + 8]
<         mov     byte ptr [rsp + 71], 0
<         mov     rcx, qword ptr [rsp + 24]
<         mov     rax, qword ptr [rsp + 32]
<         mov     qword ptr [rsp + 72], rcx
<         mov     qword ptr [rsp + 80], rax
<         mov     rsi, qword ptr [rsp + 72]
<         mov     rdx, qword ptr [rsp + 80]
<         mov     rax, qword ptr [rip + core::array::try_from_fn@GOTPCREL]
<         call    rax
<         jmp     .LBB25_7
< .LBB25_6:
<         ud2
< .LBB25_7:
<         mov     rax, qword ptr [rsp + 16]
<         add     rsp, 104
<         ret
< .LBB25_8:
<         mov     rdi, qword ptr [rsp + 88]
<         call    _Unwind_Resume@PLT
<         ud2
< .LBB25_9:
<         mov     rax, qword ptr [rip + core::ptr::drop_in_place<core::iter::adapters::map::Map<core::array::drain::Drain<core::mem::maybe_uninit::MaybeUninit<u8>>,core::ops::try_trait::NeverShortCircuit<u8>::wrap_mut_1<core::mem::maybe_uninit::MaybeUninit<u8>,example::testa::{{closure}}>::{{closure}}>>@GOTPCREL]
<         lea     rdi, [rsp + 24]
<         call    rax
<         jmp     .LBB25_8
<         mov     rax, qword ptr [rip + core::panicking::panic_in_cleanup@GOTPCREL]
<         call    rax
<         ud2
< 
< core::array::try_from_trusted_iterator::next::{{closure}}:
<         push    rax
<         call    qword ptr [rip + <core::iter::adapters::map::Map<I,F> as core::iter::traits::unchecked_iterator::UncheckedIterator>::next_unchecked@GOTPCREL]
<         pop     rcx
<         ret
< 
< core::array::<impl [T; N]>::map:
<         sub     rsp, 104
<         mov     qword ptr [rsp], rdi
<         mov     qword ptr [rsp + 8], rdi
<         movups  xmm0, xmmword ptr [rsi]
<         movups  xmm1, xmmword ptr [rsi + 16]
<         movaps  xmmword ptr [rsp + 64], xmm1
<         movaps  xmmword ptr [rsp + 48], xmm0
<         mov     rax, qword ptr [rip + core::array::drain::drain_array_with@GOTPCREL]
<         lea     rdi, [rsp + 16]
<         lea     rsi, [rsp + 48]
<         call    rax
<         jmp     .LBB27_3
< .LBB27_1:
<         xor     eax, eax
<         test    al, 1
<         jne     .LBB27_5
<         jmp     .LBB27_4
<         mov     rcx, rax
<         mov     eax, edx
<         mov     qword ptr [rsp + 88], rcx
<         mov     dword ptr [rsp + 96], eax
<         jmp     .LBB27_1
< .LBB27_3:
<         mov     rax, qword ptr [rsp + 8]
<         mov     rcx, qword ptr [rsp]
<         movups  xmm0, xmmword ptr [rsp + 16]
<         movups  xmm1, xmmword ptr [rsp + 32]
<         movups  xmmword ptr [rcx + 16], xmm1
<         movups  xmmword ptr [rcx], xmm0
<         add     rsp, 104
<         ret
< .LBB27_4:
<         mov     rdi, qword ptr [rsp + 88]
<         call    _Unwind_Resume@PLT
<         ud2
< .LBB27_5:
<         jmp     .LBB27_4
< 
< core::array::<impl [T; N]>::try_map::{{closure}}:
<         sub     rsp, 24
<         mov     rax, rdi
<         mov     qword ptr [rsp], rax
<         mov     qword ptr [rsp + 8], rsi
<         mov     qword ptr [rsp + 16], rdx
<         mov     rsi, qword ptr [rsp + 8]
<         mov     rdx, qword ptr [rsp + 16]
<         call    qword ptr [rip + core::array::try_from_trusted_iterator@GOTPCREL]
827,890d436
< core::array::drain::drain_array_with:
<         sub     rsp, 136
<         mov     qword ptr [rsp + 8], rdi
<         mov     qword ptr [rsp + 16], rdi
<         mov     rax, qword ptr [rsi]
<         mov     qword ptr [rsp + 24], rax
<         mov     rax, qword ptr [rsi + 8]
<         mov     qword ptr [rsp + 32], rax
<         mov     rax, qword ptr [rsi + 16]
<         mov     qword ptr [rsp + 40], rax
<         mov     rax, qword ptr [rsi + 24]
<         mov     qword ptr [rsp + 48], rax
<         xor     eax, eax
<         test    al, 1
<         jne     .LBB29_2
<         lea     rax, [rsp + 24]
<         add     rax, 32
<         mov     qword ptr [rsp + 104], rax
<         jmp     .LBB29_3
< .LBB29_2:
<         mov     eax, 32
<         mov     qword ptr [rsp + 104], rax
< .LBB29_3:
<         mov     rdi, qword ptr [rsp + 8]
<         lea     rax, [rsp + 24]
<         mov     qword ptr [rsp + 112], rax
<         mov     rax, qword ptr [rsp + 104]
<         mov     rcx, qword ptr [rsp + 112]
<         mov     qword ptr [rsp + 72], rcx
<         mov     qword ptr [rsp + 80], rax
<         mov     rcx, qword ptr [rsp + 72]
<         mov     rax, qword ptr [rsp + 80]
<         mov     qword ptr [rsp + 56], rcx
<         mov     qword ptr [rsp + 64], rax
<         mov     rcx, qword ptr [rsp + 56]
<         mov     rax, qword ptr [rsp + 64]
<         mov     qword ptr [rsp + 88], rcx
<         mov     qword ptr [rsp + 96], rax
<         mov     rsi, qword ptr [rsp + 88]
<         mov     rdx, qword ptr [rsp + 96]
<         mov     rax, qword ptr [rip + core::array::<impl [T; N]>::try_map::{{closure}}@GOTPCREL]
<         call    rax
<         jmp     .LBB29_6
< .LBB29_4:
<         xor     eax, eax
<         test    al, 1
<         jne     .LBB29_8
<         jmp     .LBB29_7
<         mov     rcx, rax
<         mov     eax, edx
<         mov     qword ptr [rsp + 120], rcx
<         mov     dword ptr [rsp + 128], eax
<         jmp     .LBB29_4
< .LBB29_6:
<         mov     rax, qword ptr [rsp + 16]
<         add     rsp, 136
<         ret
< .LBB29_7:
<         mov     rdi, qword ptr [rsp + 120]
<         call    _Unwind_Resume@PLT
<         ud2
< .LBB29_8:
<         jmp     .LBB29_7
< 
900c446
<         jbe     .LBB30_2
---
>         jbe     .LBB13_2
902c448
<         lea     rdi, [rip + .L__unnamed_7]
---
>         lea     rdi, [rip + .L__unnamed_5]
907c453
< .LBB30_2:
---
> .LBB13_2:
947c493
<         jne     .LBB31_2
---
>         jne     .LBB14_2
950,952c496,498
<         jne     .LBB31_4
<         jmp     .LBB31_3
< .LBB31_2:
---
>         jne     .LBB14_4
>         jmp     .LBB14_3
> .LBB14_2:
984c530
< .LBB31_3:
---
> .LBB14_3:
987c533
<         lea     rax, [rip + .L__unnamed_8]
---
>         lea     rax, [rip + .L__unnamed_6]
1001c547
< .LBB31_4:
---
> .LBB14_4:
1022c568
<         jne     .LBB32_2
---
>         jne     .LBB15_2
1025,1027c571,573
<         jne     .LBB32_4
<         jmp     .LBB32_3
< .LBB32_2:
---
>         jne     .LBB15_4
>         jmp     .LBB15_3
> .LBB15_2:
1035c581
< .LBB32_3:
---
> .LBB15_3:
1038c584
<         lea     rax, [rip + .L__unnamed_8]
---
>         lea     rax, [rip + .L__unnamed_6]
1052c598
< .LBB32_4:
---
> .LBB15_4:
1069c615
<         jne     .LBB33_2
---
>         jne     .LBB16_2
1074,1075c620,621
<         jmp     .LBB33_3
< .LBB33_2:
---
>         jmp     .LBB16_3
> .LBB16_2:
1078c624
< .LBB33_3:
---
> .LBB16_3:
1094c640
<         jne     .LBB34_2
---
>         jne     .LBB17_2
1099,1100c645,646
<         jmp     .LBB34_3
< .LBB34_2:
---
>         jmp     .LBB17_3
> .LBB17_2:
1103c649
< .LBB34_3:
---
> .LBB17_3:
1112,1165d657
<         ret
< 
< core::slice::iter::IterMut<T>::as_mut_slice:
<         sub     rsp, 72
<         mov     qword ptr [rsp + 16], rdi
<         mov     rax, qword ptr [rdi]
<         mov     qword ptr [rsp + 24], rax
<         xor     eax, eax
<         test    al, 1
<         jne     .LBB35_2
<         mov     rax, qword ptr [rsp + 16]
<         mov     rcx, qword ptr [rax + 8]
<         mov     qword ptr [rsp], rcx
<         mov     rax, qword ptr [rax]
<         mov     qword ptr [rsp + 8], rax
<         mov     al, 1
<         test    al, 1
<         jne     .LBB35_4
<         jmp     .LBB35_3
< .LBB35_2:
<         mov     rax, qword ptr [rsp + 16]
<         mov     rax, qword ptr [rax + 8]
<         mov     qword ptr [rsp + 32], rax
<         jmp     .LBB35_6
< .LBB35_3:
<         lea     rdi, [rip + .L__unnamed_9]
<         lea     rdx, [rip + .L__unnamed_10]
<         mov     rax, qword ptr [rip + core::panicking::panic@GOTPCREL]
<         mov     esi, 73
<         call    rax
<         ud2
< .LBB35_4:
<         mov     al, 1
<         test    al, 1
<         jne     .LBB35_5
<         jmp     .LBB35_3
< .LBB35_5:
<         mov     rcx, qword ptr [rsp + 8]
<         mov     rax, qword ptr [rsp]
<         sub     rax, rcx
<         shr     rax, 0
<         mov     qword ptr [rsp + 32], rax
< .LBB35_6:
<         mov     rax, qword ptr [rsp + 24]
<         mov     qword ptr [rsp + 56], rax
<         mov     rax, qword ptr [rsp + 32]
<         mov     qword ptr [rsp + 64], rax
<         mov     rcx, qword ptr [rsp + 56]
<         mov     rax, qword ptr [rsp + 64]
<         mov     qword ptr [rsp + 40], rcx
<         mov     qword ptr [rsp + 48], rax
<         mov     rax, qword ptr [rsp + 40]
<         mov     rdx, qword ptr [rsp + 48]
<         add     rsp, 72
1173c665
<         lea     rcx, [rip + .L__unnamed_11]
---
>         lea     rcx, [rip + .L__unnamed_7]
1185c677
<         jne     .LBB36_2
---
>         jne     .LBB18_2
1191,1192c683,684
<         jmp     .LBB36_3
< .LBB36_2:
---
>         jmp     .LBB18_3
> .LBB18_2:
1195c687
< .LBB36_3:
---
> .LBB18_3:
1238,1249d729
<         ret
< 
< <core::array::Guard<T> as core::ops::drop::Drop>::drop:
<         mov     rcx, qword ptr [rdi]
<         mov     rax, qword ptr [rdi + 16]
<         sub     rax, 0
<         mov     qword ptr [rsp - 16], rcx
<         mov     qword ptr [rsp - 8], rax
<         mov     rcx, qword ptr [rsp - 16]
<         mov     rax, qword ptr [rsp - 8]
<         mov     qword ptr [rsp - 32], rcx
<         mov     qword ptr [rsp - 24], rax
1252,1257d731
< <core::array::drain::Drain<T> as core::ops::drop::Drop>::drop:
<         push    rax
<         call    qword ptr [rip + core::slice::iter::IterMut<T>::as_mut_slice@GOTPCREL]
<         pop     rax
<         ret
< 
1270c744
<         jne     .LBB43_2
---
>         jne     .LBB23_2
1278,1280c752,754
<         jne     .LBB43_4
<         jmp     .LBB43_3
< .LBB43_2:
---
>         jne     .LBB23_4
>         jmp     .LBB23_3
> .LBB23_2:
1284,1287c758,761
<         jmp     .LBB43_6
< .LBB43_3:
<         lea     rdi, [rip + .L__unnamed_9]
<         lea     rdx, [rip + .L__unnamed_10]
---
>         jmp     .LBB23_6
> .LBB23_3:
>         lea     rdi, [rip + .L__unnamed_8]
>         lea     rdx, [rip + .L__unnamed_9]
1292c766
< .LBB43_4:
---
> .LBB23_4:
1295,1297c769,771
<         jne     .LBB43_5
<         jmp     .LBB43_3
< .LBB43_5:
---
>         jne     .LBB23_5
>         jmp     .LBB23_3
> .LBB23_5:
1303c777
< .LBB43_6:
---
> .LBB23_6:
1318,1347d791
< <core::array::drain::Drain<T> as core::iter::traits::iterator::Iterator>::size_hint:
<         mov     rax, rdi
<         mov     rcx, qword ptr [rsi + 8]
<         mov     rdx, qword ptr [rsi]
<         sub     rcx, rdx
<         mov     qword ptr [rsp - 8], rcx
<         mov     rcx, qword ptr [rsp - 8]
<         mov     qword ptr [rsp - 16], rcx
<         mov     qword ptr [rsp - 24], 1
<         mov     qword ptr [rdi], rcx
<         mov     rdx, qword ptr [rsp - 24]
<         mov     rcx, qword ptr [rsp - 16]
<         mov     qword ptr [rdi + 8], rdx
<         mov     qword ptr [rdi + 16], rcx
<         ret
< 
< <core::ops::try_trait::NeverShortCircuit<T> as core::ops::try_trait::Try>::from_output:
<         mov     rax, rdi
<         movups  xmm0, xmmword ptr [rsi]
<         movups  xmm1, xmmword ptr [rsi + 16]
<         movups  xmmword ptr [rdi + 16], xmm1
<         movups  xmmword ptr [rdi], xmm0
<         ret
< 
< <core::ops::try_trait::NeverShortCircuit<T> as core::ops::try_trait::Try>::branch:
<         mov     al, dil
<         mov     byte ptr [rsp - 1], al
<         mov     al, byte ptr [rsp - 1]
<         ret
< 
1357c801
<         jne     .LBB48_2
---
>         jne     .LBB25_2
1364,1365c808,809
<         jmp     .LBB48_3
< .LBB48_2:
---
>         jmp     .LBB25_3
> .LBB25_2:
1372c816
< .LBB48_3:
---
> .LBB25_3:
1374c818
<         jne     .LBB48_5
---
>         jne     .LBB25_5
1380,1382c824,826
<         jne     .LBB48_7
<         jmp     .LBB48_6
< .LBB48_5:
---
>         jne     .LBB25_7
>         jmp     .LBB25_6
> .LBB25_5:
1384,1385c828,829
<         jmp     .LBB48_9
< .LBB48_6:
---
>         jmp     .LBB25_9
> .LBB25_6:
1392,1393c836,837
<         jmp     .LBB48_8
< .LBB48_7:
---
>         jmp     .LBB25_8
> .LBB25_7:
1398c842
< .LBB48_8:
---
> .LBB25_8:
1401c845
< .LBB48_9:
---
> .LBB25_9:
1412c856
<         jne     .LBB49_2
---
>         jne     .LBB26_2
1420,1422c864,866
<         jne     .LBB49_4
<         jmp     .LBB49_3
< .LBB49_2:
---
>         jne     .LBB26_4
>         jmp     .LBB26_3
> .LBB26_2:
1426,1429c870,873
<         jmp     .LBB49_6
< .LBB49_3:
<         lea     rdi, [rip + .L__unnamed_9]
<         lea     rdx, [rip + .L__unnamed_10]
---
>         jmp     .LBB26_6
> .LBB26_3:
>         lea     rdi, [rip + .L__unnamed_8]
>         lea     rdx, [rip + .L__unnamed_9]
1434c878
< .LBB49_4:
---
> .LBB26_4:
1437,1439c881,883
<         jne     .LBB49_5
<         jmp     .LBB49_3
< .LBB49_5:
---
>         jne     .LBB26_5
>         jmp     .LBB26_3
> .LBB26_5:
1445c889
< .LBB49_6:
---
> .LBB26_6:
1473c917
<         lea     rcx, [rip + .L__unnamed_12]
---
>         lea     rcx, [rip + .L__unnamed_10]
1485c929
< .LBB50_1:
---
> .LBB27_1:
1497,1508c941
<         jne     .LBB50_3
<         mov     rdi, qword ptr [rsp + 48]
<         mov     rax, qword ptr [rsp + 64]
<         mov     qword ptr [rsp + 453], rax
<         mov     rax, qword ptr [rsp + 72]
<         mov     qword ptr [rsp + 461], rax
<         mov     rax, qword ptr [rsp + 80]
<         mov     qword ptr [rsp + 469], rax
<         mov     rax, qword ptr [rsp + 88]
<         mov     qword ptr [rsp + 477], rax
<         lea     rsi, [rsp + 453]
<         call    qword ptr [rip + core::array::<impl [T; N]>::map@GOTPCREL]
---
>         jne     .LBB27_3
1509a943,951
>         mov     rcx, qword ptr [rsp + 48]
>         movups  xmm0, xmmword ptr [rsp + 64]
>         movups  xmm1, xmmword ptr [rsp + 80]
>         movaps  xmmword ptr [rsp + 464], xmm1
>         movaps  xmmword ptr [rsp + 448], xmm0
>         movups  xmm0, xmmword ptr [rsp + 448]
>         movups  xmm1, xmmword ptr [rsp + 464]
>         movups  xmmword ptr [rcx + 16], xmm1
>         movups  xmmword ptr [rcx], xmm0
1512c954
< .LBB50_3:
---
> .LBB27_3:
1520,1522c962,964
<         jne     .LBB50_4
<         jmp     .LBB50_5
< .LBB50_4:
---
>         jne     .LBB27_4
>         jmp     .LBB27_5
> .LBB27_4:
1549,1550c991,992
<         jmp     .LBB50_6
< .LBB50_5:
---
>         jmp     .LBB27_6
> .LBB27_5:
1552c994
<         lea     rdx, [rip + .L__unnamed_13]
---
>         lea     rdx, [rip + .L__unnamed_11]
1557c999
< .LBB50_6:
---
> .LBB27_6:
1569c1011
<         je      .LBB50_1
---
>         je      .LBB27_1
1578c1020
<         jmp     .LBB50_6
---
>         jmp     .LBB27_6
1580,1594c1022
< example::testa::{{closure}}:
<         mov     al, sil
<         ret
< 
< .L__unnamed_9:
<         .ascii  "assertion failed: 0 < pointee_size && pointee_size <= isize::MAX as usize"
< 
< .L__unnamed_14:
<         .ascii  "/rustc/2bbb6198933abf193c0ef1d18d9d70f99eed59ba/library/core/src/ptr/const_ptr.rs"
< 
< .L__unnamed_10:
<         .quad   .L__unnamed_14
<         .asciz  "Q\000\000\000\000\000\000\0000\003\000\000\t\000\000"
< 
< .L__unnamed_15:
---
> .L__unnamed_12:
1598c1026
<         .quad   .L__unnamed_15
---
>         .quad   .L__unnamed_12
1606c1034
< .L__unnamed_16:
---
> .L__unnamed_13:
1610c1038
<         .quad   .L__unnamed_16
---
>         .quad   .L__unnamed_13
1613c1041
< .L__unnamed_17:
---
> .L__unnamed_14:
1617c1045
<         .quad   .L__unnamed_17
---
>         .quad   .L__unnamed_14
1621,1630d1048
<         .ascii  "assertion failed: iter.size_hint().0 >= N"
< 
< .L__unnamed_18:
<         .ascii  "/rustc/2bbb6198933abf193c0ef1d18d9d70f99eed59ba/library/core/src/array/mod.rs"
< 
< .L__unnamed_6:
<         .quad   .L__unnamed_18
<         .asciz  "M\000\000\000\000\000\000\000\022\003\000\000\005\000\000"
< 
< .L__unnamed_7:
1633c1051
< .L__unnamed_19:
---
> .L__unnamed_15:
1636,1637c1054,1055
< .L__unnamed_8:
<         .quad   .L__unnamed_19
---
> .L__unnamed_6:
>         .quad   .L__unnamed_15
1640c1058
< .L__unnamed_20:
---
> .L__unnamed_16:
1643,1644c1061,1062
< .L__unnamed_11:
<         .quad   .L__unnamed_20
---
> .L__unnamed_7:
>         .quad   .L__unnamed_16
1647c1065,1075
< .L__unnamed_21:
---
> .L__unnamed_8:
>         .ascii  "assertion failed: 0 < pointee_size && pointee_size <= isize::MAX as usize"
> 
> .L__unnamed_17:
>         .ascii  "/rustc/2bbb6198933abf193c0ef1d18d9d70f99eed59ba/library/core/src/ptr/const_ptr.rs"
> 
> .L__unnamed_9:
>         .quad   .L__unnamed_17
>         .asciz  "Q\000\000\000\000\000\000\0000\003\000\000\t\000\000"
> 
> .L__unnamed_18:
1650,1651c1078,1079
< .L__unnamed_12:
<         .quad   .L__unnamed_21
---
> .L__unnamed_10:
>         .quad   .L__unnamed_18
1654,1655c1082,1083
< .L__unnamed_13:
<         .quad   .L__unnamed_21
---
> .L__unnamed_11:
>         .quad   .L__unnamed_18

Why ❔

I was reading the code to understand what this was doing and noticed this. Seemed like an unopinionated improvement, unless I'm missing something here.

Checklist

@austinabell
Copy link
Author

This pattern is repeated through the codebase. I forgot to mention that I'm happy to update other instances once a maintainer indicates this change can come in :) If so, let me know if ideal to update this PR or open a PR for each instance

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