Accessing statics is not always done optimally in sdcc. You can deny use of iy to speed it up by adding "--reserve-regs-iy" but that's still not close to a straightforward static load/store.
At the moment you have to correct these things with peephole rules. We have around 400 or so if you want to try this peephole set:
struct and union accesses are much more compliacted than accesses to other variables. They get translated into pointer accesses via a pointer consisitng of the base address of the struct and an offset. While we were able to improve the situation, especially for nested structs via some optimizations, they are still not as efficient as accesses to variables outside of struct/union.
Philipp
P.S.: I prefer the sdcc-user mailing list to the discussion forum.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the replies.
I do understand that struct and union access is more complicated. What I don't get is why SDCC seems to be able to do a 16-bit access to a variable in the first case and it seems not to be able then, when the variable is in a struct/union.
After all, even with "base address+constant offset", we should get the same code:
ld hl,(#_baseaddress+0)
Of course I don't really know anything about SDCC internals, I'm just curious...
Is there any chance to have someone address this in SDCC code? May I help with it?
Or anyway, any hint on how I could avoid using unions? Can I have global variables at same address of other global variables?
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Bothering you again... I've got another quirky result.
my 'old' code was:
which compiled to:
Now in my new code I need to replace the 'KeysStatus' variable with an union. I did this:
but that compiled to:
any idea on why is this happening? :|
Thanks!
Accessing statics is not always done optimally in sdcc. You can deny use of iy to speed it up by adding "--reserve-regs-iy" but that's still not close to a straightforward static load/store.
At the moment you have to correct these things with peephole rules. We have around 400 or so if you want to try this peephole set:
http://z88dk.cvs.sourceforge.net/viewvc/z88dk/z88dk/libsrc/_DEVELOPMENT/sdcc_peeph.3
Most of these rules are designed for high max-allocs-per-node (200000, specifically) and --reserve-regs-iy active.
struct and union accesses are much more compliacted than accesses to other variables. They get translated into pointer accesses via a pointer consisitng of the base address of the struct and an offset. While we were able to improve the situation, especially for nested structs via some optimizations, they are still not as efficient as accesses to variables outside of struct/union.
Philipp
P.S.: I prefer the sdcc-user mailing list to the discussion forum.
Thanks for the replies.
I do understand that struct and union access is more complicated. What I don't get is why SDCC seems to be able to do a 16-bit access to a variable in the first case and it seems not to be able then, when the variable is in a struct/union.
After all, even with "base address+constant offset", we should get the same code:
Of course I don't really know anything about SDCC internals, I'm just curious...
Is there any chance to have someone address this in SDCC code? May I help with it?
Or anyway, any hint on how I could avoid using unions? Can I have global variables at same address of other global variables?
Thanks!