diff --git a/MicroBenchmarks/LoopVectorization/RuntimeChecks.cpp b/MicroBenchmarks/LoopVectorization/RuntimeChecks.cpp --- a/MicroBenchmarks/LoopVectorization/RuntimeChecks.cpp +++ b/MicroBenchmarks/LoopVectorization/RuntimeChecks.cpp @@ -4,6 +4,8 @@ #include "benchmark/benchmark.h" +#define ITERATIONS 1000000000 + static std::mt19937 rng; // Initialize array A with random numbers. @@ -126,3 +128,25 @@ } } BENCHMARK(benchVecWithRuntimeChecks4PointersDAfterA)->Arg(32)->Arg(1000); + +// Convert each vector element from T to int8_t in a vectorized loop +template static void vecWithRuntimeChecksofTruncVecInLoop(T *A, const uint8_t *B, int iterations) { + for (unsigned i = 0; i < iterations; i++) { + A[i] = B[i]; + } +} + +void benchVecWithRuntimeChecksofTruncVeci64InLoop(benchmark::State &state) { + std::unique_ptr A(new uint64_t[ITERATIONS]); + std::unique_ptr B(new uint8_t[ITERATIONS]); + init_data(A, ITERATIONS); + init_data(B, ITERATIONS); + vecWithRuntimeChecksofTruncVecInLoop(&A[0], &B[0], ITERATIONS); + for (auto _ : state) { + benchmark::DoNotOptimize(A); + benchmark::DoNotOptimize(B); + benchmark::ClobberMemory(); + vecWithRuntimeChecksofTruncVecInLoop(&A[0], &B[0], ITERATIONS); + } +} +BENCHMARK(benchVecWithRuntimeChecksofTruncVeci64InLoop);