Skip to content

ARM64 Vector2 multiplication breaks in .NET 8 #98137

Closed

Description

@NoelFB

Description

On Linux and MacOS, various Vector2 floating point multiplications break after running for a few hundred milliseconds.

Running this code in Release Mode on a dotnet new console application on ARM64 results in the Y component of the vector being zero.

using System.Numerics;

while (true)
{
    Thread.Sleep(10);
    Step(4.0f);
}

static void Step(float number)
{
    var variable = Vector2.One * number;
    if (variable.X != variable.Y)
        throw new Exception("Components don't match");
    Console.WriteLine(variable);
}

This does not occur in Debug Mode. If I don't wrap the code in a function (Step) it doesn't seem to happen. If I hard code the floating value (Vector2.One * 4.0f) it doesn't seem to happen.

Reproduction Steps

Simply create a new console project in .NET 8 and run the above code in Program.cs with dotnet run -c Release. After running for a few hundred milliseconds the application will throw an exception.

Expected behavior

Multiplication should always result in <4,4>

Actual behavior

Multiplication results in <4,0> after several hundred milliseconds

Regression?

Does not occur in .NET 7, only .NET 8

Known Workarounds

No response

Configuration

.NET 8, ARM64, MacOS (have had reports of this same problem on ARM64 Linux)

Other information

This has been an issue found in our open source game Celeste 64 for users running the game on ARM64 for both MacOS and Linux. I personally have only tested on MacOS.

Activity

  1. ghost added
    untriaged
    on Feb 7, 2024
  2. isadorasophia commented on Feb 7, 2024

    @isadorasophia

    @tannergooding could you help triaging this?

  3. added
    area-CodeGen-coreclr
    and removed on Feb 8, 2024
  4. tannergooding commented on Feb 8, 2024

    @tannergooding
    Member

    This was fixed by @jakobbotsch in .NET 9 via #94413, which was fixing a different issue caused by the types of op1/op2 mismatching for MultiplyByScalar (one is a TYP_SIMD16, the other a TYP_SIMD8).

    The simple fix should be backporting this PR to .NET 8.


    Independently, we should ensure an issue exists to ensure constant folding does work for this scenario and that the correctly typed operand is selected.

  5. jakobbotsch commented on Feb 8, 2024

    @jakobbotsch
    Member

    This was fixed by @jakobbotsch in .NET 9 via #94413, which was fixing a different issue caused by the types of op1/op2 mismatching for MultiplyByScalar (one is a TYP_SIMD16, the other a TYP_SIMD8).

    That PR fixed the type mismatch but also deliberately this particular issue, which I noticed while working on the other one (#94413 (comment)).

  6. theofficialgman commented on Feb 9, 2024

    @theofficialgman

    Configuration

    .NET 8, ARM64, MacOS (have had reports of this same problem on ARM64 Linux)

    can confirm running the testcase results in an exception after 77 iterations on arm64 linux

  7. removed
    untriaged
    on Feb 13, 2024
  8. added this to the 8.0.x milestone on Feb 13, 2024
  9. jakobbotsch commented on Jun 5, 2024

    @jakobbotsch
    Member

    The fix is available in the current .NET 8 release.

  10. locked and limited conversation to collaborators on Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions