cutils: Add test for buffer_is_zero
Signed-off-by: Richard Henderson <rth@twiddle.net>
Message-Id: <1472496380-19706-6-git-send-email-rth@twiddle.net>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/util/bufferiszero.c b/util/bufferiszero.c
index a3a842f..4af3caa 100644
--- a/util/bufferiszero.c
+++ b/util/bufferiszero.c
@@ -162,6 +162,19 @@
cpuid_cache = cache;
}
+#define HAVE_NEXT_ACCEL
+bool test_buffer_is_zero_next_accel(void)
+{
+ /* If no bits set, we just tested buffer_zero_int, and there
+ are no more acceleration options to test. */
+ if (cpuid_cache == 0) {
+ return false;
+ }
+ /* Disable the accelerator we used before and select a new one. */
+ cpuid_cache &= cpuid_cache - 1;
+ return true;
+}
+
static bool select_accel_fn(const void *buf, size_t len)
{
uintptr_t ibuf = (uintptr_t)buf;
@@ -180,6 +193,13 @@
#define select_accel_fn buffer_zero_int
#endif
+#ifndef HAVE_NEXT_ACCEL
+bool test_buffer_is_zero_next_accel(void)
+{
+ return false;
+}
+#endif
+
/*
* Checks if a buffer is all zeroes
*/