c - How to BSWAP the lower 32-bit of 64-bit register? -


i've been looking answer how use bswap lower 32-bit sub-register of 64-bit register. example, 0x0123456789abcdef inside rax register, , want change 0x01234567efcdab89 single instruction (because of performance).

so tried following inline function:

#define bswap(t) {  \     __asm__ __volatile__ (  \             "bswap %k0" \             : "=q" (t)  \             : "q" (t)); \ } 

and result 0x00000000efcdab89. don't understand why compiler acts this. know efficient solution?

ah, yes, understand problem now:

the x86-64 processors implicitly zero-extend 32-bit registers 64-bit when doing 32-bit operations (on %eax, %ebx, etc). maintain compatibility legacy code expects 32-bit semantics these registers, understand it.

so i'm afraid there no way ror on lower 32 bits of 64-bit register. you'll have use series of several instructions...


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -