01cda16
This is a combination of two upstream commits to support building on s390x:
01cda16
01cda16
commit 2c01ecec641eb7b4a23d7c0620589ca49bd41697
01cda16
Author: Neale Ferguson <neale@sinenomine.net>
01cda16
Date:   Mon May 15 16:25:47 2017 -0400
01cda16
01cda16
    Add s390x support
01cda16
01cda16
commit a6861b6adde4d0f5c0c2f9eae87758a348a44419
01cda16
Author: Samy Al Bahra <sbahra@backtrace.io>
01cda16
Date:   Sat Jun 10 15:36:04 2017 -0400
01cda16
01cda16
    build/ck.build.s390x: Explicitly define s390x.
01cda16
    
01cda16
    This is sticking to the idiom in Concurrency Kit, to safe-guard against
01cda16
    freestanding (or non-Linux) targets with different conventions.
01cda16
01cda16
diff -up ck-0.6.0/build/ck.build.s390x.s390fix ck-0.6.0/build/ck.build.s390x
01cda16
--- ck-0.6.0/build/ck.build.s390x.s390fix	2018-07-17 08:30:09.263803192 +0200
01cda16
+++ ck-0.6.0/build/ck.build.s390x	2018-07-17 08:32:16.442797601 +0200
01cda16
@@ -0,0 +1,2 @@
01cda16
+CFLAGS+=-m64 -O0 -g -D__s390x__
01cda16
+LDFLAGS+=-m64
01cda16
diff -up ck-0.6.0/configure.s390fix ck-0.6.0/configure
01cda16
--- ck-0.6.0/configure.s390fix	2017-02-27 21:50:14.000000000 +0100
01cda16
+++ ck-0.6.0/configure	2018-07-17 08:30:09.263803192 +0200
01cda16
@@ -482,6 +482,13 @@ case $PLATFORM in
01cda16
 		PLATFORM=aarch64
01cda16
 		ENVIRONMENT=64
01cda16
 		;;
01cda16
+	"s390x")
01cda16
+		RTM_ENABLE="CK_MD_RTM_DISABLE"
01cda16
+		LSE_ENABLE="CK_MD_LSE_DISABLE"
01cda16
+		MM="${MM:-"CK_MD_RMO"}"
01cda16
+		PLATFORM=s390x
01cda16
+		ENVIRONMENT=64
01cda16
+		;;
01cda16
 	*)
01cda16
 		RTM_ENABLE="CK_MD_RTM_DISABLE"
01cda16
 		LSE_ENABLE="CK_MD_LSE_DISABLE"
01cda16
diff -up ck-0.6.0/include/ck_pr.h.s390fix ck-0.6.0/include/ck_pr.h
01cda16
--- ck-0.6.0/include/ck_pr.h.s390fix	2017-02-27 21:50:14.000000000 +0100
01cda16
+++ ck-0.6.0/include/ck_pr.h	2018-07-17 08:30:09.263803192 +0200
01cda16
@@ -43,6 +43,8 @@
01cda16
 #include "gcc/sparcv9/ck_pr.h"
01cda16
 #elif defined(__ppc64__)
01cda16
 #include "gcc/ppc64/ck_pr.h"
01cda16
+#elif defined(__s390x__)
01cda16
+#include "gcc/s390x/ck_pr.h"
01cda16
 #elif defined(__ppc__)
01cda16
 #include "gcc/ppc/ck_pr.h"
01cda16
 #elif defined(__arm__)
01cda16
diff -up ck-0.6.0/include/gcc/s390x/ck_f_pr.h.s390fix ck-0.6.0/include/gcc/s390x/ck_f_pr.h
01cda16
--- ck-0.6.0/include/gcc/s390x/ck_f_pr.h.s390fix	2018-07-17 08:30:09.263803192 +0200
01cda16
+++ ck-0.6.0/include/gcc/s390x/ck_f_pr.h	2018-07-17 08:30:09.263803192 +0200
01cda16
@@ -0,0 +1,97 @@
01cda16
+/* DO NOT EDIT. This is auto-generated from feature.sh */
01cda16
+#define CK_F_PR_ADD_32
01cda16
+#define CK_F_PR_ADD_64
01cda16
+#define CK_F_PR_ADD_INT
01cda16
+#define CK_F_PR_ADD_PTR
01cda16
+#define CK_F_PR_ADD_UINT
01cda16
+#define CK_F_PR_AND_32
01cda16
+#define CK_F_PR_AND_64
01cda16
+#define CK_F_PR_AND_INT
01cda16
+#define CK_F_PR_AND_PTR
01cda16
+#define CK_F_PR_AND_UINT
01cda16
+#define CK_F_PR_CAS_32
01cda16
+#define CK_F_PR_CAS_32_VALUE
01cda16
+#define CK_F_PR_CAS_64
01cda16
+#define CK_F_PR_CAS_64_VALUE
01cda16
+#define CK_F_PR_CAS_INT
01cda16
+#define CK_F_PR_CAS_INT_VALUE
01cda16
+#define CK_F_PR_CAS_PTR
01cda16
+#define CK_F_PR_CAS_PTR_VALUE
01cda16
+#define CK_F_PR_CAS_UINT
01cda16
+#define CK_F_PR_CAS_UINT_VALUE
01cda16
+#define CK_F_PR_DEC_32
01cda16
+#define CK_F_PR_DEC_64
01cda16
+#define CK_F_PR_DEC_INT
01cda16
+#define CK_F_PR_DEC_PTR
01cda16
+#define CK_F_PR_DEC_UINT
01cda16
+#define CK_F_PR_FAA_32
01cda16
+#define CK_F_PR_FAA_64
01cda16
+#define CK_F_PR_FAA_INT
01cda16
+#define CK_F_PR_FAA_PTR
01cda16
+#define CK_F_PR_FAA_UINT
01cda16
+#define CK_F_PR_FAS_32
01cda16
+#define CK_F_PR_FAS_64
01cda16
+#define CK_F_PR_FAS_INT
01cda16
+#define CK_F_PR_FAS_PTR
01cda16
+#define CK_F_PR_FAS_UINT
01cda16
+#define CK_F_PR_FAS_DOUBLE
01cda16
+#define CK_F_PR_FENCE_LOAD
01cda16
+#define CK_F_PR_FENCE_LOAD_DEPENDS
01cda16
+#define CK_F_PR_FENCE_MEMORY
01cda16
+#define CK_F_PR_FENCE_STORE
01cda16
+#define CK_F_PR_FENCE_STRICT_LOAD
01cda16
+#define CK_F_PR_FENCE_STRICT_LOAD_DEPENDS
01cda16
+#define CK_F_PR_FENCE_STRICT_MEMORY
01cda16
+#define CK_F_PR_FENCE_STRICT_STORE
01cda16
+#define CK_F_PR_INC_32
01cda16
+#define CK_F_PR_INC_64
01cda16
+#define CK_F_PR_INC_INT
01cda16
+#define CK_F_PR_INC_PTR
01cda16
+#define CK_F_PR_INC_UINT
01cda16
+#define CK_F_PR_LOAD_16
01cda16
+#define CK_F_PR_LOAD_32
01cda16
+#define CK_F_PR_LOAD_64
01cda16
+#define CK_F_PR_LOAD_8
01cda16
+#define CK_F_PR_LOAD_CHAR
01cda16
+#define CK_F_PR_LOAD_DOUBLE
01cda16
+#define CK_F_PR_LOAD_INT
01cda16
+#define CK_F_PR_LOAD_PTR
01cda16
+#define CK_F_PR_LOAD_SHORT
01cda16
+#define CK_F_PR_LOAD_UINT
01cda16
+#define CK_F_PR_NEG_32
01cda16
+#define CK_F_PR_NEG_64
01cda16
+#define CK_F_PR_NEG_INT
01cda16
+#define CK_F_PR_NEG_PTR
01cda16
+#define CK_F_PR_NEG_UINT
01cda16
+#define CK_F_PR_NOT_32
01cda16
+#define CK_F_PR_NOT_64
01cda16
+#define CK_F_PR_NOT_INT
01cda16
+#define CK_F_PR_NOT_PTR
01cda16
+#define CK_F_PR_NOT_UINT
01cda16
+#define CK_F_PR_OR_32
01cda16
+#define CK_F_PR_OR_64
01cda16
+#define CK_F_PR_OR_INT
01cda16
+#define CK_F_PR_OR_PTR
01cda16
+#define CK_F_PR_OR_UINT
01cda16
+#define CK_F_PR_STALL
01cda16
+#define CK_F_PR_STORE_16
01cda16
+#define CK_F_PR_STORE_32
01cda16
+#define CK_F_PR_STORE_64
01cda16
+#define CK_F_PR_STORE_8
01cda16
+#define CK_F_PR_STORE_CHAR
01cda16
+#define CK_F_PR_STORE_DOUBLE
01cda16
+#define CK_F_PR_STORE_INT
01cda16
+#define CK_F_PR_STORE_PTR
01cda16
+#define CK_F_PR_STORE_SHORT
01cda16
+#define CK_F_PR_STORE_UINT
01cda16
+#define CK_F_PR_SUB_32
01cda16
+#define CK_F_PR_SUB_64
01cda16
+#define CK_F_PR_SUB_INT
01cda16
+#define CK_F_PR_SUB_PTR
01cda16
+#define CK_F_PR_SUB_UINT
01cda16
+#define CK_F_PR_XOR_32
01cda16
+#define CK_F_PR_XOR_64
01cda16
+#define CK_F_PR_XOR_INT
01cda16
+#define CK_F_PR_XOR_PTR
01cda16
+#define CK_F_PR_XOR_UINT
01cda16
+
01cda16
diff -up ck-0.6.0/include/gcc/s390x/ck_pr.h.s390fix ck-0.6.0/include/gcc/s390x/ck_pr.h
01cda16
--- ck-0.6.0/include/gcc/s390x/ck_pr.h.s390fix	2018-07-17 08:30:09.264803200 +0200
01cda16
+++ ck-0.6.0/include/gcc/s390x/ck_pr.h	2018-07-17 08:30:09.263803192 +0200
01cda16
@@ -0,0 +1,372 @@
01cda16
+/*
01cda16
+ * Copyright 2009-2015 Samy Al Bahra.
01cda16
+ * All rights reserved.
01cda16
+ *
01cda16
+ * Redistribution and use in source and binary forms, with or without
01cda16
+ * modification, are permitted provided that the following conditions
01cda16
+ * are met:
01cda16
+ * 1. Redistributions of source code must retain the above copyright
01cda16
+ *    notice, this list of conditions and the following disclaimer.
01cda16
+ * 2. Redistributions in binary form must reproduce the above copyright
01cda16
+ *    notice, this list of conditions and the following disclaimer in the
01cda16
+ *    documentation and/or other materials provided with the distribution.
01cda16
+ *
01cda16
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
01cda16
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
01cda16
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
01cda16
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
01cda16
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
01cda16
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
01cda16
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
01cda16
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
01cda16
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
01cda16
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
01cda16
+ * SUCH DAMAGE.
01cda16
+ */
01cda16
+
01cda16
+#ifndef CK_PR_S390X_H
01cda16
+#define CK_PR_S390X_H
01cda16
+
01cda16
+#ifndef CK_PR_H
01cda16
+#error Do not include this file directly, use ck_pr.h
01cda16
+#endif
01cda16
+
01cda16
+#include <ck_cc.h>
01cda16
+#include <ck_md.h>
01cda16
+
01cda16
+/*
01cda16
+ * The following represent supported atomic operations.
01cda16
+ * These operations may be emulated.
01cda16
+ */
01cda16
+#include "ck_f_pr.h"
01cda16
+
01cda16
+/*
01cda16
+ * Minimum interface requirement met.
01cda16
+ */
01cda16
+#define CK_F_PR
01cda16
+
01cda16
+/*
01cda16
+ * This bounces the hardware thread from low to medium
01cda16
+ * priority. I am unsure of the benefits of this approach
01cda16
+ * but it is used by the Linux kernel.
01cda16
+ */
01cda16
+CK_CC_INLINE static void
01cda16
+ck_pr_stall(void)
01cda16
+{
01cda16
+	__sync_synchronize();
01cda16
+	return;
01cda16
+}
01cda16
+
01cda16
+#define CK_PR_FENCE(T)					\
01cda16
+	CK_CC_INLINE static void			\
01cda16
+	ck_pr_fence_strict_##T(void)			\
01cda16
+	{						\
01cda16
+		__sync_synchronize();			\
01cda16
+	}
01cda16
+
01cda16
+/*
01cda16
+ * These are derived from:
01cda16
+ *     http://www.ibm.com/developerworks/systems/articles/powerpc.html
01cda16
+ */
01cda16
+CK_PR_FENCE(atomic)
01cda16
+CK_PR_FENCE(atomic_store)
01cda16
+CK_PR_FENCE(atomic_load)
01cda16
+CK_PR_FENCE(store_atomic)
01cda16
+CK_PR_FENCE(load_atomic)
01cda16
+CK_PR_FENCE(store)
01cda16
+CK_PR_FENCE(store_load)
01cda16
+CK_PR_FENCE(load)
01cda16
+CK_PR_FENCE(load_store)
01cda16
+CK_PR_FENCE(memory)
01cda16
+CK_PR_FENCE(acquire)
01cda16
+CK_PR_FENCE(release)
01cda16
+CK_PR_FENCE(acqrel)
01cda16
+CK_PR_FENCE(lock)
01cda16
+CK_PR_FENCE(unlock)
01cda16
+
01cda16
+#undef CK_PR_FENCE
01cda16
+
01cda16
+#define CK_PR_LOAD(S, M, T, C, I)					\
01cda16
+	CK_CC_INLINE static T						\
01cda16
+	ck_pr_md_load_##S(const M *target)				\
01cda16
+	{								\
01cda16
+		T r;							\
01cda16
+		__asm__ __volatile__(I "\t%0, %1\n"			\
01cda16
+					: "=r" (r)			\
01cda16
+					: "Q"  (*(const C *)target)	\
01cda16
+					: "memory");			\
01cda16
+		return (r);						\
01cda16
+	}
01cda16
+
01cda16
+CK_PR_LOAD(ptr, void, void *, uint64_t, "lg")
01cda16
+
01cda16
+#define CK_PR_LOAD_S(S, T, I) CK_PR_LOAD(S, T, T, T, I)
01cda16
+
01cda16
+CK_PR_LOAD_S(64, uint64_t, "lg")
01cda16
+CK_PR_LOAD_S(32, uint32_t, "llgf")
01cda16
+CK_PR_LOAD_S(16, uint16_t, "llgh")
01cda16
+CK_PR_LOAD_S(8, uint8_t, "llgc")
01cda16
+CK_PR_LOAD_S(uint, unsigned int, "llgf")
01cda16
+CK_PR_LOAD_S(int, int, "llgf")
01cda16
+CK_PR_LOAD_S(short, short, "lgh")
01cda16
+CK_PR_LOAD_S(char, char, "lgb")
01cda16
+#ifndef CK_PR_DISABLE_DOUBLE
01cda16
+CK_CC_INLINE static double
01cda16
+ck_pr_md_load_double(const double *target)
01cda16
+{
01cda16
+	double r;
01cda16
+	__asm__ __volatile__("ld  %0, %1\n"
01cda16
+				: "=f" (r)
01cda16
+				: "Q"  (*(const double *)target)   
01cda16
+				: "memory");
01cda16
+	return (r);			
01cda16
+}
01cda16
+#endif
01cda16
+
01cda16
+#undef CK_PR_LOAD_S
01cda16
+#undef CK_PR_LOAD
01cda16
+
01cda16
+#define CK_PR_STORE(S, M, T, C, I)				\
01cda16
+	CK_CC_INLINE static void				\
01cda16
+	ck_pr_md_store_##S(M *target, T v)			\
01cda16
+	{							\
01cda16
+		__asm__ __volatile__(I "\t%1, %0\n"		\
01cda16
+					: "=Q" (*(C *)target)	\
01cda16
+					: "r" (v)		\
01cda16
+					: "memory");		\
01cda16
+		return;						\
01cda16
+	}
01cda16
+
01cda16
+CK_PR_STORE(ptr, void, const void *, uint64_t, "stg")
01cda16
+
01cda16
+#define CK_PR_STORE_S(S, T, I) CK_PR_STORE(S, T, T, T, I)
01cda16
+
01cda16
+CK_PR_STORE_S(64, uint64_t, "stg")
01cda16
+CK_PR_STORE_S(32, uint32_t, "st")
01cda16
+CK_PR_STORE_S(16, uint16_t, "sth")
01cda16
+CK_PR_STORE_S(8, uint8_t, "stc")
01cda16
+CK_PR_STORE_S(uint, unsigned int, "st")
01cda16
+CK_PR_STORE_S(int, int, "st")
01cda16
+CK_PR_STORE_S(short, short, "sth")
01cda16
+CK_PR_STORE_S(char, char, "stc")
01cda16
+#ifndef CK_PR_DISABLE_DOUBLE
01cda16
+CK_CC_INLINE static void
01cda16
+ck_pr_md_store_double(double *target, double v)
01cda16
+{
01cda16
+	__asm__ __volatile__(" std  %1, %0\n"
01cda16
+				: "=Q" (*(double *)target)   
01cda16
+				: "f"  (v)
01cda16
+				: "0", "memory");
01cda16
+}
01cda16
+#endif
01cda16
+
01cda16
+#undef CK_PR_STORE_S
01cda16
+#undef CK_PR_STORE
01cda16
+
01cda16
+CK_CC_INLINE static bool
01cda16
+ck_pr_cas_64_value(uint64_t *target, uint64_t compare, uint64_t set, uint64_t *value)
01cda16
+{
01cda16
+	*value = __sync_val_compare_and_swap(target,compare,set);
01cda16
+        return (*value == compare);
01cda16
+}
01cda16
+
01cda16
+CK_CC_INLINE static bool
01cda16
+ck_pr_cas_ptr_value(void *target, void *compare, void *set, void *value)
01cda16
+{
01cda16
+	uintptr_t previous;
01cda16
+
01cda16
+	previous = __sync_val_compare_and_swap((uintptr_t *) target,
01cda16
+					       (uintptr_t) compare,
01cda16
+					       (uintptr_t) set);
01cda16
+	*((uintptr_t *) value) = previous;
01cda16
+        return (previous == (uintptr_t) compare);
01cda16
+}
01cda16
+
01cda16
+CK_CC_INLINE static bool
01cda16
+ck_pr_cas_64(uint64_t *target, uint64_t compare, uint64_t set)
01cda16
+{
01cda16
+	return(__sync_bool_compare_and_swap(target,compare,set));
01cda16
+}
01cda16
+
01cda16
+CK_CC_INLINE static bool
01cda16
+ck_pr_cas_ptr(void *target, void *compare, void *set)
01cda16
+{
01cda16
+	return(__sync_bool_compare_and_swap((uintptr_t *) target,
01cda16
+					    (uintptr_t) compare,
01cda16
+					    (uintptr_t) set));
01cda16
+}
01cda16
+
01cda16
+#define CK_PR_CAS(N, T)							\
01cda16
+	CK_CC_INLINE static bool					\
01cda16
+	ck_pr_cas_##N##_value(T *target, T compare, T set, T *value)	\
01cda16
+	{								\
01cda16
+		*value = __sync_val_compare_and_swap(target,		\
01cda16
+						     compare,		\
01cda16
+						     set);		\
01cda16
+		return(*value == compare);				\
01cda16
+	}								\
01cda16
+	CK_CC_INLINE static bool					\
01cda16
+	ck_pr_cas_##N(T *target, T compare, T set)			\
01cda16
+	{								\
01cda16
+		return(__sync_bool_compare_and_swap(target,		\
01cda16
+						   compare,		\
01cda16
+						   set));		\
01cda16
+	}
01cda16
+
01cda16
+CK_PR_CAS(32, uint32_t)
01cda16
+CK_PR_CAS(uint, unsigned int)
01cda16
+CK_PR_CAS(int, int)
01cda16
+
01cda16
+#undef CK_PR_CAS
01cda16
+
01cda16
+CK_CC_INLINE static void *
01cda16
+ck_pr_fas_ptr(void *target, void *v)
01cda16
+{
01cda16
+	return((void *)__atomic_exchange_n((uintptr_t *) target, (uintptr_t) v, __ATOMIC_ACQUIRE));
01cda16
+}
01cda16
+
01cda16
+#define CK_PR_FAS(N, M, T)							\
01cda16
+	CK_CC_INLINE static T							\
01cda16
+	ck_pr_fas_##N(M *target, T v)						\
01cda16
+	{									\
01cda16
+		return(__atomic_exchange_n(target, v, __ATOMIC_ACQUIRE));	\
01cda16
+	}
01cda16
+
01cda16
+CK_PR_FAS(64, uint64_t, uint64_t)
01cda16
+CK_PR_FAS(32, uint32_t, uint32_t)
01cda16
+CK_PR_FAS(int, int, int)
01cda16
+CK_PR_FAS(uint, unsigned int, unsigned int)
01cda16
+
01cda16
+#ifndef CK_PR_DISABLE_DOUBLE
01cda16
+CK_CC_INLINE static double
01cda16
+ck_pr_fas_double(double *target, double *v)
01cda16
+{
01cda16
+	double previous;
01cda16
+
01cda16
+	__asm__ __volatile__ ("	   lg   1,%2\n"
01cda16
+			      "0:  lg	0,%1\n"
01cda16
+			      "    csg	0,1,%1\n"
01cda16
+			      "    jnz	0b\n"
01cda16
+			      "    ldgr %0,0\n"
01cda16
+			      : "=f" (previous) 
01cda16
+			      : "Q" (target), "Q" (v)
01cda16
+			      : "0", "1", "cc", "memory");
01cda16
+	return (previous);
01cda16
+}
01cda16
+#endif
01cda16
+
01cda16
+#undef CK_PR_FAS
01cda16
+
01cda16
+/*
01cda16
+ * Atomic store-only binary operations.
01cda16
+ */
01cda16
+#define CK_PR_BINARY(K, S, M, T)				\
01cda16
+	CK_CC_INLINE static void				\
01cda16
+	ck_pr_##K##_##S(M *target, T d)				\
01cda16
+	{							\
01cda16
+		d = __sync_fetch_and_##K((T *)target, d);	\
01cda16
+		return;						\
01cda16
+	}
01cda16
+
01cda16
+#define CK_PR_BINARY_S(K, S, T) CK_PR_BINARY(K, S, T, T)
01cda16
+
01cda16
+#define CK_PR_GENERATE(K)			\
01cda16
+	CK_PR_BINARY(K, ptr, void, void *)	\
01cda16
+	CK_PR_BINARY_S(K, char, char)		\
01cda16
+	CK_PR_BINARY_S(K, int, int)		\
01cda16
+	CK_PR_BINARY_S(K, uint, unsigned int)	\
01cda16
+	CK_PR_BINARY_S(K, 64, uint64_t)		\
01cda16
+	CK_PR_BINARY_S(K, 32, uint32_t)		\
01cda16
+	CK_PR_BINARY_S(K, 16, uint16_t)		\
01cda16
+	CK_PR_BINARY_S(K, 8, uint8_t)
01cda16
+
01cda16
+CK_PR_GENERATE(add)
01cda16
+CK_PR_GENERATE(sub)
01cda16
+CK_PR_GENERATE(and)
01cda16
+CK_PR_GENERATE(or)
01cda16
+CK_PR_GENERATE(xor)
01cda16
+
01cda16
+#undef CK_PR_GENERATE
01cda16
+#undef CK_PR_BINARY_S
01cda16
+#undef CK_PR_BINARY
01cda16
+
01cda16
+#define CK_PR_UNARY(S, M, T)			\
01cda16
+	CK_CC_INLINE static void		\
01cda16
+	ck_pr_inc_##S(M *target)		\
01cda16
+	{					\
01cda16
+		ck_pr_add_##S(target, (T)1);	\
01cda16
+		return;				\
01cda16
+	}					\
01cda16
+	CK_CC_INLINE static void		\
01cda16
+	ck_pr_dec_##S(M *target)		\
01cda16
+	{					\
01cda16
+		ck_pr_sub_##S(target, (T)1);	\
01cda16
+		return;				\
01cda16
+	}
01cda16
+
01cda16
+#define CK_PR_UNARY_X(S, M) 	  					\
01cda16
+	CK_CC_INLINE static void					\
01cda16
+	ck_pr_not_##S(M *target)					\
01cda16
+	{								\
01cda16
+		M newval;						\
01cda16
+		do {							\
01cda16
+			newval = ~(*target);				\
01cda16
+		} while (!__sync_bool_compare_and_swap(target, 		\
01cda16
+						      *target,		\
01cda16
+						      newval));		\
01cda16
+	}								\
01cda16
+	CK_CC_INLINE static void					\
01cda16
+	ck_pr_neg_##S(M *target)					\
01cda16
+	{								\
01cda16
+		M newval;						\
01cda16
+		do {							\
01cda16
+			newval = -(*target);				\
01cda16
+		} while (!__sync_bool_compare_and_swap(target, 		\
01cda16
+						      *target,		\
01cda16
+						      newval));		\
01cda16
+	}								
01cda16
+
01cda16
+#define CK_PR_UNARY_S(S, M) CK_PR_UNARY(S, M, M) \
01cda16
+			    CK_PR_UNARY_X(S, M)
01cda16
+
01cda16
+CK_PR_UNARY(ptr, void, void *)
01cda16
+CK_PR_UNARY_S(char, char)
01cda16
+CK_PR_UNARY_S(int, int)
01cda16
+CK_PR_UNARY_S(uint, unsigned int)
01cda16
+CK_PR_UNARY_S(64, uint64_t)
01cda16
+CK_PR_UNARY_S(32, uint32_t)
01cda16
+CK_PR_UNARY_S(16, uint16_t)
01cda16
+CK_PR_UNARY_S(8, uint8_t)
01cda16
+
01cda16
+#undef CK_PR_UNARY_S
01cda16
+#undef CK_PR_UNARY
01cda16
+
01cda16
+CK_CC_INLINE static void *
01cda16
+ck_pr_faa_ptr(void *target, uintptr_t delta)
01cda16
+{
01cda16
+	uintptr_t previous;
01cda16
+
01cda16
+	previous = __sync_fetch_and_add((uintptr_t *) target, delta);
01cda16
+
01cda16
+	return (void *)(previous);
01cda16
+}
01cda16
+
01cda16
+#define CK_PR_FAA(S, T)							\
01cda16
+	CK_CC_INLINE static T						\
01cda16
+	ck_pr_faa_##S(T *target, T delta)				\
01cda16
+	{								\
01cda16
+		T previous;						\
01cda16
+									\
01cda16
+		previous = __sync_fetch_and_add(target, delta);		\
01cda16
+									\
01cda16
+		return (previous);					\
01cda16
+	}
01cda16
+
01cda16
+CK_PR_FAA(64, uint64_t)
01cda16
+CK_PR_FAA(32, uint32_t)
01cda16
+CK_PR_FAA(uint, unsigned int)
01cda16
+CK_PR_FAA(int, int)
01cda16
+
01cda16
+#undef CK_PR_FAA
01cda16
+
01cda16
+#endif /* CK_PR_S390X_H */
01cda16
diff -up ck-0.6.0/src/ck_ht_hash.h.s390fix ck-0.6.0/src/ck_ht_hash.h
01cda16
--- ck-0.6.0/src/ck_ht_hash.h.s390fix	2017-02-27 21:50:14.000000000 +0100
01cda16
+++ ck-0.6.0/src/ck_ht_hash.h	2018-07-17 08:30:09.264803200 +0200
01cda16
@@ -88,7 +88,15 @@ static inline uint64_t rotl64 ( uint64_t
01cda16
 
01cda16
 FORCE_INLINE static uint32_t getblock ( const uint32_t * p, int i )
01cda16
 {
01cda16
+#if __s390x__
01cda16
+  uint32_t res;
01cda16
+
01cda16
+  __asm__ ("	lrv	%0,%1\n"
01cda16
+	   : "=r" (res) : "Q" (p[i]) : "cc", "mem");
01cda16
+  return res;
01cda16
+#else
01cda16
   return p[i];
01cda16
+#endif
01cda16
 }
01cda16
 
01cda16
 //-----------------------------------------------------------------------------