This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Scalar vector binary operation


On 08/14/2010 09:37 AM, Artem Shinkarov wrote:
> +/* Build a vector of type VECTYPE where all the elements are SCs.  */
> +tree
> +build_vector_from_val (const tree sc, const tree vectype) 
> +{
> +  tree t = NULL_TREE;
> +  int i, nunits = TYPE_VECTOR_SUBPARTS (vectype);
> +
> +  if (sc == error_mark_node)
> +    return sc;
> +
> +  gcc_assert (TREE_TYPE (sc) == TREE_TYPE (vectype));
> +
> +  for (i = 0; i < nunits; ++i)
> +    t = tree_cons (NULL_TREE, sc, t);
> +
> +  if (CONSTANT_CLASS_P (sc))
> +    return build_vector (vectype, t);
> +  else 
> +    return build_constructor_from_list (vectype, t);
> +}
> +

Better to use build_constructor and build_vector_from_ctor.
We've been trying to eliminate TREE_LIST.

> +static inline bool
> +expr_fits_type_p (const tree expr, const tree type )

No explicit inline marker.

This function doesn't handle real/integer type crosses.
I.e. v4sf * long or v4si * 2.0.  It will crash for some
of the combinations.

> +static inline int
> +scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1)

No explicit inline marker.

> +#define MSG "Conversion of scalar to vector involves truncation"
> +#define MSG_FLOAT "Truncating floating point constant to vector " \
> +                  "precision does not preserve value"
> +#define ERROR(MSG, LOC, RET) { error_at (LOC, MSG); return RET; }

This is, frankly, gross.

> +      case RSHIFT_EXPR:
> +      case LSHIFT_EXPR:
> +        if (TREE_CODE (TREE_TYPE (op0)) == INTEGER_TYPE)
> +          return 0;

			  code0

I think you also want to check for vect << int, which is directly
supported by most cpus.  Also, you don't want a fallthru to the
real format checks.

You could probably simplify the code a bit for the arithmetic ops
if you first force op0 to be the vector operation.  Since we're not
actually emitting code here, it doesn't matter if we temporarily
"swap" non-commutative operands.

Some commentary that one of op0 or op1 is known to be vector type
and the other is known to be scalar type would also help here.

Using FP scalar types with integer vector types is probably suspect
and should generate an error.


> +  /* For 'vector <shift> scalar' or 'scalar <shift> vector', we convert 
> +     a scalar to a vector. Truncating the shift amount is ok.  */
> +  if ((code0 == VECTOR_TYPE || code1 == VECTOR_TYPE)
> +      && (code0 != code1))

  if ((code0 == VECTOR_TYPE) != (code1 == VECTOR_TYPE))

> +    {
> +        int convert_flag = scalar_to_vector (location, code, op0, op1);
> +        
> +        if (convert_flag == -2)

Definitely use a switch here.  Possibly better with an enum.


r~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]