aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/rs6000
diff options
context:
space:
mode:
authorAndrew Pinski <andrew_pinski@playstation.sony.com>2008-10-01 19:06:58 +0000
committerAndrew Pinski <pinskia@gcc.gnu.org>2008-10-01 12:06:58 -0700
commit266b48906ac36728e24c49787c6b2e063a1f7df1 (patch)
tree5084dd423fee0d3e3b356167376d3d9cc667e938 /gcc/config/rs6000
parent0b61703ca6adde635f58c71763a524b8fd922009 (diff)
downloadgcc-266b48906ac36728e24c49787c6b2e063a1f7df1.zip
gcc-266b48906ac36728e24c49787c6b2e063a1f7df1.tar.gz
gcc-266b48906ac36728e24c49787c6b2e063a1f7df1.tar.bz2
rs6000-c.c (altivec_resolve_overloaded_builtin): Handle ALTIVEC_BUILTIN_VEC_SPLATS...
2008-10-01 Andrew Pinski <andrew_pinski@playstation.sony.com> * config/rs6000/rs6000-c.c (altivec_resolve_overloaded_builtin): Handle ALTIVEC_BUILTIN_VEC_SPLATS, ALTIVEC_BUILTIN_VEC_PROMOTE, ALTIVEC_BUILTIN_VEC_EXTRACT, and ALTIVEC_BUILTIN_VEC_INSERT specially, they translate to non builtins. * config/rs6000/rs6000.c (altivec_init_builtins): Add new variable opaque_ftype_opaque. Define builtins __builtin_vec_splats, __builtin_vec_promote, __builtin_vec_extract, and __builtin_vec_insert. * config/rs6000/rs6000.h (enum rs6000_builtins): Add ALTIVEC_BUILTIN_VEC_EXTRACT, ALTIVEC_BUILTIN_VEC_PROMOTE, ALTIVEC_BUILTIN_VEC_INSERT, and ALTIVEC_BUILTIN_VEC_SPLATS. * config/rs6000/altivec.h (vec_extract): Define (vec_insert): Define. (vec_splats): Define. (vec_promote): Define. 2008-10-01 Andrew Pinski <andrew_pinski@playstation.sony.com> * gcc.target/powerpc/altivec-cell-1.c: New test. * gcc.target/powerpc/altivec-cell-2.c: New test. * gcc.target/powerpc/altivec-cell-3.c: New test. * gcc.target/powerpc/altivec-cell-4.c: New test. * gcc.target/powerpc/altivec-cell-5.c: New test. * g++.dg/ext/altivec-cell-1.C: New test. * g++.dg/ext/altivec-cell-2.C: New test. * g++.dg/ext/altivec-cell-3.C: New test. * g++.dg/ext/altivec-cell-4.C: New test. * g++.dg/ext/altivec-cell-5.C: New test. 2008-10-01 Andrew Pinski <andrew_pinski@playstation.sony.com> * tree.c (lvalue_p_1): COMPOUND_LITERAL_EXPR is also an lvalue. From-SVN: r140821
Diffstat (limited to 'gcc/config/rs6000')
-rw-r--r--gcc/config/rs6000/altivec.h5
-rw-r--r--gcc/config/rs6000/rs6000-c.c192
-rw-r--r--gcc/config/rs6000/rs6000.c8
-rw-r--r--gcc/config/rs6000/rs6000.h6
4 files changed, 209 insertions, 2 deletions
diff --git a/gcc/config/rs6000/altivec.h b/gcc/config/rs6000/altivec.h
index 39efc49..cfe384c 100644
--- a/gcc/config/rs6000/altivec.h
+++ b/gcc/config/rs6000/altivec.h
@@ -304,6 +304,11 @@
#define vec_vsubuws __builtin_vec_vsubuws
#define vec_xor __builtin_vec_xor
+#define vec_extract __builtin_vec_extract
+#define vec_insert __builtin_vec_insert
+#define vec_splats __builtin_vec_splats
+#define vec_promote __builtin_vec_promote
+
/* Predicates.
For C++, we use templates in order to allow non-parenthesized arguments.
For C, instead, we use macros since non-parenthesized arguments were
diff --git a/gcc/config/rs6000/rs6000-c.c b/gcc/config/rs6000/rs6000-c.c
index 9ffa43e..ed9b6c0 100644
--- a/gcc/config/rs6000/rs6000-c.c
+++ b/gcc/config/rs6000/rs6000-c.c
@@ -2973,6 +2973,198 @@ altivec_resolve_overloaded_builtin (tree fndecl, tree arglist)
|| fcode > ALTIVEC_BUILTIN_OVERLOADED_LAST)
return NULL_TREE;
+ /* For now treat vec_splats and vec_promote as the same. */
+ if (fcode == ALTIVEC_BUILTIN_VEC_SPLATS
+ || fcode == ALTIVEC_BUILTIN_VEC_PROMOTE)
+ {
+ tree type, arg;
+ int size;
+ int i;
+ bool unsigned_p;
+ VEC(constructor_elt,gc) *vec;
+ const char *name = fcode == ALTIVEC_BUILTIN_VEC_SPLATS ? "vec_splats": "vec_promote";
+
+ if (!arglist)
+ {
+ error ("%s only accepts %d arguments", name, (fcode == ALTIVEC_BUILTIN_VEC_PROMOTE)+1 );
+ return error_mark_node;
+ }
+ if (fcode == ALTIVEC_BUILTIN_VEC_SPLATS && TREE_CHAIN (arglist))
+ {
+ error ("%s only accepts 1 argument", name);
+ return error_mark_node;
+ }
+ if (fcode == ALTIVEC_BUILTIN_VEC_PROMOTE && !TREE_CHAIN (arglist))
+ {
+ error ("%s only accepts 2 arguments", name);
+ return error_mark_node;
+ }
+ /* Ignore promote's element argument. */
+ if (fcode == ALTIVEC_BUILTIN_VEC_PROMOTE
+ && TREE_CHAIN (TREE_CHAIN (arglist)))
+ {
+ error ("%s only accepts 2 arguments", name);
+ return error_mark_node;
+ }
+ if (fcode == ALTIVEC_BUILTIN_VEC_PROMOTE
+ && !INTEGRAL_TYPE_P (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arglist)))))
+ goto bad;
+
+ arg = TREE_VALUE (arglist);
+ type = TREE_TYPE (arg);
+ if (!SCALAR_FLOAT_TYPE_P (type)
+ && !INTEGRAL_TYPE_P (type))
+ goto bad;
+ unsigned_p = TYPE_UNSIGNED (type);
+ if (type == long_long_unsigned_type_node
+ || type == long_long_integer_type_node)
+ goto bad;
+ switch (TYPE_MODE (type))
+ {
+ case SImode:
+ type = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
+ size = 4;
+ break;
+ case HImode:
+ type = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
+ size = 8;
+ break;
+ case QImode:
+ type = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
+ size = 16;
+ break;
+ case SFmode: type = V4SF_type_node; size = 4; break;
+ default:
+ goto bad;
+ }
+ arg = save_expr (fold_convert (TREE_TYPE (type), arg));
+ vec = VEC_alloc (constructor_elt, gc, size);
+ for(i = 0; i < size; i++)
+ {
+ constructor_elt *elt;
+
+ elt = VEC_quick_push (constructor_elt, vec, NULL);
+ elt->index = NULL_TREE;
+ elt->value = arg;
+ }
+ return build_constructor (type, vec);
+ }
+
+ /* For now use pointer tricks to do the extaction. */
+ if (fcode == ALTIVEC_BUILTIN_VEC_EXTRACT)
+ {
+ tree arg1;
+ tree arg1_type;
+ tree arg2;
+ tree arg1_inner_type;
+ tree decl, stmt;
+ tree innerptrtype;
+
+ /* No second argument. */
+ if (!arglist || !TREE_CHAIN (arglist)
+ || TREE_CHAIN (TREE_CHAIN (arglist)))
+ {
+ error ("vec_extract only accepts 2 arguments");
+ return error_mark_node;
+ }
+
+ arg2 = TREE_VALUE (TREE_CHAIN (arglist));
+ arg1 = TREE_VALUE (arglist);
+ arg1_type = TREE_TYPE (arg1);
+
+ if (TREE_CODE (arg1_type) != VECTOR_TYPE)
+ goto bad;
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (arg2)))
+ goto bad;
+ /* Build *(((arg1_inner_type*)&(vector type){arg1})+arg2). */
+ arg1_inner_type = TREE_TYPE (arg1_type);
+ arg2 = build_binary_op (input_location, BIT_AND_EXPR, arg2,
+ build_int_cst (TREE_TYPE (arg2),
+ TYPE_VECTOR_SUBPARTS (arg1_type)
+ - 1), 0);
+ decl = build_decl (VAR_DECL, NULL_TREE, arg1_type);
+ DECL_EXTERNAL (decl) = 0;
+ TREE_PUBLIC (decl) = 0;
+ DECL_CONTEXT (decl) = current_function_decl;
+ TREE_USED (decl) = 1;
+ TREE_TYPE (decl) = arg1_type;
+ TREE_READONLY (decl) = TYPE_READONLY (arg1_type);
+ DECL_INITIAL (decl) = arg1;
+ stmt = build1 (DECL_EXPR, arg1_type, decl);
+ TREE_ADDRESSABLE (decl) = 1;
+ SET_EXPR_LOCATION (stmt, input_location);
+ stmt = build1 (COMPOUND_LITERAL_EXPR, arg1_type, stmt);
+
+ innerptrtype = build_pointer_type (arg1_inner_type);
+
+ stmt = build_unary_op (ADDR_EXPR, stmt, 0);
+ stmt = convert (innerptrtype, stmt);
+ stmt = build_binary_op (input_location, PLUS_EXPR, stmt, arg2, 1);
+ stmt = build_indirect_ref (stmt, NULL, input_location);
+
+ return stmt;
+ }
+
+ /* For now use pointer tricks to do the insertation. */
+ if (fcode == ALTIVEC_BUILTIN_VEC_INSERT)
+ {
+ tree arg0;
+ tree arg1;
+ tree arg2;
+ tree arg1_type;
+ tree arg1_inner_type;
+ tree decl, stmt;
+ tree innerptrtype;
+
+ /* No second or third arguments. */
+ if (!arglist || !TREE_CHAIN (arglist)
+ || !TREE_CHAIN (TREE_CHAIN (arglist))
+ || TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))))
+ {
+ error ("vec_insert only accepts 3 arguments");
+ return error_mark_node;
+ }
+
+ arg0 = TREE_VALUE (arglist);
+ arg1 = TREE_VALUE (TREE_CHAIN (arglist));
+ arg1_type = TREE_TYPE (arg1);
+ arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
+
+ if (TREE_CODE (arg1_type) != VECTOR_TYPE)
+ goto bad;
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (arg2)))
+ goto bad;
+ /* Build *(((arg1_inner_type*)&(vector type){arg1})+arg2) = arg0. */
+ arg1_inner_type = TREE_TYPE (arg1_type);
+ arg2 = build_binary_op (input_location, BIT_AND_EXPR, arg2,
+ build_int_cst (TREE_TYPE (arg2),
+ TYPE_VECTOR_SUBPARTS (arg1_type)
+ - 1), 0);
+ decl = build_decl (VAR_DECL, NULL_TREE, arg1_type);
+ DECL_EXTERNAL (decl) = 0;
+ TREE_PUBLIC (decl) = 0;
+ DECL_CONTEXT (decl) = current_function_decl;
+ TREE_USED (decl) = 1;
+ TREE_TYPE (decl) = arg1_type;
+ TREE_READONLY (decl) = TYPE_READONLY (arg1_type);
+ DECL_INITIAL (decl) = arg1;
+ stmt = build1 (DECL_EXPR, arg1_type, decl);
+ TREE_ADDRESSABLE (decl) = 1;
+ SET_EXPR_LOCATION (stmt, input_location);
+ stmt = build1 (COMPOUND_LITERAL_EXPR, arg1_type, stmt);
+
+ innerptrtype = build_pointer_type (arg1_inner_type);
+
+ stmt = build_unary_op (ADDR_EXPR, stmt, 0);
+ stmt = convert (innerptrtype, stmt);
+ stmt = build_binary_op (input_location, PLUS_EXPR, stmt, arg2, 1);
+ stmt = build_indirect_ref (stmt, NULL, input_location);
+ stmt = build2 (MODIFY_EXPR, TREE_TYPE (stmt), stmt,
+ convert (TREE_TYPE (stmt), arg0));
+ stmt = build2 (COMPOUND_EXPR, arg1_type, stmt, decl);
+ return stmt;
+ }
+
for (n = 0;
!VOID_TYPE_P (TREE_VALUE (fnargs)) && arglist;
fnargs = TREE_CHAIN (fnargs), arglist = TREE_CHAIN (arglist), n++)
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 24d6761..6b9367b 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -9784,7 +9784,9 @@ altivec_init_builtins (void)
tree int_ftype_opaque
= build_function_type_list (integer_type_node,
opaque_V4SI_type_node, NULL_TREE);
-
+ tree opaque_ftype_opaque
+ = build_function_type (integer_type_node,
+ NULL_TREE);
tree opaque_ftype_opaque_int
= build_function_type_list (opaque_V4SI_type_node,
opaque_V4SI_type_node, integer_type_node, NULL_TREE);
@@ -9953,9 +9955,13 @@ altivec_init_builtins (void)
def_builtin (MASK_ALTIVEC, "__builtin_vec_stvrxl", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_VEC_STVRXL);
}
def_builtin (MASK_ALTIVEC, "__builtin_vec_step", int_ftype_opaque, ALTIVEC_BUILTIN_VEC_STEP);
+ def_builtin (MASK_ALTIVEC, "__builtin_vec_splats", opaque_ftype_opaque, ALTIVEC_BUILTIN_VEC_SPLATS);
+ def_builtin (MASK_ALTIVEC, "__builtin_vec_promote", opaque_ftype_opaque, ALTIVEC_BUILTIN_VEC_PROMOTE);
def_builtin (MASK_ALTIVEC, "__builtin_vec_sld", opaque_ftype_opaque_opaque_int, ALTIVEC_BUILTIN_VEC_SLD);
def_builtin (MASK_ALTIVEC, "__builtin_vec_splat", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_SPLAT);
+ def_builtin (MASK_ALTIVEC, "__builtin_vec_extract", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_EXTRACT);
+ def_builtin (MASK_ALTIVEC, "__builtin_vec_insert", opaque_ftype_opaque_opaque_int, ALTIVEC_BUILTIN_VEC_INSERT);
def_builtin (MASK_ALTIVEC, "__builtin_vec_vspltw", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_VSPLTW);
def_builtin (MASK_ALTIVEC, "__builtin_vec_vsplth", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_VSPLTH);
def_builtin (MASK_ALTIVEC, "__builtin_vec_vspltb", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_VSPLTB);
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index ac00e11..e1023da 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -2603,6 +2603,7 @@ enum rs6000_builtins
ALTIVEC_BUILTIN_VEC_AND,
ALTIVEC_BUILTIN_VEC_ANDC,
ALTIVEC_BUILTIN_VEC_AVG,
+ ALTIVEC_BUILTIN_VEC_EXTRACT,
ALTIVEC_BUILTIN_VEC_CEIL,
ALTIVEC_BUILTIN_VEC_CMPB,
ALTIVEC_BUILTIN_VEC_CMPEQ,
@@ -2812,7 +2813,10 @@ enum rs6000_builtins
ALTIVEC_BUILTIN_VEC_VUPKLSH,
ALTIVEC_BUILTIN_VEC_XOR,
ALTIVEC_BUILTIN_VEC_STEP,
- ALTIVEC_BUILTIN_OVERLOADED_LAST = ALTIVEC_BUILTIN_VEC_STEP,
+ ALTIVEC_BUILTIN_VEC_PROMOTE,
+ ALTIVEC_BUILTIN_VEC_INSERT,
+ ALTIVEC_BUILTIN_VEC_SPLATS,
+ ALTIVEC_BUILTIN_OVERLOADED_LAST = ALTIVEC_BUILTIN_VEC_SPLATS,
/* SPE builtins. */
SPE_BUILTIN_EVADDW,