diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d3298c..241858d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ if (NANOBENCH_STANDALONE_PROJECT) # we have to globally set the property here, so it actually works https://cmake.org/pipermail/cmake/2010-March/036020.html set_source_files_properties( - src/test/tutorial_fast_v1.cpp + src/test/tutorial_fast_v1.cpp src/test/tutorial_fast_v2.cpp PROPERTIES COMPILE_FLAGS "-fno-sanitize=integer") diff --git a/src/include/nanobench.h b/src/include/nanobench.h index 39b0a7e..27df08f 100644 --- a/src/include/nanobench.h +++ b/src/include/nanobench.h @@ -2404,6 +2404,14 @@ class LinuxPerformanceCounters { return (a + divisor / 2) / divisor; } + ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined") + static inline uint32_t mix(uint32_t x) noexcept { + x ^= x << 13; + x ^= x >> 17; + x ^= x << 5; + return x; + } + template ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined") void calibrate(Op&& op) { @@ -2443,15 +2451,10 @@ class LinuxPerformanceCounters { uint64_t const numIters = 100000U + (std::random_device{}() & 3); uint64_t n = numIters; uint32_t x = 1234567; - auto fn = [&]() { - x ^= x << 13; - x ^= x >> 17; - x ^= x << 5; - }; beginMeasure(); while (n-- > 0) { - fn(); + x = mix(x); } endMeasure(); detail::doNotOptimizeAway(x); @@ -2461,8 +2464,8 @@ class LinuxPerformanceCounters { beginMeasure(); while (n-- > 0) { // we now run *twice* so we can easily calculate the overhead - fn(); - fn(); + x = mix(x); + x = mix(x); } endMeasure(); detail::doNotOptimizeAway(x); diff --git a/src/scripts/all.sh b/src/scripts/all.sh index 5094c04..3436aa1 100755 --- a/src/scripts/all.sh +++ b/src/scripts/all.sh @@ -25,7 +25,7 @@ function build() { ${NICE} cmake --build . rm -f ubsan.log* - UBSAN_OPTIONS=print_stacktrace=1:log_path=ubsan.log:suppressions=${ROOTDIR}/ubsan.supp ${NICE} ./nb + UBSAN_OPTIONS=print_stacktrace=1:log_path=ubsan.log:suppressions=${ROOTDIR}/ubsan.supp ./nb if ls ubsan.log* 1> /dev/null 2>&1; then cat ubsan.log* exit 1 diff --git a/src/test/example_random_number_generators.cpp b/src/test/example_random_number_generators.cpp index b57854b..4f8b94f 100644 --- a/src/test/example_random_number_generators.cpp +++ b/src/test/example_random_number_generators.cpp @@ -9,7 +9,7 @@ # if defined(__GNUC__) || defined(__clang__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wpedantic" - using uint128_t = unsigned __int128; +using uint128_t = unsigned __int128; # pragma GCC diagnostic pop # endif #elif (defined(_MSC_VER) && SIZE_MAX == UINT64_MAX) @@ -99,6 +99,7 @@ class NasamRng { NasamRng(uint64_t seed) noexcept : mState(seed) {} + ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined") uint64_t operator()() noexcept { auto x = mState++; @@ -115,6 +116,7 @@ class NasamRng { private: // rotate right template + ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined") static T rotr(T x, size_t k) { return (x >> k) | (x << (8U * sizeof(T) - k)); } @@ -143,6 +145,7 @@ class Sfc4 { } } + ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined") uint64_t operator()() noexcept { uint64_t tmp = mA + mB + mCounter++; mA = mB ^ (mB >> 11U); @@ -152,6 +155,7 @@ class Sfc4 { } private: + ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined") static constexpr uint64_t rotl(uint64_t x, unsigned k) noexcept { return (x << k) | (x >> (64U - k)); } @@ -193,6 +197,7 @@ class RomuTrio { } private: + ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined") static constexpr uint64_t rotl(uint64_t x, unsigned k) noexcept { return (x << k) | (x >> (64U - k)); } @@ -229,6 +234,7 @@ class RomuDuo { } private: + ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined") static constexpr uint64_t rotl(uint64_t x, unsigned k) noexcept { return (x << k) | (x >> (64U - k)); } @@ -266,6 +272,7 @@ class RomuDuoJr { } private: + ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined") static constexpr uint64_t rotl(uint64_t x, unsigned k) noexcept { return (x << k) | (x >> (64U - k)); } diff --git a/src/test/unit_romutrio.cpp b/src/test/unit_romutrio.cpp index 62ea36d..8a05c65 100644 --- a/src/test/unit_romutrio.cpp +++ b/src/test/unit_romutrio.cpp @@ -3,6 +3,7 @@ namespace { +ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined") constexpr uint64_t rotl(uint64_t x, unsigned k) noexcept { return (x << k) | (x >> (64U - k)); } diff --git a/ubsan.supp b/ubsan.supp index a70cdaa..39304d9 100644 --- a/ubsan.supp +++ b/ubsan.supp @@ -1,5 +1,8 @@ +# https://github.com/gcc-mirror/gcc/blob/master/libsanitizer/ubsan/ubsan_checks.inc implicit-integer-sign-change:random.tcc signed-integer-overflow:random.tcc unsigned-integer-overflow:random.tcc +shift-base:random.tcc +shift-exponent:random.tcc unsigned-integer-overflow:random.h unsigned-integer-overflow:example_random_number_generators.cpp