www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - missing bswap(ushort) intrinsic

A 16-bit byte swap seems to be missing ?
(from std.intrinsic, only has a 32-bit)

I know that the i486+ only has a "BSWAP"
instruction, but others might have it...


Here is my "all-D" implementation:

 ushort bswap(ushort v)
 {
     return ((v<<8)|(v>>>8));
 }

You can add masks if you want to ? --anders PS. I have heard that "bswap" is slow on e.g. the Pentium IV CPU, anyway ? (but I haven't done any benchmarking)
Oct 28 2004