This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc porting - machine description for realizing multiplication with a routine call
Hi,
if I not provide any MD statement for multiplication, GCC generates a
call __mulqi3
So I can think to provide an assembly routine "__mulqi3".
But the problem (from my understanding) is how to ensure to save and
restore properly the registers which are used internally by the
routine, and to manage the input and output register sof the routine
properly too.
I can't find any advice on the web on how to easily implement
multiplication when no a "mul" instruction is provided by the target
architecture ISA. Surely a proper assembly routine must be provided,
but I miss how to "link" it properly.
Many thanks,
Diego
2013/2/7 Chung-Ju Wu <jasonwucj@gmail.com>:
> Hi Diego,
>
> 1. According to the insn rtx of error message,
> I think you can check the design of "*move_reg" pattern.
> You probably missed some constraints.
>
> 2. Since there is no 'mul' instruction on your target,
> perhaps you can try not to provide any multiply naming patterns.
> GCC will generate library call for you.
> See Chapter 4 of GCC Internals for more information. :)
>
>
> Best regards,
> jasonwucj
>
>
> 2013/2/8 Diego Bernini <diego.bernini@gmail.com>:
>> Hi to all,
>> I am porting GCC to a custom architecture.
>>
>> The custom architecture has not a "mul" instruction. Hence I am
>> working to generate a proper routine call. The external routine ("
>> __mulqi3") expect to have the first parameter inside the reg #0, the
>> second parameter inside the reg #1 and then it puts the result inside
>> the reg #0.
>>
>> Starting from the porting for AVR, I tried to add the following
>> machine description definitions:
>>
>> define_expand "mulqi3"
>> [(set (match_operand:QI 0 "register_operand" "")
>> (mult:QI (match_operand:QI 1 "register_operand" "")
>> (match_operand:QI 2 "register_operand" "")))]
>> ""
>> "
>> emit_insn (gen_mulqi3_call (operands[0], operands[1], operands[2]));
>> DONE;
>> ")
>>
>> (define_expand "mulqi3_call"
>> [(set (reg:QI 0) (match_operand:QI 1 "register_operand" ""))
>> (set (reg:QI 1) (match_operand:QI 2 "register_operand" ""))
>> (parallel [(set (reg:QI 0) (mult:QI (reg:QI 0) (reg:QI 1)))
>> (clobber (reg:QI 1))
>> ])
>> (set (match_operand:QI 0 "register_operand" "") (reg:QI 0))]
>> ""
>> "")
>>
>> (define_insn "*mulqi3_call"
>> [(set (reg:QI 0) (mult:QI (reg:QI 0) (reg:QI 1)))
>> (clobber (reg:QI 1))
>> ]
>> ""
>> "call __mulqi3"
>> )
>>
>> There is something wrong with these definitions, because trying to
>> compile a simple multiplication I obtain
>>
>> error: insn does not satisfy its constraints:
>> (insn 51 25 26 (set (reg:QI 0 A0 [orig:51 a ] [51])
>> (reg:QI 2 A2)) 5 {*move_regs} (nil)
>> (nil))
>>
>>
>> Any advice?
>>
>> Best,
>> Diego