Re: Byte swap asm optimization

Discussion in 'C Programming' started by Ian Collins, Apr 6, 2012.

  1. Ian Collins

    Ian Collins Guest

    On 04/ 6/12 08:03 PM, Guillaume Dargaud wrote:
    > Hello all,
    > a little bit off topic, but I'd like some help on how to optimize one of my
    > C progs which requires byte swaps on 64-bits integers.
    >
    > It's been about 20 years since my last lines of assembly, so I'm notably
    > rusty. Also I've never used the asm keyword while in C.
    >
    > I've seen the bswap x86 asm instruction and tried to find example without
    > success.
    >
    > How would I go to using C inline assembly to swap a long long variable ?
    > Thanks


    For one example, see

    http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/amd64/gen/byteorder.s#44

    --
    Ian Collins
    Ian Collins, Apr 6, 2012
    #1
    1. Advertising

  2. On 06-Apr-12 10:02, Guillaume Dargaud wrote:
    > I got this to work fine:
    > unsigned long x=0x12345678;
    > asm("bswapl %0"
    > : "=r" (x)
    > : "0" (x));
    >
    > But I can't compile the following:
    > unsigned long long x=0x123456789abcdef0ULL;
    > asm("bswapq %0"
    > : "=r" (x)
    > : "0" (x));
    > Error: suffix or operands invalid for `bswap'
    >
    > I'm on a x86_64 processor, but with a 32-bit distro, maybe that's the
    > reason?


    If by "32-bit distro" you mean that your OS is x86, then you are limited
    to x86 programs. The bswapq instruction is only available in x86-64
    programs, which will only run on an x86-64 OS.

    For information on how to emulate bswapq by using two bswapl
    instructions, I would suggest checking in comp.lang.asm.x86.

    S

    --
    Stephen Sprunk "God does not play dice." --Albert Einstein
    CCIE #3723 "God is an inveterate gambler, and He throws the
    K5SSS dice at every possible opportunity." --Stephen Hawking
    Stephen Sprunk, Apr 6, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edwin Knoppert

    define byte asm substitute?

    Edwin Knoppert, Jan 11, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    496
    Edwin Knoppert
    Jan 11, 2006
  2. Niels Dekker (no reply address)

    What swap is called when using std::swap?

    Niels Dekker (no reply address), Jul 19, 2006, in forum: C++
    Replies:
    4
    Views:
    986
    Niels Dekker (no reply address)
    Jul 20, 2006
  3. Replies:
    17
    Views:
    644
    ┬Ča\\/b
    Aug 12, 2007
  4. Ravikiran

    Zero Optimization and Sign Optimization???

    Ravikiran, Nov 17, 2008, in forum: C Programming
    Replies:
    22
    Views:
    861
    Thad Smith
    Nov 24, 2008
  5. James Kuyper

    Re: Byte swap asm optimization

    James Kuyper, Apr 6, 2012, in forum: C Programming
    Replies:
    1
    Views:
    595
    Stephen Sprunk
    Apr 6, 2012
Loading...

Share This Page