I'm porting GCC compiler to a new processor architecture. It is similer to v850 architecture ("/gcc/config/v850") and almost done. But I have a problem in multiplication arithmetic operation. Architecture supports only unsigned multiplication. In signed case, I have to use "__mulsi3" library function from lib1funcs.asm. So I need to call library function when it is signed. Implemented "mulsi3" instruction as follows. Does anybody know how can call any library functions from {target}.md file or {target}.c file? help me...
I followed "sh" architecture ("/gcc/config/sh") and implemented like sh architecture. GCC build ok. but when I compile test code on target, there is a bug message. (file => emit-rtl.c:862)
(define_insn "mulsi3"
[(set (match_operand:SI 0 "register_operand" "=r,r")
(mult:SI (match_operand:SI 1 "nonmemory_operand" "r,r")
(match_operand:SI 2 "nonmemory_operand" "r,i")))]
""
"*
{
/* REG */
if(GET_CODE (operands[2]) == REG)
{
return \"mul %0,%1,%2\";
}
/* IMMEDIATE */
else
{
/* unsigned case */
if(CONST_OK_FOR_M(INTVAL(operands[2])))
{
return \"muli %0,%1,%2\";
}
/* signed case */
else
{
/******************************************/
/* need to call __mulsi3 library function */
/******************************************/
}
}
}
"
[(set_attr "length" "6,6")
(set_attr "cc" "none_0hit,none_0hit")
(set_attr "type" "mult")])
From OSDev Wiki. The GNU Compiler Collection uses a special library called libgcc during code generation, which contains shared code that would be inefficient to duplicate every time as well as auxiliary helper routines and runtime support.
gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.
For example, specifying --program-prefix=foo- would result in ' gcc ' being installed as /usr/local/bin/foo-gcc . Appends suffix to the names of programs to install in bindir (see above). For example, specifying --program-suffix=-3.1 would result in ' gcc ' being installed as /usr/local/bin/gcc-3.1 .
mulsi3 is special name. You can give it to insn patterns only when they are extremely simple.
Really in your case mulsi3 pattern should be define_expand, then you can make it fail on some branches (with explicit FAIL statement). Compiler should generate libgcc call when specialized expand pattern fails.
But there are two more corrections:
1) Prefer pattern matching to explicit if-else inside pattern. I.e. write separate =r,r,r and =r,r,i instruction patterns, constrain both by predicates and constraints to allowed ranges. Compiler should generate libgcc call if it can not find pattern that fits as well, you don't need (and in most cases it is bad idea) to write FAIL explicitly.
2) Be careful with predicate/constraint matching. "nonmemory operand" is extremely bad predicate for "r,r". Say, you have legitimate constant here and your program is big, and reload can not find register... and everything blows up.
I also recommend you to ask such in-depth questions in the [email protected] maillist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With