Skip to content
Snippets Groups Projects
Commit 1af4a845 authored by Victor Do Nascimento's avatar Victor Do Nascimento
Browse files

Libatomic: Make ifunc selector behavior contingent on importing file

By querying previously-defined file-identifier macros, `host-config.h'
is able to get information about its environment and, based on this
information, select more appropriate function-specific ifunc
selectors.  This reduces the number of unnecessary feature tests that
need to be carried out in order to find the best atomic implementation
for a function at run-time.

An immediate benefit of this is that we can further fine-tune the
architectural requirements for each atomic function without risk of
incurring the maintenance and runtime-performance penalties of having
to maintain an ifunc selector with a huge number of alternatives, most
of which are irrelevant for any particular function.  Consequently,
for AArch64 targets, we relax the architectural requirements of
`compare_exchange_16', which now requires only LSE as opposed to the
newer LSE2.

The new flexibility provided by this approach also means that certain
functions can now be called directly, doing away with ifunc selectors
altogether when only a single implementation is available for it on a
given target.  As per the macro expansion framework laid out in
`libatomic_i.h', such functions should have their names prefixed with
`__atomic_' as opposed to `libat_'.  This is the same prefix applied
to function names when Libatomic is configured with
`--disable-gnu-indirect-function'.

To achieve this, these functions unconditionally apply the aliasing
rule that at present is conditionally applied only when libatomic is
built without ifunc support, which ensures that the default
`libat_##NAME' is accessible via the equivalent `__atomic_##NAME' too.
This is ensured by using the new `ENTRY_ALIASED' macro.

Finally, this means we are able to do away with a whole set of
function aliases that were needed until now, thus considerably
cleaning up the implementation.

libatomic/ChangeLog:

	* config/linux/aarch64/atomic_16.S: Remove unnecessary
	aliasing.
	(LSE): New.
	(ENTRY_ALIASED): Likewise.
	* config/linux/aarch64/host-config.h (LSE_ATOP): New.
	(LSE2_ATOP): Likewise.
	(LSE128_ATOP): Likewise.
	(IFUNC_COND_1): Make its definition conditional on above 3
	macros.
	(IFUNC_NCOND): Likewise.
parent 6edf6fe7
No related branches found
No related tags found
No related merge requests found
...@@ -45,17 +45,20 @@ ...@@ -45,17 +45,20 @@
.arch armv8-a+lse .arch armv8-a+lse
#define LSE128(NAME) libat_##NAME##_i1 #define LSE128(NAME) libat_##NAME##_i1
#define LSE2(NAME) libat_##NAME##_i2 #define LSE(NAME) libat_##NAME##_i1
#define LSE2(NAME) libat_##NAME##_i1
#define CORE(NAME) libat_##NAME #define CORE(NAME) libat_##NAME
#define ATOMIC(NAME) __atomic_##NAME #define ATOMIC(NAME) __atomic_##NAME
/* Emit __atomic_* entrypoints if no ifuncs. */
#define ENTRY_ALIASED(NAME) ENTRY2 (CORE (NAME), ALIAS (NAME, ATOMIC, CORE))
#if HAVE_IFUNC #if HAVE_IFUNC
# define ENTRY(NAME) ENTRY2 (CORE (NAME), ) # define ENTRY(NAME) ENTRY2 (CORE (NAME), )
# define ENTRY_FEAT(NAME, FEAT) ENTRY2 (FEAT (NAME), ) # define ENTRY_FEAT(NAME, FEAT) ENTRY2 (FEAT (NAME), )
# define END_FEAT(NAME, FEAT) END2 (FEAT (NAME)) # define END_FEAT(NAME, FEAT) END2 (FEAT (NAME))
#else #else
/* Emit __atomic_* entrypoints if no ifuncs. */ # define ENTRY(NAME) ENTRY_ALIASED (NAME)
# define ENTRY(NAME) ENTRY2 (CORE (NAME), ALIAS (NAME, ATOMIC, CORE))
#endif #endif
#define END(NAME) END2 (CORE (NAME)) #define END(NAME) END2 (CORE (NAME))
...@@ -291,7 +294,7 @@ END (compare_exchange_16) ...@@ -291,7 +294,7 @@ END (compare_exchange_16)
#if HAVE_FEAT_LSE2 #if HAVE_FEAT_LSE2
ENTRY_FEAT (compare_exchange_16, LSE2) ENTRY_FEAT (compare_exchange_16, LSE)
ldp exp0, exp1, [x1] ldp exp0, exp1, [x1]
mov tmp0, exp0 mov tmp0, exp0
mov tmp1, exp1 mov tmp1, exp1
...@@ -324,11 +327,11 @@ ENTRY_FEAT (compare_exchange_16, LSE2) ...@@ -324,11 +327,11 @@ ENTRY_FEAT (compare_exchange_16, LSE2)
/* ACQ_REL/SEQ_CST. */ /* ACQ_REL/SEQ_CST. */
4: caspal exp0, exp1, in0, in1, [x0] 4: caspal exp0, exp1, in0, in1, [x0]
b 0b b 0b
END_FEAT (compare_exchange_16, LSE2) END_FEAT (compare_exchange_16, LSE)
#endif #endif
ENTRY (fetch_add_16) ENTRY_ALIASED (fetch_add_16)
mov x5, x0 mov x5, x0
cbnz w4, 2f cbnz w4, 2f
...@@ -350,7 +353,7 @@ ENTRY (fetch_add_16) ...@@ -350,7 +353,7 @@ ENTRY (fetch_add_16)
END (fetch_add_16) END (fetch_add_16)
ENTRY (add_fetch_16) ENTRY_ALIASED (add_fetch_16)
mov x5, x0 mov x5, x0
cbnz w4, 2f cbnz w4, 2f
...@@ -372,7 +375,7 @@ ENTRY (add_fetch_16) ...@@ -372,7 +375,7 @@ ENTRY (add_fetch_16)
END (add_fetch_16) END (add_fetch_16)
ENTRY (fetch_sub_16) ENTRY_ALIASED (fetch_sub_16)
mov x5, x0 mov x5, x0
cbnz w4, 2f cbnz w4, 2f
...@@ -394,7 +397,7 @@ ENTRY (fetch_sub_16) ...@@ -394,7 +397,7 @@ ENTRY (fetch_sub_16)
END (fetch_sub_16) END (fetch_sub_16)
ENTRY (sub_fetch_16) ENTRY_ALIASED (sub_fetch_16)
mov x5, x0 mov x5, x0
cbnz w4, 2f cbnz w4, 2f
...@@ -620,7 +623,7 @@ ENTRY_FEAT (and_fetch_16, LSE128) ...@@ -620,7 +623,7 @@ ENTRY_FEAT (and_fetch_16, LSE128)
END_FEAT (and_fetch_16, LSE128) END_FEAT (and_fetch_16, LSE128)
ENTRY (fetch_xor_16) ENTRY_ALIASED (fetch_xor_16)
mov x5, x0 mov x5, x0
cbnz w4, 2f cbnz w4, 2f
...@@ -642,7 +645,7 @@ ENTRY (fetch_xor_16) ...@@ -642,7 +645,7 @@ ENTRY (fetch_xor_16)
END (fetch_xor_16) END (fetch_xor_16)
ENTRY (xor_fetch_16) ENTRY_ALIASED (xor_fetch_16)
mov x5, x0 mov x5, x0
cbnz w4, 2f cbnz w4, 2f
...@@ -664,7 +667,7 @@ ENTRY (xor_fetch_16) ...@@ -664,7 +667,7 @@ ENTRY (xor_fetch_16)
END (xor_fetch_16) END (xor_fetch_16)
ENTRY (fetch_nand_16) ENTRY_ALIASED (fetch_nand_16)
mov x5, x0 mov x5, x0
mvn in0, in0 mvn in0, in0
mvn in1, in1 mvn in1, in1
...@@ -688,7 +691,7 @@ ENTRY (fetch_nand_16) ...@@ -688,7 +691,7 @@ ENTRY (fetch_nand_16)
END (fetch_nand_16) END (fetch_nand_16)
ENTRY (nand_fetch_16) ENTRY_ALIASED (nand_fetch_16)
mov x5, x0 mov x5, x0
mvn in0, in0 mvn in0, in0
mvn in1, in1 mvn in1, in1
...@@ -714,7 +717,7 @@ END (nand_fetch_16) ...@@ -714,7 +717,7 @@ END (nand_fetch_16)
/* __atomic_test_and_set is always inlined, so this entry is unused and /* __atomic_test_and_set is always inlined, so this entry is unused and
only required for completeness. */ only required for completeness. */
ENTRY (test_and_set_16) ENTRY_ALIASED (test_and_set_16)
/* RELAXED/ACQUIRE/CONSUME/RELEASE/ACQ_REL/SEQ_CST. */ /* RELAXED/ACQUIRE/CONSUME/RELEASE/ACQ_REL/SEQ_CST. */
mov x5, x0 mov x5, x0
...@@ -725,39 +728,6 @@ ENTRY (test_and_set_16) ...@@ -725,39 +728,6 @@ ENTRY (test_and_set_16)
END (test_and_set_16) END (test_and_set_16)
#if HAVE_IFUNC
/* Alias entry points which are the same in LSE2 and LSE128. */
ALIAS (load_16, LSE128, LSE2)
ALIAS (store_16, LSE128, LSE2)
ALIAS (compare_exchange_16, LSE128, LSE2)
ALIAS (fetch_add_16, LSE128, LSE2)
ALIAS (add_fetch_16, LSE128, LSE2)
ALIAS (fetch_sub_16, LSE128, LSE2)
ALIAS (sub_fetch_16, LSE128, LSE2)
ALIAS (fetch_xor_16, LSE128, LSE2)
ALIAS (xor_fetch_16, LSE128, LSE2)
ALIAS (fetch_nand_16, LSE128, LSE2)
ALIAS (nand_fetch_16, LSE128, LSE2)
ALIAS (test_and_set_16, LSE128, LSE2)
/* Alias entry points which are the same in baseline and LSE2. */
ALIAS (exchange_16, LSE2, CORE)
ALIAS (fetch_add_16, LSE2, CORE)
ALIAS (add_fetch_16, LSE2, CORE)
ALIAS (fetch_sub_16, LSE2, CORE)
ALIAS (sub_fetch_16, LSE2, CORE)
ALIAS (fetch_or_16, LSE2, CORE)
ALIAS (or_fetch_16, LSE2, CORE)
ALIAS (fetch_and_16, LSE2, CORE)
ALIAS (and_fetch_16, LSE2, CORE)
ALIAS (fetch_xor_16, LSE2, CORE)
ALIAS (xor_fetch_16, LSE2, CORE)
ALIAS (fetch_nand_16, LSE2, CORE)
ALIAS (nand_fetch_16, LSE2, CORE)
ALIAS (test_and_set_16, LSE2, CORE)
#endif
/* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ /* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */
#define FEATURE_1_AND 0xc0000000 #define FEATURE_1_AND 0xc0000000
#define FEATURE_1_BTI 1 #define FEATURE_1_BTI 1
......
...@@ -48,15 +48,36 @@ typedef struct __ifunc_arg_t { ...@@ -48,15 +48,36 @@ typedef struct __ifunc_arg_t {
# define _IFUNC_ARG_HWCAP (1ULL << 62) # define _IFUNC_ARG_HWCAP (1ULL << 62)
#endif #endif
#if N == 16 /* From the file which imported `host-config.h' we can ascertain which
# define IFUNC_COND_1 (has_lse128 (hwcap, features)) architectural extension provides relevant atomic support. From this,
# define IFUNC_COND_2 (has_lse2 (hwcap, features)) we can proceed to tweak the ifunc selector behavior. */
# define IFUNC_NCOND(N) 2 #if defined (LAT_CAS_N)
#else # define LSE_ATOP
# define IFUNC_COND_1 (hwcap & HWCAP_ATOMICS) #elif defined (LAT_LOAD_N) || defined (LAT_STORE_N)
# define IFUNC_NCOND(N) 1 # define LSE2_ATOP
#elif defined (LAT_EXCH_N) || defined (LAT_FIOR_N) || defined (LAT_FAND_N)
# define LSE128_ATOP
#endif #endif
# if N == 16
# if defined (LSE_ATOP)
# define IFUNC_NCOND(N) 1
# define IFUNC_COND_1 (hwcap & HWCAP_ATOMICS)
# elif defined (LSE2_ATOP)
# define IFUNC_NCOND(N) 1
# define IFUNC_COND_1 (has_lse2 (hwcap, features))
# elif defined (LSE128_ATOP)
# define IFUNC_NCOND(N) 1
# define IFUNC_COND_1 (has_lse128 (hwcap, features))
# else
# define IFUNC_NCOND(N) 0
# define IFUNC_ALT 1
# endif
# else
# define IFUNC_COND_1 (hwcap & HWCAP_ATOMICS)
# define IFUNC_NCOND(N) 1
# endif
#define MIDR_IMPLEMENTOR(midr) (((midr) >> 24) & 255) #define MIDR_IMPLEMENTOR(midr) (((midr) >> 24) & 255)
#define MIDR_PARTNUM(midr) (((midr) >> 4) & 0xfff) #define MIDR_PARTNUM(midr) (((midr) >> 4) & 0xfff)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment