By: Linus Torvalds (torvalds.delete@this.linux-foundation.org), February 17, 2013 4:08 pm
Room: Moderated Discussions
Wilco (Wilco.Dijkstra.delete@this.ntlworld.com) on February 17, 2013 1:47 pm wrote:
>
> One condition bit for arithmetic and logical operations is enough, more than 90% of the time you only need a zero/non-zero
> result.
Not true.
I just checked. At least for Linux, compare-against zero is just under 80% of the conditional branches. Not "more than 90%".
Yes, compare-against zero is the most common by far (and it's often the result of a logical 'and' op, not necessarily really "comparing" a value against zero - "test" in x86 speak), but the others aren't hugely uncommon either.
So a single bit gets you far, but there are advantages to multiple bits.
> Again, in compiled code you wouldn't notice the difference.
Umm. I was talking about compiled code.
Seriously. Look at what compilers do for smaller case statements. They very much generate a single compare and multiple branches.
Linus
>
> One condition bit for arithmetic and logical operations is enough, more than 90% of the time you only need a zero/non-zero
> result.
Not true.
I just checked. At least for Linux, compare-against zero is just under 80% of the conditional branches. Not "more than 90%".
Yes, compare-against zero is the most common by far (and it's often the result of a logical 'and' op, not necessarily really "comparing" a value against zero - "test" in x86 speak), but the others aren't hugely uncommon either.
So a single bit gets you far, but there are advantages to multiple bits.
> Again, in compiled code you wouldn't notice the difference.
Umm. I was talking about compiled code.
Seriously. Look at what compilers do for smaller case statements. They very much generate a single compare and multiple branches.
Linus