Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ee5bff

Browse files
committed
Use the built-in Log2 implementation from Vector64/128/256/512 on .NET 9+
1 parent cc01c72 commit 8ee5bff

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.netcore.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11774,6 +11774,17 @@ public static Vector512<T> Invoke(Vector512<T> t)
1177411774

1177511775
public static Vector128<T> Invoke(Vector128<T> x)
1177611776
{
11777+
#if NET9_0_OR_GREATER
11778+
if (typeof(T) == typeof(double))
11779+
{
11780+
return Vector128.Log2(x.AsDouble()).As<double, T>();
11781+
}
11782+
else
11783+
{
11784+
Debug.Assert(typeof(T) == typeof(float));
11785+
return Vector128.Log2(x.AsSingle()).As<float, T>();
11786+
}
11787+
#else
1177711788
if (typeof(T) == typeof(double))
1177811789
{
1177911790
return Log2OperatorDouble.Invoke(x.AsDouble()).As<double, T>();
@@ -11783,10 +11794,22 @@ public static Vector128<T> Invoke(Vector128<T> x)
1178311794
Debug.Assert(typeof(T) == typeof(float));
1178411795
return Log2OperatorSingle.Invoke(x.AsSingle()).As<float, T>();
1178511796
}
11797+
#endif
1178611798
}
1178711799

1178811800
public static Vector256<T> Invoke(Vector256<T> x)
1178911801
{
11802+
#if NET9_0_OR_GREATER
11803+
if (typeof(T) == typeof(double))
11804+
{
11805+
return Vector256.Log2(x.AsDouble()).As<double, T>();
11806+
}
11807+
else
11808+
{
11809+
Debug.Assert(typeof(T) == typeof(float));
11810+
return Vector256.Log2(x.AsSingle()).As<float, T>();
11811+
}
11812+
#else
1179011813
if (typeof(T) == typeof(double))
1179111814
{
1179211815
return Log2OperatorDouble.Invoke(x.AsDouble()).As<double, T>();
@@ -11796,10 +11819,22 @@ public static Vector256<T> Invoke(Vector256<T> x)
1179611819
Debug.Assert(typeof(T) == typeof(float));
1179711820
return Log2OperatorSingle.Invoke(x.AsSingle()).As<float, T>();
1179811821
}
11822+
#endif
1179911823
}
1180011824

1180111825
public static Vector512<T> Invoke(Vector512<T> x)
1180211826
{
11827+
#if NET9_0_OR_GREATER
11828+
if (typeof(T) == typeof(double))
11829+
{
11830+
return Vector512.Log2(x.AsDouble()).As<double, T>();
11831+
}
11832+
else
11833+
{
11834+
Debug.Assert(typeof(T) == typeof(float));
11835+
return Vector512.Log2(x.AsSingle()).As<float, T>();
11836+
}
11837+
#else
1180311838
if (typeof(T) == typeof(double))
1180411839
{
1180511840
return Log2OperatorDouble.Invoke(x.AsDouble()).As<double, T>();
@@ -11809,9 +11844,11 @@ public static Vector512<T> Invoke(Vector512<T> x)
1180911844
Debug.Assert(typeof(T) == typeof(float));
1181011845
return Log2OperatorSingle.Invoke(x.AsSingle()).As<float, T>();
1181111846
}
11847+
#endif
1181211848
}
1181311849
}
1181411850

11851+
#if !NET9_0_OR_GREATER
1181511852
/// <summary>double.Log2(x)</summary>
1181611853
internal readonly struct Log2OperatorDouble : IUnaryOperator<double>
1181711854
{
@@ -12396,6 +12433,7 @@ public static Vector512<float> Invoke(Vector512<float> x)
1239612433
);
1239712434
}
1239812435
}
12436+
#endif
1239912437

1240012438
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1240112439
private static Vector128<T> ElementWiseSelect<T>(Vector128<T> mask, Vector128<T> left, Vector128<T> right)

0 commit comments

Comments
 (0)