2 ms·
I've discovered the x86_64 opcode CMOVL -- a conditional move -- because of this. if (array[i] < boundary) count+=2; I had to work hard to make GCC not pr
by whoopdedo 12y ago
I've discovered the x86_64 opcode CMOVL -- a conditional move -- because of this.
if (array[i] < boundary) count+=2;
I had to work hard to make GCC not produce optimal code. Even this
if (array[i] < boundary) return count+1; else return count;
came out the same as all the others.
Avoiding branch prediction is hardly news. Was the article's author even compiling with optimizations enabled?
- WWLink 12y agoIt does seem weird that the compiler didn't catch that one.
- mtdewcmu 12y ago>>Was the article's author even compiling with optimizations enabled? Quite possibly not. Which, I guess, is reasonable, since the point was really about cpu instructions and not C compilers. What comes out is more predictable with optimizations off. Note that the author mentions the optimizer in relation to the second version. I think it might be because that code generates a branch with optimizations off in Visual C++. gcc seems to treat ?: as inherently a cmov and VC++ seems to treat it no differently than an if.