Jump to page: 1 210  
Page
Thread overview
Tail pad optimization, cache friendlyness and C++ interrop
Jun 10, 2014
deadalnix
Jun 10, 2014
bearophile
Jun 10, 2014
Marc Schütz
Jun 10, 2014
Dmitry Olshansky
Jun 10, 2014
Walter Bright
Jun 11, 2014
deadalnix
Jun 11, 2014
Walter Bright
Jun 11, 2014
deadalnix
Jun 11, 2014
Walter Bright
Jun 11, 2014
deadalnix
Jun 11, 2014
Walter Bright
Jun 11, 2014
deadalnix
Jun 11, 2014
Walter Bright
Jun 11, 2014
deadalnix
Jun 11, 2014
Walter Bright
Jun 11, 2014
Timon Gehr
Jun 11, 2014
Walter Bright
Jun 15, 2014
David Nadlinger
Jun 15, 2014
Walter Bright
Jun 15, 2014
Timon Gehr
Jun 15, 2014
Walter Bright
Jun 15, 2014
Timon Gehr
Jun 15, 2014
Walter Bright
Jun 15, 2014
Timon Gehr
Jun 16, 2014
Walter Bright
Jun 16, 2014
Walter Bright
Jun 16, 2014
Timon Gehr
Jun 17, 2014
Walter Bright
Jun 17, 2014
deadalnix
Jun 17, 2014
Walter Bright
Jun 17, 2014
deadalnix
Jun 17, 2014
Walter Bright
Jun 17, 2014
Walter Bright
Jun 17, 2014
Timon Gehr
Jun 18, 2014
deadalnix
Jun 18, 2014
Walter Bright
Jun 18, 2014
deadalnix
Jun 18, 2014
Walter Bright
Jun 18, 2014
Joakim
Jun 18, 2014
Rikki Cattermole
Jun 18, 2014
Joakim
Jun 18, 2014
Walter Bright
Jun 18, 2014
Artur Skawina
Jun 18, 2014
Dicebot
Jun 19, 2014
Artur Skawina
Jun 19, 2014
Walter Bright
Jun 19, 2014
Joakim
Jun 20, 2014
Walter Bright
Jun 20, 2014
David Nadlinger
Jun 20, 2014
Artur Skawina
Jun 20, 2014
Walter Bright
Jun 20, 2014
Dicebot
Jun 21, 2014
Artur Skawina
Jun 22, 2014
SomeDude
Jun 22, 2014
Iain Buclaw
Jun 22, 2014
Artur Skawina
Jun 22, 2014
Dicebot
Jun 22, 2014
Artur Skawina
Jun 22, 2014
Dicebot
Jun 22, 2014
Walter Bright
Jun 22, 2014
David Nadlinger
Jun 22, 2014
Joakim
Jun 22, 2014
Walter Bright
Jun 18, 2014
Matthias Bentrup
Jun 18, 2014
Dicebot
Jun 18, 2014
H. S. Teoh
Jun 19, 2014
Walter Bright
Jun 18, 2014
Luís Marques
Jun 18, 2014
Marc Schütz
Jun 18, 2014
Luís Marques
Jun 18, 2014
deadalnix
Jun 19, 2014
Tobias Pankrath
Jun 19, 2014
H. S. Teoh
Jun 19, 2014
H. S. Teoh
Jun 19, 2014
H. S. Teoh
Jun 19, 2014
Timon Gehr
Jun 19, 2014
deadalnix
Jun 19, 2014
Timon Gehr
Jun 19, 2014
Timon Gehr
Jun 19, 2014
Timon Gehr
Jun 15, 2014
bearophile
Jun 15, 2014
Maxim Fomin
Jun 15, 2014
Walter Bright
Jun 15, 2014
Walter Bright
Jun 11, 2014
Remo
Jun 15, 2014
Sean Cavanaugh
June 10, 2014
I was messing around with clang codegen and noticed that sometime it optimize structs using the tail pad, and sometime it doesn't. It ended up in the following stack overflow question :

http://stackoverflow.com/questions/24110347/when-extending-a-padded-struct-why-cant-extra-fields-be-placed-in-the-tail-pad

It seems that C++ will use the padding left in a struct to pack more stuff in there. I was wonering what position we want to have with D.

Packing elements efficiently is a major importance for performance. For now, D uses C style packing (ie: nothing in the tail pad) as far as I know. This is missed opportunities to pack more (I have many places in SDC where it could be beneficial from using tail pad).

If we are gonna interoperable with C++, then we need to understand the tail pad optimization anyway. So here is what I propose:

extern(D) do tail pad optimize.
extern(C) struct do not tail pad optimize.
extern(C++) do tail pad with C++ rules:
do not tail pad if (otherwise tail pad):
1. has no non-static data members that aren't standard-layout
2. has no virtual functions and no virtual base classes
3. has the same access control for all non-static data members
4. has no base classes that aren't standard-layout
5. either has no base class with non-static data members or has no non-static data members in the most derived class and only one base with them
6. has no base classes of the same type as the first non-static data member

thought ?
June 10, 2014
deadalnix:

> thought ?

I think for D there is a lower handing fruit: the D specs allow to reorder class instance fields, but I think the D front-end is not yet doing that.

Bye,
bearophile
June 10, 2014
On Tuesday, 10 June 2014 at 08:57:26 UTC, bearophile wrote:
> deadalnix:
>
>> thought ?
>
> I think for D there is a lower handing fruit: the D specs allow to reorder class instance fields, but I think the D front-end is not yet doing that.

But only for classes, not for structs.
June 10, 2014
10-Jun-2014 11:30, deadalnix пишет:
[snip]
> extern(D) do tail pad optimize.
> extern(C) struct do not tail pad optimize.
> extern(C++) do tail pad with C++ rules:
> do not tail pad if (otherwise tail pad):
> 1. has no non-static data members that aren't standard-layout
> 2. has no virtual functions and no virtual base classes
> 3. has the same access control for all non-static data members
> 4. has no base classes that aren't standard-layout
> 5. either has no base class with non-static data members or has no
> non-static data members in the most derived class and only one base with
> them
> 6. has no base classes of the same type as the first non-static data member
>
> thought ?

Would be useful, but as proposed it might break some of current C bindings silently (unless it's extern(C): at the top of file).


-- 
Dmitry Olshansky
June 10, 2014
On 6/10/2014 12:30 AM, deadalnix wrote:
> thought ?

This does not apply to D structs because D structs do not inherit.

C doesn't have classes, so no issues there.

extern(C++) class should match the C++ ABI for this.

extern(D) class we are free to innovate with the layout.

I suggest turning this into a bugzilla enhancement request.
June 11, 2014
On Tuesday, 10 June 2014 at 20:50:46 UTC, Walter Bright wrote:
> On 6/10/2014 12:30 AM, deadalnix wrote:
>> thought ?
>
> This does not apply to D structs because D structs do not inherit.
>
> C doesn't have classes, so no issues there.
>
> extern(C++) class should match the C++ ABI for this.
>
> extern(D) class we are free to innovate with the layout.
>
> I suggest turning this into a bugzilla enhancement request.

I'm talking about structs, not classes.
June 11, 2014
On 6/10/2014 5:27 PM, deadalnix wrote:
> I'm talking about structs, not classes.

Ok, but since D structs do not inherit, how does tail pad optimization apply?
June 11, 2014
On Wednesday, 11 June 2014 at 02:10:18 UTC, Walter Bright wrote:
> On 6/10/2014 5:27 PM, deadalnix wrote:
>> I'm talking about structs, not classes.
>
> Ok, but since D structs do not inherit, how does tail pad optimization apply?

struct S1 {
     int a;
     byte b;
}

struct S2 {
     S1 s1;
     char c;
}

Sé could be 8 byte long (some variation of this are in C++ for
instance if I make a public and b private).
June 11, 2014
On 6/10/2014 7:44 PM, deadalnix wrote:
> On Wednesday, 11 June 2014 at 02:10:18 UTC, Walter Bright wrote:
>> On 6/10/2014 5:27 PM, deadalnix wrote:
>>> I'm talking about structs, not classes.
>>
>> Ok, but since D structs do not inherit, how does tail pad optimization apply?
>
> struct S1 {
>       int a;
>       byte b;
> }
>
> struct S2 {
>       S1 s1;
>       char c;
> }
>
> Sé could be 8 byte long (some variation of this are in C++ for
> instance if I make a public and b private).

Do any C++ compilers do this for this case, or just for the inheritance one?
June 11, 2014
On 6/10/2014 7:44 PM, deadalnix wrote:
> On Wednesday, 11 June 2014 at 02:10:18 UTC, Walter Bright wrote:
>> On 6/10/2014 5:27 PM, deadalnix wrote:
>>> I'm talking about structs, not classes.
>>
>> Ok, but since D structs do not inherit, how does tail pad optimization apply?
>
> struct S1 {
>       int a;
>       byte b;
> }
>
> struct S2 {
>       S1 s1;
>       char c;
> }

Hmm, this could have serious problems with the following:

S1 s1;
S2 s2;
s2.c = 3;
memcpy(&s2.s1, &s1, sizeof(S1)); // Oops! stomped on s2.c

« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10