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

Skip to content

Commit 1fc86b5

Browse files
committed
Add an IsKnownConstant path to SinCos
1 parent 2a779ab commit 1fc86b5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public static partial class Math
9595
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9696
public static unsafe (double Sin, double Cos) SinCos(double x)
9797
{
98+
if (RuntimeHelpers.IsKnownConstant(x))
99+
{
100+
return (Sin(x), Cos(x));
101+
}
102+
98103
double sin, cos;
99104
SinCos(x, &sin, &cos);
100105
return (sin, cos);
@@ -119,6 +124,7 @@ public static unsafe (double Sin, double Cos) SinCos(double x)
119124
[MethodImpl(MethodImplOptions.InternalCall)]
120125
private static extern unsafe double ModF(double x, double* intptr);
121126

127+
[Intrinsic]
122128
[MethodImpl(MethodImplOptions.InternalCall)]
123129
private static extern unsafe void SinCos(double x, double* sin, double* cos);
124130
}

src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public static partial class MathF
9292
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9393
public static unsafe (float Sin, float Cos) SinCos(float x)
9494
{
95+
if (RuntimeHelpers.IsKnownConstant(x))
96+
{
97+
return (Sin(x), Cos(x));
98+
}
99+
95100
float sin, cos;
96101
SinCos(x, &sin, &cos);
97102
return (sin, cos);
@@ -116,6 +121,7 @@ public static unsafe (float Sin, float Cos) SinCos(float x)
116121
[MethodImpl(MethodImplOptions.InternalCall)]
117122
private static extern unsafe float ModF(float x, float* intptr);
118123

124+
[Intrinsic]
119125
[MethodImpl(MethodImplOptions.InternalCall)]
120126
private static extern unsafe void SinCos(float x, float* sin, float* cos);
121127
}

0 commit comments

Comments
 (0)