ARM bare-metal programming in D (cont) - volatile

Walter Bright newshound2 at digitalmars.com
Wed Oct 23 23:48:13 PDT 2013


On 10/23/2013 11:19 PM, Mike wrote:
> Thanks for the answer, Walter. I think this would be acceptable in many (most?)
> cases, but not where high performance is needed I think these functions add too
> much overhead if they are not inlined and in a critical path (bit-banging IO,
> for example). Afterall, a read/write to a volatile address is a single atomic
> instruction, if done properly.
>
> Is there a way to tell D to remove the function overhead, for example, like a
> "naked" attribute, yet still retain the "volatile" behavior?

You have to give up on volatile. Nobody agrees on what it means. What does 
"don't optimize" mean? And that's not at all the same thing as "atomic".

I wouldn't worry about peek/poke being too slow unless you actually benchmark it 
and prove it is. Then, your alternatives are:

1. Write it in ordinary D, compile it, check the code generated, and if it is 
what you want, you're golden (at least for that compiler & switches).

2. Write it in inline asm. That's what it's for.

3. Write it in an external C function and link it in.


More information about the Digitalmars-d mailing list