ROL and ROR

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

ROL and ROR

Post by blueznl »

we have >> and <<but>>1 & $7B) | x<<7
[/code]

for a ror (roll over right) of a byte

may i suggest to add ROL and ROR to our ever increasing collection of great purebasic features? :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
SunSatION
User
User
Posts: 85
Joined: Tue Jun 21, 2005 7:26 pm
Location: Malta

Post by SunSatION »

Don't know if i can post here, but you can use ROR and ROL

Code: Select all

x = 10
ROL x,1
Debug x
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

Second the request for native PureBasic commands/functions that support logical (versus Arithmetic) Shifts and Rotations.

It would make a nice addition to the language (along with unsigned integers :D)
Dare2 cut down to size
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

i mean, look at the following, it's HORRIBLE

Code: Select all

Procedure.l x_rol(x.l)                                               ; rol a long
  ;
  ; *** shift all bits one left, move msb to bit 0
  ;
  ProcedureReturn (x<<1 | (x>>31 & $01))
EndProcedure

Procedure.l x_ror(x.l)                                               ; ror a long
  ;
  ; *** shift all bits one right, move lsb to bit 31
  ;
  ProcedureReturn ((x>>1 & $7FFFFFFF) | x<<31)
EndProcedure

Procedure.b x_rolb(x.b)                                              ; rol a byte
  ;
  ; *** shift all bits one left, move msb to bit 0
  ;
  ; need to either use an asm enhanced version of this routine, or pester fred into
  ; making it a primitive :-)
  ;
  ProcedureReturn (x<<1 | (x>>7 & $01))
EndProcedure

Procedure.b x_rorb(x.b)                                              ; ror a byte
  ;
  ; *** shift all bits one right, move lsb to bit 7
  ;
  ; need to either use an asm enhanced version of this routine, or pester fred into
  ; making it a primitive :-)
  ;
  ProcedureReturn ((x>>1 & $7F) | x<<7)
EndProcedure
horrible but the best i could come up with, and i do know nothing about asm so no luck there either... better solutions / work arounds are obviously welcome :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
SunSatION
User
User
Posts: 85
Joined: Tue Jun 21, 2005 7:26 pm
Location: Malta

Post by SunSatION »

So, check if I get it right, you want these operation on a 32-bit number?
dioxin
User
User
Posts: 97
Joined: Thu May 11, 2006 9:53 pm

Post by dioxin »

Blueznl,
I don't get it.
What's wrong with SunSatION's suggestion? It should work on integers of any size, 8, 16 or 32 bits, it's neat and it's quick.

The fact it happens to be an ASM instruction is not a reason to avoid it. After all, if the compiler is written well then it's exactly what the compiler will convert your code into anyway.


Paul.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

dioxin wrote:The fact it happens to be an ASM instruction is not a reason to avoid it.
Now what happens on PowerPC with that x86 instruction? Also, it can't be used in an expression and you need to turn on inline asm, which has many annoyances.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

dioxin, yes, you are right, but the whole idea of purebasic is that it 1. is a basic, and 2. is platform independent

we should not have to use asm or winapi to do basic functions, so yes it's no issue but i want to do it in native pb :-)

that's why it's a feature request :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply