On Thursday, 24 October 2013 at 06:48:07 UTC, Walter Bright wrote:
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.

Well, I wasn't rooting for volatile, I just wanted a way to read/write my IO registers as fast as possible with D.

I think the last two methods you've given confirm my suspicions and will work. But... I had my heart set on doing it all in D :-(

Thanks for the answers.

Reply via email to