if you made the array from longs or ints does the c compiler make better code for bit rotation ? , you could always access the array as bytes via a union . just a thought
if you made the array from longs or ints does the c compiler make better code for bit rotation ? , you could always access the array as bytes via a union . just a thought
The array is already bytes, either declared BYTE or unsigned char.
The problem with C is aside from port pin bits or their latch registers which appear to be specially accounted for,
you still need to apply a mask to bytes to change one bit, or look/ test for a bit.
Something like asm “shift right with carry” does not seem to exist unless you went back to inline assembler in the C.
But I still think in every case the dsPic still wins because it’s running so much faster than the 20MHz/4 that I’m used to.
I’ve run into this way before now... C does suck at that.
Apologies, I wanted the picture to be interesting, but not thrown off YouTube.
You can see a large patch of the same colour because it’s a block cipher.
I had to apply a huge Xor mask to every image before hand to cover that.
nice pic , what I was really think is , will a I bit shift on a long execute quicker than doing a 1 bit shift through 4 bytes
Art,why not give an 18F a try at 64MHz? Wouldn't that be a bit faster than 20MHz chips?
Robert
Speed doesn’t address the problem Robert ( convenient floating point math),
but I should have tried out some faster pics years ago yes!
Richard, you’re probably right, and I didn’t think of that.
At least 16 bit rotation should take the same time, and in this instance the bytes don’t have to be bytes.
I don’t think C can create an alias of another variable type like PBP does (it might cost more time to access them)
but accessing an array out of bounds has worked on every platform I’ve tried, and probably for PBP too although not needed.
Code:unsigned char bytearray[2]; long longarray[2]; Now bytearray[2],bytearray[3], etc. can access the bytes of longarray.
you use a union
eg
union U32_
{
unsigned long l; // For accessing the whole 32-bits
unsigned char b[4]; // For accessing as individual bytes
};
char mybyte;
union u32_ my_array;
my_array.l= 0b00001111000011110000111100001111
mybyte=my_array.b[3];
Last edited by richard; - 16th May 2015 at 02:56. Reason: can't count o's and ones
ThanksI’m sure that will be handy.
Bookmarks