Branchless: Introduce ToBool().

This commit is contained in:
hashlag
2026-08-30 01:51:19 +03:00
parent 72e4803939
commit 7e82f3d01a
3 changed files with 10 additions and 2 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ public:
return return
{ {
.IsOkay_ = static_cast<bool>(isOkay), .IsOkay_ = Branchless::ToBool(isOkay),
.PadSize_ = Branchless::Sel<uint8_t>(isOkay, padSize, 0) .PadSize_ = Branchless::Sel<uint8_t>(isOkay, padSize, 0)
}; };
} }
+1 -1
View File
@@ -66,7 +66,7 @@ public:
return return
{ {
.IsOkay_ = static_cast<bool>(isOkay), .IsOkay_ = Branchless::ToBool(isOkay),
.PadSize_ = Branchless::Sel<uint8_t>(isOkay, padSize, 0) .PadSize_ = Branchless::Sel<uint8_t>(isOkay, padSize, 0)
}; };
} }
+8
View File
@@ -82,6 +82,14 @@ struct Branchless
return (mask & onTrue) | (~mask & onFalse); return (mask & onTrue) | (~mask & onFalse);
} }
template<typename UInt>
static constexpr bool ToBool(UInt mask) noexcept
{
static_assert(std::is_unsigned_v<UInt>);
return Sel<UInt>(mask, 1, 0);
}
}; };
} // namespace Chaos::Service } // namespace Chaos::Service