Skip to content

Incorrect ABI when passing f32/f64 on a function with #[target_feature(enable = "sse2")] #82529

Closed
@Amanieu

Description

@Amanieu

Godbolt link

The following code passes a floating-point value using the wrong ABI:

use std::arch::x86::*;

// This function expects a in xmm0
#[target_feature(enable = "sse2")]
unsafe fn sse2(a: f64) -> __m128d {
    _mm_set1_pd(a)
}

pub unsafe fn non_sse2(a: f64) -> __m128d {
    // This passes a on the stack
    sse2(a)
}

Assembly output:

example::sse2:
        mov     eax, ecx
        movsd   qword ptr [ecx], xmm0
        movsd   qword ptr [ecx + 8], xmm0
        ret

example::non_sse2:
        push    esi
        sub     esp, 8
        mov     esi, dword ptr [esp + 16]
        fld     qword ptr [esp + 20]
        fstp    qword ptr [esp]
        mov     ecx, esi
        call    example::sse2
        mov     eax, esi
        add     esp, 8
        pop     esi
        ret     4

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-x86_32Target: x86 processors, 32 bit (like i686-*) (IA-32)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions