3 ms·
It would be great to have builtin for CMOV. But I also want GCC to utilize the hack with the SBB instruction when I write something like: (unsigned)a < (unsign
by jpegqs 5y ago
It would be great to have builtin for CMOV. But I also want GCC to utilize the hack with the SBB instruction when I write something like:
(unsigned)a < (unsigned)b ? ~0 : 0
Instead of three instructions what it generates.
- account42 5y agoIt does use cmp + sbb? https://godbolt.org/z/hnvqrcTcW https://godbolt.org/z/hnvqrcTcW
- jpegqs 5y agoCool, but it doesn't generate SBB in real code, but instead gives me something like this: xorl %r11d, %r11d cmpl %r12d, %eax seta %r11b And if I do both of these, side by side: tmp = rc.code < rc_bound ? ~0 : 0; if (rc.code < rc_bound) rc.range = rc_bound; Then GCC generates an if-else branch. Thus, inline assembly is the only option so far to prevent the compiler from doing something dumb.