#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <ctype.h>
#include <math.h>
#include <sched.h>
return static_cast<uint64_t>(t.tv_sec) * NS_PER_SEC + t.tv_nsec;
}
+// Static analyzer warns about potential memory leak of orig_ptr
+// in getAlignedMemory. That is true and the callers in this program
+// do not free orig_ptr. But, we don't care about that in this
+// going-obsolete test program. So, here is a hack to trick the
+// static analyzer.
+static void *saved_orig_ptr;
+
// Allocate memory with a specific alignment and return that pointer.
// This function assumes an alignment value that is a power of 2.
// If the alignment is 0, then use the pointer returned by malloc.
uint8_t *getAlignedMemory(uint8_t *orig_ptr, int alignment, int or_mask) {
uint64_t ptr = reinterpret_cast<uint64_t>(orig_ptr);
+ saved_orig_ptr = orig_ptr;
if (alignment > 0) {
// When setting the alignment, set it to exactly the alignment chosen.
// The pointer returned will be guaranteed not to be aligned to anything
return 0;
}
-int benchmarkCpu(const char* /*name*/, const command_data_t &cmd_data, void_func_t /*func*/) {
- // Use volatile so that the loop is not optimized away by the compiler.
- volatile int cpu_foo;
-
- MAINLOOP(cmd_data,
- for (cpu_foo = 0; cpu_foo < 100000000; cpu_foo++),
- (double)time_ns/NS_PER_SEC,
- printf("cpu took %.06f seconds\n", avg),
- printf(" cpu average %.06f seconds std dev %f min %0.6f seconds max %0.6f seconds\n", \
- running_avg, computeStdDev(square_avg, running_avg), min, max));
-
- return 0;
-}
-
int benchmarkMemset(const char *name, const command_data_t &cmd_data, void_func_t func) {
memset_func_t memset_func = reinterpret_cast<memset_func_t>(func);
BENCH_ONE_BUF(name, cmd_data, ;, memset_func(buf, i, size));
return 0;
}
+int benchmarkMemmoveBackwards(const char *name, const command_data_t &cmd_data, void_func_t func) {
+ memcpy_func_t memmove_func = reinterpret_cast<memcpy_func_t>(func);
+
+ size_t size = cmd_data.args[0];
+ size_t alloc_size = size * 2 + 3 * cmd_data.dst_align;
+ uint8_t* src = allocateAlignedMemory(size, cmd_data.src_align, cmd_data.src_or_mask);
+ if (!src)
+ return -1;
+ // Force memmove to do a backwards copy by getting a pointer into the source buffer.
+ uint8_t* dst = getAlignedMemory(src+1, cmd_data.dst_align, cmd_data.dst_or_mask);
+ if (!dst)
+ return -1;
+ MAINLOOP_DATA(name, cmd_data, size, memmove_func(dst, src, size));
+ return 0;
+}
+
int benchmarkMemread(const char *name, const command_data_t &cmd_data, void_func_t /*func*/) {
int size = cmd_data.args[0];
size_t k;
MAINLOOP_DATA(name, cmd_data, size,
for (k = 0; k < size/sizeof(uint32_t); k++) foo = src[k]);
+ free(src);
return 0;
}
// Create the mapping structure.
function_t function_table[] = {
- { "cpu", benchmarkCpu, NULL },
{ "memcpy", benchmarkMemcpy, reinterpret_cast<void_func_t>(memcpy) },
{ "memcpy_cold", benchmarkMemcpyCold, reinterpret_cast<void_func_t>(memcpy) },
+ { "memmove_forward", benchmarkMemcpy, reinterpret_cast<void_func_t>(memmove) },
+ { "memmove_backward", benchmarkMemmoveBackwards, reinterpret_cast<void_func_t>(memmove) },
{ "memread", benchmarkMemread, NULL },
{ "memset", benchmarkMemset, reinterpret_cast<void_func_t>(memset) },
{ "memset_cold", benchmarkMemsetCold, reinterpret_cast<void_func_t>(memset) },