Jump to page: 1 2 3
Thread overview
Rotation operator proposal
Mar 13, 2003
Ziemowit Zglinski
Mar 13, 2003
Ilya Minkov
Mar 13, 2003
Ziemowit Zglinski
Mar 13, 2003
Bill Cox
Mar 13, 2003
Sean L. Palmer
Mar 13, 2003
Bill Cox
Apr 01, 2003
Walter
Apr 01, 2003
Sean L. Palmer
Apr 01, 2003
Burton Radons
Apr 01, 2003
Sean L. Palmer
Apr 02, 2003
Charles Banas
Apr 03, 2003
Burton Radons
Apr 03, 2003
Sean L. Palmer
Apr 25, 2003
Walter
Apr 25, 2003
Sean L. Palmer
Apr 25, 2003
Walter
Apr 25, 2003
Sean L. Palmer
Apr 25, 2003
Walter
Mar 13, 2003
Ben Woodhead
Mar 13, 2003
Mike Wynn
Mar 13, 2003
Jonathan Andrew
Mar 14, 2003
Ben Woodhead
March 13, 2003
While programming a lot of embedded application, I often miss a rotation operator in almost all programming languages. This operation  is implemented in all processor architectures and still difficult to achieve from a high level language.

Taking opportunity of not yet fully defined language, I propose to add two
rotation operators to the language definition:
Rotate right - @>  or @>>
Rotate left  - <@  or <<@

The behaviour should be analogue to the logical shift operators, except the bit shifted out would be shift in on the opposite side in place of 0. Number bits rotated should correspond to the length of the actual data type.

Thank You,

--  Ziemowit

    ziemek@tera.com.pl
March 13, 2003
I would prefer the following operators:

rotate right = |>>
rotate left = <<|

since '>>' means shift and '|' means or, it makes more sense to shift bits and then or them at the opposite end.


"Ziemowit Zglinski" <Ziemowit_member@pathlink.com> wrote in message news:b4pt22$gg1$1@digitaldaemon.com...
> While programming a lot of embedded application, I often miss a rotation operator in almost all programming languages. This operation  is
implemented in
> all processor architectures and still difficult to achieve from a high
level
> language.
>
> Taking opportunity of not yet fully defined language, I propose to add two
> rotation operators to the language definition:
> Rotate right - @>  or @>>
> Rotate left  - <@  or <<@
>
> The behaviour should be analogue to the logical shift operators, except
the bit
> shifted out would be shift in on the opposite side in place of 0. Number
bits
> rotated should correspond to the length of the actual data type.
>
> Thank You,
>
> --  Ziemowit
>
>     ziemek@tera.com.pl


March 13, 2003
I like the idea. It's like a simple small thing and useful which was missing from C. It goes into the same cthegory as BSF and BSR, which have been made standard already (as intrinsics or in library).

Nontheless, it might be against D's philosophy that algorithms should work independant of data width. Though i don't see much of a problem since there's a size property.

The tokens could just as well be  <|  and |> or something like that.

-i.

Ziemowit Zglinski wrote:
> While programming a lot of embedded application, I often miss a rotation
> operator in almost all programming languages. This operation  is implemented in
> all processor architectures and still difficult to achieve from a high level
> language.
> 
> Taking opportunity of not yet fully defined language, I propose to add two
> rotation operators to the language definition:
> Rotate right - @>  or @>>
> Rotate left  - <@  or <<@
> 
> The behaviour should be analogue to the logical shift operators, except the bit
> shifted out would be shift in on the opposite side in place of 0. Number bits
> rotated should correspond to the length of the actual data type.
> 
> Thank You,
> 
> --  Ziemowit
> 
>     ziemek@tera.com.pl

March 13, 2003
The operators @> and <@ for rotation I saw in a script language, so perhaps it would be wise to reuse them.

Another plus is, that you can SEE the rotation :-)

But really important is the availability of the operator and not the look...

--  Ziemowit

ziemek@tera.com.pl

In article <b4puq9$hfu$1@digitaldaemon.com>, Ilya Minkov says...
>
>I like the idea. It's like a simple small thing and useful which was missing from C. It goes into the same cthegory as BSF and BSR, which have been made standard already (as intrinsics or in library).
>
>Nontheless, it might be against D's philosophy that algorithms should work independant of data width. Though i don't see much of a problem since there's a size property.
>
>The tokens could just as well be  <|  and |> or something like that.
>
>-i.
>
>Ziemowit Zglinski wrote:
>> While programming a lot of embedded application, I often miss a rotation operator in almost all programming languages. This operation  is implemented in all processor architectures and still difficult to achieve from a high level language.
>> 
>> Taking opportunity of not yet fully defined language, I propose to add two
>> rotation operators to the language definition:
>> Rotate right - @>  or @>>
>> Rotate left  - <@  or <<@
>> 
>> The behaviour should be analogue to the logical shift operators, except the bit shifted out would be shift in on the opposite side in place of 0. Number bits rotated should correspond to the length of the actual data type.
>> 
>> Thank You,
>> 
>> --  Ziemowit
>> 
>>     ziemek@tera.com.pl
>


March 13, 2003
I'm not opposed to the idea, since it can lead to more efficient code. If D adds rotation operations, I'd also like access to the carry flag.

Bill

Ziemowit Zglinski wrote:
> The operators @> and <@ for rotation I saw in a script language,
> so perhaps it would be wise to reuse them. 
> 
> Another plus is, that you can SEE the rotation :-)
> 
> But really important is the availability of the operator and not the look...
> 
> --  Ziemowit
> 
> ziemek@tera.com.pl
> 
> In article <b4puq9$hfu$1@digitaldaemon.com>, Ilya Minkov says...
> 
>>I like the idea. It's like a simple small thing and useful which was missing from C. It goes into the same cthegory as BSF and BSR, which have been made standard already (as intrinsics or in library).
>>
>>Nontheless, it might be against D's philosophy that algorithms should work independant of data width. Though i don't see much of a problem since there's a size property.
>>
>>The tokens could just as well be  <|  and |> or something like that.
>>
>>-i.
>>
>>Ziemowit Zglinski wrote:
>>
>>>While programming a lot of embedded application, I often miss a rotation
>>>operator in almost all programming languages. This operation  is implemented in
>>>all processor architectures and still difficult to achieve from a high level
>>>language.
>>>
>>>Taking opportunity of not yet fully defined language, I propose to add two
>>>rotation operators to the language definition:
>>>Rotate right - @>  or @>>
>>>Rotate left  - <@  or <<@
>>>
>>>The behaviour should be analogue to the logical shift operators, except the bit
>>>shifted out would be shift in on the opposite side in place of 0. Number bits
>>>rotated should correspond to the length of the actual data type.
>>>
>>>Thank You,
>>>
>>>--  Ziemowit
>>>
>>>    ziemek@tera.com.pl
>>
> 
> 

March 13, 2003
The carry flag is not nearly as portable.  Some architectures might not need one.  I don't know of any such processors, but maybe some embedded system?

But I can't count the number of times I had to write my own rotate operator in C:

#ifdef _MSC_VER

#include <whatever.h>
uint rotateleft(uint x, int bits) { return __lrotl(x,bits); }

#elif defined(_MIPS_R3000X)

uint rotateleft(uint x, int bits) { asm { "rol blah2,blah1,bits" : "=r
blah2" (x) : "r blah1" (x), "r bits" (bits) }; }

#else

uint rotateleft(uint x, int bits) { return (x << bits) | (x >>
(sizeof(x)*8-bits)); }

#endif

Gets even crazier if you're dealing with signed types.  I hate having to bend over backward to get at some low level basic functionality that almost all machines have.

Isn't this what high level languages were supposed to be for, to make programs more portable, to keep us from having to worry about piddly machine architecture differences? No, we still have to know about them but now we can't do anything about it directly.

BSF/BSR sound mighty useful for doing bit array work or figuring out which power of two to use for textures.

Any of this can be emulated if the target processor doesn't have it.  It's a question of whether the functionality is useful enough to warrant inclusion.

Chances are that if there is a machine instruction on some chip somewhere, that the functionality the instruction has IS considered useful to a fairly large and intelligent group of people.  If enough processors have it, I can't see why it can't be part of the language or at very least the RTL.

Sean

"Bill Cox" <bill@viasic.com> wrote in message news:3E709A01.8070804@viasic.com...
> I'm not opposed to the idea, since it can lead to more efficient code. If D adds rotation operations, I'd also like access to the carry flag.
>
> Bill


March 13, 2003
I hate to ask, but what is a rotation operator, or what is it for..

Thanks Ben
"Ziemowit Zglinski" <Ziemowit_member@pathlink.com> wrote in message
news:b4pt22$gg1$1@digitaldaemon.com...
> While programming a lot of embedded application, I often miss a rotation operator in almost all programming languages. This operation  is
implemented in
> all processor architectures and still difficult to achieve from a high
level
> language.
>
> Taking opportunity of not yet fully defined language, I propose to add two
> rotation operators to the language definition:
> Rotate right - @>  or @>>
> Rotate left  - <@  or <<@
>
> The behaviour should be analogue to the logical shift operators, except
the bit
> shifted out would be shift in on the opposite side in place of 0. Number
bits
> rotated should correspond to the length of the actual data type.
>
> Thank You,
>
> --  Ziemowit
>
>     ziemek@tera.com.pl


March 13, 2003
"Ben Woodhead" <zander@echotech.ca> wrote in message news:b4qoiq$16b5$1@digitaldaemon.com...
> I hate to ask, but what is a rotation operator, or what is it for..
>
a = (b<<c)|(b>>>-c);

:)

it rotates the bits as if they where on a cylinder, rather than shifting
them
its use in almost all symetric cipher code (I know idea does not)
64 bit rotate of 2 32 bit values along with 32 x32 => 64 bit multiply are
also useful when doing fixed point maths.
be I think they should be intrinsics. no more operators, >> and >>> are o.k.
but !<> and all those float comparisons confuse the hell out of me, I
understand why but why !!






March 13, 2003

Sean L. Palmer wrote:
> The carry flag is not nearly as portable.  Some architectures might not need
> one.  I don't know of any such processors, but maybe some embedded system?

I'm not familiar with any CPUs or MCUs without a carry.  Also, the compiler could easily emulate it.  I think a bigger problem is how to cleanly integrate it into the langauge.  Perl would probably do it with a system-wide global variable.  Yuk.  Certainly the rotation operators integrate smoothly.

Bill

March 13, 2003
The rotation operator (at least as I've used it) shifts bits around in a value, so if you had a value

11110000,

and rotated it left two positions, you would have

11000011, the bits just get shifted over left two positions, with the
ones on the left coming back around to the right. As far as I know, its
mostly used for encryption, and multiplication and division within processors
use rotation (shifts, anyway) for faster operation.

Even small microcontrollers like the HC11 have this capability built in to the machine code, so I don't see why there shouldn't be a special operator for it in D.

-Jon
In article <b4qoiq$16b5$1@digitaldaemon.com>, Ben Woodhead says...
>
>I hate to ask, but what is a rotation operator, or what is it for..
>
>Thanks Ben
>"Ziemowit Zglinski" <Ziemowit_member@pathlink.com> wrote in message
>news:b4pt22$gg1$1@digitaldaemon.com...
>> While programming a lot of embedded application, I often miss a rotation operator in almost all programming languages. This operation  is
>implemented in
>> all processor architectures and still difficult to achieve from a high
>level
>> language.
>>
>> Taking opportunity of not yet fully defined language, I propose to add two
>> rotation operators to the language definition:
>> Rotate right - @>  or @>>
>> Rotate left  - <@  or <<@
>>
>> The behaviour should be analogue to the logical shift operators, except
>the bit
>> shifted out would be shift in on the opposite side in place of 0. Number
>bits
>> rotated should correspond to the length of the actual data type.
>>
>> Thank You,
>>
>> --  Ziemowit
>>
>>     ziemek@tera.com.pl
>
>


« First   ‹ Prev
1 2 3