# Ticket #1948(closed enhancement: wontfix)

Opened 13 years ago

## Do not check for equality

Reported by: Owned by: pavlinux minor mcview master Optimization zaytsev no branch

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 13 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:2 Changed 13 years ago by zaytsev

What is the difference?

### comment:3 follow-up: ↓ 4 Changed 13 years ago by zaytsev

I mean it's still one command?

### comment:4 in reply to: ↑ 3 Changed 13 years ago by pavlinux

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 13 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 13 years ago by pavlinux

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

The probability of coincidence of 100 cycles of 1 clock tick, 4 times greater than 450 cycles.

### comment:7 follow-up: ↓ 9 Changed 13 years ago by zaytsev

Wow! is all I can say...

### comment:8 Changed 13 years ago by pavlinux

Software Optimization Guide for AMD64 Processors

page 130

### comment:9 in reply to: ↑ 7 Changed 13 years ago by pavlinux

Wow! is all I can say...

~ 350 nanosec faster :)

### comment:10 in reply to: ↑ 6 ; follow-up: ↓ 11 Changed 13 years ago by ossi

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

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 13 years ago by pavlinux

it's beyond me what you mean by that ...

Забей... Не нужно это людям... cmovge, cmovle... придумают тоже...
галактико в опасности, а тут наносекунды экономить...

### comment:12 Changed 13 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 13 years ago by andrew_b

Strict inequality (a<=b) is slower than non-strict one (a>b). :)

### comment:14 in reply to: ↑ 13 ; follow-up: ↓ 16 Changed 13 years ago by andrew_b

• Description modified (diff)

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).

### comment:15 Changed 13 years ago by slyfox

• Status changed from new to closed
• Resolution set to wontfix

You seem to hit wrong bugzilla: http://gcc.gnu.org/bugzilla/
Pipe stall graphs are "welcome" though ;]

### comment:16 in reply to: ↑ 14 Changed 13 years ago by pavlinux

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).

Not ( a <= b ) faster then ( a > b ), but ( b < a ) faster then ( a > b ) :)

### comment:17 Changed 6 years ago by andrew_b

• Branch state set to no branch
• Milestone Future Releases deleted
Note: See TracTickets for help on using tickets.