3 ms·
Won't the wrapper be inlined and the condition branch-predicted? In that case, you literally aren't letting a single machine cycle be wasted.
by btown 12y ago
Won't the wrapper be inlined and the condition branch-predicted? In that case, you literally aren't letting a single machine cycle be wasted.
- gizmo686 12y agoWell, you might waste a cycle on the first run (or any-run after the branch has been flushed from the branch prediction table), as well as wasting cycles elsewhere from clobbering the table. One solution to both of these problems I have thought about, but do not work at a low enough level to know if it is already a thing, is an opcode for unlikely branches. Sementiclly, this would behave like a normal jmp instruction, but the CPU branch predictor would always assume that the jump is not taken, and not bother keeping track of it. In this particular case, it would also involve a way of signalling to the compiler (or the compiler inferring), but for loops it could be usefull. Of course, in this case it is also possible that the compiler can infer that the branch can never be taken and remove it, so you really do not loose anything.
- dezgeg 12y ago> One solution to both of these problems I have thought about, but do not work at a low enough level to know if it is already a thing, is an opcode for unlikely branches. x86 actually does have jump instructions with branch prediction hints, but surprisingly modern CPUs will completely ignore those hints. Perhaps they never really caused large enough performance improvements to be worthwhile, or something. > In this particular case, it would also involve a way of signalling to the compiler (or the compiler inferring), [...] This functionality does exist, and Linux does make use of them. See the macros likely() and unlikely() at http://lxr.free-electrons.com/source/include/linux/compiler.h#L131 http://lxr.free-electrons.com/source/include/linux/compiler....
- bri3d 12y agoThis solution was often part of http://en.wikipedia.org/wiki/Very_long_instruction_word http://en.wikipedia.org/wiki/Very_long_instruction_word architectures. Itanium had the exact instructions you propose - look up ".dpxx" and ".spxx" for more.
- deleted 12y ago[deleted]