Skip to content

Commit

Permalink
aarch64: include feature test in crc32c, add asm unit to makefile.
Browse files Browse the repository at this point in the history
  • Loading branch information
kspalaiologos committed Oct 15, 2024
1 parent 7bd8357 commit a48be0b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
16 changes: 13 additions & 3 deletions crc32c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions xpar-aarch64.asm → xpar-aarch64.S
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* 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

Expand Down

0 comments on commit a48be0b

Please sign in to comment.