Merge "Use inline keyword without underscores consistently" into main
diff --git a/libc/arch-arm64/dynamic_function_dispatch.cpp b/libc/arch-arm64/dynamic_function_dispatch.cpp
index db002b8..a42c361 100644
--- a/libc/arch-arm64/dynamic_function_dispatch.cpp
+++ b/libc/arch-arm64/dynamic_function_dispatch.cpp
@@ -30,18 +30,22 @@
#include <stddef.h>
#include <sys/auxv.h>
-#define MIDR_IMPL_ID_SHIFT 24u
-#define MIDR_IMPL_ID_MASK 0xFF
-#define CPU_VARIANT_SHIFT 20u
-#define CPU_VARIANT_MASK 0xF
+static inline bool __bionic_is_oryon(unsigned long hwcap) {
+ if (!(hwcap & HWCAP_CPUID)) return false;
-/* Macro to identify CPU implementer */
-#define QCOM_IMPL_ID 0x51
+ // Extract the implementor and variant bits from MIDR_EL1.
+ // https://www.kernel.org/doc/html/latest/arch/arm64/cpu-feature-registers.html#list-of-registers-with-visible-features
+ unsigned long midr;
+ __asm__ __volatile__("mrs %0, MIDR_EL1" : "=r"(midr));
+ uint16_t cpu = (midr >> 20) & 0xfff;
-/* Macro to indentify qualcomm CPU variants which supports
- * __memcpy_aarch64_nt routine
- */
-#define QCOM_ORYON_CPU_VARIANTS 0x5
+ auto make_cpu = [](unsigned implementor, unsigned variant) {
+ return (implementor << 4) | variant;
+ };
+
+ // Check for implementor Qualcomm's variants 0x1..0x5 (Oryon).
+ return cpu >= make_cpu('Q', 0x1) && cpu <= make_cpu('Q', 0x5);
+}
extern "C" {
@@ -62,68 +66,20 @@
typedef void* memcpy_func(void*, const void*, size_t);
DEFINE_IFUNC_FOR(memcpy) {
- unsigned long midr;
- unsigned int impl_id, cpu_variant;
-
- /* Check if hardware capability CPUID is available */
- if (arg->_hwcap & HWCAP_CPUID) {
- /* Read the MIDR register */
- asm("mrs %0, MIDR_EL1 \n\t" : "=r"(midr));
-
- /* Extract the CPU Implementer ID */
- impl_id = (midr >> MIDR_IMPL_ID_SHIFT) & (MIDR_IMPL_ID_MASK);
-
- /* Check for Qualcomm implementer ID */
- if (impl_id == QCOM_IMPL_ID) {
- cpu_variant = (midr >> CPU_VARIANT_SHIFT) & CPU_VARIANT_MASK;
-
- /* Check for Qualcomm Oryon CPU variants: 0x1, 0x2, 0x3, 0x4, 0x5 */
- if (cpu_variant <= QCOM_ORYON_CPU_VARIANTS) {
+ if (__bionic_is_oryon(arg->_hwcap)) {
RETURN_FUNC(memcpy_func, __memcpy_aarch64_nt);
- } else {
+ } else if (arg->_hwcap & HWCAP_ASIMD) {
+ RETURN_FUNC(memcpy_func, __memcpy_aarch64_simd);
+ } else {
RETURN_FUNC(memcpy_func, __memcpy_aarch64);
- }
}
- }
- /* If CPU implementer is not Qualcomm, choose the custom
- * implementation based on CPU architecture feature
- * */
- if (arg->_hwcap & HWCAP_ASIMD) {
- RETURN_FUNC(memcpy_func, __memcpy_aarch64_simd);
- } else {
- RETURN_FUNC(memcpy_func, __memcpy_aarch64);
- }
}
typedef void* memmove_func(void*, const void*, size_t);
DEFINE_IFUNC_FOR(memmove) {
- unsigned long midr;
- unsigned int impl_id, cpu_variant;
-
- /* Check if hardware capability CPUID is available */
- if (arg->_hwcap & HWCAP_CPUID) {
- /* Read the MIDR register */
- asm("mrs %0, MIDR_EL1 \n\t" : "=r"(midr));
-
- /* Extract the CPU Implementer ID */
- impl_id = (midr >> MIDR_IMPL_ID_SHIFT) & (MIDR_IMPL_ID_MASK);
-
- /* Check for Qualcomm implementer ID */
- if (impl_id == QCOM_IMPL_ID) {
- cpu_variant = (midr >> CPU_VARIANT_SHIFT) & CPU_VARIANT_MASK;
-
- /* Check for Qualcomm Oryon CPU variants: 0x1, 0x2, 0x3, 0x4, 0x5 */
- if (cpu_variant <= QCOM_ORYON_CPU_VARIANTS) {
- RETURN_FUNC(memcpy_func, __memmove_aarch64_nt);
- } else {
- RETURN_FUNC(memcpy_func, __memmove_aarch64);
- }
- }
- }
- /* If CPU implementer is not Qualcomm, choose the custom
- * implementation based on CPU architecture feature
- * */
- if (arg->_hwcap & HWCAP_ASIMD) {
+ if (__bionic_is_oryon(arg->_hwcap)) {
+ RETURN_FUNC(memcpy_func, __memmove_aarch64_nt);
+ } else if (arg->_hwcap & HWCAP_ASIMD) {
RETURN_FUNC(memmove_func, __memmove_aarch64_simd);
} else {
RETURN_FUNC(memmove_func, __memmove_aarch64);
@@ -137,32 +93,11 @@
typedef int memset_func(void*, int, size_t);
DEFINE_IFUNC_FOR(memset) {
- unsigned long midr;
- unsigned int impl_id, cpu_variant;
-
- if (arg->_hwcap & HWCAP_CPUID) {
- /* Read the MIDR register */
- asm("mrs %0, MIDR_EL1 \n\t" : "=r"(midr));
-
- /* Extract the CPU Implementer ID */
- impl_id = (midr >> MIDR_IMPL_ID_SHIFT) & (MIDR_IMPL_ID_MASK);
-
- /* Check for Qualcomm implementer ID */
- if (impl_id == QCOM_IMPL_ID) {
- cpu_variant = (midr >> CPU_VARIANT_SHIFT) & CPU_VARIANT_MASK;
-
- /* Check for Qualcomm Oryon CPU variants: 0x1, 0x2, 0x3, 0x4, 0x5 */
- if (cpu_variant <= QCOM_ORYON_CPU_VARIANTS) {
+ if (__bionic_is_oryon(arg->_hwcap)) {
RETURN_FUNC(memset_func, __memset_aarch64_nt);
- } else {
- RETURN_FUNC(memset_func, __memset_aarch64);
- }
} else {
- RETURN_FUNC(memset_func, __memset_aarch64);
+ RETURN_FUNC(memset_func, __memset_aarch64);
}
- } else {
- RETURN_FUNC(memset_func, __memset_aarch64);
- }
}
typedef char* stpcpy_func(char*, const char*, size_t);
diff --git a/libc/include/limits.h b/libc/include/limits.h
index 48e7ea9..80fc45d 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -136,6 +136,9 @@
#define IOV_MAX 1024
#define SEM_VALUE_MAX 0x3fffffff
+/** Do not use: prefer getline() or asprintf() rather than hard-coding an arbitrary size. */
+#define LINE_MAX _POSIX2_LINE_MAX
+
/* POSIX says these belong in <unistd.h> but BSD has some in <limits.h>. */
#include <bits/posix_limits.h>
diff --git a/libc/include/sched.h b/libc/include/sched.h
index b1f1842..9f043b6 100644
--- a/libc/include/sched.h
+++ b/libc/include/sched.h
@@ -99,7 +99,7 @@
};
/**
- * [sched_setscheduler(2)](http://man7.org/linux/man-pages/man2/sched_getcpu.2.html)
+ * [sched_setscheduler(2)](https://man7.org/linux/man-pages/man2/sched_setscheduler.2.html)
* sets the scheduling policy and associated parameters for the given thread.
*
* Returns 0 on success and returns -1 and sets `errno` on failure.
@@ -107,7 +107,7 @@
int sched_setscheduler(pid_t __pid, int __policy, const struct sched_param* _Nonnull __param);
/**
- * [sched_getscheduler(2)](http://man7.org/linux/man-pages/man2/sched_getcpu.2.html)
+ * [sched_getscheduler(2)](https://man7.org/linux/man-pages/man2/sched_getscheduler.2)
* gets the scheduling policy for the given thread.
*
* Returns a non-negative thread policy on success and returns -1 and sets
diff --git a/linker/arch/arm64/tlsdesc_resolver.S b/linker/arch/arm64/tlsdesc_resolver.S
index ad155e2..84407dd 100644
--- a/linker/arch/arm64/tlsdesc_resolver.S
+++ b/linker/arch/arm64/tlsdesc_resolver.S
@@ -56,12 +56,12 @@
ldr x22, [x0] // TlsDynamicResolverArg::generation
cmp x21, x22
- b.lo .fallback
+ b.lo L(fallback)
ldr x21, [x0, #8] // TlsIndex::module_id
ldr x22, [x0, #16] // TlsIndex::offset
ldr x21, [x20, x21, lsl #3] // TlsDtv::modules[module_id]
- cbz x21, .fallback
+ cbz x21, L(fallback)
add x0, x21, x22
sub x0, x0, x19
@@ -75,7 +75,7 @@
.cfi_restore x20
ret
-.fallback:
+L(fallback):
.cfi_restore_state
ldp x21, x22, [sp, #16]
.cfi_restore x21
diff --git a/tests/headers/posix/limits_h.c b/tests/headers/posix/limits_h.c
index 7e92d81..0ca80a5 100644
--- a/tests/headers/posix/limits_h.c
+++ b/tests/headers/posix/limits_h.c
@@ -130,10 +130,10 @@
MACRO(CHARCLASS_NAME_MAX);
MACRO(COLL_WEIGHTS_MAX);
MACRO(EXPR_NEST_MAX);
- MACRO(LINE_MAX);
MACRO(NGROUPS_MAX);
MACRO(RE_DUP_MAX);
#endif
+ MACRO(LINE_MAX);
MACRO_VALUE(_POSIX_CLOCKRES_MIN, 20000000);
diff --git a/tests/limits_test.cpp b/tests/limits_test.cpp
index e5902ad..bc13a3f 100644
--- a/tests/limits_test.cpp
+++ b/tests/limits_test.cpp
@@ -21,6 +21,7 @@
TEST(limits, macros) {
ASSERT_EQ(8, CHAR_BIT);
ASSERT_EQ(8 * static_cast<int>(sizeof(int)), WORD_BIT);
+ ASSERT_EQ(2048, LINE_MAX);
ASSERT_EQ(20, NZERO);
#if !defined(MB_LEN_MAX)
#error MB_LEN_MAX