Re: [SO] question on trivial function inlining

2009-07-10 Thread bearophile
BCS:
> > But I'd also like to show that answer of mine to D developers,
> done here
> :)

Do D devs take a look at this D.learn newsgroup, once in a while? :-)

Anyway, just to be sure I have done four more little tests, that show an ideal 
situation. Real world situations are probably worse.

version(Tango) import tango.stdc.stdio: printf;

class Test1 {
 int x;
}

class Test2 {
 int _x;
 int x() { return this._x; }
 void x(int xx) { this._x = xx; }
}

void main() {
auto t = new Test1;
t.x = 4;
printf("%d\n", t.x);
}

/*
DMD ASM:

_D16getters_setters15Test21xMFZicomdat
mov EAX,8[EAX]
ret

_D16getters_setters15Test21xMFiZv   comdat
mov ECX,4[ESP]
mov 8[EAX],ECX
ret 4

main:
pushEAX
mov EAX,offset FLAT:_D16getters_setters15Test17__ClassZ
pushEAX
callnear ptr __d_newclass
mov ECX,offset FLAT:_D16getters_setters15Test26__vtblZ[020h]
mov dword ptr 8[EAX],4
pushdword ptr 8[EAX]
pushECX
callnear ptr _printf
add ESP,0Ch
xor EAX,EAX
pop ECX
ret

--

LDC ASM:

_D7getset15Test21xMFZi:
movl8(%eax), %eax
ret

_D7getset15Test21xMFiZv:
movl4(%esp), %ecx
movl%ecx, 8(%eax)
ret $4

main:
subl$12, %esp
movl$4, 4(%esp)
movl$.str2, (%esp)
callprintf
xorl%eax, %eax
addl$12, %esp
ret $8
*/

Here the LDC code is almost optimal, thanks to Frits van Bommel and others.

==

Now with a (virtual) getter and setter:

version(Tango) import tango.stdc.stdio: printf;

class Test1 {
 int x;
}

class Test2 {
 int _x;
 int x() { return this._x; }
 void x(int xx) { this._x = xx; }
}

void main() {
auto t = new Test2;
t.x = 4;
printf("%d\n", t.x);
}

/*
DMD ASM:

_D16getters_setters25Test21xMFZicomdat
mov EAX,8[EAX]
ret

_D16getters_setters25Test21xMFiZv   comdat
mov ECX,4[ESP]
mov 8[EAX],ECX
ret 4

main:
pushEAX
mov EAX,offset FLAT:_D16getters_setters25Test27__ClassZ
pushEBX
pushESI
push4
pushEAX
callnear ptr __d_newclass
add ESP,4
mov ECX,[EAX]
mov EBX,EAX
calldword ptr 01Ch[ECX]
mov EDX,[EBX]
mov EAX,EBX
calldword ptr 018h[EDX]
mov ESI,offset FLAT:_D16getters_setters25Test26__vtblZ[020h]
pushEAX
pushESI
callnear ptr _printf
add ESP,8
xor EAX,EAX
pop ESI
pop EBX
pop ECX
ret

-

LDC ASM:

_D7getset25Test21xMFZi:
movl8(%eax), %eax
ret

_D7getset25Test21xMFiZv:
movl4(%esp), %ecx
movl%ecx, 8(%eax)
ret $4

main:
subl$12, %esp
movl$_D7getset25Test27__ClassZ, (%esp)
call_d_allocclass
movl$_D7getset25Test26__vtblZ, (%eax)
movl$0, 4(%eax)
movl$4, 8(%eax)
movl$4, 4(%esp)
movl$.str2, (%esp)
callprintf
xorl%eax, %eax
addl$12, %esp
ret $8
*/

I like LDC and LDC developers (and LLVM) :-)

If 't' is defined as a scoped class, then LDC produces this main:

main:
subl$20, %esp
movl$_D8getset2b5Test26__vtblZ, 8(%esp)
movl$0, 12(%esp)
movl$4, 16(%esp)
movl$4, 4(%esp)
movl$.str2, (%esp)
callprintf
leal8(%esp), %eax
movl%eax, (%esp)
call_d_callfinalizer
xorl%eax, %eax
addl$20, %esp
ret $8

That's better. But recently I have asked ChristianK to improve that some more,
removing part of that call to _d_callfinalizer, leaving only a call to the 
monitor management:
http://www.dsource.org/projects/ldc/ticket/339
*/

Bye,
bearophile


Re: [SO] question on trivial function inlining

2009-07-10 Thread BCS

Reply to bearophile,


BCS:

OK, if you want you can copy it on the StackOverflow


done there


But I'd also like to show that answer of mine to D developers,


done here

:)




Re: [SO] question on trivial function inlining

2009-07-10 Thread bearophile
BCS:
> Mind if I echo that back to SO?

OK, if you want you can copy it on the StackOverflow site (even if it's bad 
advertising for the D language and even if there are some small grammar errors 
in what I have written, I have written it quickly, and English isn't my first 
language) :-)

But I'd also like to show that answer of mine to D developers, because (an 
improvement in) the front-end may help in devirtualizing some class methods.

Bye,
bearophile


Re: [SO] question on trivial function inlining

2009-07-10 Thread BCS

Reply to bearophile,


Benjamin Shropshire:


Anyone care to add more details?
http://stackoverflow.com/questions/1109995/do-getters-and-setters-imp
act-performance-in-c-d-java/1110324#1110324

[...]

Bye,
bearophile


Mind if I echo that back to SO?




Re: [SO] question on trivial function inlining

2009-07-10 Thread bearophile
Benjamin Shropshire:
> Anyone care to add more details?
> http://stackoverflow.com/questions/1109995/do-getters-and-setters-impact-performance-in-c-d-java/1110324#1110324

I think DMD is currently unable to de-virtualize virtual getters and setters. 
Virtual calls are a bit slower by itself, but they also don't allow inlining, 
so successive standard optimizations can't be done. So if such accesses to the 
attribute is a virtual call and this happens in a "hot" part of the code, then 
it may slow down your code significantly. (if it happens in non-hot parts of 
the code it has usually no effects. That's why Java Hot Spot doesn't need 
optimize all your code to produce a very fast program anyway).

I have encouraged Frits van Bommel to improve the devirtualization capabilities 
of LDC:
http://www.dsource.org/projects/ldc/changeset/1506%3A76936858d1c6
Now LDC is able to do that in few very simple situations, but most times the 
situation is unchanged compared to DMD. Eventually LLVM will improve, so this 
situation can improve by itself. But the front-end too may do something about 
this.

Some documentation about this topic, something older:
http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=B26C4304DB1DA05ECBD67CA7D9313511?doi=10.1.1.7.7766&rep=rep1&type=pdf

Some more modern:
http://ols.fedoraproject.org/GCC/Reprints-2006/namolaru-reprint.pdf

Bye,
bearophile


Re: Regex

2009-07-10 Thread BLS

Robert Fraser wrote:

BLS wrote:

Vladimir Voinkov wrote:
std.regex can't be used in compile time function call. It's quite 
frustrating...


see dsource.org .. afaik there is a compile time regex project. hth


http://www.dsource.org/projects/scregexp

But the generated functions aren't CTFE-compatible AFAIK. A CTFE regex 
engine would be um... "tricky" to say the least. About 50GB of memory 
tricky (on DMD, LDC has a GC... though, it's still just as slow with 
CTFE). Really, if you need that level of code manipulation, a 
preprocessor is probably a better choice.


Ouch!
Remaining question :
>>> std.regex can't be used in compile time function call

Why this* don't work for you ?
*  http://www.digitalmars.com/d/2.0/templates-revisited.html
(middle of the document / Regular Expression Compiler)



[SO] question on trivial function inlining

2009-07-10 Thread Benjamin Shropshire

Anyone care to add more details?

http://stackoverflow.com/questions/1109995/do-getters-and-setters-impact-performance-in-c-d-java/1110324#1110324




Release binary

2009-07-10 Thread Vladimir Voinkov
I've noticed that constant strings are still presented in release bynary:

static invariant string Abc0 = "abcdefg";
static const string Abc1 = "abcdefg";

A source compiles with -O -release and the strings are not referenced. Is 
linked able to optimize them out?


DSSS on linux: Failed to determine DSSS installed prefix

2009-07-10 Thread Trass3r
I've setup dsss exactly how it is described and added it to the PATH, 
but it always states: "Failed to determine DSSS' installed prefix".


It's the same problem as here:
http://www.mail-archive.com/digitalmars-d-learn@puremagic.com/msg00291.html

but the solution doesn't work for me.
./dsss --prefix=/home/.../D/dsss/ install
-> Unrecognized argument: --prefix=/home/.../D/dsss/

What am I doing wrong?