* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Fix new dotnet-format issues after rebase * Address review comments * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * cpu tests: Disable CA2211 for CodeBaseAddress and DataBaseAddress * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * Apply suggestions from code review Co-authored-by: Ac_K <Acoustik666@gmail.com> * First dotnet format pass * Fix naming rule violations * Remove naming rule violation exceptions * Fix comment style * Use targeted new * Remove redundant code * Remove comment alignment * Remove naming rule exceptions * Add trailing commas * Use nameof expression * Reformat to add remaining trailing commas --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
93 lines
3.2 KiB
C#
93 lines
3.2 KiB
C#
using ARMeilleure.Translation;
|
|
using NUnit.Framework;
|
|
using Ryujinx.Cpu.Jit;
|
|
using Ryujinx.Tests.Memory;
|
|
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Ryujinx.Tests.Cpu
|
|
{
|
|
internal class EnvironmentTests
|
|
{
|
|
#pragma warning disable IDE0052 // Remove unread private member
|
|
private static Translator _translator;
|
|
#pragma warning restore IDE0052
|
|
|
|
private static void EnsureTranslator()
|
|
{
|
|
// Create a translator, as one is needed to register the signal handler or emit methods.
|
|
_translator ??= new Translator(new JitMemoryAllocator(), new MockMemoryManager(), true);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
|
|
private static float GetDenormal()
|
|
{
|
|
return BitConverter.Int32BitsToSingle(1);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
|
|
private static float GetZero()
|
|
{
|
|
return BitConverter.Int32BitsToSingle(0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// This test ensures that managed methods do not reset floating point control flags.
|
|
/// This is used to avoid changing control flags when running methods that don't require it, such as SVC calls, software memory...
|
|
/// </summary>
|
|
[Test]
|
|
public void FpFlagsPInvoke()
|
|
{
|
|
EnsureTranslator();
|
|
|
|
// Subnormal results are not flushed to zero by default.
|
|
// This operation should not be allowed to do constant propagation, hence the methods that explicitly disallow inlining.
|
|
Assert.AreNotEqual(GetDenormal() + GetZero(), 0f);
|
|
|
|
bool methodCalled = false;
|
|
bool isFz = false;
|
|
|
|
var managedMethod = () =>
|
|
{
|
|
// Floating point math should not modify fp flags.
|
|
float test = 2f * 3.5f;
|
|
|
|
if (test < 4f)
|
|
{
|
|
throw new Exception("Sanity check.");
|
|
}
|
|
|
|
isFz = GetDenormal() + GetZero() == 0f;
|
|
|
|
try
|
|
{
|
|
if (test >= 4f)
|
|
{
|
|
throw new Exception("Always throws.");
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// Exception handling should not modify fp flags.
|
|
|
|
methodCalled = true;
|
|
}
|
|
};
|
|
|
|
var method = TranslatorTestMethods.GenerateFpFlagsPInvokeTest();
|
|
|
|
// This method sets flush-to-zero and then calls the managed method.
|
|
// Before and after setting the flags, it ensures subnormal addition works as expected.
|
|
// It returns a positive result if any tests fail, and 0 on success (or if the platform cannot change FP flags)
|
|
int result = method(Marshal.GetFunctionPointerForDelegate(managedMethod));
|
|
|
|
// Subnormal results are not flushed to zero by default, which we should have returned to exiting the method.
|
|
Assert.AreNotEqual(GetDenormal() + GetZero(), 0f);
|
|
|
|
Assert.True(result == 0);
|
|
Assert.True(methodCalled);
|
|
Assert.True(isFz);
|
|
}
|
|
}
|
|
}
|