On Wed, Mar 11, 2009 at 08:33:34AM +0100, Georg-Johann Lay wrote:

> Stelian Pop schrieb:
>> On Tue, Mar 10, 2009 at 10:18:10PM +0100, Georg-Johann Lay wrote:
>>
>>
>>> Note that no one is generating an insn that looks like "*jump". Maybe 
>>>  insn combine and peep2 would try to build such a pattern, but that 
>>> is  not what helpd you out here. Write the expander as parallel of a 
>>> (set  (pc) ...) and a (clobber (match_scratch ...)) so that an 
>>> appropriate  insn is expanded.
>>
>>
>> Like this ?
>>
>> (define_expand "jump"
>>   [(parallel [(set (pc) (label_ref (match_operand 0 "" "")))
>>               (clobber (match_scratch:QI 1 "=&r"))])]
>>   ""
>>   ""
>> )
>
> Constraints are useless in expanders.

Of course, copy'n'paste error.

> You really need a QI scratch? Your  
> insn looks as if HI was needed as you load hi and lo part of the scratch.

Yes, QI is correct: my microcontroller is a bit special in that in has
16 bit bytes (BITS_PER_UNIT=16).

[...]

> So you have just one alternative "=&r", and in the case of rjmp the  
> scratch is unused.

Ok, so I ended up with (omitting the jump lengths for now):

(define_insn "*jump"
  [(set (pc)
        (label_ref (match_operand 0 "" "")))
   (clobber (match_scratch:QI 1 "=&r"))]
  ""
  {
        return "ldih %1,hi(%l0)\n\t\n\tldil %1,lo(%l0)\n\tijmp (%1)";
  }
)

(define_expand "jump"
  [(parallel [(set (pc) (label_ref (match_operand 0 "" "")))
              (clobber (match_scratch:QI 1 ""))])]
  ""
  ""
)

It doesn't work. It causes a loop somewhere in gcc. I can get a gdb
trace if needed.

> Note that you emit up to three instructions, so the  
> -2048/2047 may crash in corner cases.

Right, thanks !

> You can have a look at avr, it computes jump lengths as well but afaIr  
> without needing a scratch for long jumps.

I'll do. I'm trying now first to get the indirect jump to work, and I'll
put the test for the jumps lenghts later.

Thanks,

-- 
Stelian Pop <stel...@popies.net>

Reply via email to