Add type rules for binary operators - #772
Conversation
|
I think I got all the binary operators in the grammar. The matrix ones are confusing, please check. I'm going off matrixNxM means N columns an M rows. |
|
Also fixes #707 |
| <td>Component-wise logical shift right (OpShiftRightLogical) | ||
| <tr><td>*e1* : i32<br> | ||
| *e2* : i32<br> | ||
| <td class="nowrap">`e1 >> e2` : u32 |
There was a problem hiding this comment.
Ah, right. I forgot about that.
It turns out we have >> and >>> exactly opposite to what Java does.
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html
I'll file an issue for that.
| <tr><td>*e1* : *T*<br> | ||
| *e2* : *T*<br> | ||
| *T* is vec*N*<i32> | ||
| <td class="nowrap">`e1 >> e2` : *T* |
There was a problem hiding this comment.
Sorry, I've lost the context now.
There was a problem hiding this comment.
Usually it's a ditto to the comment above, so I'm guessing this is in reference to >> vs >>>?
| <tr><td>*e1* : u32<br> | ||
| *e2* : u32<br> | ||
| <td class="nowrap">`e1 != e2` : bool | ||
| <td>Inequality (OpIEqual) |
| <td>Component-wise equality (OpIEqual) | ||
| <tr><td>*e1* : *T*<br> | ||
| *e2* : *T*<br> | ||
| *T* is vec*N*<in;i32> |
| *e2* : *T*<br> | ||
| *T* is vec*N*<u32> | ||
| <td class="nowrap">`e1 != e2` : vec*N*<bool> | ||
| <td>Component-wise inequality (OpIEqual) |
|
Discussed at the 2020-05-19 meeting. |
| <tr><td>*e1* : *T*<br> *e2* : *T*<br> *T* is *FloatVec*<td>`e1 / e2` : *T*<td>Component-wise floating point division (OpFDiv) | ||
| <tr><td>*e1* : *T*<br> *e2* : *T*<br> *T* is *IntVec* with unsigned component<td>`e1 % e2` : *T*<td>Component-wise unsigned integer modulus (OpUMod) | ||
| <tr><td>*e1* : *T*<br> *e2* : *T*<br> *T* is *IntVec* with signed component<td>`e1 % e2` : *T*<td>Component-wise signed integer remainder (OpSMod) | ||
| <tr><td>*e1* : *T*<br> *e2* : *T*<br> *T* is *FloatVec*<td>`e1 % e2` : *T*<td>Component-wise floating point division (OpFMod) |
There was a problem hiding this comment.
Fixed in next commit to "modulus"
| <tr><td>*e1* : u32<br> *e2* : u32<td>`e1 / e2` : u32<td>Unsigned integer division (OpUDiv) | ||
| <tr><td>*e1* : i32<br> *e2* : i32<td>`e1 / e2` : i32<td>Signed integer division (OpSDiv) | ||
| <tr><td>*e1* : f32<br> *e2* : f32<td>`e1 / e2` : f32<td>Floating point division (OpFAdd) | ||
| <tr><td>*e1* : u32<br> *e2* : u32<td>`e1 % e2` : u32<td>Unsigned integer modulus (OpUMod) |
There was a problem hiding this comment.
Is it helpful to draw a distinction between modulus and remainder for an unsigned number? The difference concerns negative numbers. For clarity and consistency, could we not call them something different here?
There was a problem hiding this comment.
Good question. I would say these are the type rules, and are not a complete spec of how arithmetic works. I expect we'll need a whole other section to specify the behaviours of operations. We may end up migrating descriptions over to that new section. I am coming around to the need for a larger scale reorg of the spec.
| *T* is *FloatVec* | ||
| <td>`e1 * e2` : *T*<br> | ||
| `e2 * e1` : *T* | ||
| <td>Scalar multiplication of vector (OpVectorTimesScalar) |
There was a problem hiding this comment.
I think it would be helpful to say "multiplication of a vector and a scalar"
| *T* is mat*N*x*M*<f32> | ||
| <td>`e1 * e2` : *T*<br> | ||
| `e2 * e1` : *T* | ||
| <td>Scalar multiplication of matrix (OpMatrixTimesScalar) |
There was a problem hiding this comment.
I think it would be helpful to say "multiplication of a matrix and a scalar"
| *e2* : mat*M*x*K*<f32><br> | ||
| <td>`e1 * e2` : mat*M*x*N*<f32><br> | ||
| <td>Matrix times matrix (OpMatrixTimesMatrix) | ||
| </table> |
There was a problem hiding this comment.
I don't see matrix x matrix multiplication in here. I expect we follow the same rules we learned in trigonometry class, but it might be worth mentioning for completeness.
There was a problem hiding this comment.
? Matrix times matrix is at line 1773-1776
We no longer need those builtins: - PR gpuweb#772 added type rules for signed integer comparisons - Resolution of gpuweb#706 is to not have unordered floating point comparisons as a direct language feature.
- Use >>> as it's used in the grammar - Fix typographical < - Fix comments about correspondence to OpINotEqual
d53a82f to
bf66713
Compare
| <tr><td>`SHIFT_RIGHT`<td>>> | ||
| <tr><td>`LESS_THAN`<td>< | ||
| <tr><td>`LESS_THAN_EQUAL`<td><= | ||
| <tr><td>`SHIFT_LEFT`<td><< |
There was a problem hiding this comment.
nit: These should really (eventually) be escaped somehow to avoid weird html parsing issues. I'd just put them in code tags: `<<` etc.
We no longer need those builtins: - PR gpuweb#772 added type rules for signed integer comparisons - Resolution of gpuweb#706 is to not have unordered floating point comparisons as a direct language feature.
We no longer need those builtins: - PR gpuweb#772 added type rules for signed integer comparisons - Resolution of gpuweb#706 is to not have unordered floating point comparisons as a direct language feature.
Fixes #726