GLBasic forum

Main forum => GLBasic - en => Topic started by: bigsofty on 2008-Feb-07

Title: Bit Shifts
Post by: bigsofty on 2008-Feb-07
Some BIT shifting instructions could be a handy addition. In platforms without maths co-processors its a simple and quick way of doing multiplication and division. Its also generally handy for manipulating bit flags in variables.

Not a C++ guy but I think its "a = b >> 2" although I prefer the SHL, SHR, ROR, ROL etc... used by assembly.

Just a thought.
Title: Bit Shifts
Post by: Moru on 2008-Feb-07
Yes, that's what I want too, see my post a few hours earlier about Little / Big endian :-)
Title: Bit Shifts
Post by: Kitty Hello on 2008-Feb-07
Since GLBasic is using floating point numbers only, shifting is not speed improvement.
What I would write - and what you could do yourself is:
Code (glbasic) Select
FUNCTION ASL: a, s
   RETURN a / POW(2, s)
ENDFUNCTION

FUNCTION ASR: a, s
   RETURN a * POW(2, s)
ENDFUNCTION
Instead of the POW you propably wand an inline with an integer shift... You'd have to check which one is faster.
Title: Re: Bit Shifts
Post by: Heiko on 2009-Mar-19
Thats better.

Code (glbasic) Select
FUNCTION ASL: a, s
   RETURN a * POW(2, s)
ENDFUNCTION

FUNCTION ASR: a, s
   RETURN a / POW(2, s)
ENDFUNCTION
Title: Re: Bit Shifts
Post by: Moru on 2009-Mar-19
I would like instructions like bitshift and bitrotate left and right just for completeness of the language. I know I would use them and I'm sure others want them too. I don't care if it's fast or not, they are usefull in other areas too.

Rotate is moving bits to the right and when they go out the right side they pop up on the left side again, shift is just moving them out the right side and replacing the new bits with zeroes from the left.
Title: Re: Bit Shifts
Post by: Kitty Hello on 2009-Mar-19
Code (glbasic) Select

FUNCTION ASL: a% b%
INLINE
a << = b;
ENDINLINE
RETURN a
ENDFUNCTION

Title: Re: Bit Shifts
Post by: FutureCow on 2009-Apr-17
I think it would be great to add the commands to the base language for completeness too.