From: Matthew Malcomson <mmalcom...@nvidia.com>

Cc'ing in build machinery maintainers who can hopefully check the
validity of those changes.

N.b. would appreciate information on who to Cc in for the libatomic
parts of this patch.  I don't see anyone in the MAINTAINERS file against
libatomic.

-------------- >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                    | 10 ++--
 libatomic/Makefile.in                    |  6 +-
 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, 104 insertions(+), 98 deletions(-)

diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am
index efadd9dcd48..0f2122822d6 100644
--- a/libatomic/Makefile.am
+++ b/libatomic/Makefile.am
@@ -86,9 +86,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
@@ -99,7 +99,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))
@@ -107,7 +107,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
 
@@ -120,7 +120,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)))
diff --git a/libatomic/Makefile.in b/libatomic/Makefile.in
index 9798e7c09e9..1b31ac90141 100644
--- a/libatomic/Makefile.in
+++ b/libatomic/Makefile.in
@@ -432,13 +432,13 @@ 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))
 @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
 
@@ -894,7 +894,7 @@ vpath % $(strip $(search_path))
 -include $(wildcard $(DEPDIR)/*.Ppo)
 
 %_.lo: Makefile
-       $(LTCOMPILE) $(M_DEPS) $(M_SIZE) $(M_IFUNC) -c -o $@ $(M_SRC)
+       $(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
diff --git a/libatomic/cas_n.c b/libatomic/cas_n.c
index 2a6357e48db..8200cfa671d 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 5ac512e7a83..f7173ea2d54 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 9de92fc93ce..908b11b6e0e 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 eb518ca652d..53b2b10dbcd 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 0dd14c69c63..f27d219c3d3 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 c67160ea471..b9d7f9699e4 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 0c08165c1f3..e43bb2a3600 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 184d3de1009..5e484457427 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 32b75cec654..66fc2d06938 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 fefff3a57a4..4782f290edf 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 861a22da152..0e01a38c1b3 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 657c8e23ed2..decdbc1c108 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 079e22d75ba..e9cf03ba7f0 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 9321b3a4e02..a17d3604c66 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


Reply via email to