这是indexloc提供的服务,不要输入任何密码
Skip to content

Define behavior of negative shifts #827

@pow2clk

Description

@pow2clk

The behavior of a shift operation when the right operand indicating the amount to shift is negative is somewhat vague in many languages. This issue is of concern regardless of whether the shift is arithmetic or logical.

Options as I see them include:

  1. Reverse the direction of the shift
  2. Treat all right operands as unsigned
  3. produce an error negative shifts

Option 1 might give unexpected results and introduces the weird situation where a left shift might become a right shift, which introduces the arithmetic or logical shift issue. If arithmetic right shifts are limited to signed values, as might end up being the case, but left shifts are open to unsigned, this could be a back door method of applying an arithmetic shift to an unsigned value.
Option 2 eliminates the negative shift problem, but whenever a negative value is encountered, we'll be getting an overshift, which just passes the buck into another issue.
Option 3 is perfectly fine to produce a compile error when the right side is a literal, but if it's a variable, the error has to be runtime, which is often not very convenient in shading languages.

Metadata

Metadata

Assignees

Labels

wgslWebGPU Shading Language Issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions