[Issue 7181] Make bswap a recognized sequence, rather than an intrinsic

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 29 12:25:28 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=7181



--- Comment #4 from Andrei Alexandrescu <andrei at metalanguage.com> 2011-12-29 12:25:27 PST ---
(In reply to comment #2)
> (In reply to comment #1)
> > (In reply to comment #0)
> > > In the same way that abs, rol and ror are recognized, bswap(int x)
> > > could be identified from:
> > > 
> > > ( x << 24 ) | ( x << 8 ) & 0xff0000 | ( x >> 8 ) & 0xff00 | ( x >> 24 );
> > > 
> > > and this would be completely portable.
> > 
> > Even if this pattern gets recognized and optimized, I suggest to keep a bswap
> > function in Phobos, to avoid writing all that bug-prone stuff (I'd like a
> > rol/ror function pair too in Phobos).
> 
> Definitely. It would just change from:
> 
> int bswap(int); /* intrinsic */
> 
> into
> 
> int bswap(int x)
> {
>     return ( x << 24 ) | ( x << 8 ) & 0xff0000 | ( x >> 8 ) & 0xff00 | ( x >>
> 24 );
> }

I only now realized the meaning of this remark... took me some 10 minutes.
Clever.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list