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... )
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.
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.