Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5ad6eb5

Browse files
author
Commitfest Bot
committed
[CF 5779] v1 - Review/Pull Request: Adding new CRC32C implementation for IBM S390X
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5779 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/918d9941377f6e83fbfebe96ba496ccaefa3803f.camel@ibm.com Author(s): Eduard Stefes
2 parents b006bcd + 4c9a336 commit 5ad6eb5

File tree

10 files changed

+773
-14
lines changed

10 files changed

+773
-14
lines changed

config/c-compiler.m4

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,21 @@ if test x"$pgac_cv_gcc_atomic_int64_cas" = x"yes"; then
545545
AC_DEFINE(HAVE_GCC__ATOMIC_INT64_CAS, 1, [Define to 1 if you have __atomic_compare_exchange_n(int64 *, int64 *, int64).])
546546
fi])# PGAC_HAVE_GCC__ATOMIC_INT64_CAS
547547

548+
# PGAC_HAVE_GCC__ATOMIC_STORE_N
549+
# -----------------------------
550+
# Check if the compiler understands __atomic_store_n for 64bit
551+
# types, and define HAVE_GCC__ATOMIC_STORE_N if so.
552+
AC_DEFUN([PGAC_HAVE_GCC__ATOMIC_STORE_N],
553+
[AC_CACHE_CHECK(for builtin __atomic int64 atomic store operations, pgac_cv_gcc_atomic_store_n,
554+
[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdint.h>],
555+
[int64_t val = 0;
556+
__atomic_store_n(&val,1,__ATOMIC_SEQ_CST);])],
557+
[pgac_cv_gcc_atomic_store_n="yes"],
558+
[pgac_cv_gcc_atomic_store_n="no"])])
559+
if test x"$pgac_cv_gcc_atomic_store_n" = x"yes"; then
560+
AC_DEFINE(HAVE_GCC__ATOMIC_STORE_N, 1, [Define to 1 if you have __atomic_store_n(int64 *, int64 , int).])
561+
fi])# PGAC_HAVE_GCC__ATOMIC_STORE_N
562+
548563
# PGAC_SSE42_CRC32_INTRINSICS
549564
# ---------------------------
550565
# Check if the compiler supports the x86 CRC instructions added in SSE 4.2,
@@ -684,6 +699,62 @@ fi
684699
undefine([Ac_cachevar])dnl
685700
])# PGAC_LOONGARCH_CRC32C_INTRINSICS
686701

702+
# PGAC_S390X_VECTOR_VX_INTRINSICS
703+
# --------------------------------
704+
# Check if the compiler supports the S390X vector intrinsics, using
705+
# __attribute__((vector_size(16))), vec_gfmsum_accum_128
706+
#
707+
# These instructions where introduced with -march=z13.
708+
# the test arg1 is mandatory and should be either:
709+
# '-fzvector' for clang
710+
# '-mzarch' for gcc
711+
#
712+
# If the intrinsics are supported, sets
713+
# pgac_s390x_vector_intrinsics, and CFLAGS_CRC.
714+
AC_DEFUN([PGAC_S390X_VECTOR_VX_INTRINSICS],
715+
[define([Ac_cachevar], [AS_TR_SH([pgac_cv_s390x_vector_intrinsics_$1_$2])])dnl
716+
AC_CACHE_CHECK([for __attribute__((vector_size(16))), vec_gfmsum_accum_128 with CFLAGS=$1 $2], [Ac_cachevar],
717+
[pgac_save_CFLAGS=$CFLAGS
718+
CFLAGS="$pgac_save_CFLAGS $1 $2"
719+
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <vecintrin.h>],
720+
[unsigned long long a __attribute__((vector_size(16))) = { 0 };
721+
unsigned long long b __attribute__((vector_size(16))) = { 0 };
722+
unsigned char c __attribute__((vector_size(16))) = { 0 };
723+
c = vec_gfmsum_accum_128(a, b, c);
724+
return 0;])],
725+
[Ac_cachevar=yes],
726+
[Ac_cachevar=no])
727+
CFLAGS="$pgac_save_CFLAGS"])
728+
if test x"$Ac_cachevar" = x"yes"; then
729+
CFLAGS_CRC="$1 $2"
730+
AS_TR_SH([pgac_s390x_vector_intrinsics_$1_$2])=yes
731+
fi
732+
undefine([Ac_cachevar])dnl
733+
])# PGAC_S390X_VECTOR_VX_INTRINSICS
734+
735+
# PGAC_S390X_BAD_VECTOR_INTRINSICS
736+
# ---------------------------
737+
#
738+
#
739+
# If the intrinsics are bad, sets pgac_s390x_bad_vector_intrinsics.
740+
AC_DEFUN([PGAC_S390X_BAD_VECTOR_INTRINSICS],
741+
[define([Ac_cachevar], [AS_TR_SH([pgac_cv_s390x_bad_vector_intrinsics])])dnl
742+
AC_CACHE_CHECK([for Compiler Version with known bad S390X Vector Intrinsics],[Ac_cachevar],
743+
[AC_LINK_IFELSE([AC_LANG_PROGRAM([],
744+
[#ifdef __clang__
745+
# if ((__clang_major__ == 18) || (__clang_major__ == 19 && (__clang_minor__ < 1 || (__clang_minor__ == 1 && __clang_patchlevel__ < 2))))
746+
# error CRC32-VX optimizations are broken due to compiler bug in Clang versions: 18.0.0 <= clang_version < 19.1.2. Either disable the CRC32-VX optimization, or switch to another compiler/compiler version.
747+
# endif
748+
#endif
749+
return 0;])],
750+
[Ac_cachevar=yes],
751+
[Ac_cachevar=no])])
752+
if test x"$Ac_cachevar" = x"yes"; then
753+
pgac_s390x_bad_vector_intrinsics=no
754+
fi
755+
undefine([Ac_cachevar])dnl
756+
])# PGAC_S390X_BAD_VECTOR_INTRINSICS
757+
687758
# PGAC_XSAVE_INTRINSICS
688759
# ---------------------
689760
# Check if the compiler supports the XSAVE instructions using the _xgetbv

configure

Lines changed: 272 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17540,7 +17540,38 @@ if test x"$pgac_cv_gcc_atomic_int64_cas" = x"yes"; then
1754017540
$as_echo "#define HAVE_GCC__ATOMIC_INT64_CAS 1" >>confdefs.h
1754117541

1754217542
fi
17543+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for builtin __atomic int64 atomic store operations" >&5
17544+
$as_echo_n "checking for builtin __atomic int64 atomic store operations... " >&6; }
17545+
if ${pgac_cv_gcc_atomic_store_n+:} false; then :
17546+
$as_echo_n "(cached) " >&6
17547+
else
17548+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
17549+
/* end confdefs.h. */
17550+
#include <stdint.h>
17551+
int
17552+
main ()
17553+
{
17554+
int64_t val = 0;
17555+
__atomic_store_n(&val,1,__ATOMIC_SEQ_CST);
17556+
;
17557+
return 0;
17558+
}
17559+
_ACEOF
17560+
if ac_fn_c_try_link "$LINENO"; then :
17561+
pgac_cv_gcc_atomic_store_n="yes"
17562+
else
17563+
pgac_cv_gcc_atomic_store_n="no"
17564+
fi
17565+
rm -f core conftest.err conftest.$ac_objext \
17566+
conftest$ac_exeext conftest.$ac_ext
17567+
fi
17568+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_gcc_atomic_store_n" >&5
17569+
$as_echo "$pgac_cv_gcc_atomic_store_n" >&6; }
17570+
if test x"$pgac_cv_gcc_atomic_store_n" = x"yes"; then
17571+
17572+
$as_echo "#define HAVE_GCC__ATOMIC_STORE_N 1" >>confdefs.h
1754317573

17574+
fi
1754417575

1754517576
# Check for x86 cpuid instruction
1754617577
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __get_cpuid" >&5
@@ -18088,6 +18119,212 @@ if test x"$pgac_cv_loongarch_crc32c_intrinsics" = x"yes"; then
1808818119
fi
1808918120

1809018121

18122+
# Check for S390X Vector intrinsics to do CRC calculations.
18123+
#
18124+
# First check for the host cpu
18125+
if test x"$host_cpu" = x"s390x"; then
18126+
# Second check if we have atomic store
18127+
if test x"$pgac_cv_gcc_atomic_store_n" = x"yes"; then
18128+
# Third check if we have a compiler with bad intrinsics
18129+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Compiler Version with known bad S390X Vector Intrinsics" >&5
18130+
$as_echo_n "checking for Compiler Version with known bad S390X Vector Intrinsics... " >&6; }
18131+
if ${pgac_cv_s390x_bad_vector_intrinsics+:} false; then :
18132+
$as_echo_n "(cached) " >&6
18133+
else
18134+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
18135+
/* end confdefs.h. */
18136+
18137+
int
18138+
main ()
18139+
{
18140+
#ifdef __clang__
18141+
# if ((__clang_major__ == 18) || (__clang_major__ == 19 && (__clang_minor__ < 1 || (__clang_minor__ == 1 && __clang_patchlevel__ < 2))))
18142+
# error CRC32-VX optimizations are broken due to compiler bug in Clang versions: 18.0.0 <= clang_version < 19.1.2. Either disable the CRC32-VX optimization, or switch to another compiler/compiler version.
18143+
# endif
18144+
#endif
18145+
return 0;
18146+
;
18147+
return 0;
18148+
}
18149+
_ACEOF
18150+
if ac_fn_c_try_link "$LINENO"; then :
18151+
pgac_cv_s390x_bad_vector_intrinsics=yes
18152+
else
18153+
pgac_cv_s390x_bad_vector_intrinsics=no
18154+
fi
18155+
rm -f core conftest.err conftest.$ac_objext \
18156+
conftest$ac_exeext conftest.$ac_ext
18157+
fi
18158+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_s390x_bad_vector_intrinsics" >&5
18159+
$as_echo "$pgac_cv_s390x_bad_vector_intrinsics" >&6; }
18160+
if test x"$pgac_cv_s390x_bad_vector_intrinsics" = x"yes"; then
18161+
pgac_s390x_bad_vector_intrinsics=no
18162+
fi
18163+
18164+
if test x"$pgac_s390x_bad_vector_intrinsics" != x"yes"; then
18165+
# Finally check for all possible cflag combinations
18166+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __attribute__((vector_size(16))), vec_gfmsum_accum_128 with CFLAGS=-fzvector " >&5
18167+
$as_echo_n "checking for __attribute__((vector_size(16))), vec_gfmsum_accum_128 with CFLAGS=-fzvector ... " >&6; }
18168+
if ${pgac_cv_s390x_vector_intrinsics__fzvector_+:} false; then :
18169+
$as_echo_n "(cached) " >&6
18170+
else
18171+
pgac_save_CFLAGS=$CFLAGS
18172+
CFLAGS="$pgac_save_CFLAGS -fzvector "
18173+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
18174+
/* end confdefs.h. */
18175+
#include <vecintrin.h>
18176+
int
18177+
main ()
18178+
{
18179+
unsigned long long a __attribute__((vector_size(16))) = { 0 };
18180+
unsigned long long b __attribute__((vector_size(16))) = { 0 };
18181+
unsigned char c __attribute__((vector_size(16))) = { 0 };
18182+
c = vec_gfmsum_accum_128(a, b, c);
18183+
return 0;
18184+
;
18185+
return 0;
18186+
}
18187+
_ACEOF
18188+
if ac_fn_c_try_link "$LINENO"; then :
18189+
pgac_cv_s390x_vector_intrinsics__fzvector_=yes
18190+
else
18191+
pgac_cv_s390x_vector_intrinsics__fzvector_=no
18192+
fi
18193+
rm -f core conftest.err conftest.$ac_objext \
18194+
conftest$ac_exeext conftest.$ac_ext
18195+
CFLAGS="$pgac_save_CFLAGS"
18196+
fi
18197+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_s390x_vector_intrinsics__fzvector_" >&5
18198+
$as_echo "$pgac_cv_s390x_vector_intrinsics__fzvector_" >&6; }
18199+
if test x"$pgac_cv_s390x_vector_intrinsics__fzvector_" = x"yes"; then
18200+
CFLAGS_CRC="-fzvector "
18201+
pgac_s390x_vector_intrinsics__fzvector_=yes
18202+
fi
18203+
18204+
if test x"$pgac_s390x_vector_intrinsics__fzvector_" != x"yes"; then
18205+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __attribute__((vector_size(16))), vec_gfmsum_accum_128 with CFLAGS=-fzvector -march=z13" >&5
18206+
$as_echo_n "checking for __attribute__((vector_size(16))), vec_gfmsum_accum_128 with CFLAGS=-fzvector -march=z13... " >&6; }
18207+
if ${pgac_cv_s390x_vector_intrinsics__fzvector__march_z13+:} false; then :
18208+
$as_echo_n "(cached) " >&6
18209+
else
18210+
pgac_save_CFLAGS=$CFLAGS
18211+
CFLAGS="$pgac_save_CFLAGS -fzvector -march=z13"
18212+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
18213+
/* end confdefs.h. */
18214+
#include <vecintrin.h>
18215+
int
18216+
main ()
18217+
{
18218+
unsigned long long a __attribute__((vector_size(16))) = { 0 };
18219+
unsigned long long b __attribute__((vector_size(16))) = { 0 };
18220+
unsigned char c __attribute__((vector_size(16))) = { 0 };
18221+
c = vec_gfmsum_accum_128(a, b, c);
18222+
return 0;
18223+
;
18224+
return 0;
18225+
}
18226+
_ACEOF
18227+
if ac_fn_c_try_link "$LINENO"; then :
18228+
pgac_cv_s390x_vector_intrinsics__fzvector__march_z13=yes
18229+
else
18230+
pgac_cv_s390x_vector_intrinsics__fzvector__march_z13=no
18231+
fi
18232+
rm -f core conftest.err conftest.$ac_objext \
18233+
conftest$ac_exeext conftest.$ac_ext
18234+
CFLAGS="$pgac_save_CFLAGS"
18235+
fi
18236+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_s390x_vector_intrinsics__fzvector__march_z13" >&5
18237+
$as_echo "$pgac_cv_s390x_vector_intrinsics__fzvector__march_z13" >&6; }
18238+
if test x"$pgac_cv_s390x_vector_intrinsics__fzvector__march_z13" = x"yes"; then
18239+
CFLAGS_CRC="-fzvector -march=z13"
18240+
pgac_s390x_vector_intrinsics__fzvector__march_z13=yes
18241+
fi
18242+
18243+
if test x"$pgac_s390x_vector_intrinsics__fzvector__march_z13" != x"yes"; then
18244+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __attribute__((vector_size(16))), vec_gfmsum_accum_128 with CFLAGS=-mzarch " >&5
18245+
$as_echo_n "checking for __attribute__((vector_size(16))), vec_gfmsum_accum_128 with CFLAGS=-mzarch ... " >&6; }
18246+
if ${pgac_cv_s390x_vector_intrinsics__mzarch_+:} false; then :
18247+
$as_echo_n "(cached) " >&6
18248+
else
18249+
pgac_save_CFLAGS=$CFLAGS
18250+
CFLAGS="$pgac_save_CFLAGS -mzarch "
18251+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
18252+
/* end confdefs.h. */
18253+
#include <vecintrin.h>
18254+
int
18255+
main ()
18256+
{
18257+
unsigned long long a __attribute__((vector_size(16))) = { 0 };
18258+
unsigned long long b __attribute__((vector_size(16))) = { 0 };
18259+
unsigned char c __attribute__((vector_size(16))) = { 0 };
18260+
c = vec_gfmsum_accum_128(a, b, c);
18261+
return 0;
18262+
;
18263+
return 0;
18264+
}
18265+
_ACEOF
18266+
if ac_fn_c_try_link "$LINENO"; then :
18267+
pgac_cv_s390x_vector_intrinsics__mzarch_=yes
18268+
else
18269+
pgac_cv_s390x_vector_intrinsics__mzarch_=no
18270+
fi
18271+
rm -f core conftest.err conftest.$ac_objext \
18272+
conftest$ac_exeext conftest.$ac_ext
18273+
CFLAGS="$pgac_save_CFLAGS"
18274+
fi
18275+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_s390x_vector_intrinsics__mzarch_" >&5
18276+
$as_echo "$pgac_cv_s390x_vector_intrinsics__mzarch_" >&6; }
18277+
if test x"$pgac_cv_s390x_vector_intrinsics__mzarch_" = x"yes"; then
18278+
CFLAGS_CRC="-mzarch "
18279+
pgac_s390x_vector_intrinsics__mzarch_=yes
18280+
fi
18281+
18282+
if test x"$pgac_s390x_vector_intrinsics__mzarch_" != x"yes"; then
18283+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __attribute__((vector_size(16))), vec_gfmsum_accum_128 with CFLAGS=-mzarch -march=z13" >&5
18284+
$as_echo_n "checking for __attribute__((vector_size(16))), vec_gfmsum_accum_128 with CFLAGS=-mzarch -march=z13... " >&6; }
18285+
if ${pgac_cv_s390x_vector_intrinsics__mzarch__march_z13+:} false; then :
18286+
$as_echo_n "(cached) " >&6
18287+
else
18288+
pgac_save_CFLAGS=$CFLAGS
18289+
CFLAGS="$pgac_save_CFLAGS -mzarch -march=z13"
18290+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
18291+
/* end confdefs.h. */
18292+
#include <vecintrin.h>
18293+
int
18294+
main ()
18295+
{
18296+
unsigned long long a __attribute__((vector_size(16))) = { 0 };
18297+
unsigned long long b __attribute__((vector_size(16))) = { 0 };
18298+
unsigned char c __attribute__((vector_size(16))) = { 0 };
18299+
c = vec_gfmsum_accum_128(a, b, c);
18300+
return 0;
18301+
;
18302+
return 0;
18303+
}
18304+
_ACEOF
18305+
if ac_fn_c_try_link "$LINENO"; then :
18306+
pgac_cv_s390x_vector_intrinsics__mzarch__march_z13=yes
18307+
else
18308+
pgac_cv_s390x_vector_intrinsics__mzarch__march_z13=no
18309+
fi
18310+
rm -f core conftest.err conftest.$ac_objext \
18311+
conftest$ac_exeext conftest.$ac_ext
18312+
CFLAGS="$pgac_save_CFLAGS"
18313+
fi
18314+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_s390x_vector_intrinsics__mzarch__march_z13" >&5
18315+
$as_echo "$pgac_cv_s390x_vector_intrinsics__mzarch__march_z13" >&6; }
18316+
if test x"$pgac_cv_s390x_vector_intrinsics__mzarch__march_z13" = x"yes"; then
18317+
CFLAGS_CRC="-mzarch -march=z13"
18318+
pgac_s390x_vector_intrinsics__mzarch__march_z13=yes
18319+
fi
18320+
18321+
fi
18322+
fi
18323+
fi
18324+
fi
18325+
fi
18326+
fi
18327+
1809118328

1809218329

1809318330
# Select CRC-32C implementation.
@@ -18140,9 +18377,21 @@ if test x"$USE_SLICING_BY_8_CRC32C" = x"" && test x"$USE_SSE42_CRC32C" = x"" &&
1814018377
if test x"$pgac_loongarch_crc32c_intrinsics" = x"yes"; then
1814118378
USE_LOONGARCH_CRC32C=1
1814218379
else
18143-
# fall back to slicing-by-8 algorithm, which doesn't require any
18144-
# special CPU support.
18145-
USE_SLICING_BY_8_CRC32C=1
18380+
# Use S390X vector extension.
18381+
if (test x"$pgac_s390x_vector_intrinsics__fzvector_" = x"yes" ||
18382+
test x"$pgac_s390x_vector_intrinsics__mzarch_" = x"yes"); then
18383+
USE_S390X_CRC32C=1
18384+
else
18385+
# Use S390X vector extension with runtime check.
18386+
if test x"$pgac_s390x_vector_intrinsics__fzvector__march_z13" = x"yes" ||
18387+
test x"$pgac_s390x_vector_intrinsics__mzarch__march_z13" = x"yes"; then
18388+
USE_S390X_CRC32C_WITH_RUNTIME_CHECK=1
18389+
else
18390+
# fall back to slicing-by-8 algorithm, which doesn't require any
18391+
# special CPU support.
18392+
USE_SLICING_BY_8_CRC32C=1
18393+
fi
18394+
fi
1814618395
fi
1814718396
fi
1814818397
fi
@@ -18193,12 +18442,30 @@ $as_echo "#define USE_LOONGARCH_CRC32C 1" >>confdefs.h
1819318442
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: LoongArch CRCC instructions" >&5
1819418443
$as_echo "LoongArch CRCC instructions" >&6; }
1819518444
else
18445+
if test x"$USE_S390X_CRC32C" = x"1"; then
18446+
18447+
$as_echo "#define USE_S390X_CRC32C 1" >>confdefs.h
18448+
18449+
PG_CRC32C_OBJS="pg_crc32c_s390x.o pg_crc32c_sb8.o"
18450+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: S390X Vector instructions for CRC" >&5
18451+
$as_echo "S390X Vector instructions for CRC" >&6; }
18452+
else
18453+
if test x"$USE_S390X_CRC32C_WITH_RUNTIME_CHECK" = x"1"; then
18454+
18455+
$as_echo "#define USE_S390X_CRC32C_WITH_RUNTIME_CHECK 1" >>confdefs.h
18456+
18457+
PG_CRC32C_OBJS="pg_crc32c_s390x.o pg_crc32c_s390x_choose.o pg_crc32c_sb8.o"
18458+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: S390X Vector instructions for CRC with runtime check" >&5
18459+
$as_echo "S390X Vector instructions for CRC with runtime check" >&6; }
18460+
else
1819618461

1819718462
$as_echo "#define USE_SLICING_BY_8_CRC32C 1" >>confdefs.h
1819818463

18199-
PG_CRC32C_OBJS="pg_crc32c_sb8.o"
18200-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: slicing-by-8" >&5
18464+
PG_CRC32C_OBJS="pg_crc32c_sb8.o"
18465+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: slicing-by-8" >&5
1820118466
$as_echo "slicing-by-8" >&6; }
18467+
fi
18468+
fi
1820218469
fi
1820318470
fi
1820418471
fi

0 commit comments

Comments
 (0)