Ticket #1948 (new enhancement) — at Version 14
Do not check for equality
Reported by: | pavlinux | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | mcview | Version: | master |
Keywords: | Optimization | Cc: | zaytsev |
Blocked By: | Blocking: | ||
Branch state: | no branch | Votes for changeset: |
Description (last modified by andrew_b) (diff)
Do not check for equality a and b,
if ( a = b )
then
return (a - b) # a - b = 0 :)
else
return 0 # same
a - b = 0 if a = b :)
Change History
comment:1 Changed 15 years ago by pavlinux
if (a >= b )
0: 89 fa mov %edi,%edx
2: 31 c0 xor %eax,%eax
4: 29 f2 sub %esi,%edx
6: 48 39 f7 cmp %rsi,%rdi
9: 0f 4f c2 cmovge %edx,%eax
c: c3 retq
if ( b < a )
10: 89 fa mov %edi,%edx
12: 31 c0 xor %eax,%eax
14: 29 f2 sub %esi,%edx
16: 48 39 f7 cmp %rsi,%rdi
19: 0f 4d c2 cmovl %edx,%eax
1c: c3 retq
Move condition
CMOVGE = ˜(SF ˆ OF) & ˜ZF == NOT ( SF XOR OF ) AND ( NOT ZF)
CMOVL = SF ˆ OF == SF XOR OF
comment:4 in reply to: ↑ 3 Changed 15 years ago by pavlinux
Replying to zaytsev:
I mean it's still one command?
CMOVGE = ˜(SF ˆ OF) & ˜ZF
CMOVL = SF ˆ OF
CMOVL not use "ZF" flag register, minus 3 logic operations, at same С logic
if ( a > b ) == if ( b < a) ?
It is ASSEMBLER's OPTIMIZATION =)
comment:5 follow-up: ↓ 6 Changed 15 years ago by zaytsev
I understand that it does not use ZF, but my question was is it still executed in one (or the same amount of) clock tick(s) or not?
If yes, then why even care about that?
comment:6 in reply to: ↑ 5 ; follow-up: ↓ 10 Changed 15 years ago by pavlinux
Replying to zaytsev:
I understand that it does not use ZF, but my question was is it still executed in one (or the same amount of) clock tick(s) or not?
If yes, then why even care about that?
CMOVGE - performed for 450 CPU cycles
CMOVL - about 100
The probability of coincidence of 100 cycles of 1 clock tick, 4 times greater than 450 cycles.
comment:8 Changed 15 years ago by pavlinux
Software Optimization Guide for AMD64 Processors
http://support.amd.com/us/Processor_TechDocs/25112.PDF
page 130
comment:10 in reply to: ↑ 6 ; follow-up: ↓ 11 Changed 15 years ago by ossi
Replying to pavlinux:
Replying to zaytsev:
I understand that it does not use ZF, but my question was is it still executed in one (or the same amount of) clock tick(s) or not?
If yes, then why even care about that?
CMOVGE - performed for 450 CPU cycles
CMOVL - about 100
The probability of coincidence of 100 cycles of 1 clock tick, 4 times greater than 450 cycles.
it's beyond me what you mean by that ...
comment:11 in reply to: ↑ 10 Changed 15 years ago by pavlinux
it's beyond me what you mean by that ...
Забей... Не нужно это людям... cmovge, cmovle... придумают тоже...
галактико в опасности, а тут наносекунды экономить...
comment:12 Changed 15 years ago by ossi
sounds terribly philosophical to me. mind a somewhat more technical explanation? :D
(i find it interesting irrespective of the total irrelevance to mc).
comment:13 follow-up: ↓ 14 Changed 15 years ago by andrew_b
Strict inequality (a<=b) is slower than non-strict one (a>b). :)
comment:14 in reply to: ↑ 13 Changed 15 years ago by andrew_b
- Description modified (diff)
Replying to andrew_b:
Strict inequality (a<=b) is slower than non-strict one (a>b). :)
Oh, no-no-no. :) Forget this. :) Of cause, I mean that non-strict inequality (a<=b) is slower than strict one (a>b).