public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Porting question: define_expand Vs define_split
@ 2004-11-03  6:43 Balaji S
  2004-11-03 16:43 ` DJ Delorie
  2004-11-03 16:52 ` Daniel Jacobowitz
  0 siblings, 2 replies; 3+ messages in thread
From: Balaji S @ 2004-11-03  6:43 UTC (permalink / raw)
  To: gcc

Hi all,
I am porting GCC to a new architecture using stormy16 as base.

In my architecture there is no instruction for /neg/ operation. So i planned to handle it using /sub/. I am able to accomplish this job by using either define_expand or define_split without knowing its internals as follows:

(define_expand "neghi2"
  [(set (match_operand:HI 0 "register_operand" "")
	(const_int 0))
   (set (match_dup 0)
	(minus:HI (match_dup 0)
		  (match_operand:HI 1 "register_operand" "")))]
  ""
  "")

(define_insn_and_split "neghi2"
  [(set (match_operand:HI 0 "register_operand" "=r")
	(neg:HI (match_operand:HI 1 "register_operand" "0")))]
  ""
  "#"
  "reload_completed"
  [(set (match_dup 0)
	(const_int 0))
   (set (match_dup 0)
	(minus:HI (match_dup 0)
		  (match_dup 1)))]
  "")

I do not know whether the above m/c descriptions are correct. Please correct me if any mistakes.

Moreover, i would like to know, when to use /define_expand/ and when to use /define_split/.


Thanks in advance,
Balaji S

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Porting question: define_expand Vs define_split
  2004-11-03  6:43 Porting question: define_expand Vs define_split Balaji S
@ 2004-11-03 16:43 ` DJ Delorie
  2004-11-03 16:52 ` Daniel Jacobowitz
  1 sibling, 0 replies; 3+ messages in thread
From: DJ Delorie @ 2004-11-03 16:43 UTC (permalink / raw)
  To: sivanbalaji; +Cc: gcc


Choosing between define_expand and define_insn_and_split IMHO depends
on whether gcc can optimize better with the split-up insns or with the
combined insn.  In cases with linear math, it's probably better to
define_expand.  In cases where you're splitting up a wide op into
pairs of narrow ops (like movdi->movsi), it's probably better to
define_insn_and_split (and defer until after reload) so gcc can see
the wider ops during optimization.

In the case of a missing neg, though, you can use a not/inc pair if
your machine is 2s-compliment and avoid the need for a scratch
register to hold the zero or op1 (it can be done in place).  You'd
still use a define_expand:

(define_expand "neghi2"
  [(set (match_dup 2)
	(not:HI (match_operand:HI 1 "" "")))
   (set (match_operand:HI 0 "" "")
	(plus:HI (match_dup 2)
                 (const_int 1)))]
  ""
  "operands[2] = gen_reg_rtx (HImode);"
  )

Add "register_operand" if your not/inc ops need registers.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Porting question: define_expand Vs define_split
  2004-11-03  6:43 Porting question: define_expand Vs define_split Balaji S
  2004-11-03 16:43 ` DJ Delorie
@ 2004-11-03 16:52 ` Daniel Jacobowitz
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Jacobowitz @ 2004-11-03 16:52 UTC (permalink / raw)
  To: Balaji S; +Cc: gcc

On Wed, Nov 03, 2004 at 12:11:13PM +0530, Balaji S wrote:
> Hi all,
> I am porting GCC to a new architecture using stormy16 as base.
> 
> In my architecture there is no instruction for /neg/ operation. So i 
> planned to handle it using /sub/. I am able to accomplish this job by using 
> either define_expand or define_split without knowing its internals as 
> follows:
> 
> (define_expand "neghi2"
>  [(set (match_operand:HI 0 "register_operand" "")
> 	(const_int 0))
>   (set (match_dup 0)
> 	(minus:HI (match_dup 0)
> 		  (match_operand:HI 1 "register_operand" "")))]
>  ""
>  "")
> 
> (define_insn_and_split "neghi2"
>  [(set (match_operand:HI 0 "register_operand" "=r")
> 	(neg:HI (match_operand:HI 1 "register_operand" "0")))]
>  ""
>  "#"
>  "reload_completed"
>  [(set (match_dup 0)
> 	(const_int 0))
>   (set (match_dup 0)
> 	(minus:HI (match_dup 0)
> 		  (match_dup 1)))]
>  "")
> 
> I do not know whether the above m/c descriptions are correct. Please 
> correct me if any mistakes.

The splitter is not correct.  You have constrained the input and output
to be in the same register, and are overwriting that register with 0. 
The constraints would have to be "=&r" and "r".

-- 
Daniel Jacobowitz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-11-03 16:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-03  6:43 Porting question: define_expand Vs define_split Balaji S
2004-11-03 16:43 ` DJ Delorie
2004-11-03 16:52 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).