Open
Description
Codegen for:
public static bool Equal(int x1, int x2, int y1, int y2) => (x1 == x2) && (y1 == y2);
L0000: cmp ecx, edx
L0002: jne short L000e
L0004: cmp r8d, r9d
L0007: sete al
L000a: movzx eax, al
L000d: ret
L000e: xor eax, eax
L0010: ret
Codegen for:
public static bool Equal(int x1, int x2, int y1, int y2) => ((x1 - x2) | (y1 - y2)) == 0;
L0000: sub ecx, edx
L0002: sub r8d, r9d
L0005: or ecx, r8d
L0008: sete al
L000b: movzx eax, al
L000e: ret
PS: what is the purpose for movzx eax, al
in both cases? According to godbolt neither msvc nor clang nor gcc emit it.
category:cq
theme:expression-opts
skill-level:intermediate
cost:medium