aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-11-23 17:23:05 -0500
committerJack Lloyd <[email protected]>2018-11-23 17:23:05 -0500
commitae42de8433260a37360d60b0a21665e13c4a63e8 (patch)
treebfd0f583ea2a51639ac21fbc95322fc1f84bf622 /src
parent9baff28bbc23780466b3983aec9ca3bbeb83ec1e (diff)
Implement const time select based on xor-swap
For some compilers this may make the difference between compiling using bitmasks as intendeded, and compiling with a conditional jump.
Diffstat (limited to 'src')
-rw-r--r--src/lib/utils/ct_utils.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/lib/utils/ct_utils.h b/src/lib/utils/ct_utils.h
index 0303d2a6c..63b8f4640 100644
--- a/src/lib/utils/ct_utils.h
+++ b/src/lib/utils/ct_utils.h
@@ -110,7 +110,8 @@ template<typename T>
inline constexpr T select(T mask, T from0, T from1)
{
static_assert(std::is_unsigned<T>::value, "unsigned integer type required");
- return static_cast<T>((from0 & mask) | (from1 & ~mask));
+ //return static_cast<T>((from0 & mask) | (from1 & ~mask));
+ return static_cast<T>(from1 ^ (mask & (from0 ^ from1)));
}
template<typename T>