From: Matthew Malcomson <mmalcom...@nvidia.com> Honestly don't know who should be specifically Cc'd in for this. Would appreciate any pointers.
-------------- >8 ------- 8< ----------- Many functions in libatomic are defined multiple times with different suffixes from 1, 2, 4, 8, 16. These also correspond to the size in bytes of the types that we are working on. The macro N is set to these different sizes when compiling files multiple times for different sizes. In a later patch in this same patchset, I introduce functions handling floating point types to libatomic. The sizes of these floating point types overlap with the sizes of the integer types already used. In order to handle that we need a distinction between the SUFFIX that a function handling a given type will have, and the SIZE of the data type that it will use. This distinction will allow things like defining atomic_compare_exchange_n for a given size, while still being able to distinguish between types elsewhere. Alongside this naming switch we introduce the UINTTYPE macro, which is currently identical to UTYPE. The only difference is that this is defined in terms of SIZE while UTYPE is now defined in terms of SUFFIX. This keeps a logical separation between an unsigned integer of the relevant size, and the type that we are working with. This distinction is useful for the introduction of floating point typed functions in a later patch. This patch converts the naming scheme so that the Makefile determines the SUFF parameter on the command line while libatomic_i.h defines N as SUFF. Hence codegen should not change at all, while the semantics are made distinct. We also go through all known backends to convert SIZE(<name>) to SUFFIX(<name>) accordingly. Testing: - Ensured that object files in libatomic build directory do not change (once the .debug_str and .comment sections are removed) after applying this patch. Did that for: - s390x-unknown-linux-gnu (using crosstool-ng) - aarch64 linux (native bootstrap) - arm-none-linux-gnueabihf (armv7, using cross compiler) - x86_64 linux (native bootstrap) - i686-ubuntu16.04-linux-gnu (using crosstool-ng) libatomic/ChangeLog: * Makefile.am: Rename PAT_N -> PAT_SUFF. Rename M_SIZE -> M_SUFFIX * Makefile.in: Regenerate. * cas_n.c: Replace uses of SIZE with SUFFIX. * config/linux/arm/host-config.h (atomic_compare_exchange_n): Use UINTTYPE instead of UTYPE. * config/s390/cas_n.c: Replace uses of N with SUFF, and replace uses of SIZE with SUFFIX. * config/s390/exch_n.c: Likewise. * config/s390/load_n.c: Likewise. * config/s390/store_n.c: Likewise. * config/x86/host-config.h (atomic_compare_exchange_n): Use UINTTYPE instead of UTYPE. (atomic_load_n): Likewise. (atomic_store_n): Likewise. * exch_n.c: Replace uses of SIZE with SUFFIX. * fadd_n.c: Likewise. * fop_n.c: Likewise. * libatomic_i.h: Define N in terms of SUFF (rather than have it passed on command line). (SUFFIX): New. (PTR): Define in terms of SUFF. (ITYPE): Likewise. (UTYPE): Likewise. (UINTTYPE): New. (DECLARE_ALL_SIZED): Rename to (DECLARE_ALL_SUFFIXED): this. (DECLARE_ALL_SIZED_): Rename to (DECLARE_ALL_SUFFIXED_): this. * load_n.c: Replace uses of SIZE with SUFFIX. * store_n.c: Likewise. * tas_n.c: Likewise. Signed-off-by: Matthew Malcomson <mmalcom...@nvidia.com> --- libatomic/Makefile.am | 18 +++--- libatomic/Makefile.in | 13 ++++- libatomic/cas_n.c | 8 +-- libatomic/config/linux/arm/host-config.h | 2 +- libatomic/config/s390/cas_n.c | 6 +- libatomic/config/s390/exch_n.c | 4 +- libatomic/config/s390/load_n.c | 4 +- libatomic/config/s390/store_n.c | 4 +- libatomic/config/x86/host-config.h | 14 ++--- libatomic/exch_n.c | 12 ++-- libatomic/fadd_n.c | 2 +- libatomic/fop_n.c | 22 ++++---- libatomic/libatomic_i.h | 72 +++++++++++++----------- libatomic/load_n.c | 12 ++-- libatomic/store_n.c | 12 ++-- libatomic/tas_n.c | 12 ++-- 16 files changed, 115 insertions(+), 102 deletions(-) diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am index 3840716ccba..2ee5f8fad1d 100644 --- a/libatomic/Makefile.am +++ b/libatomic/Makefile.am @@ -91,9 +91,9 @@ libatomic_la_DEPENDENCIES = $(libatomic_la_LIBADD) $(libatomic_version_dep) ## dependencies do the job just as well: -include $(wildcard $(DEPDIR)/*.Ppo) -## Naming pattern: base_n_i_.lo +## Naming pattern: base_s_i_.lo ## -## N size of data +## S suffix for data type ## I IFUNC alternative, index beginning at 1. ## ## The trailing _ in the output object file name is required to differentiate @@ -104,7 +104,7 @@ empty = space = $(empty) $(empty) PAT_SPLIT = $(subst _,$(space),$(*F)) PAT_BASE = $(word 1,$(PAT_SPLIT)) -PAT_N = $(word 2,$(PAT_SPLIT)) +PAT_SUFF = $(word 2,$(PAT_SPLIT)) PAT_S = $(word 3,$(PAT_SPLIT)) IFUNC_DEF = -DIFUNC_ALT=$(PAT_S) IFUNC_OPT = $(word $(PAT_S),$(IFUNC_OPTIONS)) @@ -112,7 +112,7 @@ IFUNC_OPT = $(word $(PAT_S),$(IFUNC_OPTIONS)) @AMDEP_TRUE@M_DEPS = -MT $@ -MD -MP -MF $(DEPDIR)/$(@F).Ppo @AMDEP_FALSE@M_DEPS = -M_SIZE = -DN=$(PAT_N) +M_SUFFIX = -DSUFF=$(PAT_SUFF) M_IFUNC = $(if $(PAT_S),$(IFUNC_DEF) $(IFUNC_OPT)) M_FILE = $(PAT_BASE)_n.c @@ -125,7 +125,7 @@ all_c_files := $(foreach dir,$(search_path),$(wildcard $(dir)/*.c)) M_SRC = $(firstword $(filter %/$(M_FILE), $(all_c_files))) %_.lo: Makefile - $(LTCOMPILE) $(M_DEPS) $(M_SIZE) $(M_IFUNC) -c -o $@ $(M_SRC) + $(LTCOMPILE) $(M_DEPS) $(M_SUFFIX) $(M_IFUNC) -c -o $@ $(M_SRC) ## Include all of the sizes in the "normal" set of compilation flags. libatomic_la_LIBADD = $(foreach s,$(SIZES),$(addsuffix _$(s)_.lo,$(SIZEOBJS))) @@ -171,12 +171,12 @@ all-multi: $(libatomic_la_LIBADD) # Copy built libatomic library to $build/gcc so it's easier to locate, # similar to libgcc. gcc_objdir = `pwd`/$(MULTIBUILDTOP)../../gcc/ +# FIXME: The above command also ends up copying libatomic.la in $gcc_objdir, +# which (somehow) ends up adding $gcc_objdir to RPATH for libraries that get +# built after libatomic, which makes RPATH insecure. Removing libatomic.la +# from $gcc_objdir seems to fix the issue. all-local: libatomic.la $(LIBTOOL) --mode=install $(INSTALL_DATA) libatomic.la $(gcc_objdir)$(MULTISUBDIR)/ - # FIXME: The above command also ends up copying libatomic.la in $gcc_objdir, - # which (somehow) ends up adding $gcc_objdir to RPATH for libraries that get - # built after libatomic, which makes RPATH insecure. Removing libatomic.la - # from $gcc_objdir seems to fix the issue. rm $(gcc_objdir)$(MULTISUBDIR)/libatomic.la # target overrides diff --git a/libatomic/Makefile.in b/libatomic/Makefile.in index a2f3a23c110..cd916aefcda 100644 --- a/libatomic/Makefile.in +++ b/libatomic/Makefile.in @@ -443,13 +443,13 @@ libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \ @PARTIAL_VXWORKS_FALSE@space = $(empty) $(empty) @PARTIAL_VXWORKS_FALSE@PAT_SPLIT = $(subst _,$(space),$(*F)) @PARTIAL_VXWORKS_FALSE@PAT_BASE = $(word 1,$(PAT_SPLIT)) -@PARTIAL_VXWORKS_FALSE@PAT_N = $(word 2,$(PAT_SPLIT)) +@PARTIAL_VXWORKS_FALSE@PAT_SUFF = $(word 2,$(PAT_SPLIT)) @PARTIAL_VXWORKS_FALSE@PAT_S = $(word 3,$(PAT_SPLIT)) @PARTIAL_VXWORKS_FALSE@IFUNC_DEF = -DIFUNC_ALT=$(PAT_S) @PARTIAL_VXWORKS_FALSE@IFUNC_OPT = $(word $(PAT_S),$(IFUNC_OPTIONS)) @PARTIAL_VXWORKS_FALSE@@AMDEP_TRUE@M_DEPS = -MT $@ -MD -MP -MF $(DEPDIR)/$(@F).Ppo @PARTIAL_VXWORKS_FALSE@@AMDEP_FALSE@M_DEPS = -@PARTIAL_VXWORKS_FALSE@M_SIZE = -DN=$(PAT_N) +@PARTIAL_VXWORKS_FALSE@M_SUFFIX = -DSUFF=$(PAT_SUFF) @PARTIAL_VXWORKS_FALSE@M_IFUNC = $(if $(PAT_S),$(IFUNC_DEF) $(IFUNC_OPT)) @PARTIAL_VXWORKS_FALSE@M_FILE = $(PAT_BASE)_n.c @@ -471,6 +471,9 @@ libatomic_la_LDFLAGS = $(libatomic_version_info) $(libatomic_version_script) \ @ARCH_X86_64_TRUE@@HAVE_IFUNC_TRUE@@PARTIAL_VXWORKS_FALSE@IFUNC_OPTIONS = -mcx16 -mcx16 libatomic_convenience_la_SOURCES = $(libatomic_la_SOURCES) libatomic_convenience_la_LIBADD = $(libatomic_la_LIBADD) + +# Copy built libatomic library to $build/gcc so it's easier to locate, +# similar to libgcc. gcc_objdir = `pwd`/$(MULTIBUILDTOP)../../gcc/ MULTISRCTOP = MULTIBUILDTOP = @@ -908,13 +911,17 @@ vpath % $(strip $(search_path)) @PARTIAL_VXWORKS_FALSE@-include $(wildcard $(DEPDIR)/*.Ppo) @PARTIAL_VXWORKS_FALSE@%_.lo: Makefile -@PARTIAL_VXWORKS_FALSE@ $(LTCOMPILE) $(M_DEPS) $(M_SIZE) $(M_IFUNC) -c -o $@ $(M_SRC) +@PARTIAL_VXWORKS_FALSE@ $(LTCOMPILE) $(M_DEPS) $(M_SUFFIX) $(M_IFUNC) -c -o $@ $(M_SRC) # Amend the automake generated all-multi rule to guarantee that all-multi # is not run in parallel with the %_.lo rules which generate $(DEPDIR)/*.Ppo # makefile fragments to avoid broken *.Ppo getting included into the Makefile # when it is reloaded during the build of all-multi. all-multi: $(libatomic_la_LIBADD) +# FIXME: The above command also ends up copying libatomic.la in $gcc_objdir, +# which (somehow) ends up adding $gcc_objdir to RPATH for libraries that get +# built after libatomic, which makes RPATH insecure. Removing libatomic.la +# from $gcc_objdir seems to fix the issue. all-local: libatomic.la $(LIBTOOL) --mode=install $(INSTALL_DATA) libatomic.la $(gcc_objdir)$(MULTISUBDIR)/ rm $(gcc_objdir)$(MULTISUBDIR)/libatomic.la diff --git a/libatomic/cas_n.c b/libatomic/cas_n.c index d75c2ea5b99..d1e27fbd4e2 100644 --- a/libatomic/cas_n.c +++ b/libatomic/cas_n.c @@ -29,7 +29,7 @@ /* If we support the builtin, just use it. */ #if !DONE && defined(atomic_compare_exchange_n) bool -SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, +SUFFIX(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, int smodel, int fmodel UNUSED) { if (maybe_specialcase_relaxed(smodel)) @@ -51,7 +51,7 @@ SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, compare-and-swap loop, possibly assisted by the OS. */ #if !DONE && N <= WORDSIZE && defined(atomic_compare_exchange_w) bool -SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, +SUFFIX(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, int smodel, int fmodel) { UWORD mask, shift, weval, woldval, wnewval, t, *wptr; @@ -98,7 +98,7 @@ SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, /* Otherwise, fall back to some sort of protection mechanism. */ #if !DONE bool -SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, +SUFFIX(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, int smodel, int fmodel UNUSED) { UTYPE oldval; @@ -122,5 +122,5 @@ SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, } #endif -EXPORT_ALIAS (SIZE(compare_exchange)); +EXPORT_ALIAS (SUFFIX(compare_exchange)); #undef LAT_CAS_N diff --git a/libatomic/config/linux/arm/host-config.h b/libatomic/config/linux/arm/host-config.h index 94a89031b23..ddf4f3f5c15 100644 --- a/libatomic/config/linux/arm/host-config.h +++ b/libatomic/config/linux/arm/host-config.h @@ -74,7 +74,7 @@ atomic_compare_exchange_w (UWORD *mptr, UWORD *eptr, UWORD newval, #if !defined(HAVE_STREXBHD) && defined(HAVE_KERNEL64) && N == 8 static inline bool -atomic_compare_exchange_n (UTYPE *mptr, UTYPE *eptr, UTYPE newval, +atomic_compare_exchange_n (UINTTYPE *mptr, UINTTYPE *eptr, UINTTYPE newval, bool weak_p UNUSED, int sm UNUSED, int fm UNUSED) { if (__kernel_cmpxchg64 (eptr, &newval, mptr) == 0) diff --git a/libatomic/config/s390/cas_n.c b/libatomic/config/s390/cas_n.c index 34ddde5ede4..8adb809639c 100644 --- a/libatomic/config/s390/cas_n.c +++ b/libatomic/config/s390/cas_n.c @@ -26,10 +26,10 @@ /* Analog to config/s390/exch_n.c. */ -#if !DONE && N == 16 +#if !DONE && SUFF == 16 bool -SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, - int smodel, int fmodel UNUSED) +SUFFIX(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval, + int smodel, int fmodel UNUSED) { if (!((uintptr_t)mptr & 0xf)) { diff --git a/libatomic/config/s390/exch_n.c b/libatomic/config/s390/exch_n.c index f800c788692..0cba3c60411 100644 --- a/libatomic/config/s390/exch_n.c +++ b/libatomic/config/s390/exch_n.c @@ -35,9 +35,9 @@ location. To avoid this the library fall back also has to use the hardware instruction if possible. */ -#if !DONE && N == 16 +#if !DONE && SUFF == 16 UTYPE -SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel UNUSED) +SUFFIX(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel UNUSED) { if (!((uintptr_t)mptr & 0xf)) { diff --git a/libatomic/config/s390/load_n.c b/libatomic/config/s390/load_n.c index a250bc3e50a..eccc1b268bd 100644 --- a/libatomic/config/s390/load_n.c +++ b/libatomic/config/s390/load_n.c @@ -26,9 +26,9 @@ /* Analog to config/s390/exch_n.c. */ -#if !DONE && N == 16 +#if !DONE && SUFF == 16 UTYPE -SIZE(libat_load) (UTYPE *mptr, int smodel) +SUFFIX(libat_load) (UTYPE *mptr, int smodel) { if (!((uintptr_t)mptr & 0xf)) { diff --git a/libatomic/config/s390/store_n.c b/libatomic/config/s390/store_n.c index 5abb26317fb..4ad1203cbcf 100644 --- a/libatomic/config/s390/store_n.c +++ b/libatomic/config/s390/store_n.c @@ -26,9 +26,9 @@ /* Analog to config/s390/exch_n.c. */ -#if !DONE && N == 16 +#if !DONE && SUFF == 16 void -SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) +SUFFIX(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) { if (!((uintptr_t)mptr & 0xf)) { diff --git a/libatomic/config/x86/host-config.h b/libatomic/config/x86/host-config.h index 162bbfcf59f..af23b9ec35b 100644 --- a/libatomic/config/x86/host-config.h +++ b/libatomic/config/x86/host-config.h @@ -101,11 +101,11 @@ load_feat1 (void) #if defined(__x86_64__) && N == 16 && IFUNC_ALT != 0 static inline bool -atomic_compare_exchange_n (UTYPE *mptr, UTYPE *eptr, UTYPE newval, +atomic_compare_exchange_n (UINTTYPE *mptr, UINTTYPE *eptr, UINTTYPE newval, bool weak_p UNUSED, int sm UNUSED, int fm UNUSED) { - UTYPE cmpval = *eptr; - UTYPE oldval = __sync_val_compare_and_swap_16 (mptr, cmpval, newval); + UINTTYPE cmpval = *eptr; + UINTTYPE oldval = __sync_val_compare_and_swap_16 (mptr, cmpval, newval); if (oldval == cmpval) return true; *eptr = oldval; @@ -122,16 +122,16 @@ atomic_compare_exchange_n (UTYPE *mptr, UTYPE *eptr, UTYPE newval, (sizeof (*ptr) == 16 ? atomic_store_n (ptr, val, model) \ : (__atomic_store_n) (ptr, val, model)) -static inline UTYPE -atomic_load_n (UTYPE *ptr, int model UNUSED) +static inline UINTTYPE +atomic_load_n (UINTTYPE *ptr, int model UNUSED) { - UTYPE ret; + UINTTYPE ret; __asm__ ("vmovdqa\t{%1, %0|%0, %1}" : "=x" (ret) : "m" (*ptr)); return ret; } static inline void -atomic_store_n (UTYPE *ptr, UTYPE val, int model UNUSED) +atomic_store_n (UINTTYPE *ptr, UINTTYPE val, int model UNUSED) { __asm__ ("vmovdqa\t{%1, %0|%0, %1}\n\tmfence" : "=m" (*ptr) : "x" (val)); } diff --git a/libatomic/exch_n.c b/libatomic/exch_n.c index 263cf5b6ca7..36f1e73cfda 100644 --- a/libatomic/exch_n.c +++ b/libatomic/exch_n.c @@ -27,9 +27,9 @@ /* If we support the builtin, just use it. */ -#if !DONE && SIZE(HAVE_ATOMIC_EXCHANGE) +#if !DONE && SUFFIX(HAVE_ATOMIC_EXCHANGE) UTYPE -SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel) +SUFFIX(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel) { if (maybe_specialcase_relaxed(smodel)) return __atomic_exchange_n (mptr, newval, __ATOMIC_RELAXED); @@ -45,7 +45,7 @@ SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel) #if !DONE && defined(atomic_compare_exchange_n) UTYPE -SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel) +SUFFIX(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel) { UTYPE oldval; @@ -69,7 +69,7 @@ SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel) compare-and-swap loop. */ #if !DONE && N <= WORDSIZE && defined(atomic_compare_exchange_w) UTYPE -SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel) +SUFFIX(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel) { UWORD mask, shift, woldval, wnewval, t, *wptr; @@ -108,7 +108,7 @@ SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel) /* Otherwise, fall back to some sort of protection mechanism. */ #if !DONE UTYPE -SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel UNUSED) +SUFFIX(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel UNUSED) { UTYPE oldval; UWORD magic; @@ -126,5 +126,5 @@ SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel UNUSED) } #endif -EXPORT_ALIAS (SIZE(exchange)); +EXPORT_ALIAS (SUFFIX(exchange)); #undef LAT_EXCH_N diff --git a/libatomic/fadd_n.c b/libatomic/fadd_n.c index 58ecbd6d62c..9d7199f6315 100644 --- a/libatomic/fadd_n.c +++ b/libatomic/fadd_n.c @@ -30,7 +30,7 @@ /* Defer to HAVE_ATOMIC_FETCH_ADD, which some targets implement specially, even if HAVE_ATOMIC_FETCH_OP is not defined. */ -#if !SIZE(HAVE_ATOMIC_FETCH_OP) +#if !SUFFIX(HAVE_ATOMIC_FETCH_OP) # undef HAVE_ATOMIC_FETCH_OP_1 # undef HAVE_ATOMIC_FETCH_OP_2 # undef HAVE_ATOMIC_FETCH_OP_4 diff --git a/libatomic/fop_n.c b/libatomic/fop_n.c index 954194a7371..04b29b0c931 100644 --- a/libatomic/fop_n.c +++ b/libatomic/fop_n.c @@ -33,9 +33,9 @@ /* If we support the builtin, just use it. */ -#if !DONE && SIZE(HAVE_ATOMIC_FETCH_OP) +#if !DONE && SUFFIX(HAVE_ATOMIC_FETCH_OP) UTYPE -SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) +SUFFIX(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) { if (maybe_specialcase_relaxed(smodel)) return C2(__atomic_fetch_,NAME) (mptr, opval, __ATOMIC_RELAXED); @@ -46,7 +46,7 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) } UTYPE -SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) +SUFFIX(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) { if (maybe_specialcase_relaxed(smodel)) return C3(__atomic_,NAME,_fetch) (mptr, opval, __ATOMIC_RELAXED); @@ -62,7 +62,7 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) #if !DONE && defined(atomic_compare_exchange_n) UTYPE -SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) +SUFFIX(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) { UTYPE oldval, t; @@ -81,7 +81,7 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) } UTYPE -SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) +SUFFIX(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) { UTYPE oldval, t; @@ -107,7 +107,7 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) compare-and-swap loop. */ #if !DONE && N < WORDSIZE && defined(atomic_compare_exchange_w) UTYPE -SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) +SUFFIX(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) { UWORD mask, shift, woldval, wopval, t, *wptr; @@ -131,7 +131,7 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) } UTYPE -SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) +SUFFIX(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) { UWORD mask, shift, woldval, wopval, t, *wptr; @@ -161,7 +161,7 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) /* Otherwise, fall back to some sort of protection mechanism. */ #if !DONE UTYPE -SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel UNUSED) +SUFFIX(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel UNUSED) { UTYPE ret; UWORD magic; @@ -179,7 +179,7 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel UNUSED) } UTYPE -SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel UNUSED) +SUFFIX(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel UNUSED) { UTYPE ret; UWORD magic; @@ -197,6 +197,6 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel UNUSED) } #endif -EXPORT_ALIAS (SIZE(C2(fetch_,NAME))); -EXPORT_ALIAS (SIZE(C2(NAME,_fetch))); +EXPORT_ALIAS (SUFFIX(C2(fetch_,NAME))); +EXPORT_ALIAS (SUFFIX(C2(NAME,_fetch))); #undef LAT_FOP_N diff --git a/libatomic/libatomic_i.h b/libatomic/libatomic_i.h index e59dd412e17..5f06bace92a 100644 --- a/libatomic/libatomic_i.h +++ b/libatomic/libatomic_i.h @@ -35,6 +35,10 @@ #include <limits.h> #include <string.h> +/* Defining N as the suffix used (always equal, but mean different things). */ +#ifdef SUFF +# define N SUFF +#endif /* Symbol concatenation macros. */ #define C2_(X,Y) X ## Y @@ -119,12 +123,14 @@ typedef unsigned UWORD __attribute__((mode(word))); N defined to be a power of 2 between 1 and 16. The SIZE macro is then used to append _N to the symbol being manipulated. */ #define SIZE(X) C3(X,_,N) +#define SUFFIX(X) C3(X,_,SUFF) #define WSIZE(X) C3(X,_,WORDSIZE) -#define PTR(N,X) ((C2(U_,N) *)X) +#define PTR(SUFF,X) ((C2(U_,SUFF) *)X) /* And thus, the type on which this compilation will be operating. */ -#define ITYPE SIZE(I) -#define UTYPE SIZE(U) +#define ITYPE SUFFIX(I) +#define UTYPE SUFFIX(U) +#define UINTTYPE SIZE(U) /* Utility macros for GCC attributes. */ #define UNUSED __attribute__((unused)) @@ -158,28 +164,28 @@ void protect_end (void *ptr, UWORD); void libat_lock_n (void *ptr, size_t n); void libat_unlock_n (void *ptr, size_t n); -/* We'll need to declare all of the sized functions a few times... */ -#define DECLARE_ALL_SIZED(N) DECLARE_ALL_SIZED_(N,C2(U_,N)) -#define DECLARE_ALL_SIZED_(N,T) \ - DECLARE_1(T, C2(load_,N), (T *mptr, int)); \ - DECLARE_1(void, C2(store_,N), (T *mptr, T val, int)); \ - DECLARE_1(T, C2(exchange_,N), (T *mptr, T, int)); \ - DECLARE_1(bool, C2(compare_exchange_,N), (T *mptr, T *, T, int, int)); \ - DECLARE_1(bool, C2(test_and_set_,N), (T *mptr, int)); \ - DECLARE_1(T, C2(fetch_add_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(fetch_sub_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(fetch_and_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(fetch_xor_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(fetch_or_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(fetch_nand_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(add_fetch_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(sub_fetch_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(and_fetch_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(xor_fetch_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(or_fetch_,N), (T *mptr, T, int)); \ - DECLARE_1(T, C2(nand_fetch_,N), (T *mptr, T, int)) - -/* All sized operations are implemented in hidden functions prefixed with +/* We'll need to declare all of the suffixed functions a few times... */ +#define DECLARE_ALL_SUFFIXED(SUFF) DECLARE_ALL_SUFFIXED_(SUFF,C2(U_,SUFF)) +#define DECLARE_ALL_SUFFIXED_(SUFF,T) \ + DECLARE_1(T, C2(load_,SUFF), (T *mptr, int)); \ + DECLARE_1(void, C2(store_,SUFF), (T *mptr, T val, int)); \ + DECLARE_1(T, C2(exchange_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(bool, C2(compare_exchange_,SUFF), (T *mptr, T *, T, int, int)); \ + DECLARE_1(bool, C2(test_and_set_,SUFF), (T *mptr, int)); \ + DECLARE_1(T, C2(fetch_add_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(fetch_sub_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(fetch_and_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(fetch_xor_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(fetch_or_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(fetch_nand_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(add_fetch_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(sub_fetch_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(and_fetch_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(xor_fetch_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(or_fetch_,SUFF), (T *mptr, T, int)); \ + DECLARE_1(T, C2(nand_fetch_,SUFF), (T *mptr, T, int)) + +/* All suffixed operations are implemented in hidden functions prefixed with "libat_". These are either renamed or aliased to the expected prefix of "__atomic". Some amount of renaming is required to avoid hiding or conflicting with the builtins of the same name, but this additional @@ -194,7 +200,7 @@ void libat_unlock_n (void *ptr, size_t n); # define MAN(X) ASMNAME(C2(__atomic_,X)) #endif -#if !defined(N) && HAVE_IFUNC +#if !defined(SUFF) && HAVE_IFUNC # define DECLARE_1(RET,NAME,ARGS) \ RET C2(libat_,NAME) ARGS MAN(NAME); \ RET C2(ifunc_,NAME) ARGS ASMNAME(C2(__atomic_,NAME)) @@ -209,15 +215,15 @@ void libat_unlock_n (void *ptr, size_t n); # define local_ libat_ #endif -DECLARE_ALL_SIZED(1); -DECLARE_ALL_SIZED(2); -DECLARE_ALL_SIZED(4); -DECLARE_ALL_SIZED(8); -DECLARE_ALL_SIZED(16); +DECLARE_ALL_SUFFIXED(1); +DECLARE_ALL_SUFFIXED(2); +DECLARE_ALL_SUFFIXED(4); +DECLARE_ALL_SUFFIXED(8); +DECLARE_ALL_SUFFIXED(16); #undef DECLARE_1 -#undef DECLARE_ALL_SIZED -#undef DECLARE_ALL_SIZED_ +#undef DECLARE_ALL_SUFFIXED +#undef DECLARE_ALL_SUFFIXED_ /* And the generic sized versions. */ void libat_load (size_t, void *, void *, int) MAN(load); diff --git a/libatomic/load_n.c b/libatomic/load_n.c index 82c31cdce37..17df00f154f 100644 --- a/libatomic/load_n.c +++ b/libatomic/load_n.c @@ -27,9 +27,9 @@ /* If we support the builtin, just use it. */ -#if !DONE && SIZE(HAVE_ATOMIC_LDST) +#if !DONE && SUFFIX(HAVE_ATOMIC_LDST) UTYPE -SIZE(libat_load) (UTYPE *mptr, int smodel) +SUFFIX(libat_load) (UTYPE *mptr, int smodel) { if (maybe_specialcase_relaxed(smodel)) return __atomic_load_n (mptr, __ATOMIC_RELAXED); @@ -48,7 +48,7 @@ SIZE(libat_load) (UTYPE *mptr, int smodel) effect load the original value. */ #if !DONE && defined(atomic_compare_exchange_n) UTYPE -SIZE(libat_load) (UTYPE *mptr, int smodel) +SUFFIX(libat_load) (UTYPE *mptr, int smodel) { UTYPE t = 0; @@ -72,7 +72,7 @@ SIZE(libat_load) (UTYPE *mptr, int smodel) /* Similar, but only assume a word-sized compare-and-swap. */ #if !DONE && N < WORDSIZE && defined(atomic_compare_exchange_w) UTYPE -SIZE(libat_load) (UTYPE *mptr, int smodel) +SUFFIX(libat_load) (UTYPE *mptr, int smodel) { UWORD shift, t, *wptr; @@ -96,7 +96,7 @@ SIZE(libat_load) (UTYPE *mptr, int smodel) /* Otherwise, fall back to some sort of protection mechanism. */ #if !DONE UTYPE -SIZE(libat_load) (UTYPE *mptr, int smodel) +SUFFIX(libat_load) (UTYPE *mptr, int smodel) { UTYPE ret; UWORD magic; @@ -113,5 +113,5 @@ SIZE(libat_load) (UTYPE *mptr, int smodel) } #endif -EXPORT_ALIAS (SIZE(load)); +EXPORT_ALIAS (SUFFIX(load)); #undef LAT_LOAD_N diff --git a/libatomic/store_n.c b/libatomic/store_n.c index 97a3133fa08..fb982e0be05 100644 --- a/libatomic/store_n.c +++ b/libatomic/store_n.c @@ -27,9 +27,9 @@ /* If we support the builtin, just use it. */ -#if !DONE && SIZE(HAVE_ATOMIC_LDST) +#if !DONE && SUFFIX(HAVE_ATOMIC_LDST) void -SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) +SUFFIX(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) { if (maybe_specialcase_relaxed(smodel)) __atomic_store_n (mptr, newval, __ATOMIC_RELAXED); @@ -46,7 +46,7 @@ SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) /* If we have compare-and-swap, use it perform the store. */ #if !DONE && defined(atomic_compare_exchange_n) void -SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) +SUFFIX(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) { UTYPE oldval; @@ -68,7 +68,7 @@ SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) compare-and-swap loop. */ #if !DONE && N < WORDSIZE && defined(atomic_compare_exchange_w) void -SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) +SUFFIX(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) { UWORD mask, shift, woldval, wnewval, t, *wptr; @@ -96,7 +96,7 @@ SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) /* Otherwise, fall back to some sort of protection mechanism. */ #if !DONE void -SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) +SUFFIX(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) { UWORD magic; @@ -110,5 +110,5 @@ SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) } #endif -EXPORT_ALIAS (SIZE(store)); +EXPORT_ALIAS (SUFFIX(store)); #undef LAT_STORE_N diff --git a/libatomic/tas_n.c b/libatomic/tas_n.c index 036a3d23307..0cf306bdf87 100644 --- a/libatomic/tas_n.c +++ b/libatomic/tas_n.c @@ -27,9 +27,9 @@ /* If we support the builtin, just use it. */ -#if !DONE && SIZE(HAVE_ATOMIC_TAS) +#if !DONE && SUFFIX(HAVE_ATOMIC_TAS) bool -SIZE(libat_test_and_set) (UTYPE *mptr, int smodel) +SUFFIX(libat_test_and_set) (UTYPE *mptr, int smodel) { if (maybe_specialcase_relaxed(smodel)) return __atomic_test_and_set (mptr, __ATOMIC_RELAXED); @@ -47,7 +47,7 @@ SIZE(libat_test_and_set) (UTYPE *mptr, int smodel) compare-and-swap loop. */ #if !DONE && N <= WORDSIZE && defined(atomic_compare_exchange_w) bool -SIZE(libat_test_and_set) (UTYPE *mptr, int smodel) +SUFFIX(libat_test_and_set) (UTYPE *mptr, int smodel) { UWORD wval, woldval, shift, *wptr, t; @@ -84,7 +84,7 @@ SIZE(libat_test_and_set) (UTYPE *mptr, int smodel) /* Otherwise, fall back to some sort of protection mechanism. */ #if !DONE && N == 1 bool -SIZE(libat_test_and_set) (UTYPE *mptr, int smodel) +SUFFIX(libat_test_and_set) (UTYPE *mptr, int smodel) { UTYPE oldval; UWORD magic; @@ -107,11 +107,11 @@ SIZE(libat_test_and_set) (UTYPE *mptr, int smodel) #if !DONE bool -SIZE(libat_test_and_set) (UTYPE *mptr, int smodel UNUSED) +SUFFIX(libat_test_and_set) (UTYPE *mptr, int smodel UNUSED) { return libat_test_and_set_1 ((U_1 *)mptr, smodel); } #endif -EXPORT_ALIAS (SIZE(test_and_set)); +EXPORT_ALIAS (SUFFIX(test_and_set)); #undef LAT_TAS_N -- 2.43.0