From patchwork Wed Sep 16 16:57:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 143978 X-Patchwork-Delegate: Wilco.Dijkstra@arm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B7184BA798E for ; Wed, 16 Sep 2026 16:59:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B7184BA798E Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=zZO7eVCH X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo2-x0e.google.com (mail-oo2-x0e.google.com [IPv6:2607:f8b0:4864:31::e]) by sourceware.org (Postfix) with ESMTPS id B15C24BA798D for ; Wed, 16 Sep 2026 16:58:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B15C24BA798D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B15C24BA798D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:31::e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789577914; cv=none; b=QS5IQi0gQGxTWXOtJHM639Swz53BZT1/iw+mYzd2+R9xbopVPBVv1upB00GNmuXt3XyEKg0ey3swrJ099whXv/4NbTFTNSjDBzKWEpjwc4u+vygvVpOFyZj1LvEm59ms8Tqggq6cXT6YYDbRYUPcy6C4MZUC89rhk6UC2JnUOl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789577914; c=relaxed/simple; bh=HdBaT+sWyVKlR4MwqF0vds/GY5U97lZMjFlw8j9buGI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qqDVGs32kfcxDP0CDXj24VQAnk7fEX4jav0q5Xy0OBqMMXJWgK1/2pRMh20foYBh31HBgnH/KCP5Woftsn46OaRzju+3XbOZdDF7edgdxnbjB/D5tcs4JafgkCe5TgevPdDRbLQm2lRfX21jIjg5grT1XLDyT+paNfRPzmuTFB0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=zZO7eVCH DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B15C24BA798D Received: by mail-oo2-x0e.google.com with SMTP id 46e09a7af769-7f4f0c89e34so885845a34.1 for ; Wed, 16 Sep 2026 09:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789577914; x=1790182714; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=V+RSVJDYNlIBEfzBG5j2p6VygcxiS3E6h45V4z03+Q4=; b=zZO7eVCHLP3CfzpunMhXgNaj3bWJ6rN3htnFvrnTGeRibgmvS8q4SNeDsrXZbHUiD+ zTykUzN7Bpt+lo5kocjJsZTdI0Dto8EqKIBExL+VTY69X+j/6acwHnhvGnRpK8XMnkLr qVbcqq0u0Fp+b5JqNUgA97W89oAuwHWnYM9N6/6jH59IZCDetTa6bGZf3HOVZEN5Bz4p LHVxeg+NR1pp1qMiy00XUXXBa6ICEYOL9LEIkND4JLeVfyNMgXyO6Vpeshk8RRiZnt9B 1Wna8aRDXfxhXiERzj21uu0PZiVnV7Qmg7KGRQZ+EyHrYmKXj7ui9P5OjI6QgQij9vTU WyZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789577914; x=1790182714; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=V+RSVJDYNlIBEfzBG5j2p6VygcxiS3E6h45V4z03+Q4=; b=ttTWZ786CchxtIrNU9+AxOotO4HCgtzCH+N29fF9+80AzrKikoJIZg6HfUtq/lKyp2 5MmzEl0dmppsQj/9EU/jJnhPIuERf/V0rdZWjS8Yqc9/oiGcKqRGghPdH+fvZpVKwtKh 6gU3gQGmc+hAqqe4m5jYVIPIA9/sfDB/pfY71NThL783CJpMiKLPR4KFKsFDgPZa/amN TfTEcdRCWgDwfrQrPVnMQ7NHID90zRKwtj52R/JdDTx1TMezHl0Tqmac/L9muFV2e1kH szgIKODgi1cEpXlOIdsAVZhrHsD2bsy3FwuwkTrsfdpamqQPQYf5MByGaQKRL9JhexvO Nm5A== X-Gm-Message-State: AFuF++lnxj64b9THIHAIsIPE5VqG6/Cj0e8jvZ2zznyckw97vum9WmUB IhCbjvzcRG2djlykhrtpm7kuiYPgeD7i6LDDWhgXHtJho0Ua9xKlvGmMRGLgrxjuim72cDKebh9 yNM/X X-Gm-Gg: AYBFou2DzJNS1cHlvvSJ+XIB+OahX3g6C3q1CiTgHqF73yADbf7DIyFWF4A3hfYEunF 1ZhIDwukKGbCFkjwb0KKvJQBOh0KFpVl1hTYI1ERXFMLtXx5NocKSW6GGpDMJKeJ1ahRyIPq/Vt tbG5ksk/M168p6gu/GprPjYplqmzhaPpfLmhqhbGKCjFJVlt0V/l2Kd6fNhrA/dAkHwS+hD1fVZ 4ahVxE5M880teGrEg3MXSVp9PcnFjTfeTb8yBWYiRDOiponuOfRzMvDKwbdNkdi1oWWZaS6vtcz Z6yhqe6j3mGqKNvwAcXY5zgUF9yVfMm7Ja4aF/akQH87uOM9Z2uqxZqT/gK2DiOvMW0f5XsVTnf H9m33SMM9U72GrBIXG4vZbe4rH7WM3CSJVhxaxSGEc3qGDjiqVOj6WArjoGzqjNeuJiL+Mz3j63 T+uXgFltmwdNl+coQRvYyqW+pmkkeAP4ER9EpXxvT7AgF/lkZjfGUTd4+nSlzVIOn/CveAlAVlf 15zQx5dVHf1DJQwwuCDTt+mUk00CgILgxUN8g== X-Received: by 2002:a05:6830:6a98:b0:7fa:5c49:5245 with SMTP id 46e09a7af769-80b2ee552c0mr4257835a34.30.1789577913827; Wed, 16 Sep 2026 09:58:33 -0700 (PDT) Received: from mandiga ([2804:1b3:a7c0:321:641:4be:8f38:f065]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-80c43e5d5d6sm364541a34.2.2026.09.16.09.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2026 09:58:32 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Wilco Dijkstra , Yury Khrustalev Subject: [PATCH 1/3] math: Add ptr_barrier to hide constant table addresses from the compiler Date: Wed, 16 Sep 2026 13:57:34 -0300 Message-ID: <20260916165825.3390083-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260916165825.3390083-1-adhemerval.zanella@linaro.org> References: <20260916165825.3390083-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org GCC folds each read of a static constant table with a visible initializer into a separate floating-point literal. On aarch64 with GCC 13, 14 and 15 every literal is placed in a mergeable section that cannot use section anchors, so each one costs an ADRP and a LDR pair instead of one address computation followed by LDP loads. For instance the accurate path of acosf materializes its 16 polynomial coefficients with 16 ADRP/LDR pair. GCC 16 fixes this for constants of 8 bytes or less (PR target/121240), but not for the 16-byte _Float128 constants used by the ldbl-128 code. The AArch64 vector routines already avoid this by reading their data through an asm barrier that hides the table address. Move that macro to a new sysdeps header, math-ptr-barrier.h, so the scalar code can use it as well. No function changes, checked with a build for aarch64-linux-gnu, x86_64-linux-gnu, arm-linux-gnueabihf, and i686-linux-gnu. --- sysdeps/aarch64/fpu/math-ptr-barrier.h | 33 ++++++++++++++++++++++++++ sysdeps/aarch64/fpu/vecmath_config.h | 10 +------- sysdeps/generic/math-ptr-barrier.h | 24 +++++++++++++++++++ sysdeps/ieee754/dbl-64/math_config.h | 1 + sysdeps/ieee754/flt-32/math_config.h | 1 + 5 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 sysdeps/aarch64/fpu/math-ptr-barrier.h create mode 100644 sysdeps/generic/math-ptr-barrier.h diff --git a/sysdeps/aarch64/fpu/math-ptr-barrier.h b/sysdeps/aarch64/fpu/math-ptr-barrier.h new file mode 100644 index 00000000000..5c37d2d7d68 --- /dev/null +++ b/sysdeps/aarch64/fpu/math-ptr-barrier.h @@ -0,0 +1,33 @@ +/* Barrier for hiding the address of constant data from the compiler. + AArch64 version. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef AARCH64_MATH_PTR_BARRIER_H +#define AARCH64_MATH_PTR_BARRIER_H 1 + +/* Return PTR but hide its value from the compiler so accesses through it + cannot be optimized based on the contents. Without it, GCC might folds + each element of a static constant table into a separate literal. */ +#define ptr_barrier(ptr) \ + ({ \ + __typeof ((ptr) + 0) __ptr = (ptr); \ + __asm ("" : "+r" (__ptr)); \ + __ptr; \ + }) + +#endif diff --git a/sysdeps/aarch64/fpu/vecmath_config.h b/sysdeps/aarch64/fpu/vecmath_config.h index b75f09e5f14..55606411874 100644 --- a/sysdeps/aarch64/fpu/vecmath_config.h +++ b/sysdeps/aarch64/fpu/vecmath_config.h @@ -20,15 +20,7 @@ #define _VECMATH_CONFIG_H #include - -/* Return ptr but hide its value from the compiler so accesses through it - cannot be optimized based on the contents. */ -#define ptr_barrier(ptr) \ - ({ \ - __typeof (ptr) __ptr = (ptr); \ - __asm("" : "+r"(__ptr)); \ - __ptr; \ - }) +#include #define V_LOG_POLY_ORDER 6 #define V_LOG_TABLE_BITS 7 diff --git a/sysdeps/generic/math-ptr-barrier.h b/sysdeps/generic/math-ptr-barrier.h new file mode 100644 index 00000000000..ffb863cb303 --- /dev/null +++ b/sysdeps/generic/math-ptr-barrier.h @@ -0,0 +1,24 @@ +/* Barrier for hiding the address of constant data from the compiler. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _MATH_PTR_BARRIER_H +#define _MATH_PTR_BARRIER_H 1 + +#define ptr_barrier(ptr) ((ptr) + 0) + +#endif /* math-ptr-barrier.h */ diff --git a/sysdeps/ieee754/dbl-64/math_config.h b/sysdeps/ieee754/dbl-64/math_config.h index 6a1f3062f84..d77c39da226 100644 --- a/sysdeps/ieee754/dbl-64/math_config.h +++ b/sysdeps/ieee754/dbl-64/math_config.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include diff --git a/sysdeps/ieee754/flt-32/math_config.h b/sysdeps/ieee754/flt-32/math_config.h index 1509c2ef626..781e6c57623 100644 --- a/sysdeps/ieee754/flt-32/math_config.h +++ b/sysdeps/ieee754/flt-32/math_config.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include