On 21 April 2012 01:17, Andrej Mitrovic <andrej.mitrovich@gmail.com> wrote:
On 4/20/12, Manu <
turkeyman@gmail.com> wrote:
> I need to clarify some things that have confused me a few times.
When in doubt you can either do a few write calls:
Sure, but as I'm trying to say, I'm already suspicious the compiler isn't doing the 'right' thing in the first place... I want to rather know what the word is, ie, the conceptual definition.
import std.stdio;
import std.concurrency;
struct FooStruct
{
static int FooX;
__gshared int FooY;
}
void test()
{
writeln(FooStruct.FooX);
writeln(FooStruct.FooY);
}
void main()
{
writeln(FooStruct.FooX);
writeln(FooStruct.FooY);
FooStruct.FooX = 1;
FooStruct.FooY = 1;
spawn(&test);
}
Or better yet look at the disassembly:
Here's FooX:
SECTION .tls$ align=16 noexecute ; section number 8, data
_D4test9FooStruct4FooXi: ; dword
dd 00000000H ; 0000 _ 0
Here's how it's loaded:
mov eax, dword [__tls_index] ; 0003 _ A1, 00000000(segrel)
mov ecx, dword [fs:__tls_array] ; 0008 _ 64: 8B. 0D,
00000000(segrel)
mov edx, dword [ecx+eax*4] ; 000F _ 8B. 14 81
mov eax, dword [_D4test9FooStruct4FooXi+edx]; 0012 _ 8B. 82, 00000000
And here's FooY:
SECTION .BSS align=16 noexecute ; section number 4, bss
_D4test9FooStruct4FooYi: ; dword
resd 1 ; 0004
And here's how it's loaded (notice the lack of having to calculate the
address based on TLS:
mov eax, dword [_D4test9FooStruct4FooYi] ; 001D _ A1, 00000004(segrel)
Adding static before __gshared doesn't seem to have any effect. DMD
ignores a lot of nonsense keyword combinations. Maybe this will
improve one day..
Right, this is precisely what I expect, and apparently the compiler knows enough about that variable that even when addressing an alias at compile time, it can still generate the appropriate TLS code. So that shows that TLS is not a problem for compile time addressing, it is only important that it is statically addressable.
So... back to my bug that Walter rejected, I don't understand the problem?