gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Code Reordering

#165497 - Dwedit - Tue Dec 23, 2008 7:40 am

In this post

wintermute wrote:

These days gcc does quite a bit of code re-ordering too where it believes that order of execution doesn't matter. This can be particularly troublesome when memory is banked - after all the compiler has absolutely no idea that writing to a particular memory location will move memory to a completely different place. That one has bitten me several times when copying data into a VRAM bank before switching it to the ARM7 or the 3D hardware - it's not that easy to debug either. If the compiler has access to more of your code it's much easier for it to put it in entirely the wrong place.

Does declaring pointers as Volatile help this at all? What about only accessing VRAM with Memcpy?[/url]
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#165503 - wintermute - Tue Dec 23, 2008 3:35 pm

I split this off from the other thread because I believe the topic is important enough not to hijack it with posts not entirely relevant to the main question.

In some cases, marking the pointer volatile will help, there are some situations where it doesn't. I'm still trying to figure this one out tbh - sequence points seem to be a bit of a black art.

As for memcpy that really depends on whether or not the compiler decides that inlining memcpy is useful. gcc can do that because memcpy is a built-in.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog