]> git.lizzy.rs Git - rust.git/commit - src/tools/clippy
Rollup merge of #66881 - krishna-veerareddy:issue-66780-bool-ord-optimization, r...
authorMazdak Farrokhzad <twingoow@gmail.com>
Wed, 11 Dec 2019 09:10:41 +0000 (10:10 +0100)
committerGitHub <noreply@github.com>
Wed, 11 Dec 2019 09:10:41 +0000 (10:10 +0100)
commit830b4ee76adea7577615c7a6950e14c22cf0fb20
treeb2c6c494190484a96c79a0ad042e0a76ea4f7e8f
parentddca1e09c36a6ce21d95fec1619f23ba59b69c8a
parent1f07aa582a41e6fc253139909d3bf9bfd04a9d6d
Rollup merge of #66881 - krishna-veerareddy:issue-66780-bool-ord-optimization, r=sfackler

Optimize Ord trait implementation for bool

Casting the booleans to `i8`s and converting their difference into `Ordering` generates better assembly than casting them to `u8`s and comparing them.

Fixes #66780

#### Comparison([Godbolt link](https://rust.godbolt.org/z/PjBpvF))

##### Old assembly:
```asm
example::boolean_cmp:
        mov     ecx, edi
        xor     ecx, esi
        test    esi, esi
        mov     eax, 255
        cmove   eax, ecx
        test    edi, edi
        cmovne  eax, ecx
        ret
```

##### New assembly:
```asm
example::boolean_cmp:
        mov     eax, edi
        sub     al, sil
        ret
```

##### Old LLVM-MCA statistics:
```
Iterations:        100
Instructions:      800
Total Cycles:      234
Total uOps:        1000

Dispatch Width:    6
uOps Per Cycle:    4.27
IPC:               3.42
Block RThroughput: 1.7
```

##### New LLVM-MCA statistics:
```
Iterations:        100
Instructions:      300
Total Cycles:      110
Total uOps:        500

Dispatch Width:    6
uOps Per Cycle:    4.55
IPC:               2.73
Block RThroughput: 1.0
```
src/libcore/cmp.rs