Closed svick closed 1 year ago
@tannergooding, translating "caller" and "M" to your example, that's saying that (if both are relaxed) a fault in MyMethod
may result in some arbitrary subset of Select
's side-effects being suppressed. The fault in MyMethod
still must be made visible.
HW_INTRINSIC
-based implementation for CMOVnn
: https://github.com/EgorBo/runtime-1/commit/1271fe536cc3274867a7306424d45c8db76be8ca
static int Test1(int x)
{
return x == 42 ? 1000 : 2000;
}
static int Test2(int x, int a, int b)
{
return x == 42 ? a : b;
}
; Method Tests:Test1(int):int
G_M56601_IG01:
G_M56601_IG02:
83F92A cmp ecx, 42
B8E8030000 mov eax, 0x3E8
BAD0070000 mov edx, 0x7D0
0F45C2 cmovne eax, edx
G_M56601_IG03:
C3 ret
; Total bytes of code: 17
; Method Tests:Test2(int,int,int):int
G_M50938_IG01:
G_M50938_IG02:
83F92A cmp ecx, 42
8BC2 mov eax, edx
410F45C0 cmovne eax, r8d
G_M50938_IG03:
C3 ret
; Total bytes of code: 10
Works better with PGO (COMPlus_TieredPGO=1
) 🙂:
Conditional jumps, especially those that are hard to predict, are fairly expensive, so they should be avoided if possible. One way to avoid them is to use conditional moves and similar instructions (like
sete
). As far as I can tell, RuyJit never does this and I think it should.For example, take these two methods:
For both of them, RyuJit generates a conditional jump:
For comparison, here are the same methods compiled using Clang and GCC with
-O1
(by Compiler Explorer):GCC 6.2:
Clang 3.9.0:
category:cq theme:basic-cq skill-level:expert cost:large impact:small