GBR is an index register that is intended to be used as a pointer to global data (the full name is after all Global Base Register). However it only has a single addressing mode and a limited range which reduces its usefulness. It would however be a pretty good fit for something like a pointer to the SGL workarea, though even that struct may be too large. Digging a little further, I was incorrect regarding GCC. It can use GBR for thread-local storage, but is still unable to generate GBR-indexed addressing modes. The SuperH TLS spec... says that thread-local objects are accessed via address variables generated by the linker, so there may not be much motivation to implement the feature. Here's a modified example: Code: | | | typedef struct { int aaa; int bbb; int ccc; } Foo_t; __thread Foo_t *FooPtr; int Func(void) { FooPtr->aaa = 1; FooPtr->bbb = 2; FooPtr->ccc = 3; } |
and the generated assembly: Code: | | | 00000000 <_Func>: 0: d1 04 mov.l 14 <_Func+0x14>,r1 ! 0x0 <_Func> 2: 00 12 stc gbr,r0 4: 02 1e mov.l @(r0,r1),r2 6: e1 01 mov #1,r1 8: 22 12 mov.l r1,@r2 a: e1 02 mov #2,r1 c: 12 11 mov.l r1,@(4,r2) e: e1 03 mov #3,r1 10: 00 0b rts 12: 12 12 mov.l r1,@(8,r2) 14: 00 00 .word 0x0000 |
As you can see, the generated code isn't terribly efficient - address variables that fit within the 8-bit displacement range could be loaded directly. I don't know if using TLS requires some special support from the runtime if you do want to use the feature. |