From a48be0b5d74935531bdbd4737dcd15b1ce5282b2 Mon Sep 17 00:00:00 2001 From: Kamila Szewczyk Date: Tue, 15 Oct 2024 13:32:40 +0200 Subject: [PATCH] aarch64: include feature test in crc32c, add asm unit to makefile. --- Makefile.am | 4 ++++ configure.ac | 9 +++++++++ crc32c.c | 16 +++++++++++++--- xpar-aarch64.asm => xpar-aarch64.S | 3 --- 4 files changed, 26 insertions(+), 6 deletions(-) rename xpar-aarch64.asm => xpar-aarch64.S (94%) diff --git a/Makefile.am b/Makefile.am index ced1432..9206978 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,6 +10,10 @@ SUFFIXES = .asm $(NASM) $(NAFLAGS) -o $@ $< endif +if XPAR_AARCH64 +xpar_SOURCES += xpar-aarch64.S +endif + # Developer convenience targets .PHONY: update-ChangeLog update-ChangeLog: diff --git a/configure.ac b/configure.ac index 33d4c41..2e4e773 100644 --- a/configure.ac +++ b/configure.ac @@ -34,6 +34,15 @@ else AM_CONDITIONAL([XPAR_X86_64], [false]) fi +AC_ARG_ENABLE([aarch64], [AS_HELP_STRING([--enable-aarch64], [Enable aarch64 platform specific code.])], [enable_aarch64=$enableval], [enable_aarch64=no]) +if test "x$enable_aarch64" = "xyes"; then + AC_DEFINE([XPAR_AARCH64], [1], [Enable aarch64 platform specific code.]) + AM_CONDITIONAL([XPAR_AARCH64], [true]) + AM_PROG_AS +else + AM_CONDITIONAL([XPAR_AARCH64], [false]) +fi + AC_ARG_ENABLE([native], [AS_HELP_STRING([--enable-native], [Enable native platform optimisations.])], [enable_native=$enableval], [enable_native=no]) if test "x$enable_native" = "xyes"; then AX_APPEND_COMPILE_FLAGS([-march=native -mtune=native]) diff --git a/crc32c.c b/crc32c.c index 047d850..fa1776b 100644 --- a/crc32c.c +++ b/crc32c.c @@ -89,26 +89,36 @@ u32 crc32c_tabular(u32 crc, u8 * data, sz length) { return crc; } +typedef u32 (*crc32c_func)(u32, u8 *, sz); + #if defined(XPAR_X86_64) #ifdef HAVE_FUNC_ATTRIBUTE_SYSV_ABI #define EXTERNAL_ABI __attribute__((sysv_abi)) #else #define EXTERNAL_ABI #endif - - typedef u32 (*crc32c_func)(u32, u8 *, sz); + extern EXTERNAL_ABI int crc32c_x86_64_cpuflags(void); extern EXTERNAL_ABI u32 crc32c_small_x86_64_sse42(u32, u8 *, sz); +#elif defined(XPAR_AARCH64) + extern int crc32c_aarch64_cpuflags(void); + extern u32 crc32c_small_aarch64_neon(u32, u8 *, sz); #endif u32 crc32c(u8 * data, sz length) { -#if defined(XPAR_X86_64) static int cpuflags = -1; +#if defined(XPAR_X86_64) if (cpuflags == -1) cpuflags = crc32c_x86_64_cpuflags(); if (cpuflags & 1) return crc32c_small_x86_64_sse42(0xFFFFFFFFL, data, length) ^ 0xFFFFFFFFL; else return crc32c_tabular(0xFFFFFFFFL, data, length) ^ 0xFFFFFFFFL; +#elif defined(XPAR_AARCH64) + if (cpuflags == -1) cpuflags = crc32c_aarch64_cpuflags(); + if (cpuflags) + return crc32c_small_aarch64_neon(0xFFFFFFFFL, data, length) ^ 0xFFFFFFFFL; + else + return crc32c_tabular(0xFFFFFFFFL, data, length) ^ 0xFFFFFFFFL; #else return crc32c_tabular(0xFFFFFFFFL, data, length) ^ 0xFFFFFFFFL; #endif diff --git a/xpar-aarch64.asm b/xpar-aarch64.S similarity index 94% rename from xpar-aarch64.asm rename to xpar-aarch64.S index 9eb9862..18f524b 100644 --- a/xpar-aarch64.asm +++ b/xpar-aarch64.S @@ -12,9 +12,6 @@ along with this program. If not, see . */ -/* TODO: CPU support checks, merging this into crc32c.c and the build - system. Unsure how to do all that right now. */ - .section .text .extern getauxval