Skip to content

Commit

Permalink
nasty kludge for msabi
Browse files Browse the repository at this point in the history
  • Loading branch information
kspalaiologos committed Oct 14, 2024
1 parent 9f073f9 commit fcac412
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
9 changes: 8 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ if test "x$enable_x86_64" = "xyes"; then
AC_DEFINE([XPAR_X86_64], [1], [Enable x86_64 platform specific code.])
AM_CONDITIONAL([XPAR_X86_64], [true])
AX_PROG_NASM
AX_GCC_FUNC_ATTRIBUTE([sysv_abi])

# Check if the target platform is Windows specifically.
# It needs a large amount of nasty kludges to work.
case "$target_os" in
*cygwin* | *mingw* | *windows*)
AC_DEFINE([XPAR_WINDOWS], [1], [Set if compiling on Windows.])
;;
esac
else
AM_CONDITIONAL([XPAR_X86_64], [false])
fi
Expand Down
14 changes: 6 additions & 8 deletions crc32c.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,21 @@ u32 crc32c_tabular(u32 crc, u8 * data, sz length) {
}

#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);
extern int crc32c_x86_64_cpuflags(void);
extern u32 crc32c_small_x86_64_sse42(u32, u8 *, sz);
#endif

u32 crc32c(u8 * data, sz length) {
#if defined(XPAR_X86_64)
static int cpuflags = -1;
if (cpuflags == -1) cpuflags = crc32c_x86_64_cpuflags();
if (cpuflags & 1)
#if defined(XPAR_WINDOWS)
return crc32c_small_x86_64_sse42_msabi(0xFFFFFFFFL, data, length) ^ 0xFFFFFFFFL;
#else
return crc32c_small_x86_64_sse42(0xFFFFFFFFL, data, length) ^ 0xFFFFFFFFL;
#endif
else
return crc32c_tabular(0xFFFFFFFFL, data, length) ^ 0xFFFFFFFFL;
#else
Expand Down
16 changes: 8 additions & 8 deletions m4/ax_prog_nasm.m4
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ AC_DEFUN([AX_PROG_NASM],[
AC_CHECK_PROGS(NASM, [nasm nasmw yasm])
test -z "$NASM" && AC_MSG_ERROR([no nasm (Netwide Assembler) found])
AC_MSG_CHECKING([for object file format of host system])
case "$host_os" in
AC_MSG_CHECKING([for object file format of target system])
case "$target_os" in
cygwin* | mingw* | pw32* | interix*)
case "$host_cpu" in
case "$target_cpu" in
x86_64 | amd64)
objfmt='Win64-COFF'
;;
Expand All @@ -31,7 +31,7 @@ case "$host_os" in
objfmt='a.out'
;;
linux*)
case "$host_cpu" in
case "$target_cpu" in
x86_64 | amd64)
objfmt='ELF64'
;;
Expand All @@ -44,7 +44,7 @@ case "$host_os" in
if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
objfmt='BSD-a.out'
else
case "$host_cpu" in
case "$target_cpu" in
x86_64 | amd64)
objfmt='ELF64'
;;
Expand All @@ -55,7 +55,7 @@ case "$host_os" in
fi
;;
solaris* | sunos* | sysv* | sco*)
case "$host_cpu" in
case "$target_cpu" in
x86_64 | amd64)
objfmt='ELF64'
;;
Expand All @@ -65,7 +65,7 @@ case "$host_os" in
esac
;;
darwin* | rhapsody* | nextstep* | openstep* | macos*)
case "$host_cpu" in
case "$target_cpu" in
x86_64 | amd64)
objfmt='Mach-O64'
;;
Expand All @@ -82,7 +82,7 @@ esac
AC_MSG_RESULT([$objfmt])
if test "$objfmt" = 'ELF ?'; then
objfmt='ELF'
AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.])
AC_MSG_WARN([unexpected target system. assumed that the format is $objfmt.])
fi
AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ])
Expand Down
16 changes: 13 additions & 3 deletions xpar-x86_64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,26 @@ crc32c_small_x86_64_sse42:
.done:
retq

; Some *cough* compilers use leading underscores. Please them.
; Is there a better solution?

; clang bug workaround for MacOS
global _crc32c_x86_64_cpuflags
global _crc32c_small_x86_64_sse42
_crc32c_x86_64_cpuflags:
jmp crc32c_x86_64_cpuflags
_crc32c_small_x86_64_sse42:
jmp crc32c_small_x86_64_sse42

; clang bug workaround for Windows
global crc32c_small_x86_64_sse42_msabi
crc32c_small_x86_64_sse42_msabi:
push rdi
mov rdi, rcx
push rsi
mov rsi, rdx
mov rdx, r8
call crc32c_small_x86_64_sse42
pop rsi
pop rdi
ret

; Need .GNU-stack to mark the stack as non-executable on ELF targets.
%ifdef ELF
Expand Down

0 comments on commit fcac412

Please sign in to comment.