Bit Shifts

Previous topic - Next topic

bigsofty

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.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Moru

Yes, that's what I want too, see my post a few hours earlier about Little / Big endian :-)

Kitty Hello

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.

Heiko

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

Moru

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.

Kitty Hello

Code (glbasic) Select

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


FutureCow

I think it would be great to add the commands to the base language for completeness too.