Boost logo

Boost :

Subject: Re: [boost] Boost.En?dian comments
From: Tim Blechmann (tim_at_[hidden])
Date: 2011-09-05 19:26:05


> > 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?
[snip]
> 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.

i would assume that this algorithm is way more friendly for out-of-order
machines as it is should make use of instruction level parallelism.

it might be hard to verify the benefit with a synthetic benchmark, though ...

tim




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