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

Why use ‘call CORINFO_HELP_DBL2ULNG’ when double to ulong instead of vcvttsd2si #95846

Closed
minxuanz opened this issue Dec 11, 2023 · 2 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Comments

@minxuanz
Copy link
Contributor

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    static public ulong D2UL(double d) => (ulong)d;

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    static public uint D2UINT(double d) => (uint)d;

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    static public long D2L(double d) => (long)d;

unlike double to uint,when double to ulong , it will call CORINFO_HELP_DBL2ULNG

Program:D2UL(double):ulong (FullOpts):
G_M33866_IG01:  ;; offset=0x0000
       push     rax
       vzeroupper 
G_M33866_IG02:  ;; offset=0x0004
       call     CORINFO_HELP_DBL2ULNG
       nop      
G_M33866_IG03:  ;; offset=0x000A
       add      rsp, 8
       ret   


Program:D2UINT(double):uint (FullOpts):
G_M22956_IG01:  ;; offset=0x0000
       vzeroupper 
G_M22956_IG02:  ;; offset=0x0003
       vcvttsd2si  rax, xmm0
G_M22956_IG03:  ;; offset=0x0008
       ret         

but c++ compiler codegen

D2UL(double):                               # @D2UL(double)
        vcvttsd2si      rcx, xmm0
        mov     rdx, rcx
        sar     rdx, 63
        vsubsd  xmm0, xmm0, qword ptr [rip + .LCPI0_0]
        vcvttsd2si      rax, xmm0
        and     rax, rdx
        or      rax, rcx
        ret
D2UINT(double):                             # @D2UINT(double)
        vcvttsd2si      rax, xmm0
        ret
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 11, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 11, 2023
@ghost
Copy link

ghost commented Dec 11, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details
    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    static public ulong D2UL(double d) => (ulong)d;

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    static public uint D2UINT(double d) => (uint)d;

    [MethodImplAttribute(MethodImplOptions.NoInlining)]
    static public long D2L(double d) => (long)d;

unlike double to uint,when double to ulong , it will call CORINFO_HELP_DBL2ULNG

Program:D2UL(double):ulong (FullOpts):
G_M33866_IG01:  ;; offset=0x0000
       push     rax
       vzeroupper 
G_M33866_IG02:  ;; offset=0x0004
       call     CORINFO_HELP_DBL2ULNG
       nop      
G_M33866_IG03:  ;; offset=0x000A
       add      rsp, 8
       ret   


Program:D2UINT(double):uint (FullOpts):
G_M22956_IG01:  ;; offset=0x0000
       vzeroupper 
G_M22956_IG02:  ;; offset=0x0003
       vcvttsd2si  rax, xmm0
G_M22956_IG03:  ;; offset=0x0008
       ret         

but c++ compiler codegen

D2UL(double):                               # @D2UL(double)
        vcvttsd2si      rcx, xmm0
        mov     rdx, rcx
        sar     rdx, 63
        vsubsd  xmm0, xmm0, qword ptr [rip + .LCPI0_0]
        vcvttsd2si      rax, xmm0
        and     rax, rdx
        or      rax, rcx
        ret
D2UINT(double):                             # @D2UINT(double)
        vcvttsd2si      rax, xmm0
        ret
Author: monstercatss
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@huoyaoyuan
Copy link
Member

#89279

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Dec 11, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

No branches or pull requests

2 participants