Sitelet https://github.com/gpuweb/gpuweb/issues/707
Skip to content

Rule for mixed-signedness operands to integer div, rem, less-than, greater-than, less-or-equal, greater-or-equal #707

Description

@dneto0

In SPIR-V the rule on integer operations is that the signedness-semantics is determined by the opcode, not the signedness of the type of the operands

This is why, for example, it has both OpSLessThan, OpULessThan (for scalar integer values %a and %b of the same bit width):

  • %result = OpSLessThan %bool %a %b
    • Ignore the signedness of operands %a and %b compare them as if they are both signed.
  • %result = OpULessThan %bool %a %b
    • Ignore the signedness of operands %a and %b compare them as if they are both unsigned.

Similarly, there are "U" and "S" variants for Div, Rem, > , <=, >=

I think we might have touched on this issue in an earlier meeting but I don't recall a firm resolution or record in the WGSL spec.

I think the favoured option was:

  • For these binary operations, it's only valid to have operands with consistent signedness. The programmer has to insert bit-level (reinterpretation) "as" casts in order to achieve signedness-consistency.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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