<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
</head>
<body>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">On 2 Apr 2020, at 9:47, Florian Hahn wrote:</p>
</div>
<div style="white-space:normal"><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px"><blockquote style="border-left:2px solid #777; color:#999; margin:0 0 5px; padding-left:5px; border-left-color:#999"><p dir="auto">On Apr 1, 2020, at 20:48, Stephen Canon <scanon@apple.com> wrote:<br>
</p>
<blockquote style="border-left:2px solid #777; color:#BBB; margin:0 0 5px; padding-left:5px; border-left-color:#BBB"><p dir="auto">On Apr 1, 2020, at 1:23 PM, John McCall via cfe-dev <cfe-dev@lists.llvm.org> wrote:<br>
</p>
<blockquote style="border-left:2px solid #777; color:#BBB; margin:0 0 5px; padding-left:5px; border-left-color:#BBB"><p dir="auto">On 1 Apr 2020, at 13:15, Florian Hahn wrote:<br>
I agree that ideally we would not allow mis-matched binary operations to avoid surprises. It looks like the existing vector type does not perform implicit conversion for binary operations with 2 vector operands (unless the there is a type mis-match and the data size matches, then the LHS type is chosen). For binary ops with vector and scalar operands, the scalar operand is converted to the vector element type. So short4 + short4 -> short4, short4 + int -> short4, short4 + int4 -> invalid.<br>
<br>
Given that precedence, I think we should opt for not providing conversions for binary operators with two matrix operands. For the matrix and scalar versions, we could convert to the element type automatically for convenience. But at that point, the gain is probably quite small and it would be simpler to don’t do conversions in any case. Does that sound reasonable?</p>
</blockquote><p dir="auto">I think converting scalars is a necessary convenience in C given that e.g. literals are normally of type int, but yes, I think it’s fine to not implicitly convert matrices as long as you have a way to convert them explicitly.</p>
</blockquote></blockquote><p dir="auto">Converting them explicitly should be covered by the standard conversion rules, right?</p>
</blockquote></div>
<div style="white-space:normal">
<p dir="auto">Do you want matrices to be implicitly convertible in non-operator contexts? Like, if you assign a <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">float4x4</code> to an <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">int4x4</code>, should that implicitly convert the elements or be ill-formed?</p>
<p dir="auto">John.</p>
</div>
<div style="white-space:normal"><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px"><blockquote style="border-left:2px solid #777; color:#999; margin:0 0 5px; padding-left:5px; border-left-color:#999"><p dir="auto">For matrix operations implicit scalar conversions will be less important than they are for vectors, but they turned out to be really critical to have for vector programming. It may make sense to have them for matrices as well.<br>
<br>
The main issue for vectors is that there’s no way to get a sub-int literal in C (i.e. there’s no i8 suffix). This meant that simple vector code like, e.g.:<br>
<br>
uchar16 a, b;<br>
uchar16 c = a & 0xf | b << 4;<br>
<br>
Had to be written as:<br>
<br>
uchar16 c = a & (uchar16)0xf | b << (uchar16)4;<br>
<br>
Which, well, it really sucked before we added the conversion rule. This sort of thing is less common for matrix math than vector math, but it probably makes sense to match the semantics for convenience and consistency; there haven’t really been a lot of drawbacks to the vector semantics.<br>
<br>
There should be no implicit conversions for matrix operands (and certainly not the C usual arithmetic conversions; approximately no one wants that behavior).<br>
</p>
</blockquote><p dir="auto">Thanks, I’ve updated the arithmetic conversion rules in <a href="https://reviews.llvm.org/D76612" style="color:#777">https://reviews.llvm.org/D76612</a> with the text below:<br>
<br>
* If both operands are of matrix type, no arithmetic conversion is performed.<br>
* If one operand is of matrix type and the other operand is of an integer or<br>
floating point type, convert the integer or floating point operand to the<br>
underlying element type of the operand of matrix type.<br>
<br>
Cheers,<br>
Florian</p>
</blockquote></div>
<div style="white-space:normal">
</div>
</div>
</body>
</html>