Byte Order Swapping Function
Piotr Szturmaj
bncrbme at jadamspam.pl
Thu Jul 14 05:52:08 PDT 2011
Steven Schveighoffer wrote:
> On Thu, 14 Jul 2011 06:12:00 -0400, Piotr Szturmaj
> <bncrbme at jadamspam.pl> wrote:
>
>
>> Btw. How compiler intrinsics work? I see there's only bswap
>> declaration (without body) in core.bitop. Where can I find compiler
>> code which actually substitutes bswap() into real instructions?
>
> A complier intrinsic is a special function that the compiler replaces
> with inline code. The idea is, some targets of the compiler have
> instructions which implement the function, so instead of doing a
> function call and inline assembly, the compiler just replaces the call
> to a single instruction (in this case bswap).
>
> So the answer is, you won't find that code anywhere :) If you grep for
> bswap in the dmd source, you might find out how it does it.
>
> -Steve
Thanks, I actually meant code which is generated by the compiler :) I
wanted to know how it's generated. Now I know that bswap() is actually
substituted by BSWAP x86 instruction on that architecture. I found that
16 bit bswap may be implemented using XCHG instruction, but
unfortunately there's no equivalent for 64 bit swap in 32 bit mode (only
in x86-64).
More information about the Digitalmars-d
mailing list