yank '>>>'?

KennyTM~ kennytm at gmail.com
Sun Dec 6 12:05:06 PST 2009


On Dec 7, 09 03:41, Don wrote:
> dsimcha wrote:
>> == Quote from bearophile (bearophileHUGS at lycos.com)'s article
>>> Andrei Alexandrescu:
>>>> Should we yank operator>>>?
>>> We can change it purpose and add the other one:
>>> <<< rotate left
>>>>>> rotate right
>>> Bye,
>>> bearophile
>>
>> This is a good idea, although rotate may be seldom enough used not to
>> warrant its
>> own (possibly overloadable) operator. std.intrinsic might be a better
>> place for
>> rotate. On the other hand, rotate is a single ASM instruction, at
>> least on x86.
>> In a close to the metal language, there needs to be a straightforward,
>> efficient
>> way to access it.
>
> I think DMD should just do what gcc does: recognize that
> (x << 32-n | x>>n) is ror n
> (x << n | x>> 32-n) is rol n
>
> where x is int. Ugly, but doesn't require an intrinsic.
>

It's still better to provide a std.???.rol(T)(T x) and ror because that 
(least) ugly code only works if you already know x is a uint. That ror 
code won't work if x is signed (int: cast into uint first) or is 64-bit 
(ulong: replace 32 with (8*x.sizeof)).



More information about the Digitalmars-d mailing list