Addition of shift to add instruction

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User19104
Level 3
Level 3
First like received
Hi,

I'm using the hightec compiler, and I'm seeing the following:
4153.attach

For addind a value, the compiler adds a shift left of 3.... why is that?

offset = (j<<5);
0x80000C2E 19 EF FC FF LD.W d15,[a14]-0x4
0x80000C32 06 5F SH d15,0x5
0x80000C34 53 1F 40 20 MUL.U e2,d15,0x1
0x80000C38 89 E2 68 F9 ST.D [a14]-0x18,e2
offset += destLoc;
0x80000C3C 19 EF E8 FF LD.W d15,[a14]-0x18
0x80000C40 06 3F SH d15,0x3
0x80000C42 19 E2 F4 FF LD.W d2,[a14]-0xC
0x80000C46 42 2F ADD d15,d2
0x80000C48 0B F0 00 28 MOV e2,d15
0x80000C4C 89 E2 68 F9 ST.D [a14]-0x18,e2


this causes the value of offset to be larger than I intend it to be.
0 Likes
5 Replies
NeMa_4793301
Level 6
Level 6
10 likes received 10 solutions authored 5 solutions authored
Can you include more code here - how are offset and destLoc declared?
0 Likes
User19104
Level 3
Level 3
First like received
Hi,

The code:

uint16 password = IfxScuWdt_getSafetyWatchdogPassword();
uint32 j = 0, i=0;
uint64 *dst;
uint64 *destLoc = 0;
volatile uint32 delay = 0;
uint32 offset = 0;


if (((((uint32)dest & 0xff000000) == 0xa0000000) || ((uint32)dest & 0xff000000) == 0x80000000)) // program flash
{
destLoc = (uint64 *) (0xa0000000 | (uint32)dest);
}
else if (((uint32)dest & 0xff000000) == 0xaf000000) // data flash
{
destLoc = (uint64 *) (0xaf000000 | (uint32)dest);
}

for (j= 0; j < size/0x20; j++)
{
IfxFlash_clearStatus(0);
offset = (j<<5);
offset += destLoc;
0 Likes
NeMa_4793301
Level 6
Level 6
10 likes received 10 solutions authored 5 solutions authored
Why use uint64? The AURIX only supports a 32-bit address space.

I'd use an explicit typecast for the line offset += destLoc:
offset += (uint32) destLoc;
0 Likes
User19104
Level 3
Level 3
First like received
Thought about it, but dn't understand why does it matter.

works anyway.
0 Likes
MoD
Employee
Employee
50 likes received 500 replies posted 100 solutions authored
This comes from the pointer arithmetic:
pointer 64 bit -> right shift 3
pointer 32 bit -> right shift 2
pointer 16 bit -> right shift 1
pointer 8 bit -> right shift 0
0 Likes