ASM help needed... (on x86/windows/gcc)

Lloyd Dupont lloyd@nova-mind.com
Fri May 20 07:02:00 GMT 2005


After lots of test, (and some experimental ASM which I quickly discard for 
my too rusty ASM skills) I found this nice solution build from idea 
from the sources:
(However an ASM version with a jump would have been much more reliable 
(regarding argument forwarding, particularly with variable argument list), 
simple and fast):
-----------------------
DLL_EXPORT retval_t objcsharp_msg_send(id obj, const char* msg, ...)
{
 void* args = __builtin_apply_args();
 SEL sel = sel_get_uid(msg);
 Method_t m = class_get_instance_method (obj->class_pointer, sel);
 if(m != NULL)
 {
  __builtin_return( __builtin_apply(
   (void(*)()) m->method_imp,
   args,
   method_get_sizeof_arguments(m)
  ));
 }
 else
 {
        SEL frwd_sel = sel_get_any_uid("forwardInvocation:");
     if(sel && __objc_responds_to (obj, frwd_sel))
     {
      NSInvocation * i = [[NSInvocation alloc] initWithArgframe: args 
selector: sel];
      [i autorelease];
      [obj forwardInvocation:i];
     }
     else
     {
      objc_error (obj, OBJC_ERR_UNIMPLEMENTED, "ObjectiveC Runtime error, 
unimplemented method: %s\n", msg);
     }
  return 0;
 }
}
-----------------------

for info here was the kind of ASM I was looking at:
---- pseudo ASM (failing) ------
retval_t objc_msgSend(id obj, SEL sel, ...)
{
    asm(" pusha \r\n");
    IMP imp = objc_msg_lookup(obj, sel);
    asm(" popa \r\n");
    asm( "longjmp %0 \r\n" : "=p" (imp) );
}
---------------------------------



----- Original Message ----- 
From: "Andrew Pinski" <pinskia@physics.uc.edu>
To: "Lloyd Dupont" <lloyd@nova-mind.com>
Cc: "Mike Stump" <mrs@apple.com>; <gcc@gcc.gnu.org>
Sent: Friday, May 20, 2005 10:25 AM
Subject: Re: ASM help needed... (on x86/windows/gcc)


> 
> On May 19, 2005, at 8:10 PM, Lloyd Dupont wrote:
> 
>> Simple, I'm building an ObjectiveC binding from .NET.
>> Basically my .NET code generator transform all objectiveC method in a 
>> call to
>> objc_msg_send() (from the .NET code, which could call C directly)
>>
>> the problem with _built_in_apply() is you need to know the size of the 
>> stack.
>> and that's a real issue for method such as +stringWithFormat:... with 
>> takes a variable number of argument
> 
> I would suggest you look into how libobjc implements forward.
> Thanks,
> Andrew Pinski
>



More information about the Gcc mailing list