the (significant) cost of a transition instruction?

Sorry ... (premature) optimization is the root of all evil, but I would like to know: is it more expensive to have a jmp instruction and not have it (unallocated code)? I am for a methodology to learn how to calculate these things. This is purely research, not practical, I'm trying to find my way in a theoretical problem, and my test code brought this. Thanks.

+4
source share
2 answers

You will need to test it on your architecture if you really want to know.

But in general, on modern processors there is a minimum cost of an unconditional transition. It is largely largely free of a small amount of cache overhead. It will probably run in parallel with neighboring instructions, so it may not even cost you a clock cycle. This is because a jump can be performed by one of several parallel execution blocks .

Look at it this way: a single read of main memory is probably 100-200 times more expensive.

This is a subset of branch prediction in general, but there is no risk of mistaken branch prediction, so you can eliminate the need to reset the instruction pipeline , which is the main cost associated with conditional branching.

+8
source

Well, it's better not to jump. In the early days, conditional jumps were written so that the most probable condition would not cause a jump. Thus, no instruction at all is required, obviously, faster, but I canโ€™t say how expensive it is compared to other instructions. Maybe you should measure a billion jumps anyway ...

+1
source

Source: https://habr.com/ru/post/1341438/


All Articles