From 902c392690f0048a3421726b98766aa1bac6f411 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Wed, 19 Jun 2024 12:58:16 -0700 Subject: [PATCH] Add an IsKnownConstant path to SinCos --- .../System.Private.CoreLib/src/System/Math.CoreCLR.cs | 5 +++++ .../System.Private.CoreLib/src/System/MathF.CoreCLR.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs index 1384da2c81d1f..530355082d26d 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs @@ -95,6 +95,11 @@ public static partial class Math [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe (double Sin, double Cos) SinCos(double x) { + if (RuntimeHelpers.IsKnownConstant(x)) + { + return (Sin(x), Cos(x)); + } + double sin, cos; SinCos(x, &sin, &cos); return (sin, cos); diff --git a/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs index 2bef2b8d3e175..90403480bf5df 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs @@ -92,6 +92,11 @@ public static partial class MathF [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe (float Sin, float Cos) SinCos(float x) { + if (RuntimeHelpers.IsKnownConstant(x)) + { + return (Sin(x), Cos(x)); + } + float sin, cos; SinCos(x, &sin, &cos); return (sin, cos);