Jump to page: 1 24  
Page
Thread overview
yank '>>>'?
Dec 06, 2009
Ellery Newcomer
Dec 06, 2009
bearophile
Dec 06, 2009
dsimcha
Dec 06, 2009
Adam D. Ruppe
Dec 06, 2009
Michel Fortin
Dec 06, 2009
bearophile
Dec 06, 2009
Ary Borenszweig
Dec 06, 2009
Michel Fortin
Dec 06, 2009
Don
Dec 06, 2009
KennyTM~
Dec 06, 2009
Don
Dec 06, 2009
bearophile
Dec 06, 2009
Don
Dec 06, 2009
KennyTM~
Dec 06, 2009
bearophile
Dec 06, 2009
KennyTM~
Dec 06, 2009
dsimcha
Dec 06, 2009
Denis Koroskin
Dec 06, 2009
Chad J
Dec 06, 2009
Walter Bright
Dec 07, 2009
Jerry Quinn
Dec 07, 2009
KennyTM~
Dec 07, 2009
Simen kjaeraas
Dec 07, 2009
Jerry Quinn
Dec 06, 2009
Lionello Lunesu
Dec 07, 2009
retard
Dec 06, 2009
dsimcha
Dec 06, 2009
Don
Dec 06, 2009
Don
Dec 06, 2009
Walter Bright
Dec 06, 2009
Walter Bright
Dec 06, 2009
Lionello Lunesu
December 06, 2009
D has operator >>> which means "unsigned shift to the right", inherited from Java. But it doesn't need it because D has unsigned types, which can be used to effect unsigned shift. (Java, lacking unsigned types, had no other way around but to define a new operator.)

Should we yank operator>>>?


Andrei
December 06, 2009
On 12/06/2009 10:11 AM, Andrei Alexandrescu wrote:
> D has operator >>> which means "unsigned shift to the right", inherited
> from Java. But it doesn't need it because D has unsigned types, which
> can be used to effect unsigned shift. (Java, lacking unsigned types, had
> no other way around but to define a new operator.)
>
> Should we yank operator>>>?
>
>
> Andrei

taking the opportunity to review what the difference is between >> and >>>

for signed integers, >> is equivalent to divide by 2. It leaves the sign bit unchanged. >>> is an actual bit shift. Neither moves the lower n bits to the upper n bits or anything like that.

for unsigned integers, >> is equivalent to divide by 2. >>> is an actual bit shift, but that's equivalent to divide by 2, so >> and >>> are the same.

I've never liked that >> doesn't actually shift all of the bits, and the only valid use for it is equivalent to

a / 2^^n

except less readable. Although I don't suppose one should be doing bitwise manipulations with signed integers in the first place..
December 06, 2009
Andrei Alexandrescu:
> Should we yank operator>>>?

We can change it purpose and add the other one:
<<< rotate left
>>> rotate right

Bye,
bearophile
December 06, 2009
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail@erdani.org)'s article
> D has operator >>> which means "unsigned shift to the right", inherited
> from Java. But it doesn't need it because D has unsigned types, which
> can be used to effect unsigned shift. (Java, lacking unsigned types, had
> no other way around but to define a new operator.)
> Should we yank operator>>>?
> Andrei

I've never used >>> before, so I'm not 100% sure I understand what it's supposed to do.  However, I wrote a test program to see if it does what I think, and if my understanding is correct, it's not even properly implemented.  The fact that noone's noticed until now is a pretty clear indication that noone uses >>> .

Test program:

import std.stdio;

void main() {
    int i = 0b10000000_00000000_00000000_00000010;

    int iSigned = i >> 2;
    writefln(" int  >>:  %.32b", iSigned);

    int iUnsigned = i >>> 2;
    writefln(" int >>>:  %.32b", iUnsigned);

    uint u = cast(uint) i;

    uint uSigned = u >> 2;
    writefln(" uint >>:  %.32b", uSigned);

    uint uUnsigned = u >>> 2;
    writefln("uint >>>:  %.32b", uUnsigned);
}

Output (DMD 2.037):

 int  >>:  11100000000000000000000000000000
 int >>>:  11100000000000000000000000000000
 uint >>:  00100000000000000000000000000000
uint >>>:  00100000000000000000000000000000
December 06, 2009
== Quote from bearophile (bearophileHUGS@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.
December 06, 2009
On Sun, Dec 06, 2009 at 05:36:49PM +0000, dsimcha wrote:
> In a close to the metal language, there needs to be a straightforward, efficient way to access it.

You could always do what I did in my D SHA implementations:

uint something = whatever;

asm { rol something, 5; }

something += stuff;

We have inline asm, so I say just go ahead and use it.

Though, if you did want a D function for it (SafeD could use it then I guess), std.intrinsic is where I'd expect it to be.

-- 
Adam D. Ruppe
http://arsdnet.net
December 06, 2009
dsimcha:
> This is a good idea, although rotate may be seldom enough used not to warrant its own (possibly overloadable) operator.

Overloadable rotate operators can be used to rotate items inside an user-defined array, in my dlibs I have the templated functions rotateLeft and rotateRight, and I have used them once in a while.


> std.intrinsic might be a better place for rotate.<

In std.intrinsic I'd like to see ways to read and use the carry bit, from D.

Bye,
bearophile
December 06, 2009
On 2009-12-06 13:07:29 -0500, "Adam D. Ruppe" <destructionator@gmail.com> said:

> On Sun, Dec 06, 2009 at 05:36:49PM +0000, dsimcha wrote:
>> In a close to the metal language, there needs to be a straightforward, efficient
>> way to access it.
> 
> You could always do what I did in my D SHA implementations:
> 
> uint something = whatever;
> 
> asm { rol something, 5; }
> 
> something += stuff;
> 
> We have inline asm, so I say just go ahead and use it.

The problem with asm is portability. You can't go very far from x86 with the above code, and if you do you end up with static ifs everywhere, adding a readability problem.

So an intrinsic or a built-in operator is much better.

-- 
Michel Fortin
michel.fortin@michelf.com
http://michelf.com/

December 06, 2009
On 2009-12-06 12:36:49 -0500, dsimcha <dsimcha@yahoo.com> said:

> == Quote from bearophile (bearophileHUGS@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.

The first time I searched for a way to rotate bits, I searched for an operator and didn't find one (it was in C++ I think). So I wrote my own function; it wasn't worth the time searching further.

I support <<< and >>> for rotate left and right, as an operator is the most obvious place to look for such a basic operation.

-- 
Michel Fortin
michel.fortin@michelf.com
http://michelf.com/

December 06, 2009
bearophile wrote:
> dsimcha:
>> This is a good idea, although rotate may be seldom enough used not to warrant its
>> own (possibly overloadable) operator.
> 
> Overloadable rotate operators can be used to rotate items inside an user-defined array, in my dlibs I have the templated functions rotateLeft and rotateRight, and I have used them once in a while.
> 
> 
>> std.intrinsic might be a better place for rotate.<
> 
> In std.intrinsic I'd like to see ways to read and use the carry bit, from D.
> 
> Bye,
> bearophile

Write an enhancement request.
« First   ‹ Prev
1 2 3 4