Inline assembler in D and LDC, round 2
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sat Feb 7 18:03:30 PST 2009
Walter Bright wrote:
> Frits van Bommel wrote:
>> Luckily, inline asm is treated as a function literal in LLVM, and it
>> can return one or more values to the caller if the constraints string
>> specifies which registers will contain them. So if LDC just specifies
>> (e.g.) EAX/EDX:EAX/ST(0) to contain the result of the inline asm, it
>> can get the value in the register(s) in question as an LLVM value that
>> can be returned without any problem.
>> The only really tricky bits are (a) figuring out how the constraints
>> string works, exactly[1] and (b) figuring out which register(s) the
>> return value should be in.
>
> You understand the LLVM better than anyone else here <g>, so I suggest
I just happened to remember the broad strokes of how inline asm works in
LLVM[1], and saw the relevance to this discussion. I'm not sure if that
qualifies as knowing LLVM as a whole better than anyone else here.
[1]: i.e. "like gcc extended asm, but with different syntax"
> that you pick what you think will work best, and leave it at that for
> now. I don't think there's a good reason to get too stuck on this. If a
> better solution emerges during testing, it can be corrected.
Lindquist says (on IRC) that he has already implemented this on his
local machine and it's working quite nicely (for x86).
He hasn't pushed it to the dsource repository yet; it requires people
compiling from there to update their LLVM since apparently with LLVM 2.4
the EDX:EAX 64-bit int constraint doesn't work. Updating to the 2.5
branch fixes it though, so it looks like LDC will be requiring v2.5 soon.
Porting to other architectures shouldn't be too hard either. The code
that generates the constraint string for x86 is pretty clean and short
so adding (e.g.) x86-64 support should only require a bit of
copy+paste+edit after some research into calling conventions.
More information about the Digitalmars-d
mailing list