Inline assembler in D and LDC, round 2

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Thu Feb 5 05:42:18 PST 2009


Don wrote:
> Frits van Bommel wrote:
>> Walter Bright wrote:
>>> Frits van Bommel wrote:
>>>> Is it really that hard? Can't you just detect this case (non-void 
>>>> function without a 'return' at the end but with inline asm inside)?
>>>>
>>>> Since the compiler should know the calling convention[1], the 
>>>> register that will contain the return value of the function should 
>>>> be a simple lookup (based on target architecture, cc and return type).
>>>> Just add that register as an output of the inline asm and return it...
>>>
>>> dmd doesn't attempt to figure out which register is the return value. 
>>> It just assumes that the registers specified by the ABI for the 
>>> function's return type have the proper return value in them.
>>
>> That isn't an option for LDC, which is why I suggested another approach.
> 
> What's the difference? Walter's approach assumes there's a "return EAX;" 
> at the end of every function returning an int, for example; your 
> approach seems to be to add it.

His approach depends on DMD directly emitting x86 machine code, so it 
can just emit 'RET' and be done with it.

LDC on the other hand needs to emit LLVM asm, which requires it to 
specify an explicit return value. My approach is a way to extract that 
return value from the inline asm, allowing it to emulate DMD behavior 
within the LLVM IR.



More information about the Digitalmars-d mailing list