Commit 8c12f564 by Sean Risser

Fix unsigned "less than zero" comparison

From the SPIR-V spec: OpSMod's result is the remainder r of Operand 1 divided by Operand 2 where if r != 0, the sign of r is the same as the sign of Operand 2. The less than comparison here was trying to correct the cases where C's modulo had a different sign than SPIR-V's modulo. We can solve this by directly comparing the sign of the C modulo against Operand 2's sign. Bug chromium:973848 Change-Id: I27c88b7aaed35db5ba4df2cc0aac6061098f32c4 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/32868Tested-by: 's avatarSean Risser <srisser@google.com> Presubmit-Ready: Sean Risser <srisser@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 5d73f03b
...@@ -6103,10 +6103,10 @@ namespace sw ...@@ -6103,10 +6103,10 @@ namespace sw
case spv::OpSMod: case spv::OpSMod:
if (r == 0) r = UINT32_MAX; if (r == 0) r = UINT32_MAX;
if (l == static_cast<uint32_t>(INT32_MIN)) l = UINT32_MAX; if (l == static_cast<uint32_t>(INT32_MIN)) l = UINT32_MAX;
if (l * r < 0) // Test if a signed-multiply would be negative.
v = static_cast<int32_t>(l) % static_cast<int32_t>(r) + r; v = static_cast<int32_t>(l) % static_cast<int32_t>(r);
else if ((v & 0x80000000) != (r & 0x80000000))
v = static_cast<int32_t>(l) % static_cast<int32_t>(r); v += r;
break; break;
case spv::OpShiftRightLogical: case spv::OpShiftRightLogical:
v = l >> r; v = l >> r;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment