Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Moving parts of System.Math and System.MathF to be shared with CoreRT. #14119

Merged
merged 8 commits into from
Sep 23, 2017
Merged

Moving parts of System.Math and System.MathF to be shared with CoreRT. #14119

merged 8 commits into from
Sep 23, 2017

Conversation

tannergooding
Copy link
Member

This splits System.Math and System.MathF into partial classes so that parts of the code can be shared with CoreRT.

The changes on the native side are:

  • COMDouble and COMSingle now export a FMod function which wraps fmod
  • COMDouble and COMSingle now export a ModF function which matches the native signature
  • COMDouble and COMSingle no longer export a Round function

The changes on the managed side are:

  • A few more AggressiveInlining attributes, to match CoreRT
  • Round is now implemented in managed code
  • RoundInternal is directly inlined now
  • Truncate calls a new modf private function, rather than InternalTruncate which itself called SplitFraction
  • copysign is a new private function directly implemented in managed code (this supports Round)

Everything else is just moving the types around between the files or non functional changes such as:

  • Adding braces that were previously missing
  • Using a ternary expression (instead of if/else) when we are selecting between two return values
  • Using the keyword rather than full type name (this seems to be the more common and recommended behavior)

@tannergooding
Copy link
Member Author

FYI. @jkotas

@tannergooding
Copy link
Member Author

Also FYI. @mellinoe

@@ -13,712 +13,73 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention has been to rename the CoreCLR specific part like Math.CoreCLR.cs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return div;
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern double fmod(double x, double y);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CamelCase naming?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

FCIntrinsic("Pow", COMDouble::Pow, CORINFO_INTRINSIC_Pow)
FCIntrinsic("Round", COMDouble::Round, CORINFO_INTRINSIC_Round)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that Round will be no longer treated as intrinsic by the JIT.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the mechanism used to treat a non FCALL method as intrinsic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark the method with [Intrinsic] attribute and recognize it by name in the JIT.

#13815 introduced this mechanism.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, thanks!

I've already added the [Intrinsic] attribute, so I should just need to recognize it by name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkotas, I ended up adding two new named intrinsics (one for Math.Round and one for MathF.Round).

I then modified the Compiler::impIntrinsic in importer to map the new named intrinsic to the old CORINFO intrinsic.

This looks to be working end to end right now, since the named intrinsic checks only happen in morph and importer, but only before the GenTree* has been created.

// changes (such as if we support all methods in a class as intrinsic), we can reorder
// the checks to account for that.

if ((namespaceName != nullptr) && (className != nullptr) && (methodName != nullptr))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the reordering to put all the null checks up front. I have something similar in some of my pending changes.

However, I believe the jit will always be asking if a particular method is an intrinsic here. So I suggest the comment be removed or reworded.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to no longer include the part about reordering if it ever changes.

case NI_Math_Round:
{
// Math.Round and MathF.Round used to be a legacy JIT intrinsic. In order
// to simplify the transition, we will just treat it as if it was still the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: "legacy" has special meaning in the jit code base. Maybe say "used to be a traditional jit intrinsic."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to use 'traditional' rather than legacy.

}

retNode = op1;
retNode = impMathIntrinsic(method, sig, callType, intrinsicID, tailCall);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still going to see CORINFO_INTRINISC_Round on desktop -- desktop does not have the new-style intrinsics.

So it needs to remain in here for now.

If that seems messy, you can hide it from CoreCLR builds with ifdefs, but I wouldn't bother.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndyAyersMS, just to confirm, removing the mapping from ecalllist (in the VM layer) should be fine, correct?

Not sure which parts of the codebase are shared with Desktop and which parts aren't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the mapping from ecalllist (in the VM layer) should be fine, correct?

Yes.

Not sure which parts of the codebase are shared with Desktop and which parts aren't.

JIT and GC is.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left you some notes. The desktop compat one is the most serious.

@tannergooding
Copy link
Member Author

All feedback given so far has been resolved. Please let me know if anything else needs to be changed.

@tannergooding
Copy link
Member Author

Going to ping on this to see if it can get merged before EOD today, that way I can work on dotnet/corert#3167 and https://github.com/dotnet/corefx/issues/16428 this weekend.

// Currently we only have intrinsics at the method level, so we can check that
// namespaceName, className, and methodName are all not null upfront.

if ((namespaceName != nullptr) && (className != nullptr) && (methodName != nullptr))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It would be nice to early out here to save an extra level of indention for the actual matching code that is likely going to grow pretty big.

@jkotas
Copy link
Member

jkotas commented Sep 22, 2017

@dotnet-bot test Windows_NT x64 corefx_baseline
@dotnet-bot test Windows_NT x86 corefx_baseline
@dotnet-bot test Ubuntu x64 corefx_baseline

@jkotas
Copy link
Member

jkotas commented Sep 22, 2017

The VM and CoreLib parts look fine to me - assuming the corefx tests that I have triggered pass.

@AndyAyersMS or somebody else on @dotnet/jit-contrib should sing off on the JIT part.

@tannergooding
Copy link
Member Author

Thanks!

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates. Looks good.

@tannergooding
Copy link
Member Author

The Ubuntu job hasn't updated yet but it failed due to clang being missing:

13:29:18 Setting up directories for build
13:29:18 Checking pre-requisites...
13:29:18 Please install clang before running this script
13:29:18 Command execution failed with exit code 1.

@tannergooding
Copy link
Member Author

Requeued the job and it seems to be actually going now (new machine).

The bad machine (missing clang) was: ubuntu1404-20170821-aec340 -- cc @mmitche

@tannergooding
Copy link
Member Author

Actually, I take that back. The new run failed as well with the same issue:

13:51:17 Done initializing tools.
13:51:18 Running: /mnt/j/workspace/dotnet_coreclr/master/jitstress/x64_checked_ubuntu_corefx_baseline_prtest/_/fx/src/Native/build-native.sh   x64  Release  Linux  --numproc 4  -portable  toolSetDir=c:\tools\clr /p:CoreCLROverridePath=/mnt/j/workspace/dotnet_coreclr/master/jitstress/x64_checked_ubuntu_corefx_baseline_prtest/bin/Product/Linux.x64.Checked
13:51:18 Setting up directories for build
13:51:18 Checking pre-requisites...
13:51:18 Please install clang before running this script
13:51:18 Command execution failed with exit code 1.
13:51:18 [Current build status] check if current [SUCCESS] is worse or equals then [SUCCESS] and better or equals then [SUCCESS]

CC. @jkotas, it doesn't look to be related to my changes.

@tannergooding
Copy link
Member Author

Its definitely strange since clang is found by a separate script at an early step in the build.

@janvorli
Copy link
Member

I am sorry, the CoreFX tests in the CI for that change have passed, so I have assumed the VMs were fixed.

@janvorli
Copy link
Member

@mikem8361, @tannergooding, @jkotas I am going to revert that change. It requires creating the revert manually though since github doesn't want to do it automatically.

@tannergooding
Copy link
Member Author

@jkotas, looks like Windows_NT both failed in an unrelated area. System.Threading.Extensions.Tests failed due to FailFast: SetStateMachine should not be used.

@tannergooding
Copy link
Member Author

It looks like all other tests passed.

@janvorli
Copy link
Member

Revert PR is up: dotnet/corefx#24215

@tannergooding
Copy link
Member Author

@stephentoub
Copy link
Member

looks like Windows_NT both failed in an unrelated area. System.Threading.Extensions.Tests

Which test?

@stephentoub
Copy link
Member

Oh, I see, that test should be deleted. I'll do so. You can ignore the failure.

@tannergooding
Copy link
Member Author

@dotnet-bot test Ubuntu x64 corefx_baseline

@tannergooding
Copy link
Member Author

@dotnet-bot test Windows_NT x64 corefx_baseline
@dotnet-bot test Windows_NT x86 corefx_baseline

@tannergooding
Copy link
Member Author

Both known blocking failures have been fixed. I've requeued the tests.

@jkotas, am I good to merge later tonight if all three runs come back green?

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@jkotas
Copy link
Member

jkotas commented Sep 23, 2017

Could you please also rename src/mscorlib/src/System/Math.cs to src/mscorlib/src/System/Math.CoreCLR.cs ?

@tannergooding
Copy link
Member Author

Could you please also rename src/mscorlib/src/System/Math.cs to src/mscorlib/src/System/Math.CoreCLR.cs ?

Done. Thought I had done this already.

@tannergooding
Copy link
Member Author

@dotnet-bot test Windows_NT x64 corefx_baseline
@dotnet-bot test Windows_NT x86 corefx_baseline
@dotnet-bot test Ubuntu x64 corefx_baseline

@tannergooding
Copy link
Member Author

tannergooding commented Sep 23, 2017

Ubuntu is failing four of the FileSystemWatcherTests:

System.IO.Tests.FileSystemWatcherTests_netstandard17.EndInit_ResumesPausedEnableRaisingEvents
System.IO.Tests.FileSystemWatcherTests_netstandard17.EndInit_ResumesPausedEnableRaisingEvents(setBeforeBeginInit: True)
System.IO.Tests.FileSystemWatcherTests_netstandard17.EndInit_ResumesPausedEnableRaisingEvents(setBeforeBeginInit: False)
System.IO.Tests.File_Create_Tests.FileSystemWatcher_File_Create

I don't see these failing anywhere else, so I will investigate them tomorrow morning.

Looks like the failures are all that the test is expected some event to occur, but it is not receiving it

@tannergooding
Copy link
Member Author

Ok, looks like the Ubuntu FileSystemWatcherTests failures are not unique to my PR. They are also failing in the corefx_baseline for current master. Ex: https://ci.dot.net/job/dotnet_coreclr/job/master/job/jitstress/job/x64_checked_ubuntu_corefx_baseline/298/

@tannergooding
Copy link
Member Author

Its going to take a bit, but I'm going to try to pin down the commit that introduced the regression.

@tannergooding
Copy link
Member Author

The Ubuntu FileSystemWatcherTests failures were introduced in #14043. -- CC. @stephentoub, @pjanotti, @JeremyKuhne

@tannergooding
Copy link
Member Author

@jkotas, can this be merged?

@tannergooding
Copy link
Member Author

Logged a bug for the issue here: https://github.com/dotnet/coreclr/issues/14154

@jkotas jkotas merged commit bfaad96 into dotnet:master Sep 23, 2017
@tannergooding
Copy link
Member Author

Thanks!

@tannergooding
Copy link
Member Author

@jkotas, it looks like a PR to mirror these changes has not gone up to CoreRT yet.

Given that there will be some fixup required there as well, could you tag me when it comes up?

@jkotas
Copy link
Member

jkotas commented Sep 25, 2017

PR to mirror these changes has not gone up to CoreRT yet.

cc @safern

@safern
Copy link
Member

safern commented Sep 25, 2017

Taking a look now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants