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: [C++] Handle ?: for vectors


On Wed, 17 Oct 2012, Jason Merrill wrote:

On 10/17/2012 12:56 PM, Marc Glisse wrote:
+      if (!COMPARISON_CLASS_P (arg1))
+	{
+	  if (TYPE_UNSIGNED (TREE_TYPE (arg1_type)))
+	    {
+	      arg1_type = signed_type_for (arg1_type);
+	      arg1 = convert (arg1_type, arg1);
+	    }
+	  arg1 = build2 (LT_EXPR, arg1_type, arg1,
+			 build_zero_cst (arg1_type));
+	}

Why LT_EXPR rather than NE_EXPR?

Assuming we try to follow OpenCL:


6.3i

The ternary selection operator (?:) operates on three expressions (exp1 ? exp2 : exp3). This operator evaluates the first expression exp1, which can be a scalar or vector result except float. If the result is a scalar value then it selects to evaluate the second expression if the result compares unequal to 0, otherwise it selects to evaluate the third expression. If the result is a vector value, then this is equivalent to calling select(exp3, exp2, exp1). The select function is described in table 6.14. The second and third expressions can be any type, as long their types match, or there is a conversion in section 6.2.1 Implicit Conversions that can be applied to one of the expressions to make their types match, or one is a vector and the other is a scalar and the scalar may be subject to the usual arithmetic conversion to the element type used by the vector operand and widened to the same type as the vector type. This resulting matching type is the type of the entire expression.


table 6.14:


gentype select (gentype a, gentype b, igentype c)

For each component of a vector type,
result[i] = if MSB of c[i] is set ? b[i] : a[i].

===

We could deviate from OpenCL in a few places though, if you prefer.

Note that operator! (not implemented) still means == 0.


Thanks for the quick comment despite the meeting,


--
Marc Glisse


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