Hi, just wanted to let you know about places where float.MinNative/float.MaxNative could perhaps be used over the branchful
a < b ? a : b (or similar) logic to maybe get some perf:
https://gist.github.com/BoyBaykiller/78738c2e26770f19e954e2361bd49198
To give some context, I was prototyping an optimization in RyuJIT for patterns like:
float Min(float a, float b)
{
return a < b ? a : b;
}
where we currently emit a compare+branch:
G_M000_IG02:
vucomiss xmm1, xmm0
jbe SHORT G_M000_IG04
G_M000_IG03:
ret
G_M000_IG04:
vmovaps xmm0, xmm1
G_M000_IG05:
ret
to instead use the native x64-specific vminss/vmaxss instruction:
G_M21498_IG02:
vminss xmm0, xmm0, xmm1
G_M21498_IG03:
ret
And the link above shows the automated assembly differences it produced in methods from this project.
Note that my prototyped optimization won't make it into the JIT.
float.{Min/Max}Native is the way to get good perf accross all platforms, assuming potentially different edge-case handling can be tolerated.
On x64 it will use the same vminss/vmaxss
Hi, just wanted to let you know about places where
float.MinNative/float.MaxNativecould perhaps be used over the branchfula < b ? a : b(or similar) logic to maybe get some perf:https://gist.github.com/BoyBaykiller/78738c2e26770f19e954e2361bd49198
To give some context, I was prototyping an optimization in RyuJIT for patterns like:
where we currently emit a compare+branch:
to instead use the native x64-specific
vminss/vmaxssinstruction:And the link above shows the automated assembly differences it produced in methods from this project.
Note that my prototyped optimization won't make it into the JIT.
float.{Min/Max}Nativeis the way to get good perf accross all platforms, assuming potentially different edge-case handling can be tolerated.On x64 it will use the same
vminss/vmaxss