Hi,
I met a weird problem with eVC3, which seems like a real bug.
The code:
The ARM asm I got from eVC:
That means "return (l < 0) ? (lineartbl[-l] + 1) : lineartbl[-l]"...terrible...
If I rewrite the function as:
This time the compiler is doing the right thing:
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|