Re: [PATCH] libgfortran: add fallback for trigonometric pi-based functions

2025-07-06 Thread Tobias Burnus
On Sunday, July 6, 2025, Yuao Ma  wrote:
>>> Since I don't have root/sudo permissions on my devbox, I manually
downloaded
>>> and compiled the autoconf 2.69 tarball. This means there might be some
minor
>>> discrepancies compared to the version shipped with OS distributions.

In principle, having autoconf/automake locally is normal as the distro's
version too new.

>>> I suspect the issue could be related to platforms where `off_t` is
32-bit,
>>> causing a left shift of 62 to result in undefined behavior. The commit
at
https://cgit.git.savannah.gnu.org/cgit/autoconf.git/commit/?id=a1d8293f3bfa2516f9a0424e3a6e63c2f8e93c6e
>>> seems to support my theory.

As that commit is from 2020 and 2.69 in from 2012, it seems as if your
autoconf is too new. Can you re-check that the right version is at the
beginning of the PATH?

Note that there is a CI job that checks whether the generated files are in
deed up to date, i.e. the current trunk should be fine unless someone has
messed up.

The other question is whether the autoconf version shouldn't be updated,
given that 2.69 is quite old.

Tobias,
currently a less active due to FTO.


Re: [PATCH] libgfortran: add fallback for trigonometric pi-based functions

2025-07-06 Thread Yuao Ma

Hi Tobias,

On 7/6/2025 6:34 PM, Tobias Burnus wrote:
As that commit is from 2020 and 2.69 in from 2012, it seems as if your 
autoconf is too new. Can you re-check that the right version is at the 
beginning of the PATH?


Note that there is a CI job that checks whether the generated files are 
in deed up to date, i.e. the current trunk should be fine unless someone 
has messed up.




It is possible that autoconf 2.69 contains this commit, as we can see 
from 
https://github.com/autotools-mirror/autoconf/commit/a1d8293f3bfa2516f9a0424e3a6e63c2f8e93c6e 
that it has been backported to v2.69b - v2.69e.


The main reason is that my devbox has autoconf2.69 (2.69-3.1) from 
Debian, released on Sat, 19 Nov 2022 21:40:11 +0200, which includes the 
commit from 2020. This version takes precedence over my compiled 
version. Once I switch to my compiled version, the generation output 
functions as expected.


The other question is whether the autoconf version shouldn't be updated, 
given that 2.69 is quite old.


Upgrading this basic component may seem like a major change, but opting 
for the same version with a backported patch appears to be a better choice.


I have used the old version to create a new patch. Hope this looks good 
to you.


YuaoFrom 2d62a2f707e43f37b4d886b7ed3aa40f2ab62437 Mon Sep 17 00:00:00 2001
From: Yuao Ma 
Date: Sun, 6 Jul 2025 20:55:08 +0800
Subject: [PATCH] libgfortran: add fallback for trigonometric pi-based
 functions

This patch introduces a fallback implementation for pi-based trigonometric
functions, ensuring broader compatibility and robustness. The new
implementation supports float, double, and long double data types. Accordingly,
the test cases for r4 and r8 have been revised to reflect these changes.

libgfortran/ChangeLog:

* Makefile.am: Add c23_functions.c to Makefile.
* Makefile.in: Regenerate.
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Check if trig-pi functions exist.
* gfortran.map: Add a section for c23 functions.
* libgfortran.h: Include c23 proto file.
* c23_protos.h: Add c23 proto file and trig-pi funcs.
* intrinsics/c23_functions.c: Add trig-pi fallback impls.

gcc/testsuite/ChangeLog:

* gfortran.dg/dec_math_5.f90: Revise test to use fallback.

Signed-off-by: Yuao Ma 
Co-authored-by: Steven G. Kargl 
---
 gcc/testsuite/gfortran.dg/dec_math_5.f90 |   36 +-
 libgfortran/Makefile.am  |4 +
 libgfortran/Makefile.in  |8 +
 libgfortran/c23_protos.h |  133 +++
 libgfortran/config.h.in  |   63 ++
 libgfortran/configure| 1010 ++
 libgfortran/configure.ac |   23 +
 libgfortran/gfortran.map |   25 +
 libgfortran/intrinsics/c23_functions.c   |  308 +++
 libgfortran/libgfortran.h|1 +
 10 files changed, 1593 insertions(+), 18 deletions(-)
 create mode 100644 libgfortran/c23_protos.h
 create mode 100644 libgfortran/intrinsics/c23_functions.c

diff --git a/gcc/testsuite/gfortran.dg/dec_math_5.f90 
b/gcc/testsuite/gfortran.dg/dec_math_5.f90
index a7ff3275236..7bcf07fce67 100644
--- a/gcc/testsuite/gfortran.dg/dec_math_5.f90
+++ b/gcc/testsuite/gfortran.dg/dec_math_5.f90
@@ -102,26 +102,26 @@ program p
   if (abs(c1 - 0.5) > e3) stop 39
   if (abs(d1 - 0.5) > e4) stop 40
 
-  a1 = acospi(0.5)
-  b1 = acospi(-0.5)
+  a1 = 0.5; a1 = acospi(a1)
+  b1 = -0.5; b1 = acospi(b1)
   c1 = acospi(0.5)
   d1 = acospi(-0.5)
-  if (abs(a1 - 1.0 / 3) > e1) stop 41
-  if (abs(b1 - 2.0 / 3) > e2) stop 42
+  if (abs(a1 - 1._4 / 3) > e1) stop 41
+  if (abs(b1 - 2._8 / 3) > e2) stop 42
   if (abs(c1 - 1.0 / 3) > e3) stop 43
   if (abs(d1 - 2.0 / 3) > e4) stop 44
 
-  a1 = asinpi(0.5)
-  b1 = asinpi(-0.5)
+  a1 = 0.5; a1 = asinpi(a1)
+  b1 = -0.5; b1 = asinpi(b1)
   c1 = asinpi(0.5)
   d1 = asinpi(-0.5)
-  if (abs(a1 - 1.0 / 6) > e1) stop 45
-  if (abs(b1 + 1.0 / 6) > e2) stop 46
+  if (abs(a1 - 1._4 / 6) > e1) stop 45
+  if (abs(b1 + 1._8 / 6) > e2) stop 46
   if (abs(c1 - 1.0 / 6) > e3) stop 47
   if (abs(d1 + 1.0 / 6) > e4) stop 48
 
-  a1 = atanpi(1.0)
-  b1 = atanpi(-1.0)
+  a1 = 1.0; a1 = atanpi(a1)
+  b1 = -1.0; b1 = atanpi(b1)
   c1 = atanpi(1.0)
   d1 = atanpi(-1.0)
   if (abs(a1 - 0.25) > e1) stop 49
@@ -129,8 +129,8 @@ program p
   if (abs(c1 - 0.25) > e3) stop 51
   if (abs(d1 + 0.25) > e4) stop 52
 
-  a1 = atan2pi(1.0, 1.0)
-  b1 = atan2pi(1.0, 1.0)
+  a1 = 1.0; a1 = atan2pi(a1, a1)
+  b1 = 1.0; b1 = atan2pi(b1, b1)
   c1 = atan2pi(1.0, 1.0)
   d1 = atan2pi(1.0, 1.0)
   if (abs(a1 - 0.25) > e1) stop 53
@@ -138,8 +138,8 @@ program p
   if (abs(c1 - 0.25) > e3) stop 55
   if (abs(d1 - 0.25) > e4) stop 56
 
-  a1 = cospi(1._4 / 3)
-  b1 = cospi(-1._8 / 3)
+  a1 = 1._4 / 3; a1 = cospi(a1)
+  b1 = -1._8 / 3; b1 = cospi(b1)
   c1 = cospi(4._ep / 3)
   d1 = cospi(-4._16 / 3)
   if (abs(a1 - 0.5) > e1) stop 57
@@ -147,8 +147,8 @@ pro