yank '>>>'?

Don nospam at nospam.com
Sun Dec 6 12:16:00 PST 2009


KennyTM~ wrote:
> 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)).

That's why I said 'where x is uint'. I was trying to keep the example 
simple.
There is no way anyone should EVER be doing a rotation on a signed type 
-- that's insane.




More information about the Digitalmars-d mailing list