Boost logo

Boost :

Subject: Re: [boost] Proposed templated integer_sort
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2008-12-17 19:08:49


On Wed, Dec 17, 2008 at 18:40, Steven Ross <spreadsort_at_[hidden]> wrote:
>
> I could do that, but I would often need one more iteration than is strictly
> necessary, and I wouldn't be able to reuse integer_sort to sort the positive
> floats. I have no reason to believe that going 8 bits at a time would be
> any faster, unless it can save me a memory operation to work around a
> casting restriction that isn't enforced on all (any?) platforms.
>

Uh, the casting restriction is "enforced". GCC's optimizer takes
advantage of the aliasing rules, so breaking them is a great way for
your code to not work after optimization in GCC. There are warnings
for it, too:

int foo(float f) {
    return *(int*)&f;
}

aliasing_demo.cxx: In function 'int foo(float)':
aliasing_demo.cxx:2: warning: dereferencing type-punned pointer will
break strict-aliasing rules

And as I mentioned earlier (Dec 16th), decent optimizers convert the
memcpy into the bitcast that's what you wanted in the first place, so
since there's nothing to save, it does sound like the 8-bits-at-a-time
version is a bad idea.


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