This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
rfc: auto-casted vector types
- From: Aldy Hernandez <aldyh at redhat dot com>
- To: GCC Mailinglist <gcc at gcc dot gnu dot org>
- Cc: Nick Clifton <nickc at redhat dot com>, Jim Wilson <wilson at redhat dot com>
- Date: Thu, 13 Feb 2003 13:01:47 -0800
- Subject: rfc: auto-casted vector types
The PPC E500 API specifies that vector types of type __ev64_opaque__
(V2SImode) can interconvert with other vector types without a cast.
For example:
#define __vector __attribute__((vector_size(8)))
typedef int __vector __ev64_opaque__;
typedef float __vector __ev64_fs__;
typedef int __vector __ev64_int__;
__ev64_fs__ f;
__ev64_int__ i;
__ev64_opaque__ op;
/* Do not require a cast. */
op = f;
f = op;
op = i;
i = op;
I had originally kludged a solution in comptypes() and
convert_for_assignment() because I thought nobody would be interested
(or would agree), but Nick has since cleaned up my patches a bit, and
they don't look that bad: three lines of actual generic code.
I'd like to get input on:
(a) the feasibility of including these patches
(b) alternate solutions that would be accepted
(c) including the patch below in contrib/
As you can probably guess, I didn't design the API, so no flames please
;-).
Comments?
2003-02-13 Nick Clifton <nickc@redhat.com>
Aldy Hernandez <aldyh@redhat.com>
* doc/tm.texi: Document TARGET_VECTOR_TYPES_COMPATIBLE.
* c-typeck.c (comptypes): Take into account
TARGET_VECTOR_TYPES_COMPATIBLE.
(convert_for_assignment): Same.
* config/rs6000/rs6000-protos.h
(rs6000_spe_vector_types_compatible): Prototype.
* config/rs6000/rs6000.c (is_ev64_opaque_type): New.
(rs6000_spe_vector_types_compatible): New.
* config/rs6000/rs6000.h (TARGET_VECTOR_TYPES_COMPATIBLE): Define.
Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.198
diff -c -p -r1.198 tm.texi
*** doc/tm.texi 31 Jan 2003 23:34:17 -0000 1.198
--- doc/tm.texi 13 Feb 2003 20:50:20 -0000
*************** Define this macro to be nonzero if the p
*** 1302,1307 ****
--- 1302,1312 ----
involving vector mode @var{mode}. At the very least, it must have
move
patterns for this mode.
+ @findex TARGET_VECTOR_TYPES_COMPATIBLE
+ @item TARGET_VECTOR_TYPES_COMPATIBLE(@var{tree1}, @var{tree2})
+ Define this macro to return nonzero if no cast is needed when copying
+ a value of type @var{tree1} to a value of type @var{tree2}.
+
@findex STACK_SAVEAREA_MODE
@item STACK_SAVEAREA_MODE (@var{save_level})
If defined, an expression of type @code{enum machine_mode} that
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.218
diff -c -p -r1.218 c-typeck.c
*** c-typeck.c 1 Feb 2003 13:09:39 -0000 1.218
--- c-typeck.c 13 Feb 2003 20:50:35 -0000
*************** comptypes (type1, type2)
*** 574,579 ****
--- 574,586 ----
val = 1;
break;
+ case VECTOR_TYPE:
+ #ifdef TARGET_VECTOR_TYPES_COMPATIBLE
+ /* The target might allow certain vector types to be
compatible. */
+ val = TARGET_VECTOR_TYPES_COMPATIBLE (t1, t2);
+ #endif
+ break;
+
default:
break;
}
*************** convert_for_assignment (type, rhs, errty
*** 4061,4066 ****
--- 4068,4079 ----
rhs = build1 (NOP_EXPR, type, rhs);
return rhs;
}
+ #ifdef TARGET_VECTOR_TYPES_COMPATIBLE
+ /* Some types can interconvert without explicit casts. */
+ else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
+ && TARGET_VECTOR_TYPES_COMPATIBLE (type, rhstype))
+ return convert (type, rhs);
+ #endif
/* Arithmetic types all interconvert, and enum is treated like int.
*/
else if ((codel == INTEGER_TYPE || codel == REAL_TYPE
|| codel == ENUMERAL_TYPE || codel == COMPLEX_TYPE
Index: config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.422
diff -c -p -r1.422 rs6000.c
*** config/rs6000/rs6000.c 10 Feb 2003 18:42:19 -0000 1.422
--- config/rs6000/rs6000.c 13 Feb 2003 20:51:03 -0000
*************** static void is_altivec_return_reg PARAMS
*** 265,270 ****
--- 265,271 ----
static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int));
static void altivec_frame_fixup PARAMS ((rtx, rtx, HOST_WIDE_INT));
static int easy_vector_constant PARAMS ((rtx));
+ static int is_ev64_opaque_type PARAMS ((tree));
/* Hash table stuff for keeping track of TOC entries. */
*************** rs6000_memory_move_cost (mode, class, in
*** 13522,13527 ****
--- 13523,13556 ----
return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
else
return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
+ }
+
+ static int
+ is_ev64_opaque_type (type)
+ tree type;
+ {
+ return (TYPE_NAME (type)
+ && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
+ && DECL_NAME (TYPE_NAME (type))
+ && strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))),
+ "__ev64_opaque__") == 0);
+ }
+
+ /* Return true iff vector type1 can be converted into vector type2.
*/
+
+ int
+ rs6000_spe_vector_types_compatible (t1, t2)
+ tree t1;
+ tree t2;
+ {
+ if (TREE_CODE (t1) != VECTOR_TYPE || TREE_CODE (t2) != VECTOR_TYPE)
+ return 0;
+
+ if (TYPE_NAME (t1) || TYPE_NAME (t2))
+ return is_ev64_opaque_type (t1) || is_ev64_opaque_type (t2);
+
+ /* The V2SI type is the basis of the ev64_opaque type. */
+ return t1 == V2SI_type_node || t2 == V2SI_type_node;
}
#include "gt-rs6000.h"
Index: config/rs6000/rs6000.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.h,v
retrieving revision 1.251
diff -c -p -r1.251 rs6000.h
*** config/rs6000/rs6000.h 8 Feb 2003 03:59:40 -0000 1.251
--- config/rs6000/rs6000.h 13 Feb 2003 20:51:11 -0000
*************** extern int rs6000_default_long_calls;
*** 892,897 ****
--- 892,901 ----
|| (MODE) == V1DImode \
|| (MODE) == V2SImode)
+ /* Allow SPE vector types to be inter-converted. */
+ #define TARGET_VECTOR_TYPES_COMPATIBLE(t1,t2) \
+ (TARGET_SPE ? rs6000_spe_vector_types_compatible (t1, t2) : 0)
+
/* Define this macro to be nonzero if the port is prepared to handle
insns involving vector mode MODE. At the very least, it must have
move patterns for this mode. */