Hello,
Looks like compiler generated buggy code when it handles "unsigned long int"
types:
Following simplified c code produces incorrect comparison code on line
marked with "**--->"
while(1) {
if(cThreadIndex == cLastThreadIndex) {
cThreadIndex = 0;
} else {
cThreadIndex++;
}
if((threads[cThreadIndex].m_cThreadFlags & THREAD_FLAG_SLEEPING) == 0) {
break;
**---> } else if(threads[cThreadIndex].m_dwWakeupTime <= dwCurrentTime) {
break;
}
}
------
Here is the assembly output: (this "restore r15 at the third line from the
bottom upsets the flag register")
.L6:
cmp.b &cLastThreadIndex, &cThreadIndex
jne .L9
mov.b #llo(0), &cThreadIndex
jmp .L10
.L9:
add.b #llo(1), &cThreadIndex
.L10:
mov.b &cThreadIndex, r14
mov r14, r15
rla r15
rla r15
add r14, r15
rla r15
add #threads+8, r15
mov.b @r15, r15
and.b #llo(1), r15
tst.b r15
jne .L11
jmp .L7
.L11:
mov.b &cThreadIndex, r14
mov r14, r15
rla r15
rla r15
add r14, r15
rla r15
add #threads, r15
mov &dwCurrentTime, r13
mov &dwCurrentTime+2, r14
sub @r15+, r13
subc @r15+, r14
sub #4, r15 ; restore r15
jlo .L6
.L7: