How can I do a circular bit shift in propeller C
Invent-O-Doc
Posts: 768
I know people use statements all the time like a = z << 2; , which gives a bit shift and everything that goes to the end of the variable's bit range gets chopped off, but doesn't the propeller have a PASM for a bit rotation that takes bits from one side to another in the form of a rotation???
SPIN has the '->' and '<-' operators that do this.
Is there any equivalent to this rotation command using C or C++ in Simple IDE????
The examples I see on C sites are fairly inefficient compared to an equivalent of the prop's own bit rotate.
SPIN has the '->' and '<-' operators that do this.
Is there any equivalent to this rotation command using C or C++ in Simple IDE????
The examples I see on C sites are fairly inefficient compared to an equivalent of the prop's own bit rotate.
Comments
Not in this case with propgcc it seems:
Compiles down to: Using: /opt/parallax/bin/propeller-elf-gcc -Os -Wall -S -o rol.s rol.c
As we see there are two shifts and an OR operation.
Similar with GCC on my PC.
Don't we have an intrinsic in propgcc to do this inline?
Of course a >> on a signed number propagates the sign bit down from the top so it can never be the same as a ror. Unless some extra masking is in place to remove propagated bits.
In the rol case we would also be applying a >> to a signed number (the "(a >> (32 - b))" part. That would then require a mask to get rid of the propagated sign bits so it's probably better for the compiler to do what it does.
Note the use of "lret". I guess it's the same thing.
Except.. If I compile with "-mcog" then it the same as yours.
Never mind.
-Os or -O2 or -O3 work.
-O1 does not.