summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authortuexen <tuexen@FreeBSD.org>2017-06-01 09:00:38 +0000
committertuexen <tuexen@FreeBSD.org>2017-06-01 09:00:38 +0000
commit2f7fd785bc7cf75ead8ffac67a74edeb62c7d0c7 (patch)
treefd124a7e73656e650bf6662869bc348476d31ff6 /tests
parente6c0f4792f47e2613dbb38acb329c8f57dd3bbab (diff)
downloadFreeBSD-src-2f7fd785bc7cf75ead8ffac67a74edeb62c7d0c7.zip
FreeBSD-src-2f7fd785bc7cf75ead8ffac67a74edeb62c7d0c7.tar.gz
MFC r317512:
armv8 has support for optional CRC32C instructions. This patch checks if they are available and if that is true make use of them. Thank you very much to Andrew Turner for providing help and review the patch! Reviewed by: andrew Differential Revision: https://reviews.freebsd.org/D10499
Diffstat (limited to 'tests')
-rw-r--r--tests/sys/kern/Makefile8
-rw-r--r--tests/sys/kern/libkern_crc32.c19
2 files changed, 26 insertions, 1 deletions
diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
index d78785c..35cc8c7 100644
--- a/tests/sys/kern/Makefile
+++ b/tests/sys/kern/Makefile
@@ -25,10 +25,16 @@ NETBSD_ATF_TESTS_C+= mqueue_test
CFLAGS.mqueue_test+= -I${SRCTOP}/tests
LIBADD.mqueue_test+= rt
-.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
+.if ${MACHINE_ARCH} == "amd64" || \
+ ${MACHINE_ARCH} == "i386" || \
+ ${MACHINE_ARCH} == "aarch64"
ATF_TESTS_C+= libkern_crc32
CFLAGS.libkern_crc32+= -msse4 -DUSERSPACE_TESTING
+.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
LDADD.libkern_crc32+= ${SRCTOP}/sys/libkern/x86/crc32_sse42.c
+.else
+LDADD.libkern_crc32+= ${SRCTOP}/sys/libkern/arm64/crc32c_armv8.S
+.endif
.endif
# subr_unit.c contains functions whose prototypes lie in headers that cannot be
diff --git a/tests/sys/kern/libkern_crc32.c b/tests/sys/kern/libkern_crc32.c
index 5eef045..03d0231 100644
--- a/tests/sys/kern/libkern_crc32.c
+++ b/tests/sys/kern/libkern_crc32.c
@@ -32,7 +32,13 @@
#include <atf-c.h>
+#if defined(__amd64__) || defined(__i386__)
extern uint32_t sse42_crc32c(uint32_t, const unsigned char *, unsigned);
+#elif defined(__aarch64__)
+extern uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned);
+#else
+#error These tests are not supported on this platform
+#endif
ATF_TC_WITHOUT_HEAD(crc32c_basic_correctness);
ATF_TC_BODY(crc32c_basic_correctness, tc)
@@ -79,8 +85,13 @@ ATF_TC_BODY(crc32c_basic_correctness, tc)
ATF_REQUIRE(nitems(inputs) == nitems(results));
for (i = 0; i < nitems(inputs); i++) {
+#if defined(__amd64__) || defined(__i386__)
act = sse42_crc32c(~0, (const void *)&inputs[i],
sizeof(inputs[0]));
+#else
+ act = armv8_crc32c(~0, (const void *)&inputs[i],
+ sizeof(inputs[0]));
+#endif
ATF_REQUIRE_MSG(act == results[i],
"crc32c(0x%jx) = 0x%08x, got 0x%08x", (uintmax_t)inputs[i],
results[i], act);
@@ -100,7 +111,11 @@ ATF_TC_BODY(crc32c_alignment, tc)
for (i = 1; i < 8; i++) {
memcpy(&buf[i], &input, sizeof(input));
+#if defined(__amd64__) || defined(__i386__)
act = sse42_crc32c(~0, (const void *)&buf[i], sizeof(input));
+#else
+ act = armv8_crc32c(~0, (const void *)&buf[i], sizeof(input));
+#endif
ATF_REQUIRE_MSG(act == result,
"crc32c(0x%jx) = 0x%08x, got 0x%08x", (uintmax_t)input,
result, act);
@@ -117,7 +132,11 @@ ATF_TC_BODY(crc32c_trailing_bytes, tc)
const uint32_t result = 0xec638d62;
uint32_t act;
+#if defined(__amd64__) || defined(__i386__)
act = sse42_crc32c(~0, input, sizeof(input));
+#else
+ act = armv8_crc32c(~0, input, sizeof(input));
+#endif
ATF_REQUIRE_MSG(act == result, "expected 0x%08x, got 0x%08x", result,
act);
}
OpenPOWER on IntegriCloud