Re: A modest proposal: eliminate template code bloat

2012-04-09 Thread Somedude
Le 08/04/2012 16:18, H. S. Teoh a écrit : On Sun, Apr 08, 2012 at 03:01:56PM +0400, Dmitry Olshansky wrote: I think it's been ages since I meant to ask why nobody (as in compiler vendors) does what I think is rather simple optimization. In the short term the plan is to introduce a link-time

Re: A modest proposal: eliminate template code bloat

2012-04-09 Thread Dmitry Olshansky
On 09.04.2012 5:11, Daniel Murphy wrote: Dmitry Olshanskydmitry.o...@gmail.com wrote in message news:jlsmka$22ce$1...@digitalmars.com... The refinement is merging prefixes and suffixes of course. And for that one needs to calculate hashes for all of prefixes and all of suffixes. I will define

Re: A modest proposal: eliminate template code bloat

2012-04-09 Thread Artur Skawina
On 04/09/12 08:21, Somedude wrote: Le 08/04/2012 16:18, H. S. Teoh a écrit : On Sun, Apr 08, 2012 at 03:01:56PM +0400, Dmitry Olshansky wrote: I think it's been ages since I meant to ask why nobody (as in compiler vendors) does what I think is rather simple optimization. In the short term

Re: A modest proposal: eliminate template code bloat

2012-04-09 Thread H. S. Teoh
On Mon, Apr 09, 2012 at 08:21:08AM +0200, Somedude wrote: Le 08/04/2012 16:18, H. S. Teoh a écrit : On Sun, Apr 08, 2012 at 03:01:56PM +0400, Dmitry Olshansky wrote: I think it's been ages since I meant to ask why nobody (as in compiler vendors) does what I think is rather simple

Re: A modest proposal: eliminate template code bloat

2012-04-09 Thread Daniel Murphy
H. S. Teoh hst...@quickfur.ath.cx wrote in message news:mailman.1518.1333937643.4860.digitalmar...@puremagic.com... Why is it so important to have unique addresses for functions? Just because I can't think of a use case doesn't mean nobody is relying on it! But I guess there really isn't

Re: A modest proposal: eliminate template code bloat

2012-04-09 Thread H. S. Teoh
On Mon, Apr 09, 2012 at 11:58:01PM +1000, Daniel Murphy wrote: H. S. Teoh hst...@quickfur.ath.cx wrote in message news:mailman.1518.1333937643.4860.digitalmar...@puremagic.com... Why is it so important to have unique addresses for functions? Just because I can't think of a use case

A modest proposal: eliminate template code bloat

2012-04-08 Thread Dmitry Olshansky
I think it's been ages since I meant to ask why nobody (as in compiler vendors) does what I think is rather simple optimization. In the short term the plan is to introduce a link-time flavored optimization at code generation or (better) link step. For simplicity let's assume compiler does

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Marco Leise
Am Sun, 08 Apr 2012 15:01:56 +0400 schrieb Dmitry Olshansky dmitry.o...@gmail.com: I think it's been ages since I meant to ask why nobody (as in compiler vendors) does what I think is rather simple optimization. In the short term the plan is to introduce a link-time flavored optimization

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread H. S. Teoh
On Sun, Apr 08, 2012 at 03:01:56PM +0400, Dmitry Olshansky wrote: I think it's been ages since I meant to ask why nobody (as in compiler vendors) does what I think is rather simple optimization. In the short term the plan is to introduce a link-time flavored optimization at code generation

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Artur Skawina
On 04/08/12 13:01, Dmitry Olshansky wrote: 3. After any function was generated compiler checks an entry in the duplicate table that matches size, followed by matching checksum and only then (if required) doing a straight memcmp. If it happens that there is a match compiler just throws

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Dmitry Olshansky
On 08.04.2012 18:21, Artur Skawina wrote: On 04/08/12 13:01, Dmitry Olshansky wrote: 3. After any function was generated compiler checks an entry in the duplicate table that matches size, followed by matching checksum and only then (if required) doing a straight memcmp. If it happens that

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Artur Skawina
On 04/08/12 17:20, Dmitry Olshansky wrote: On 08.04.2012 18:21, Artur Skawina wrote: On 04/08/12 13:01, Dmitry Olshansky wrote: 3. After any function was generated compiler checks an entry in the duplicate table that matches size, followed by matching checksum and only then (if required)

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Marco Leise
Am Sun, 8 Apr 2012 07:18:26 -0700 schrieb H. S. Teoh hst...@quickfur.ath.cx: We'd have to make sure the checksum doesn't end up in the final executable though, otherwise the bloat may negate any gains we've made. Executables (and object files) are made up mostly of sections, some of which are

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Marco Leise
Am Sun, 08 Apr 2012 16:21:14 +0200 schrieb Artur Skawina art.08...@gmail.com: On 04/08/12 13:01, Dmitry Olshansky wrote: 3. After any function was generated compiler checks an entry in the duplicate table that matches size, followed by matching checksum and only then (if required) doing

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Andrei Alexandrescu
On 4/8/12 10:59 AM, Artur Skawina wrote: On 04/08/12 17:20, Dmitry Olshansky wrote: On 08.04.2012 18:21, Artur Skawina wrote: On 04/08/12 13:01, Dmitry Olshansky wrote: 3. After any function was generated compiler checks an entry in the duplicate table that matches size, followed by matching

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Dmitry Olshansky
On 08.04.2012 19:59, Artur Skawina wrote: On 04/08/12 17:20, Dmitry Olshansky wrote: On 08.04.2012 18:21, Artur Skawina wrote: On 04/08/12 13:01, Dmitry Olshansky wrote: 3. After any function was generated compiler checks an entry in the duplicate table that matches size, followed by

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Dmitry Olshansky
On 08.04.2012 18:18, H. S. Teoh wrote: [snip] 1. Every time a function is generated (or pretty much any symbol) not only a size calculated but also a checksum* of it's data. (If we go for link-time optimization we should find a place to stick it to in the object file) We'd have to make sure

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Dmitry Olshansky
On 08.04.2012 16:37, Marco Leise wrote: [snip] Template bloat could be especially important to 'fix' on embedded systems. I think I this idea largely formed years ago when I was working with c++ on 8bit micros. You won't believe the amount of code size one can save by using one separate

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread H. S. Teoh
On Sun, Apr 08, 2012 at 08:45:19PM +0400, Dmitry Olshansky wrote: On 08.04.2012 18:18, H. S. Teoh wrote: [snip] We'd have to make sure the checksum doesn't end up in the final executable though, otherwise the bloat may negate any gains we've made. Easy the symbol size is in object file

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Marco Leise
Am Sun, 08 Apr 2012 20:58:15 +0400 schrieb Dmitry Olshansky dmitry.o...@gmail.com: On 08.04.2012 16:37, Marco Leise wrote: [snip] Template bloat could be especially important to 'fix' on embedded systems. I think I this idea largely formed years ago when I was working with c++ on 8bit

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Dmitry Olshansky
On 08.04.2012 21:24, H. S. Teoh wrote: Yeah, that's what I was thinking of. This would be a very big gain for the new AA implementation, for example. I wouldn't have to worry so much about template bloat if most of the instantiations are going to get merged anyway. :-) Right the advantage is

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Andrei Alexandrescu
On 4/8/12 1:49 PM, Dmitry Olshansky wrote: P.S. Damn, I could have done a nice paper on that... too late :) You may always do. Andrei

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Walter Bright
On 4/8/2012 4:01 AM, Dmitry Olshansky wrote: I think it's been ages since I meant to ask why nobody (as in compiler vendors) does what I think is rather simple optimization. I worked out how to do it a while ago, but there's been no time to implement it. (You can't do a memcmp because of all

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Dmitry Olshansky
On 08.04.2012 22:51, Walter Bright wrote: On 4/8/2012 4:01 AM, Dmitry Olshansky wrote: I think it's been ages since I meant to ask why nobody (as in compiler vendors) does what I think is rather simple optimization. I worked out how to do it a while ago, but there's been no time to implement

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Dmitry Olshansky
On 08.04.2012 22:49, Dmitry Olshansky wrote: The refinement is merging prefixes and suffixes of course. And for that one needs to calculate hashes for all of prefixes and all of suffixes. I will define _all_ later on. First observation is that if you calculated partial checksums for prefixes

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread H. S. Teoh
On Sun, Apr 08, 2012 at 10:56:43PM +0400, Dmitry Olshansky wrote: On 08.04.2012 22:51, Walter Bright wrote: [...] The main difficulty is not being able to modify the linker. So you're pretty much limited to what the compiler is able to do before linking. D does allow the compiler to deal with

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Artur Skawina
On 04/08/12 18:14, Andrei Alexandrescu wrote: On 4/8/12 10:59 AM, Artur Skawina wrote: On 04/08/12 17:20, Dmitry Olshansky wrote: On 08.04.2012 18:21, Artur Skawina wrote: On 04/08/12 13:01, Dmitry Olshansky wrote: 3. After any function was generated compiler checks an entry in the

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Daniel Murphy
Artur Skawina art.08...@gmail.com wrote in message news:mailman.1480.1333900846.4860.digitalmar...@puremagic.com... Note that my point is just that the compiler needs to emit a dummy so that the addresses remain unique, eg module.f!uint: jmp module.f!int Or use a nop slide before

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Daniel Murphy
Dmitry Olshansky dmitry.o...@gmail.com wrote in message news:jlsmka$22ce$1...@digitalmars.com... The refinement is merging prefixes and suffixes of course. And for that one needs to calculate hashes for all of prefixes and all of suffixes. I will define _all_ later on. I think you'll find

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread H. S. Teoh
On Mon, Apr 09, 2012 at 10:59:26AM +1000, Daniel Murphy wrote: Artur Skawina art.08...@gmail.com wrote in message news:mailman.1480.1333900846.4860.digitalmar...@puremagic.com... Note that my point is just that the compiler needs to emit a dummy so that the addresses remain unique, eg

Re: A modest proposal: eliminate template code bloat

2012-04-08 Thread Marco Leise
Am Sun, 8 Apr 2012 19:14:22 -0700 schrieb H. S. Teoh hst...@quickfur.ath.cx: On Mon, Apr 09, 2012 at 10:59:26AM +1000, Daniel Murphy wrote: Artur Skawina art.08...@gmail.com wrote in message news:mailman.1480.1333900846.4860.digitalmar...@puremagic.com... Note that my point is just