Skip to content

Commit

Permalink
[WGSL] Constant function for abs is wrong for u32 and f16
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265257
rdar://118724534

Reviewed by Mike Wyrzykowski.

For some reason it was casting u32 to int, when the result should be the identity.
The result type also needs to be explicit, otherwise we return f32 for f16 inputs.

* Source/WebGPU/WGSL/ConstantFunctions.h:
(WGSL::UNARY_OPERATION):

Canonical link: https://commits.webkit.org/271072@main
  • Loading branch information
tadeuzagallo committed Nov 23, 2023
1 parent 342939b commit 25af3c2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/WebGPU/WGSL/ConstantFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,9 @@ CONSTANT_TRIGONOMETRIC(Cosh, cosh);
CONSTANT_TRIGONOMETRIC(Sinh, sinh);
CONSTANT_TRIGONOMETRIC(Tanh, tanh);

UNARY_OPERATION(Abs, Number, [&](auto n) {
UNARY_OPERATION(Abs, Number, [&]<typename T>(T n) -> T {
if constexpr (std::is_same_v<decltype(n), uint32_t>)
return static_cast<uint32_t>(std::abs(static_cast<int32_t>(n)));
return n;
else
return std::abs(n);
});
Expand Down

0 comments on commit 25af3c2

Please sign in to comment.