This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Endian swapping with C code on ARM


Joel Sherrill <joel@OARcorp.com> wrote:

How about just using inline assembly like this from the RTEMS ARM port?

unsigned int CPU_swap_u32(
  unsigned int value
)
{
    uint32_t   tmp = value;
    asm volatile ("EOR   %1, %0, %0, ROR #16\n"
                  "BIC   %1, %1, #0xff0000\n"
                  "MOV   %0, %0, ROR #8\n"
                  "EOR   %0, %0, %1, LSR #8\n"
                  : "=r" (value), "=r" (tmp)
                  : "0" (value), "1" (tmp));

    return value;
}

This is such a common operation. It seems a shame to render a program severely target dependent just because it wants to do endianness conversion.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]