Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpSRem is converted to MSL as an unsigned operation #2396

Closed
giomasce opened this issue Oct 19, 2024 · 0 comments · Fixed by #2397
Closed

OpSRem is converted to MSL as an unsigned operation #2396

giomasce opened this issue Oct 19, 2024 · 0 comments · Fixed by #2397

Comments

@giomasce
Copy link

giomasce commented Oct 19, 2024

Consider the attached shader, which has a OpSRem operation. When converted to MSL it becomes:

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct push_cb_struct
{
    float4 cb0[1];
};

struct main0_out
{
    float4 o0 [[color(0)]];
};

fragment main0_out main0(constant push_cb_struct& push_cb [[buffer(0)]])
{
    main0_out out = {};
    float _25 = precise::max(push_cb.cb0[0u].x, -2147483648.0);
    uint _32 = isnan(push_cb.cb0[0u].x) ? 0u : ((_25 >= 2147483648.0) ? 2147483647u : uint(int(_25)));
    float _34 = precise::max(push_cb.cb0[0u].y, -2147483648.0);
    uint _39 = isnan(push_cb.cb0[0u].y) ? 0u : ((_34 >= 2147483648.0) ? 2147483647u : uint(int(_34)));
    out.o0.x = float(int((_39 != 0u) ? (_32 - _39 * (_32 / _39)) : 4294967295u));
    out.o0.y = 0.0;
    out.o0.z = 0.0;
    out.o0.w = 0.0;
    float4 r0;
    return out;
}

The remainder operation is executed as unsigned instead of signed, which means that it is incorrect for negative numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant