I could not follow that...
Ioannis
So long as I have not ruined the way a C pointer will work...
Before any input, the 32 bits you want could be anywhere within the 7 byte array.
After computation, the memory location of the four bytes of the 32 bit value begins at array[offset].
Oh, I see. Thanks for the ideas.
Still, asm rotate will be faster.
Ioannis
I have my doubts, You only have to call it once.
Assuming there is equal chance the input is 0-31, an assembler rotate routine will be called mean of 15 times.
For a shift in either language the overhead is in finding the byte you want to shift.
Again, assuming it’s still working. I’ll be able to try in PBP soon.
If I’m mistaken and it’s not another trick you’ve worked out because of the known state of the array at the beginning, that would be helpful.
It is currently taking me the equal number of assembler instructions as there are bytes in the array to bitwise rotate an array
that has unknown contents at the beginning, which is the same as in the sixth post of this thread.
Last edited by Art; - 12th December 2015 at 05:45.
I have a problem (what a surprise, huh?) with the MPLAB. It has a tool or something that helps to measure the exact time it takes for a routine to execute. No Osciloscopes, no pins to make high / low etc.
Yes, the asm way will take from 1 to 32 times since we do not know the times to shift. But as you showed in #6, it takes give or take 5 asm instructions for one shift, max 32x5. Basic I think cannot beat that.
Ioannis
The code in post 16 that will easily beat that, and take the same duration no matter what the input.
I’ve only measured PBP by disassembly and then counting the assembler instruction time.
Bitwise rotation of each byte is one instruction, shifting and other bitwise operations that have an input value should be two assembler instructions.
But yes, using the same technique as post #16 expressed in PBP will beat the assembler in post #6.
Consider the value you begin with begins at array location 0,
and your input is 16, so you need to rotate it 16 times:
Divide the 16 by 8, and result is 2. Add 2 to the array location index and bingo:Code:00000000 00000000 00000000 00000001 ^ arraylocation[0]
The reason your 4 byte array has values around it is so you can still use the four bit value
The only thing that complicates it is that your input won’t often be evenly divisible by 2.
The rest of the code shifts the byte by the modulus.
You could still easily beat the asm rotation with a single PBP divide with modulus,
but PBP might not beat the particular implementation of asm divide and modulus!
I edited images in there because I wasn’t getting fixed width for spaces.
Last edited by Art; - 12th December 2015 at 17:58.
Bookmarks