Skip to content

Boxing zeroed arrays and slices uses rust_alloc + memset instead of rust_alloc_zeroed #80752

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

Open
leonardo-m opened this issue Jan 6, 2021 · 1 comment
Labels
A-box Area: Our favorite opsem complication C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-opsem Relevant to the opsem team

Comments

@leonardo-m
Copy link

leonardo-m commented Jan 6, 2021

#![feature(box_syntax)]

use std::convert::TryInto;

const N: usize = 100_000;

pub fn foo1() -> Vec<u32> {
    vec![0; N]
}

pub fn foo2() -> Box<[u32]> {
    box [0; N]
}

pub fn foo3() -> Box<[u32; N]> {
    box [0; N]
}

pub fn foo4() -> Box<[u32; N]> {
    vec![0; N].into_boxed_slice().try_into().unwrap()
}

Gives (rustc 1.51.0-nightly 8018418 2021-01-03):

.LCPI0_0:
    .quad   100000
    .quad   100000
foo1:
    push    rbx
    mov     rbx, rdi
    mov     edi, 400000
    mov     esi, 4
    call    qword ptr [rip + __rust_alloc_zeroed@GOTPCREL]
    test    rax, rax
    je      .LBB0_1
    mov     qword ptr [rbx], rax
    vmovaps xmm0, xmmword ptr [rip + .LCPI0_0]
    vmovups xmmword ptr [rbx + 8], xmm0
    mov     rax, rbx
    pop     rbx
    ret
.LBB0_1:
    mov     edi, 400000
    mov     esi, 4
    call    qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
    ud2


foo2:
    push    rbx
    mov     edi, 400000
    mov     esi, 4
    call    qword ptr [rip + __rust_alloc@GOTPCREL]
    test    rax, rax
    je      .LBB1_1
    mov     rbx, rax
    mov     edx, 400000
    mov     rdi, rax
    xor     esi, esi
    call    qword ptr [rip + memset@GOTPCREL]
    mov     edx, 100000
    mov     rax, rbx
    pop     rbx
    ret
.LBB1_1:
    mov     edi, 400000
    mov     esi, 4
    call    qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
    ud2


foo3:
    push    rbx
    mov     edi, 400000
    mov     esi, 4
    call    qword ptr [rip + __rust_alloc@GOTPCREL]
    test    rax, rax
    je      .LBB2_1
    mov     rbx, rax
    mov     edx, 400000
    mov     rdi, rax
    xor     esi, esi
    call    qword ptr [rip + memset@GOTPCREL]
    mov     rax, rbx
    pop     rbx
    ret
.LBB2_1:
    mov     edi, 400000
    mov     esi, 4
    call    qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
    ud2


foo4:
    push    rax
    mov     edi, 400000
    mov     esi, 4
    call    qword ptr [rip + __rust_alloc_zeroed@GOTPCREL]
    test    rax, rax
    je      .LBB3_1
    pop     rcx
    ret
.LBB3_1:
    mov     edi, 400000
    mov     esi, 4
    call    qword ptr [rip + alloc::alloc::handle_alloc_error@GOTPCREL]
    ud2    

I think box should use rust_alloc_zeroed instead.

@camelid camelid added requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jan 6, 2021
@fmease fmease removed the requires-nightly This issue requires a nightly compiler in some way. label Dec 28, 2024
@fmease fmease changed the title box (for arrays and slices) uses rust_alloc + memset instead of rust_alloc_zeroed Boxing zeroed arrays and slices uses rust_alloc + memset instead of rust_alloc_zeroed Dec 28, 2024
@fmease fmease added T-opsem Relevant to the opsem team A-box Area: Our favorite opsem complication C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Dec 28, 2024
@fmease
Copy link
Member

fmease commented Dec 28, 2024

Triage: No change except that box … (box_syntax) is no more. After replacing the box … with Box::new(…), this can still be reproduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-box Area: Our favorite opsem complication C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-opsem Relevant to the opsem team
Projects
None yet
Development

No branches or pull requests

3 participants