Sitelet https://github.com/gpuweb/gpuweb/pull/772
Skip to content

Add type rules for binary operators - #772

Merged
dj2 merged 6 commits into
gpuweb:masterfrom
dneto0:wgsl-binary-operator-type-rules
Jun 3, 2020
Merged

dj2 merged 6 commits into
gpuweb:masterfrom
dneto0:wgsl-binary-operator-type-rules

Conversation

@dneto0

@dneto0 dneto0 commented May 12, 2020

Copy link
Copy Markdown
Contributor

Fixes #726

@dneto0
dneto0 requested review from kdashg and litherum May 12, 2020 22:54
@dneto0

dneto0 commented May 12, 2020

Copy link
Copy Markdown
Contributor Author

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.

@dneto0

dneto0 commented May 14, 2020 •

Copy link
Copy Markdown
Contributor Author

Also fixes #707

@dneto0 dneto0 added wgsl resolved Resolved - waiting for a change to the WGSL specification wgsl WebGPU Shading Language Issues labels May 14, 2020
@dneto0 dneto0 added this to the MVP milestone May 14, 2020
Comment thread wgsl/index.bs Outdated
<td>Component-wise logical shift right (OpShiftRightLogical)
<tr><td>*e1* : i32<br>
*e2* : i32<br>
<td class="nowrap">`e1 >> e2` : u32

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e1 >>> e2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed #790

Comment thread wgsl/index.bs
<tr><td>*e1* : *T*<br>
*e2* : *T*<br>
*T* is vec*N*&lt;i32&gt;
<td class="nowrap">`e1 >> e2` : *T*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've lost the context now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually it's a ditto to the comment above, so I'm guessing this is in reference to >> vs >>>?

Comment thread wgsl/index.bs Outdated
<tr><td>*e1* : u32<br>
*e2* : u32<br>
<td class="nowrap">`e1 != e2` : bool
<td>Inequality (OpIEqual)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpINotEqual ?

Comment thread wgsl/index.bs Outdated
<td>Component-wise equality (OpIEqual)
<tr><td>*e1* : *T*<br>
*e2* : *T*<br>
*T* is vec*N*&ltin;i32&gt;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: <

Comment thread wgsl/index.bs Outdated
*e2* : *T*<br>
*T* is vec*N*&lt;u32&gt;
<td class="nowrap">`e1 != e2` : vec*N*&lt;bool&gt;
<td>Component-wise inequality (OpIEqual)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpINotEqual

@grorg

grorg commented May 19, 2020

Copy link
Copy Markdown
Contributor

Discussed at the 2020-05-19 meeting.

Comment thread wgsl/index.bs Outdated
<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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not division, remainder or modulus.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in next commit to "modulus"

Comment thread wgsl/index.bs
<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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread wgsl/index.bs Outdated
*T* is *FloatVec*
<td>`e1 * e2` : *T*<br>
`e2 * e1` : *T*
<td>Scalar multiplication of vector (OpVectorTimesScalar)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be helpful to say "multiplication of a vector and a scalar"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c495d96

Comment thread wgsl/index.bs Outdated
*T* is mat*N*x*M*&lt;f32&gt;
<td>`e1 * e2` : *T*<br>
`e2 * e1` : *T*
<td>Scalar multiplication of matrix (OpMatrixTimesScalar)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be helpful to say "multiplication of a matrix and a scalar"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in commit c495d96

Comment thread wgsl/index.bs
*e2* : mat*M*x*K*&lt;f32&gt;<br>
<td>`e1 * e2` : mat*M*x*N*&lt;f32&gt;<br>
<td>Matrix times matrix (OpMatrixTimesMatrix)
</table>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? Matrix times matrix is at line 1773-1776

dneto0 added a commit to dneto0/gpuweb that referenced this pull request May 19, 2020
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.
dj2 pushed a commit that referenced this pull request May 21, 2020
We no longer need those builtins:

- PR #772 added type rules for
  signed integer comparisons
- Resolution of #706 is to not
  have unordered floating point comparisons as a direct language
  feature.
Comment thread wgsl/index.bs
<tr><td>`SHIFT_RIGHT`<td>>>
<tr><td>`LESS_THAN`<td><
<tr><td>`LESS_THAN_EQUAL`<td><=
<tr><td>`SHIFT_LEFT`<td><<

@kainino0x kainino0x Jun 2, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: These should really (eventually) be escaped somehow to avoid weird html parsing issues. I'd just put them in code tags: `<<` etc.

@dj2
dj2 merged commit ef51db4 into gpuweb:master Jun 3, 2020
JusSn pushed a commit to JusSn/gpuweb that referenced this pull request Jun 8, 2020
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.
JusSn pushed a commit to JusSn/gpuweb that referenced this pull request Jun 8, 2020
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.
ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wgsl resolved Resolved - waiting for a change to the WGSL specification wgsl WebGPU Shading Language Issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task: Define type rules for binary operations

5 participants