Inline ASM in D
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sun Apr 27 07:36:23 PDT 2008
Sascha Katzner wrote:
> Walter wrote:
>> Inline assembler can only appear within functions.
>
> Is there any chance that you re-(think/work) this in the future?
>
> I've just written:
>
> uint reverseUint(void* source) {
> asm {
> naked;
> mov EAX, [EAX];
> bswap EAX;
> ret;
> }
> }
>
> ...and it strike me, that it would be *really* nice if the compiler
> would inline functions like that, either manually or automatically.
That would be why both Phobos and Tango have "uint bswap(uint)" (Phobos
in std.intrinsic, Tango in tango.core.BitManip). It's a compiler
intrinsic, meaning it should compile down to the 'bswap' asm instruction
on x86.
And it does, at least on DMD. Unfortunately GDC appears to only provide
a portable implementation with bitwise operators, not using the raw
instruction.
More information about the Digitalmars-d
mailing list