PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Another eVC3 ARM compiler bug

This is terrible...I can't believe it...

C code:
Code:

void test(unsigned char *p, unsigned char data)
{
for (int i = 0; i < 0x3C0; i++) {
p[i] = data;
}
}


ARM asm by eVC3(optimizations = Maximize speed)
Code:

; 3 : for (int i = 0; i < 0x3C0; i++) {
; 4 : p[i] = data;

mov r3, #0xF, 26 ; 0x3C0 = 960
subs r3, r3, #1
bmi |$L230| ; 00000018
|$L231|
strb r1, [r0], #1 ; !!!???
subs r3, r3, #1
bpl |$L231| ; 0000000C
|$L230|


That is to say:
Code:

for (int i = 0; i < 0x3C0; i++) {
*p = data;
}
Sergey Chaban · 06 Apr 2003, 13:59 UTC
Generated code is correct.
One register is used for loop counter (r3) and another one is a write dest (r0 = p[i]).
The instruction you marked as buggy is a so-called post-indexed addressing - r0 is automagically incremented by #1 after write (*p++ = data).
Oops...Thanks for indicating that to me :oops: