Question about x86 delegate calling convention
James Dunne
james.jdunne at gmail.com
Thu Jun 29 06:53:59 PDT 2006
Jarrett Billingsley wrote:
> I was stepping through some assembly when debugging one of my programs, and
> I noticed something a bit odd about how delegates were called.
>
> Delegates consist basically of two things: a context pointer (either 'this'
> for class members or the outer function's frame pointer for nested
> functions), and the address of the actual code. This is how D seems to call
> delegates:
>
> EAX = context ptr;
> EDX = code address;
> EBX = context ptr;
> EDX();
>
> Inside the delegate, only the EAX context pointer is ever used. 'this' is
> also passed in EAX when calling class methods directly (a.method()).
>
> My question is: why is EBX filled with the context pointer? It's never used
> in the delegate; in fact, if the delegate has some complex code, and the
> codegen needs another register, it will preserve EBX (pushing it) before
> using it.
>
> This happens even in release mode.
>
> Is this a vestige of some older calling convention for delegates?
>
> I also want to know this because I'm working on a (blatantly non-portable)
> method of dynamically calling functions at run-time (for fun).
>
>
A wild stab in the dark here, but perhaps the dup context ptr in EBX is
coincidentally the same value used for a different feature
implementation? Try all the cases of delegate calling, nested function
calling, virtual method calling, variadic function calling, etc. and
check the value of EBX vs. EAX. I have a suspicion your answer will lie
in there somewhere. :)
Then again, perhaps it's just bad codegen... but let's hope not. I
don't think anyone could answer this 100% other than Walter.
--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/MU/S d-pu s:+ a-->? C++++$ UL+++ P--- L+++ !E W-- N++ o? K? w--- O
M--@ V? PS PE Y+ PGP- t+ 5 X+ !R tv-->!tv b- DI++(+) D++ G e++>e
h>--->++ r+++ y+++
------END GEEK CODE BLOCK------
James Dunne
More information about the Digitalmars-d
mailing list