1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-26 03:29:40 +00:00

This is the same test either way around.

This commit is contained in:
Thomas Harte
2023-10-09 16:47:02 -04:00
parent 1cb26cb141
commit e46e42d896
4 changed files with 50 additions and 57 deletions
+9 -16
View File
@@ -11,7 +11,7 @@
namespace Numeric {
/// @returns @c true if there, from @c bit there was
/// @returns @c true if from @c bit there was:
/// • carry after calculating @c lhs + @c rhs if @c is_add is true; or
/// • borrow after calculating @c lhs - @c rhs if @c is_add is false;
/// producing @c result.
@@ -30,21 +30,14 @@ template <bool is_add, int bit, typename IntT> bool carried_out(IntT lhs, IntT r
}
}
// ~carried_out<>(d, ~s, r)
/// @returns @c true if there was carry into @c bit when @c source1 and @c source2 were added, producing @c result.
template <bool is_add, int bit, typename IntT> bool carried_in(IntT lhs, IntT rhs, IntT result) {
// 0 and 0 or 1 and 1 => did if 1
// 0 and 1 or 1 and 0 => did if 0
if constexpr (!is_add) {
rhs = ~rhs;
}
const bool carry = IntT(1 << bit) & (lhs ^ rhs ^ result);
if constexpr (!is_add) {
return !carry;
} else {
return carry;
}
/// @returns @c true if there was carry into @c bit when computing either:
/// • @c lhs + @c rhs; or
/// • @c lhs - @c rhs;
/// producing @c result.
template <int bit, typename IntT> bool carried_in(IntT lhs, IntT rhs, IntT result) {
// 0 and 0 or 1 and 1 => did if 1.
// 0 and 1 or 1 and 0 => did if 0.
return IntT(1 << bit) & (lhs ^ rhs ^ result);
}
}