Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround an MSVC bug with __libm_sse2_sincos_ #98207

Merged
merged 7 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/coreclr/classlibnative/float/floatdouble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ FCIMPL1_V(double, COMDouble::Sin, double x)
return sin(x);
FCIMPLEND

#if defined(_MSC_VER) && defined(TARGET_AMD64)
// The /fp:fast form of `sincos` for AMD64 returns sin twice, rather than sincos
#pragma float_control(push)
#pragma float_control(precise, on)
#endif

/*====================================SinCos====================================
**
==============================================================================*/
Expand All @@ -268,6 +274,10 @@ FCIMPL3_VII(void, COMDouble::SinCos, double x, double* pSin, double* pCos)

FCIMPLEND

#if defined(_MSC_VER) && defined(TARGET_AMD64)
#pragma float_control(pop)
#endif

/*=====================================Sinh=====================================
**
==============================================================================*/
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/classlibnative/float/floatsingle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ FCIMPL1_V(float, COMSingle::Sin, float x)
return sinf(x);
FCIMPLEND

#if defined(_MSC_VER) && defined(TARGET_AMD64)
// The /fp:fast form of `sincos` for AMD64 returns sin twice, rather than sincos
#pragma float_control(push)
#pragma float_control(precise, on)
#endif

/*====================================SinCos====================================
**
==============================================================================*/
Expand All @@ -243,6 +249,10 @@ FCIMPL3_VII(void, COMSingle::SinCos, float x, float* pSin, float* pCos)

FCIMPLEND

#if defined(_MSC_VER) && defined(TARGET_AMD64)
#pragma float_control(pop)
#endif

/*=====================================Sinh=====================================
**
==============================================================================*/
Expand Down
35 changes: 35 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_98204/Runtime_98204.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using Xunit;

public static class Runtime_98068
{
[Fact]
[InlineData(1e18)]
public static void TestSinCosDouble(double d)
{
double sin1 = Math.Sin(d);
double cos1 = Math.Cos(d);

(double sin2, double cos2) = Math.SinCos(d);

Assert.Equal(sin1, sin2);
Assert.Equal(cos1, cos2);
}

[Fact]
[InlineData(1e18f)]
public static void TestSinCosSingle(float f)
{
float sin1 = MathF.Sin(f);
float cos1 = MathF.Cos(f);

(float sin2, float cos2) = MathF.SinCos(f);

Assert.Equal(sin1, sin2);
Assert.Equal(cos1, cos2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>