Boost logo

Boost :

Subject: Re: [boost] Boost.En?dian comments
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2011-09-05 18:54:02


tymofey wrote:
> inline void reorder(int64_t source, int64_t& target)
> {
> target = ((source << 0x38) & 0xFF00000000000000)
> | ((source << 0x28) & 0x00FF000000000000)
> | ((source << 0x18) & 0x0000FF0000000000)
> | ((source << 0x08) & 0x000000FF00000000)
> | ((source >> 0x08) & 0x00000000FF000000)
> | ((source >> 0x18) & 0x0000000000FF0000)
> | ((source >> 0x28) & 0x000000000000FF00)
> | ((source >> 0x38) & 0x00000000000000FF);
> }
>
> would be more efficient?

(See my other recent post about performance first.)

I've just added something like the above suggestion:

#elif defined(USE_TYMOFEY)

   return (src<<24)
        | ((src<<8) & 0x00ff0000)
        | ((src>>8) & 0x0000ff00)
        | ((src>>24) & 0x000000ff);

The results are:

                A B
USE_TYMOFEY 12.6 3.0

Impressively, on system B gcc is able to recognise that that expression
is implemented by the rev instruction.

On system A, the expected logical instructions are generated and they
are faster than the bytewise loads and stores that Beman's code
produces. Based on the similar speed, my guess is that this code is
similar to what htonl() does.

Regards, Phil.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk