GCC complains about undefined label. I thought it was it cannot access the label, but the fact is that GCC removes everything after a return sentence.
Speed is critical here, so I don't want to use a variable and a branch if possible.
It removes too!
The problem are not the labels. The problems is that gcc removes absolutely everything after a return instruction, as it assumes I can't jump over a return.
It doesn't understand that the instruction bvt is a jump instruction!
davidgf wrote:
GCC complains about undefined label. I thought it was it cannot access the label, but the fact is that GCC removes everything after a return sentence.
Speed is critical here, so I don't want to use a variable and a branch if possible.
Just use a variable. Higher compiler optimization levels will probably hold the variable in a register anyway.
It doesn't understand that the instruction bvt is a jump instruction!
Of course it doesn't. You can't expect the compiler to analyze your inline asm.
int returnvalue = 0;
asm code....
bvt 0, exit_block_
c code...
returnvalue = 1;
exit_block_:
return returnvalue;
This should work, as it returns a zero when jumping with the assembly code and reutrn 1 when exiting normal C code, but it generates a branch followed by a delay branch slot with li v0, 0x1
GCC does just fine with inline assembly. What you are trying to do is wrong and will not work. Read the GCC manual, which pretty clearly says:
Speaking of labels, jumps from one asm to another are not supported.
Similarly you cannot jump to C labels. In gcc 4.5 you can, as long as you list them expliticly after the clobber list and follow the other restrictions: (see here).
I didn't know that, none of my assembler teachers told me.
The fact is that inline assembly is weird, it could be better to use pure assembly functions.
Where can I find Gcc calling conventions for PSP MIPS? And how can I know the offset of each struct element? Because gcc optimizations can pack or align data as the compiler wants.
This is weird, isn't it? And is it necesary to add nop before a vcmp or i can compare and branch immediatly? gcc generated code on floating point processors adds nops after comparisions:
I'll try the noreorder later, but I don't know for sure if I need to place nops after comparisions.
I don't get at all what push and pop statements do, but anyway I'll give a try.
The label problem I solved this way. My code has a lot of C comparisions with early out:
if (dist> radius) return 0;
I the last jump I changed the C code to this
if (bla bal ) {
exit_label: return 0;
} else {
bla bla
return 1;
}
so I can do
bvt 0, exit_label
There's no way the code exits function without returning anything, but this way gcc does'nt remove anything from my code and I can jump.
I'll post the conclusions so it might help someone.