Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The common case for this function is comparisions of the same
type. In this case the result is the same type. As the compiler
sees this enum with a potential value of INVALID_RESULT, the
equality optimization isn't obvious. With this code change, the
compiled code goes from:
0000000000000000 <Z13item_cmp_type11Item_resultS>:
0: 55 push %rbp
1: 89 f9 mov %edi,%ecx
3: 31 c0 xor %eax,%eax
5: 09 f1 or %esi,%ecx
7: 48 89 e5 mov %rsp,%rbp
a: 74 3d je 49 <Z13item_cmp_type11Item_resultS+0x49>
c: 8d 47 fe lea -0x2(%rdi),%eax
f: 83 e0 fd and $0xfffffffd,%eax
12: 89 c2 mov %eax,%edx
14: 8d 46 fe lea -0x2(%rsi),%eax
17: 83 e0 fd and $0xfffffffd,%eax
1a: 83 ff 02 cmp $0x2,%edi
1d: 89 c1 mov %eax,%ecx
1f: 75 0a jne 2b <Z13item_cmp_type11Item_resultS+0x2b>
21: 83 fe 02 cmp $0x2,%esi
24: b8 02 00 00 00 mov $0x2,%eax
29: 74 1e je 49 <Z13item_cmp_type11Item_resultS+0x49>
2b: 83 ff 03 cmp $0x3,%edi
2e: 74 20 je 50 <Z13item_cmp_type11Item_resultS+0x50>
30: 83 fe 03 cmp $0x3,%esi
33: 74 1b je 50 <Z13item_cmp_type11Item_resultS+0x50>
35: 85 d2 test %edx,%edx
37: b8 01 00 00 00 mov $0x1,%eax
3c: 75 0b jne 49 <Z13item_cmp_type11Item_resultS+0x49>
3e: 83 f9 01 cmp $0x1,%ecx
41: 19 c0 sbb %eax,%eax
43: 83 e0 03 and $0x3,%eax
46: 83 c0 01 add $0x1,%eax
49: 5d pop %rbp
4a: c3 retq
4b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
50: b8 03 00 00 00 mov $0x3,%eax
55: 5d pop %rbp
56: c3 retq
to:
0000000000000000 <Z13item_cmp_type11Item_resultS>:
0: 89 f8 mov %edi,%eax
2: 39 f7 cmp %esi,%edi
4: 74 2f je 35 <Z13item_cmp_type11Item_resultS+0x35>
6: 83 ff 03 cmp $0x3,%edi
9: 74 25 je 30 <Z13item_cmp_type11Item_resultS+0x30>
b: 83 fe 03 cmp $0x3,%esi
e: 74 20 je 30 <Z13item_cmp_type11Item_resultS+0x30>
10: 8d 57 fe lea -0x2(%rdi),%edx
13: b8 01 00 00 00 mov $0x1,%eax
18: 83 e2 fd and $0xfffffffd,%edx
1b: 75 18 jne 35 <Z13item_cmp_type11Item_resultS+0x35>
1d: 83 ee 02 sub $0x2,%esi
20: 83 e6 fd and $0xfffffffd,%esi
23: 83 fe 01 cmp $0x1,%esi
26: 19 c0 sbb %eax,%eax
28: 83 e0 03 and $0x3,%eax
2b: 83 c0 01 add $0x1,%eax
2e: c3 retq
2f: 90 nop
30: b8 03 00 00 00 mov $0x3,%eax
35: c3 retq
In addition to the shorted path, there are no stack operations,
and the common case, the branch at 4:, becomes easily predicted
with 4 instuctions usually executed.