This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Codegen Gurus,
First question:
2nd question:
I've been trying to work out the difference between __byte and __mov_byte
Seems
But I'm not clear why one would use __move_byte over just __byte to perform the read. In the few experiments that I tried these two seem generate the same assembly code and are equiv. operations:
Is there a difference I've missed?
-Lori
Lori Heustess said:First question:
- The prototype for __byte in the compiler guide says: int &__byte(int *array, unsigned int byte_index);
- The '&' seems to be a typo. Is that correct?
It's not a typo, the __byte intrinsic returns a C++-style reference, even in C mode.
Lori Heustess said:I've been trying to work out the difference between __byte and __mov_byte
__byte can be used on the left-hand side to set values. This is the reason it needs to return a reference.
#include <stdio.h>
int array[3] = { 0xaaaa, 0xbbbb, 0xcccc };
void main()
{
int i;
__byte(array, 0) = 0;
for (i=0;i<3;i++)
printf("%x\n", array[i]);
for (i=0;i<6;i++)
printf("%x\n", __mov_byte(array, i));
}
Archaeologist said:It's not a typo, the __byte intrinsic returns a C++-style reference, even in C mode.
Thanks, Brett - I suspected a reference, but my C++ fu is currently weak.
Archaeologist said:__byte can be used on the left-hand side to set values. This is the reason it needs to return a reference.
I'm still not sure I quite understand. I see the flexibility of __byte. Why would one use __mov_byte instead? It seems to be not as useful?
-Lori
__mov_byte is much older, and was implemented before the compiler could support an intrinsic that returns a reference. To maintain backward compatibility, __mov_byte was left as-is, and a new intrinsic (__byte) was added which returns the reference. You are right, there's nothing you can do with __mov_byte that you can't do with __byte.
Great, thanks Brett -
I've written this up into a wiki article for folks future reference.
http://processors.wiki.ti.com/index.php/Byte_Accesses_with_the_C28x_CPU
-Lori