PocketMatrix forums

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

eVC3 compiler bug?

Hi,

I met a weird problem with eVC3, which seems like a real bug.

The code:

Code:

static uint32 lineartbl[(1 << LIN_BITS) + 1];
uint32 LinearToLog(int32 l)
{
return (l < 0) ? (lineartbl[-l] + 1) : lineartbl[l];
}


The ARM asm I got from eVC:
Code:

; 36 : return (l < 0) ? (lineartbl[-l] + 1) : lineartbl[l];
ldr r1, [pc, #0xC] ; pc+8+12 = 00000014
cmp r0, #0
ldr r0, [r1, -r0, lsl #2]
addmi r0, r0, #1
mov pc, lr
|$L2845|
DCD |lineartbl|


That means "return (l < 0) ? (lineartbl[-l] + 1) : lineartbl[-l]"...terrible...

If I rewrite the function as:
Code:

uint32 LinearToLog(int32 l)
{
if (l < 0) {
return lineartbl[-l] + 1;
} else {
return lineartbl[l];
}
}


This time the compiler is doing the right thing:
Code:

; 37 : if (l < 0) {
; 38 : return lineartbl[-l] + 1;

ldr r1, [pc, #0x10] ; pc+8+16 = 00000018
cmp r0, #0
ldrmi r3, [r1, -r0, lsl #2]
addmi r0, r3, #1

; 39 : } else {
; 40 : return lineartbl[l];
ldrpl r0, [r1, +r0, lsl #2]
; 41 : }
mov pc, lr
|$L2845|
DCD |lineartbl|
Turn off "full optimization" flag - use "optimize for speed" or "... size". Apparently, the optimizer is pretty buggy in EVC3.
Good choice on variable names. The clever humor of
Code:
"[-l] + 1"
will most likely be as funny in 6 months as it is today.


I don't see the bug. If the second case works, then you solved the problem and benefited from a valuable lesson. Optimization can benefit from good readable code too.
I don't think that's funny.
The first thing is that the code was not written by me. I'm just trying to figure out the problem.
The second is, you do need to read my post carefully. It is an 'L' in "[-l]", not '1'(one). That could be easily distinguished by the syntax hilighting.
That is certainly a compiler bug and therefore I think it's pretty serious.

Having said that though I don't think the optimizer is very buggy, if it was reasonably large projects compiled with optimizations would be very buggy and in my experience they are not.
ricklei wrote:
The second is, you do need to read my post carefully. It is an 'L' in "[-l]", not '1'(one). That could be easily distinguished by the syntax hilighting.


And why would I read your post carefully? If I read everything carefully, I would get far less reading done. Its the job of the writer to write things clearly, not the job of the reader to read them carefully. If you feel the opposite is true, then we'll just have to disagree.
If it's any consolation, this bug doesn't exist in the latest MS ARM compiler that ships with Windows CE.Net Platform Builder.