diff --git a/mem/aarch64/mem_aarch64_dispatcher.c b/mem/aarch64/mem_aarch64_dispatcher.c index a89c97f..6cdcdc8 100644 --- a/mem/aarch64/mem_aarch64_dispatcher.c +++ b/mem/aarch64/mem_aarch64_dispatcher.c @@ -31,11 +31,11 @@ DEFINE_INTERFACE_DISPATCHER(isal_zero_detect) { #if defined(__linux__) - unsigned long auxval = getauxval(AT_HWCAP); - if (auxval & HWCAP_ASIMD) - return PROVIDER_INFO(mem_zero_detect_neon); + unsigned long auxval = getauxval(AT_HWCAP); + if (auxval & HWCAP_ASIMD) + return PROVIDER_INFO(mem_zero_detect_neon); #elif defined(__APPLE__) - return PROVIDER_INFO(mem_zero_detect_neon); + return PROVIDER_INFO(mem_zero_detect_neon); #endif - return PROVIDER_BASIC(mem_zero_detect); + return PROVIDER_BASIC(mem_zero_detect); } diff --git a/mem/mem_zero_detect_base.c b/mem/mem_zero_detect_base.c index 23c7348..d135898 100644 --- a/mem/mem_zero_detect_base.c +++ b/mem/mem_zero_detect_base.c @@ -31,39 +31,40 @@ #include #include "unaligned.h" -int mem_zero_detect_base(void *buf, size_t n) +int +mem_zero_detect_base(void *buf, size_t n) { - uint8_t *c = buf; - uintmax_t a = 0; + uint8_t *c = buf; + uintmax_t a = 0; - // Check buffer in native machine width comparisons - while (n >= sizeof(uintmax_t)) { - n -= sizeof(uintmax_t); - if (load_le_umax(c) != 0) - return -1; - c += sizeof(uintmax_t); - } + // Check buffer in native machine width comparisons + while (n >= sizeof(uintmax_t)) { + n -= sizeof(uintmax_t); + if (load_le_umax(c) != 0) + return -1; + c += sizeof(uintmax_t); + } - // Check remaining bytes - switch (n) { - case 7: - a |= *c++; // fall through to case 6,5,4 - case 6: - a |= *c++; // fall through to case 5,4 - case 5: - a |= *c++; // fall through to case 4 - case 4: - a |= load_le_u32(c); - break; - case 3: - a |= *c++; // fall through to case 2 - case 2: - a |= load_le_u16(c); - break; - case 1: - a |= *c; - break; - } + // Check remaining bytes + switch (n) { + case 7: + a |= *c++; // fall through to case 6,5,4 + case 6: + a |= *c++; // fall through to case 5,4 + case 5: + a |= *c++; // fall through to case 4 + case 4: + a |= load_le_u32(c); + break; + case 3: + a |= *c++; // fall through to case 2 + case 2: + a |= load_le_u16(c); + break; + case 1: + a |= *c; + break; + } - return (a == 0) ? 0 : -1; + return (a == 0) ? 0 : -1; } diff --git a/mem/mem_zero_detect_base_aliases.c b/mem/mem_zero_detect_base_aliases.c index 8c75b06..7eb9555 100644 --- a/mem/mem_zero_detect_base_aliases.c +++ b/mem/mem_zero_detect_base_aliases.c @@ -30,9 +30,11 @@ #include #include "mem_routines.h" -int mem_zero_detect_base(void *buf, size_t n); +int +mem_zero_detect_base(void *buf, size_t n); -int isal_zero_detect(void *mem, size_t len) +int +isal_zero_detect(void *mem, size_t len) { - return mem_zero_detect_base(mem, len); + return mem_zero_detect_base(mem, len); } diff --git a/mem/mem_zero_detect_perf.c b/mem/mem_zero_detect_perf.c index abdc0b0..4c8f9f9 100644 --- a/mem/mem_zero_detect_perf.c +++ b/mem/mem_zero_detect_perf.c @@ -33,27 +33,28 @@ #include "mem_routines.h" #include "test.h" -#define TEST_LEN 8*1024 +#define TEST_LEN 8 * 1024 #define TEST_TYPE_STR "_warm" -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - int val = 0; - void *buf; - struct perf start; + int val = 0; + void *buf; + struct perf start; - printf("Test mem_zero_detect_perf %d bytes\n", TEST_LEN); + printf("Test mem_zero_detect_perf %d bytes\n", TEST_LEN); - if (posix_memalign(&buf, 64, TEST_LEN)) { - printf("alloc error: Fail"); - return -1; - } + if (posix_memalign(&buf, 64, TEST_LEN)) { + printf("alloc error: Fail"); + return -1; + } - memset(buf, 0, TEST_LEN); - BENCHMARK(&start, BENCHMARK_TIME, val |= isal_zero_detect(buf, TEST_LEN)); + memset(buf, 0, TEST_LEN); + BENCHMARK(&start, BENCHMARK_TIME, val |= isal_zero_detect(buf, TEST_LEN)); - printf("mem_zero_detect_perf" TEST_TYPE_STR ": "); - perf_print(start, (long long)TEST_LEN); + printf("mem_zero_detect_perf" TEST_TYPE_STR ": "); + perf_print(start, (long long) TEST_LEN); - return 0; + return 0; } diff --git a/mem/mem_zero_detect_test.c b/mem/mem_zero_detect_test.c index 0e81bd5..ec04712 100644 --- a/mem/mem_zero_detect_test.c +++ b/mem/mem_zero_detect_test.c @@ -34,242 +34,242 @@ #include "mem_routines.h" #include "test.h" -#define TEST_MEM 10*1024*1024 -#define TEST_LEN 8*1024 +#define TEST_MEM 10 * 1024 * 1024 +#define TEST_LEN 8 * 1024 #define RAND_ALIGN 32 -#define BORDER_BYTES (5*RAND_ALIGN + 7) +#define BORDER_BYTES (5 * RAND_ALIGN + 7) #ifndef RANDOMS -# define RANDOMS 2000 +#define RANDOMS 2000 #endif #ifndef TEST_SEED -# define TEST_SEED 0x1234 +#define TEST_SEED 0x1234 #endif -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - int i, j, sign; - long long r, l; - void *buf = NULL; - unsigned char *a; - int failures = 0, ret_neg = 1; + int i, j, sign; + long long r, l; + void *buf = NULL; + unsigned char *a; + int failures = 0, ret_neg = 1; - printf("mem_zero_detect_test %d bytes, %d randoms, seed=0x%x ", TEST_MEM, RANDOMS, - TEST_SEED); - if (posix_memalign(&buf, 64, TEST_MEM)) { - printf("alloc error: Fail"); - return -1; - } + printf("mem_zero_detect_test %d bytes, %d randoms, seed=0x%x ", TEST_MEM, RANDOMS, + TEST_SEED); + if (posix_memalign(&buf, 64, TEST_MEM)) { + printf("alloc error: Fail"); + return -1; + } - srand(TEST_SEED); + srand(TEST_SEED); - // Test full zero buffer - memset(buf, 0, TEST_MEM); - failures = isal_zero_detect(buf, TEST_MEM); + // Test full zero buffer + memset(buf, 0, TEST_MEM); + failures = isal_zero_detect(buf, TEST_MEM); - if (failures) { - printf("Fail large buf test\n"); - goto exit; - } + if (failures) { + printf("Fail large buf test\n"); + goto exit; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - // Test to help memory checkers - for (i = 1; i < 2345; i++) { - uint8_t *newbuf = (uint8_t *) malloc(i); + // Test to help memory checkers + for (i = 1; i < 2345; i++) { + uint8_t *newbuf = (uint8_t *) malloc(i); - if (newbuf == NULL) { - printf("Fail alloc test - not enough memory\n"); - failures = -1; - goto exit; - } - memset(newbuf, 0, i); - failures = isal_zero_detect(newbuf, i); - free(newbuf); - if (failures) { - printf("Fail alloc test\n"); - goto exit; - } - } + if (newbuf == NULL) { + printf("Fail alloc test - not enough memory\n"); + failures = -1; + goto exit; + } + memset(newbuf, 0, i); + failures = isal_zero_detect(newbuf, i); + free(newbuf); + if (failures) { + printf("Fail alloc test\n"); + goto exit; + } + } - // Test small buffers - for (i = 0; i < TEST_LEN; i++) { - failures |= isal_zero_detect(buf, i); - if (failures) { - printf("Fail len=%d\n", i); - goto exit; - } - } + // Test small buffers + for (i = 0; i < TEST_LEN; i++) { + failures |= isal_zero_detect(buf, i); + if (failures) { + printf("Fail len=%d\n", i); + goto exit; + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - // Test small buffers near end of alloc region - a = buf; - for (i = 0; i < TEST_LEN; i++) - failures |= isal_zero_detect(&a[TEST_LEN - i], i); + // Test small buffers near end of alloc region + a = buf; + for (i = 0; i < TEST_LEN; i++) + failures |= isal_zero_detect(&a[TEST_LEN - i], i); - if (failures) { - printf("Fail:\n"); - goto exit; - } + if (failures) { + printf("Fail:\n"); + goto exit; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - // Test for detect non zero - a[TEST_MEM / 2] = 1; - ret_neg = isal_zero_detect(a, TEST_MEM); - if (ret_neg == 0) { - printf("Fail on not detect\n"); - failures = -1; - goto exit; - } - a[TEST_MEM / 2] = 0; + // Test for detect non zero + a[TEST_MEM / 2] = 1; + ret_neg = isal_zero_detect(a, TEST_MEM); + if (ret_neg == 0) { + printf("Fail on not detect\n"); + failures = -1; + goto exit; + } + a[TEST_MEM / 2] = 0; #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - // Test various non-zero offsets - for (i = 0; i < BORDER_BYTES; i++) { - for (j = 0; j < CHAR_BIT; j++) { - a[i] = 1 << j; - ret_neg = isal_zero_detect(a, TEST_MEM); - if (ret_neg == 0) { - printf("Fail on not detect offsets %d, %d\n", i, j); - failures = -1; - goto exit; - } - a[i] = 0; - } - } + // Test various non-zero offsets + for (i = 0; i < BORDER_BYTES; i++) { + for (j = 0; j < CHAR_BIT; j++) { + a[i] = 1 << j; + ret_neg = isal_zero_detect(a, TEST_MEM); + if (ret_neg == 0) { + printf("Fail on not detect offsets %d, %d\n", i, j); + failures = -1; + goto exit; + } + a[i] = 0; + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - fflush(0); + fflush(0); - // Test random non-zero offsets - for (i = 0; i < RANDOMS; i++) { - r = rand(); - r = (r % TEST_LEN) ^ (r & (RAND_ALIGN - 1)); - if (r >= TEST_LEN) - continue; + // Test random non-zero offsets + for (i = 0; i < RANDOMS; i++) { + r = rand(); + r = (r % TEST_LEN) ^ (r & (RAND_ALIGN - 1)); + if (r >= TEST_LEN) + continue; - a[r] = 1 << (r & (CHAR_BIT - 1)); - ret_neg = isal_zero_detect(a, TEST_MEM); - if (ret_neg == 0) { - printf("Fail on not detect rand %d, e=%lld\n", i, r); - failures = -1; - goto exit; - } - a[r] = 0; - } + a[r] = 1 << (r & (CHAR_BIT - 1)); + ret_neg = isal_zero_detect(a, TEST_MEM); + if (ret_neg == 0) { + printf("Fail on not detect rand %d, e=%lld\n", i, r); + failures = -1; + goto exit; + } + a[r] = 0; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - fflush(0); + fflush(0); - // Test putting non-zero byte at end of buffer - for (i = 1; i < BORDER_BYTES; i++) { - for (j = 0; j < CHAR_BIT; j++) { - a[TEST_MEM - i] = 1 << j; - ret_neg = isal_zero_detect(a, TEST_MEM); - if (ret_neg == 0) { - printf("Fail on not detect rand offset=%d, idx=%d\n", i, j); - failures = -1; - goto exit; - } - a[TEST_MEM - i] = 0; - } - } + // Test putting non-zero byte at end of buffer + for (i = 1; i < BORDER_BYTES; i++) { + for (j = 0; j < CHAR_BIT; j++) { + a[TEST_MEM - i] = 1 << j; + ret_neg = isal_zero_detect(a, TEST_MEM); + if (ret_neg == 0) { + printf("Fail on not detect rand offset=%d, idx=%d\n", i, j); + failures = -1; + goto exit; + } + a[TEST_MEM - i] = 0; + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - // Test various size buffers and non-zero offsets - for (l = 1; l < TEST_LEN; l++) { - for (i = 0; i < l + BORDER_BYTES; i++) { - failures = isal_zero_detect(a, l); + // Test various size buffers and non-zero offsets + for (l = 1; l < TEST_LEN; l++) { + for (i = 0; i < l + BORDER_BYTES; i++) { + failures = isal_zero_detect(a, l); - if (failures) { - printf("Fail on detect non-zero with l=%lld\n", l); - goto exit; - } + if (failures) { + printf("Fail on detect non-zero with l=%lld\n", l); + goto exit; + } - a[i] = 1; - ret_neg = isal_zero_detect(a, l); + a[i] = 1; + ret_neg = isal_zero_detect(a, l); - if ((i < l) && (ret_neg == 0)) { - printf("Fail on non-zero buffer l=%lld err=%d\n", l, i); - failures = -1; - goto exit; - } - if ((i >= l) && (ret_neg != 0)) { - printf("Fail on bad pass detect l=%lld err=%d\n", l, i); - failures = -1; - goto exit; - } - a[i] = 0; - } - } + if ((i < l) && (ret_neg == 0)) { + printf("Fail on non-zero buffer l=%lld err=%d\n", l, i); + failures = -1; + goto exit; + } + if ((i >= l) && (ret_neg != 0)) { + printf("Fail on bad pass detect l=%lld err=%d\n", l, i); + failures = -1; + goto exit; + } + a[i] = 0; + } + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - // Test random test size and non-zero error offsets - for (i = 0; i < RANDOMS; i++) { - r = rand(); - r = (r % TEST_LEN) ^ (r & (RAND_ALIGN - 1)); - l = r + 1 + (rand() & (CHAR_BIT - 1)); - a[r] = 1 << (r & (CHAR_BIT - 1)); - ret_neg = isal_zero_detect(a, l); - if (ret_neg == 0) { - printf("Fail on not detect rand %d, l=%lld, e=%lld\n", i, l, r); - failures = -1; - goto exit; - } - a[r] = 0; - } + // Test random test size and non-zero error offsets + for (i = 0; i < RANDOMS; i++) { + r = rand(); + r = (r % TEST_LEN) ^ (r & (RAND_ALIGN - 1)); + l = r + 1 + (rand() & (CHAR_BIT - 1)); + a[r] = 1 << (r & (CHAR_BIT - 1)); + ret_neg = isal_zero_detect(a, l); + if (ret_neg == 0) { + printf("Fail on not detect rand %d, l=%lld, e=%lld\n", i, l, r); + failures = -1; + goto exit; + } + a[r] = 0; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - fflush(0); + fflush(0); - // Test combinations of zero and non-zero buffers - for (i = 0; i < RANDOMS; i++) { - r = rand(); - r = (r % TEST_LEN) ^ (r & (RAND_ALIGN - 1)); - sign = rand() & 1 ? 1 : -1; - l = r + sign * (rand() & (2 * RAND_ALIGN - 1)); + // Test combinations of zero and non-zero buffers + for (i = 0; i < RANDOMS; i++) { + r = rand(); + r = (r % TEST_LEN) ^ (r & (RAND_ALIGN - 1)); + sign = rand() & 1 ? 1 : -1; + l = r + sign * (rand() & (2 * RAND_ALIGN - 1)); - if ((l >= TEST_LEN) || (l < 0) || (r >= TEST_LEN)) - continue; + if ((l >= TEST_LEN) || (l < 0) || (r >= TEST_LEN)) + continue; - a[r] = 1 << (r & (CHAR_BIT - 1)); - ret_neg = isal_zero_detect(a, l); + a[r] = 1 << (r & (CHAR_BIT - 1)); + ret_neg = isal_zero_detect(a, l); - if ((r < l) && (ret_neg == 0)) { - printf("Fail on non-zero rand buffer %d, l=%lld, e=%lld\n", i, l, r); - failures = -1; - goto exit; - } - if ((r >= l) && (ret_neg != 0)) { - printf("Fail on bad pass zero detect rand %d, l=%lld, e=%lld\n", i, l, - r); - failures = -1; - goto exit; - } + if ((r < l) && (ret_neg == 0)) { + printf("Fail on non-zero rand buffer %d, l=%lld, e=%lld\n", i, l, r); + failures = -1; + goto exit; + } + if ((r >= l) && (ret_neg != 0)) { + printf("Fail on bad pass zero detect rand %d, l=%lld, e=%lld\n", i, l, r); + failures = -1; + goto exit; + } - a[r] = 0; - } + a[r] = 0; + } #ifdef TEST_VERBOSE - putchar('.'); + putchar('.'); #endif - fflush(0); + fflush(0); - exit: - aligned_free(buf); - printf(failures == 0 ? " Pass\n" : " Fail\n"); - return failures; +exit: + aligned_free(buf); + printf(failures == 0 ? " Pass\n" : " Fail\n"); + return failures; }