Skip to content

Net8 - Vector2.Normalize and old(?) CPU - wrong result #99391

@sDIMMaX

Description

@sDIMMaX

Description

Vector2.Normalize - wrong result and i think this is Cpu problem (.Net use some unsuported intrinsics?)

Reproduction Steps

Console.WriteLine(Vector2.Normalize(new(0,2)));

Expected behavior

<0 1>

Actual behavior

<0 ∞>

Regression?

In 7 and 8.0.preview.1 - works
8.0.preview.2, rc.1, 8.0.201 ... - issue

Known Workarounds

No response

Configuration

I reproduced this on intel celeron e3300 and intel p6100
(Win10 and Win7) x64

Other information

Edit:
copy from
https://github.com/microsoft/referencesource/blob/master/System.Numerics/System/Numerics/Vector2.cs#L191

        public static Vector2 Normalize2(Vector2 value)
        {
            if (Vector.IsHardwareAccelerated)
            {
//-----------------------------------------------------------------------------
		Console.WriteLine("HardwareAccelerated");
//-----------------------------------------------------------------------------
                float length = value.Length();
                return value / length;
            }
            else
            {
                float ls = value.X * value.X + value.Y * value.Y;
                float invNorm = 1.0f / (float)Math.Sqrt((double)ls);

                return new Vector2(
                    value.X * invNorm,
                    value.Y * invNorm);
            }
        }

code

var v1 = new Vector2(0,2);
Console.WriteLine(Vector2.Normalize(v1));
Console.WriteLine(Normalize2(v1));

shows

<0  ∞>
HardwareAccelerated
<0  1>

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions