Joe Buck wrote:

Are you using "volatile" correctly?  There are situations where "volatile"
alone does not suffice and you need more locking, but the Linux and BSD
kernel folks manage to optimize their device driver code.

We have just been discussing a similar topic in a de.* newsgroup. A busy-loop function is used to effect a delay, not too precise, but portably. Like

#define COUNT 1000

void f() {
  /*volatile*/ /*register*/ int i;

  for (i = 0; i < COUNT; ++i)
         ;
}

If volatile is used to instruct the compiler to actually produce
a loop even when optimizing, then we get copying from/to the stack,
or memory access (ARM). What the compiler users have expected their
compiler to do is to produce an obvious loop using registers.

This doesn't always happen, and in addition some strange looking
copy-back-and-forth instructions are generated, like

  move x, y
  move y, x

(ARM, Intel)

The user said that all this was not what he had said (in a loop
like the one above).

Can there be a pragma instructing the compiler to do (ÏÏÎÎÎÎ)
as I say, in source text?




Reply via email to