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