0
$\begingroup$

I don't mean compiler flags for pipelining. I would like to program in a way that helps the compiler do optimizations using pipelining. I mean I want to order instructions in C in such a way that GCC (or other compiler) can easily pipeline my instructions. For example, if I have:

a+=b
c=a/b
d+=b
f+=b

Here, the last two 'add' operations would be pipelined, but not the first. I would turn it into:

a+=b
d+=b
f+=b
c=a/b

Notice that the three 'add' operations can be pipelined, but the floating point division cannot.

I want to know, is there more cases in which I can help the compiler do pipelining optimizations? What operations are the ones that can be generally pipelined in modern processors, and that compilers can recognize in code?

$\endgroup$
2
  • $\begingroup$ Please suggest a definition of pipelining to use with this question and upcoming answers. (In the first case, a+=b;c=a/b+1; d+=b; f+=b can (in case of the first two, must) be started synchronously.) $\endgroup$
    – greybeard
    Mar 9 at 7:07
  • $\begingroup$ Compilers can and will optimize your code. And an out-of-order processor will reorder instructions into an optimal way anyway. For example, each core in your iPhone can have a few hundred instructions scheduled for execution and will pick whichever instructions are ready. Write instructions in the way that is most readable. $\endgroup$
    – gnasher729
    Mar 9 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.