Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
jakobbotsch committed Sep 2, 2021
commit aabdb1200507602f691736dda12c46de65170dc2
29 changes: 29 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_58373/Runtime_58373.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please tell me which complus are needed to repro it on x64 windows?

Copy link
Member Author

Choose a reason for hiding this comment

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

I must have made a blunder somewhere, this test does not repro it for me either. It seems on x64 we normalize when we move the arg to the outgoing arg area/into arg register. So we need a little bit more. This exposes it on x64:

using System;
using System.Runtime.CompilerServices;

public unsafe class Runtime_58373
{
    public static int Main()
    {
        short halfValue = HalfToInt16Bits(MakeHalf());
        int x = halfValue;
        short val2 = HalfToInt16Bits(*(Half*)&x);

        return halfValue == val2 ? 100 : -1;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static Half MakeHalf()
    {
        return (Half)(-1.0f);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static short HalfToInt16Bits(Half h)
    {
        return *(short*)&h;
    }
}  

This one exposes it on x86 without unsafe except for the reinterp:

using System;
using System.Runtime.CompilerServices;

public unsafe class Runtime_58373
{
    public static int Main()
    {
        // Use up a lot of registers
        int a = GetVal();
        int b = GetVal();
        int c = GetVal();
        int d = GetVal();
        int e = GetVal();
        int f = GetVal();
        int g = GetVal();
        int h = GetVal();
        int i = GetVal();

        short val1 = HalfToInt16Bits(MakeHalf());
        Half half = MakeHalf();
        MakeHalf(); // This will spill lower 16 bits of 'half' to memory
        short val2 = HalfToInt16Bits(half); // This will pass 32 bits as arg with upper 16 bits undefined

        return val1 == val2 ? 100 + a + b + c + d + e + f + g + h + i : -1;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static int GetVal()
    {
        return 0;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static Half MakeHalf()
    {
        return default;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static short HalfToInt16Bits(Half h)
    {
        return *(short*)&h;
    }
}  

I will change the test to use these cases.

// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;

public unsafe class Runtime_58373
{
public static int Main()
{
FillStack(0, 0, 0, 0, 0, 0, 0xdeadbeef);
short val1 = HalfToInt16Bits(0, 0, 0, 0, 0, 0, (Half)42f);
FillStack(0, 0, 0, 0, 0, 0, 0xf000baaa);
short val2 = HalfToInt16Bits(0, 0, 0, 0, 0, 0, (Half)42f);

return val1 == val2 ? 100 : -1;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void FillStack(int a0, int a1, int a2, int a3, int a4, int a5, uint onStack)
{
}

[MethodImpl(MethodImplOptions.NoInlining)]
static short HalfToInt16Bits(int a0, int a1, int a2, int a3, int a4, int a5, Half h)
{
return *(short*)&h;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>