GCC compiler for the new architecture: calling an external library function

I am moving the GCC compiler into a new processor architecture. This is the similer for v850 architecture ("/ gcc / config / v850") and is almost complete. But I have a problem in the arithmetic operation of multiplication. Architecture only supports unsigned multiplication. In the signed case, I have to use the library function "__mulsi3" from lib1funcs.asm. Therefore, I need to call the library function when it is signed. The mulsi3 instruction is implemented as follows. Does anyone know how to call any library functions from the {target} .md or {target} .c file? help me...

I followed the architecture of "sh" ("/ gcc / config / sh") and implemented it as sh. GCC build fine. but when I compile the test code on target, an error message appears. (file => emit-rtl.c: 862)


mulsi3 instruction

(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")]) 

+6
source share
1 answer

mulsi3 is a special name. You can use it for introns only when they are extremely simple.

Indeed, in your case, the mulsi3 template should be define_expand, then you can make it unsuccessful on some branches (with an explicit FAIL expression). The compiler should generate a libgcc call if the custom extension template fails.

But there are two more amendments:

1) Prefer pattern matching with an explicit if-else internal pattern. That is, write separate = r, r, r and = r, r, i command templates, limit them to both predicates and restrictions on the allowable ranges. The compiler must generate a libgcc call, if it cannot find a suitable template, you do not need (and in most cases it is a bad idea) to explicitly write FAIL.

2) Be careful with matching predicates / constraints. "nonememory operand" is an extremely bad predicate for "r, r". Let's say you have a legal constant here, and your program is large, and the reboot cannot find the register ... and everything will explode.

I also recommend that you ask such detailed questions in gcc@gcc.gnu.org maillist.

+5
source

Source: https://habr.com/ru/post/983294/


All Articles