[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) | ||
{ |
vargaz
Apr 2, 2018
Member
This should use K&R indentation.
This should use K&R indentation.
migueldeicaza
Apr 2, 2018
Author
Member
I copy pasted this from CoreCLR, I rather not change the style of the copy-pasted code.
I copy pasted this from CoreCLR, I rather not change the style of the copy-pasted code.
marek-safar
Apr 4, 2018
Member
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
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
@@ -316,3 +316,142 @@ ves_icall_System_Math_SplitFractionDouble (gdouble *v) | |||
{ | |||
return modf (*v, v); | |||
} | |||
|
|||
gfloat | |||
ves_icall_System_MathF_Acos (gfloat x) |
vargaz
Apr 2, 2018
Member
This should be just float, we don't use gfloat.
This should be just float, we don't use gfloat.
migueldeicaza
Apr 2, 2018
Author
Member
We do in that file, just a couple of lines above ;-)
I dont mind updating.
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) |
vargaz
Apr 2, 2018
Member
These can be HANDLES(..) I think.
These can be HANDLES(..) I think.
migueldeicaza
Apr 2, 2018
Author
Member
What do you mean?
What do you mean?
jaykrell
Apr 2, 2018
Collaborator
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.
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.
kumpera
Apr 2, 2018
Member
@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.
@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.
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) |
kumpera
Apr 2, 2018
Member
This signature doesn't match the managed signature.
This signature doesn't match the managed signature.
migueldeicaza
Apr 2, 2018
Author
Member
Good catch, thanks!
Good catch, thanks!
migueldeicaza
Apr 2, 2018
Author
Member
I changed my mind, I kept the .NET signature.
I changed my mind, I kept the .NET signature.
migueldeicaza
Apr 2, 2018
Author
Member
Short version: done
Short version: done
} | ||
|
||
float | ||
ves_icall_System_MathF_ModF (float x, float *d) |
kumpera
Apr 2, 2018
Member
This icall must null check d
This icall must null check d
migueldeicaza
Apr 2, 2018
Author
Member
I changed this to be ref, do we still need the check in that case?
CoreCLR does not have that.
I changed this to be ref, do we still need the check in that case?
CoreCLR does not have that.
kumpera
Apr 2, 2018
Member
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.
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.
kumpera
Apr 2, 2018
Member
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.
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.
migueldeicaza
Apr 2, 2018
Author
Member
Added a check, just for sanity's sake.
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. |
Please also add |
{ | ||
public static partial class MathF | ||
{ | ||
[MethodImpl(MethodImplOptions.InternalCall)] |
marek-safar
Apr 4, 2018
Member
It'd be nice to follow Mono coding style
It'd be nice to follow Mono coding style
migueldeicaza
Apr 5, 2018
Author
Member
I rather not for code that is copy pasted, makes it simpler to track changes.
I rather not for code that is copy pasted, makes it simpler to track changes.
@@ -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 |
marek-safar
Apr 4, 2018
Member
Please use version from ../../../external/corefx/src/Common/src/CoreLib/System/MathF.cs
Please use version from ../../../external/corefx/src/Common/src/CoreLib/System/MathF.cs
migueldeicaza
Apr 5, 2018
Author
Member
Done
Done
#if MONO | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static byte Clamp(byte value, byte min, byte max) | ||
{ |
marek-safar
Apr 4, 2018
Member
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
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 |
52df0f2
into
mono:master
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
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.