Clearing an array of bytes
Vega256
Posts: 197
Hello all,
Suppose I have declared an array of bytes.
Is there some immediate operator that I can use to clear all of the bytes in the array, or do I have to use bytefill?
Suppose I have declared an array of bytes.
var byte myByte [6]
Is there some immediate operator that I can use to clear all of the bytes in the array, or do I have to use bytefill?
Comments
From the Propeller Manual (Web-PropellerManual-v1.2.pdf):
dgately
Note, though - you have an array of 6 bytes, which is divisible by 2 bytes (= 1 word), so you could use wordfill in your case, which would be slightly faster. If it was divisible by 4, longfill would be even faster than wordfill or bytefill. However, with such a small array, the speed difference is probably be insignificant. There's no code size difference AFAIK.
When possible, I define byte arrays as longs; this gives me access as longs, words, or bytes, and the best speed. You an do longfill on a byte array that is misaligned, but it's a tad slower than if the array is long-aligned.
In a recent project I did this:
Again, this allows clean access as bytes, words, or longs, and using longfill with a long-aligned array is faster than if the array is misaligned (not on an even long boundary).
I just looked at the code for byte/word/longfill in the spin interpreter. byte/word/longfill doesn't care whether what you feed it a pointer to is a byte, word, or long array. It just takes a pointer and fills stuff, using wrbyte, wrword, or wrlong and a stride of 1, 2, or 4 depending on which flavor you use (they're all in the same opcode group). If you try doing a longfill on a misaligned array (of bytes, words, or longs), the address will just get rounded down to the nearest long, like how it always happens when you try reading misaligned longs. rdlong and wrlong cannot read or write a misaligned long - they will zero the bottom two bits. It's just as fast as filling aligned longs, except that it doesn't fill starting at the pointer you feed it. It makes no difference whatsoever to longfill what type you define things as - pointers in spin don't carry type information. It's perfectly safe to longfill a byte array if it's long aligned.
Agreed. I do all the time.