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
[System.MathF] Bring support for the single-precission Math operations to Mono #7941
Conversation
#if MONO | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static byte Clamp(byte value, byte min, byte max) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use K&R indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copy pasted this from CoreCLR, I rather not change the style of the copy-pasted code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am tentative on this, would much rather see directly used ../external/corefx/src/Common/src/CoreLib/System/Math.cs
but we could do it as follow up change
mono/metadata/sysmath.c
Outdated
@@ -316,3 +316,142 @@ ves_icall_System_Math_SplitFractionDouble (gdouble *v) | |||
{ | |||
return modf (*v, v); | |||
} | |||
|
|||
gfloat | |||
ves_icall_System_MathF_Acos (gfloat x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be just float, we don't use gfloat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do in that file, just a couple of lines above ;-)
I dont mind updating.
@@ -439,6 +439,31 @@ ICALL(MATH_16, "Sqrt", ves_icall_System_Math_Sqrt) | |||
ICALL(MATH_17, "Tan", ves_icall_System_Math_Tan) | |||
ICALL(MATH_18, "Tanh", ves_icall_System_Math_Tanh) | |||
|
|||
ICALL_TYPE(MATHF, "System.MathF", MATHF_1) | |||
ICALL(MATHF_1, "Acos", ves_icall_System_MathF_Acos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can be HANDLES(..) I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many but not all lines icall-def.h have HANDLES() around them.
This is how icalls get converted to be coop-friendly.
- passes/returns coop handles instead of raw pointers
- passes an extra, initialized MonoError*
- Check the error at the end.
Eventually every line should either have HANDLES or some comment or other macro explaining why not -- for example, maybe the only one, if no pointers and no errors and performance sensitive, that combination does not want HANDLES.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vargaz wouldn't HANDLE'izing those functions produce a net loss of perf for something they don't need? IE, none raise exceptions or take ref pointers.
mono/metadata/icall-def.h
Outdated
ICALL(MATHF_13, "Floor", ves_icall_System_MathF_Floor) | ||
ICALL(MATHF_14, "Log", ves_icall_System_MathF_Log) | ||
ICALL(MATHF_15, "Log10", ves_icall_System_MathF_Log10) | ||
ICALL(MATHF_23, "ModF(float,float&)", ves_icall_System_MathF_ModF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This signature doesn't match the managed signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed my mind, I kept the .NET signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short version: done
} | ||
|
||
float | ||
ves_icall_System_MathF_ModF (float x, float *d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This icall must null check d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to be ref, do we still need the check in that case?
CoreCLR does not have that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If managed was using a byref instead of a pointer, we won't need it as we emit caller side checks. That doesn't happen with pointers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's it's only used by Truncate and Round with locals, so it's just lousy code on their end but we should be safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a check, just for sanity's sake.
Mhm, the build breaks elsewhere with a series of errors like this:
|
…ime.Extensions to match .NET Core
@monojenkins build Linux x64 |
@monojenkins build Linux AArch64 Interpreter |
@akoeplinger @marek-safar can you please check the API Diff |
The API diff looks fine to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add external/corefx/src/System.Runtime.Extensions/tests/System/MathTests.netcoreapp.cs
to corlib_xtest.dll.sources to add tests which test the new APIs
{ | ||
public static partial class MathF | ||
{ | ||
[MethodImpl(MethodImplOptions.InternalCall)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to follow Mono coding style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rather not for code that is copy pasted, makes it simpler to track changes.
mcs/class/corlib/corlib.dll.sources
Outdated
@@ -978,6 +978,8 @@ ReferenceSources/Type.cs | |||
../referencesource/mscorlib/system/invalidtimezoneexception.cs | |||
../referencesource/mscorlib/system/Lazy.cs | |||
../referencesource/mscorlib/system/math.cs | |||
../../../external/corert//src/System.Private.CoreLib/shared/System/MathF.cs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use version from ../../../external/corefx/src/Common/src/CoreLib/System/MathF.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
#if MONO | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static byte Clamp(byte value, byte min, byte max) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am tentative on this, would much rather see directly used ../external/corefx/src/Common/src/CoreLib/System/Math.cs
but we could do it as follow up change
The System.Runtime.Extensions change for a desktop could be problematic but let's see if anyone hits it |
@monojenkins commit apidiff |
Noticed this while looking at Jenkins logs today: ``` 15:00:56 /mnt/jenkins/workspace/test-mono-pull-request-amd64/mcs/class/lib/net_4_x/mscorlib.dll 15:00:56 cant resolve internal call to "System.MathF::ModF(single,single*)" (tested without signature also) ``` We need to use `single` in the icall def instead of `float`. It was introduced by mono#7941
Noticed this while looking at Jenkins logs today: ``` 15:00:56 /mnt/jenkins/workspace/test-mono-pull-request-amd64/mcs/class/lib/net_4_x/mscorlib.dll 15:00:56 cant resolve internal call to "System.MathF::ModF(single,single*)" (tested without signature also) ``` We need to use `single` in the icall def instead of `float`. It was introduced by #7941
…s to Mono (mono/mono#7941) This pull request brings support to Mono's class libraries for the new `System.MathF` type which includes operations for single-floating point. This is needed to run some new applications like: https://github.com/aras-p/ToyPathTracer With this change, it is possible to run this unmodified. With this support, and the `-O=float32` option, it is possible to improve the performance from 6.3Mrays/sec to 7.8Mrays/sec on a Mac. Oddly, this seems to be faster than .NET Core 2.1.4, which is at 4.2Mrays/sec. * Bump API snapshot submodule Commit migrated from mono/mono@52df0f2
Noticed this while looking at Jenkins logs today: ``` 15:00:56 /mnt/jenkins/workspace/test-mono-pull-request-amd64/mcs/class/lib/net_4_x/mscorlib.dll 15:00:56 cant resolve internal call to "System.MathF::ModF(single,single*)" (tested without signature also) ``` We need to use `single` in the icall def instead of `float`. It was introduced by mono/mono#7941 Commit migrated from mono/mono@d59246b
This pull request brings support to Mono's class libraries for the new
System.MathF
type which includes operations for single-floating point.This is needed to run some new applications like:
https://github.com/aras-p/ToyPathTracer
With this change, it is possible to run this unmodified. With this support, and the
-O=float32
option, it is possible to improve the performance from 6.3Mrays/sec to 7.8Mrays/sec on a Mac.Oddly, this seems to be faster than .NET Core 2.1.4, which is at 4.2Mrays/sec.