mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 07:06:11 +00:00
writer/hlsl: Special case negative zero
Fixed: tint:960 Change-Id: I04de8713fe299607f32fd93288a22b75a9dff381 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58760 Reviewed-by: Ben Clayton <bclayton@chromium.org> Reviewed-by: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
c6a73298c4
commit
efceb83536
@@ -2502,13 +2502,20 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, ast::Literal* lit) {
|
||||
if (auto* l = lit->As<ast::BoolLiteral>()) {
|
||||
out << (l->IsTrue() ? "true" : "false");
|
||||
} else if (auto* fl = lit->As<ast::FloatLiteral>()) {
|
||||
if (std::isinf(fl->value())) {
|
||||
out << (fl->value() >= 0 ? "asfloat(0x7f800000u)"
|
||||
: "asfloat(0xff800000u)");
|
||||
} else if (std::isnan(fl->value())) {
|
||||
out << "asfloat(0x7fc00000u)";
|
||||
} else {
|
||||
out << FloatToString(fl->value()) << "f";
|
||||
bool positive = !std::signbit(fl->value());
|
||||
switch (std::fpclassify(fl->value())) {
|
||||
case FP_INFINITE:
|
||||
out << (positive ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)");
|
||||
break;
|
||||
case FP_NAN:
|
||||
out << "asfloat(0x7fc00000u)";
|
||||
break;
|
||||
case FP_ZERO:
|
||||
out << (positive ? "0.0f" : "asfloat(0x80000000u)");
|
||||
break;
|
||||
default:
|
||||
out << FloatToString(fl->value()) << "f";
|
||||
break;
|
||||
}
|
||||
} else if (auto* sl = lit->As<ast::SintLiteral>()) {
|
||||
out << sl->value();
|
||||
|
||||
Reference in New Issue
Block a user