diff options
author | lloyd <[email protected]> | 2013-06-13 01:29:39 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2013-06-13 01:29:39 +0000 |
commit | fbcff1ecf40ad4014f474e1dc9691c9895137d52 (patch) | |
tree | ed302c5a84750f5df52287bba1ec2d4d098dd3bf | |
parent | 195a1434006e288416886960e9cf9e81d49e0a58 (diff) |
Change same_mem to use XORs instead of equality operators.
Potentially less prone to optimizer trickery wrt early exits,
especially as it encourages a SIMD approach which modern compilers
tend to prefer if they think they can get away with it.
-rw-r--r-- | src/utils/mem_ops.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/utils/mem_ops.h b/src/utils/mem_ops.h index 92a130310..be617ff19 100644 --- a/src/utils/mem_ops.h +++ b/src/utils/mem_ops.h @@ -62,12 +62,12 @@ inline void set_mem(T* ptr, size_t n, byte val) */ template<typename T> inline bool same_mem(const T* p1, const T* p2, size_t n) { - bool is_same = true; + volatile T difference = 0; for(size_t i = 0; i != n; ++i) - is_same &= (p1[i] == p2[i]); + difference |= (p1[i] ^ p2[i]); - return is_same; + return difference == 0; } } |