public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Deng Jianbo <dengjianbo@loongson.cn>
To: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org,
	caiyinyu@loongson.cn, i.swmail@xen0n.name
Cc: joseph_myers@mentor.com, carlos@redhat.com,
	xuchenghua@loongson.cn, Deng Jianbo <dengjianbo@loongson.cn>
Subject: [PATCH] LoongArch: Optimize math barriers
Date: Thu,  7 May 2026 10:17:40 +0800	[thread overview]
Message-ID: <20260507021740.16572-1-dengjianbo@loongson.cn> (raw)

The constraints 'frm' used in math_opt_barrier and math_force_eval cause
GCC choose fixed-point registers with lower costs in some cases, because
in LoongArch ira_reg_class_subunion[FP_REGS][GR_REGS] is initialized to
GR_REGS, extra move costs will be added when choosing FP_REGS. This
results in unnecessary instructions to move values between FP_REGS and
GR_REGS.

Most of cases in GLIBC math barriers related macros are invoked with
floating-point type paramters, this patch removes "r" constraints,
allowing GCC to keep values in floating-point registers and avoid the
extra moves.

Example from xflow function before the change:
	movfr2gr.d      $t0, $fa0
	beqz            $a0, 12 # 69960 <xflow+0x10>
	fneg.d          $fa1, $fa0
	movfr2gr.d      $t0, $fa1
	movgr2fr.d      $fa1, $t0
	fmul.d          $fa0, $fa0, $fa1
	b               -56 # 69930 <with_errno.constprop.0>

After the patch:
	fmov.d          $fa1, $fa0
	beqz            $a0, 12 # 69ac0 <xflow+0x10>
	fneg.d          $fa1, $fa0
	nop
	fmul.d          $fa0, $fa0, $fa1
	b               -52 # 69a90 <with_errno.constprop.0>
---
 sysdeps/loongarch/fpu/math-barriers.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sysdeps/loongarch/fpu/math-barriers.h b/sysdeps/loongarch/fpu/math-barriers.h
index 6a069ff41d..76835aa210 100644
--- a/sysdeps/loongarch/fpu/math-barriers.h
+++ b/sysdeps/loongarch/fpu/math-barriers.h
@@ -21,8 +21,8 @@
 
 /* Generic code forces values to memory; we don't need to do that.  */
 #define math_opt_barrier(x)					\
-  ({ __typeof (x) __x = (x); __asm ("" : "+frm" (__x)); __x; })
+  ({ __typeof (x) __x = (x); __asm ("" : "+fm" (__x)); __x; })
 #define math_force_eval(x)						\
-  ({ __typeof (x) __x = (x); __asm __volatile__ ("" : : "frm" (__x)); })
+  ({ __typeof (x) __x = (x); __asm __volatile__ ("" : : "fm" (__x)); })
 
 #endif /* math-barriers.h */
-- 
2.20.1


             reply	other threads:[~2026-05-07  2:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07  2:17 Deng Jianbo [this message]
2026-05-07  6:46 ` Andreas Schwab
2026-05-07  9:30   ` dengjianbo
2026-05-08  9:29     ` Xi Ruoyao
2026-05-08  9:47       ` dengjianbo
2026-05-25  1:09         ` dengjianbo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260507021740.16572-1-dengjianbo@loongson.cn \
    --to=dengjianbo@loongson.cn \
    --cc=adhemerval.zanella@linaro.org \
    --cc=caiyinyu@loongson.cn \
    --cc=carlos@redhat.com \
    --cc=i.swmail@xen0n.name \
    --cc=joseph_myers@mentor.com \
    --cc=libc-alpha@sourceware.org \
    --cc=xuchenghua@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).