patch: trunc/fix cleanups

Aldy Hernandez aldyh@redhat.com
Thu Feb 19 18:14:00 GMT 2004


[As discussed on IRC]

In tracking down a bug in ppc-e500, I ran into can_fix_p.  It looks
like the fix patterns won't work unless ftrunc patterns exist for the
machine description.  This isn't documented anywhere.  Luckily, only
68k and mmix suffer from this.

(What most of these back-ends want is fixuns_trunc* anyway)

I think we need a rewrite of what these patterns actually mean, and
how they're used.  But since I'd actually have to dig into a 68k
manual I don't have, this will have to do.

This trivial patch does 3 things:

  1. Remove the ftruncify() one-liner function which only gets called
     once.

  2. Document the FTRUNC/FIX dependency.

  3. Put a FIXME note for when someone's bored and wants to bring all
     this to sanity.

OK for mainline?

2004-02-19  Aldy Hernandez  <aldyh@redhat.com>

	* doc/md.texi (Standard Names): Document additional dependency on
	fix pattern.

	* optabs.c (ftruncify): Remove.
	(expand_fix): Manually inline ftruncify above.
	(can_fix_p): Add FIXME note.

Index: doc/md.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/md.texi,v
retrieving revision 1.90
diff -u -p -r1.90 md.texi
--- doc/md.texi	17 Feb 2004 05:15:00 -0000	1.90
+++ doc/md.texi	19 Feb 2004 17:43:28 -0000
@@ -2865,6 +2865,9 @@ point mode @var{n} as a signed number an
 has mode @var{n}).  This instruction's result is defined only when
 the value of operand 1 is an integer.
 
+If the machine description defines this pattern, it also needs to
+define the @code{ftrunc} pattern.
+
 @cindex @code{fixuns@var{mn}2} instruction pattern
 @item @samp{fixuns@var{m}@var{n}2}
 Convert operand 1 (valid for floating point mode @var{m}) to fixed
Index: optabs.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optabs.c,v
retrieving revision 1.207
diff -u -p -r1.207 optabs.c
--- optabs.c	11 Feb 2004 23:39:35 -0000	1.207
+++ optabs.c	19 Feb 2004 17:43:30 -0000
@@ -105,7 +105,6 @@ static void prepare_cmp_insn (rtx *, rtx
 static enum insn_code can_fix_p (enum machine_mode, enum machine_mode, int,
 				 int *);
 static enum insn_code can_float_p (enum machine_mode, enum machine_mode, int);
-static rtx ftruncify (rtx);
 static optab new_optab (void);
 static convert_optab new_convert_optab (void);
 static inline optab init_optab (enum rtx_code);
@@ -4434,6 +4433,9 @@ can_fix_p (enum machine_mode fixmode, en
       return icode;
     }
 
+  /* FIXME: This requires a port to define both FIX and FTRUNC pattern
+     for this to work. We need to rework the fix* and ftrunc* patterns
+     and documentation.  */
   tab = unsignedp ? ufix_optab : sfix_optab;
   icode = tab->handlers[fixmode][fltmode].insn_code;
   if (icode != CODE_FOR_nothing
@@ -4673,15 +4675,8 @@ expand_float (rtx to, rtx from, int unsi
     }
 }
 
-/* expand_fix: generate code to convert FROM to fixed point
-   and store in TO.  FROM must be floating point.  */
-
-static rtx
-ftruncify (rtx x)
-{
-  rtx temp = gen_reg_rtx (GET_MODE (x));
-  return expand_unop (GET_MODE (x), ftrunc_optab, x, temp, 0);
-}
+/* Generate code to convert FROM to fixed point and store in TO.  FROM
+   must be floating point.  */
 
 void
 expand_fix (rtx to, rtx from, int unsignedp)
@@ -4716,7 +4711,11 @@ expand_fix (rtx to, rtx from, int unsign
 	      from = convert_to_mode (fmode, from, 0);
 
 	    if (must_trunc)
-	      from = ftruncify (from);
+	      {
+		rtx temp = gen_reg_rtx (GET_MODE (from));
+		from = expand_unop (GET_MODE (from), ftrunc_optab, from,
+				    temp, 0);
+	      }
 
 	    if (imode != GET_MODE (to))
 	      target = gen_reg_rtx (imode);



More information about the Gcc-patches mailing list