Programming without transitions

I am trying to find articles, books or anything about jumping-free programming (x86 arch). I know that this is generally impossible, but I try to avoid jumping, but gcc uses transitions many times even with built-in func. Encoding only in the assembly is a kind of solution, but writing the equivalent of 1000 lines in C seems like the hellish side before my eyes.

+3
source share
5 answers

If your jumps are truly random, branch prediction should eliminate most of the overhead.

I would put more effort into optimizing memory access patterns in order to improve locality and reduce cache misses. These days, memory latency is the main bottleneck for performance.

Another good direction is to improve parallelism (using both vectorized SIMD instructions and, if possible, more than one core).

+7
source

I think you can keep in mind branching. There are several tricks in C to speed up certain operations.

See the hacks bit:

http://www-graphics.stanford.edu/~seander/bithacks.html

+2
source

, , , . , , . , - , . , .

, , , - , , , - .

- . , . max min. SSE-, , CPU CMOV/FCOMI/FCOMIP/FUCOMI/FUCOMIP ( : , , ., , gamedev.net).

+2

, .

, - , :

  • Loop (.. ).
  • - .

, , - - .

+1

, , - . .

, , . , , .

, , .

Someone mentioned conditional movement instructions, there are many conditional instructions on the ARM architecture, but if they are not executed, they will switch to NOP and go through one cycle. Not sure how they work on x86. This can slow down using a simple branch depending on how long the pipeline is running.

There are many other optimization tricks you could try before deleting branches.

0
source

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


All Articles