Custom calling conventions

Jacob Carlborg doob at me.com
Tue Feb 21 23:41:21 PST 2012


On 2012-02-22 05:38, Michel Fortin wrote:
> On 2012-02-21 23:13:31 +0000, Manu <turkeyman at gmail.com> said:
>
>>
>> On 21 February 2012 23:06, Jacob Carlborg <doob at me.com> wrote:
>>
>>> On 2012-02-21 22:01, Manu wrote:
>>>
>>>> On 21 February 2012 22:35, Jacob Carlborg <doob at me.com
>>>>> But to give a quick example:
>>>>>
>>>>> class Foo : NSObject
>>>>> {
>>>>> Foo foo ()
>>>>> {
>>>>> return invokeObjcSelf!(Foo, "foo");
>>>>> }
>>>>>
>>>>> Foo bar ()
>>>>> {
>>>>> return invokeObjcSelf!(Foo, "bar");
>>>>> }
>>>>> }
>>>>>
>>>>> "invokeObjcSelf" is a template function that calls an Objective-C
>>>>> method. Basically each time "invokeObjcSelf" is called a new
>>>>> instantiation of the template is created and that is put in the
>>>>> symbol table. "invokeObjcSelf" then calls several more template
>>>>> functions making the template bloat increase exponentially.
>>>>
>>>> But they should all be inlined, and the symbol table should be
>>>> stripped,
>>>> which shouldn't leave anything in the end other than the inlined
>>>> function calling code, and in my examples, this will be basically the
>>>> exact same code that you'd have to write anyway to call through some
>>>> vm's API...
>>>
>>> Well, that's not what happen with templates.
>>
>> ... really? why?
>> You've just made me very very scared for my simd module :/
>>
>> I've had a serious concern about D's lack of a force-inline for quite a
>> while...
>
> I'm not sure what Jacob is referring to.

I referring to that every instantiation of a template function is put in 
the symbol table. If this is an implementation issue with DMD not being 
able to properly optimize this I don't know. I thought that this was one 
of the major reason for the executable size when using the Objective-C/D 
bridge. For example:

void foo () {}
void main () {}

$ dmd -inline -O -release main.d
$ nm main | grep foo

00000001000012b4 T _D4main3fooFZv

Outputs one symbol as expected

---------------------------------------

void foo (T) () {}
void main () {}

$ dmd -inline -O -release main.d
$ nm main | grep foo

Doesn't output anything since the template functions is not 
instantiated, it won't even be fully compiled (only lexed and perhaps 
parsed).

--------------------------------------------------------------

void foo (T) () {}
void main ()
{
     foo!(int);
     foo!(char);
}

$ dmd -inline -O -release main.d
$ nm main | grep foo

00000001000012b8 T _D4main10__T3fooTaZ3fooFZv
00000001000012b0 T _D4main10__T3fooTiZ3fooFZv

Outputs two symbols as expected, one for each instantiation.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list