[2/6] MIPS/math: Define port-specific GET_HIGH_WORD

Message ID 20240513081429.1749898-3-syq@gcc.gnu.org
State New
Headers
Series MIPS: Improve math |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Testing passed

Commit Message

YunQiang Su May 13, 2024, 8:14 a.m. UTC
  The generic implemention may issue some unneeded stack store and
load operations.

	* sysdeps/mips/math_private.h

Signed-off-by: YunQiang Su <syq@gcc.gnu.org>
---
 sysdeps/mips/math_private.h | 56 +++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 sysdeps/mips/math_private.h
  

Comments

Adhemerval Zanella Netto May 22, 2024, 6:36 p.m. UTC | #1
On 13/05/24 05:14, YunQiang Su wrote:
> The generic implemention may issue some unneeded stack store and
> load operations.
> 
> 	* sysdeps/mips/math_private.h
> 
> Signed-off-by: YunQiang Su <syq@gcc.gnu.org>

That's not what I see with a recent GCC [1] and such macros uses generic
code for fp to int transformation where it is expected that the compiler
have all the required information to handle it correctly (check 
4e7fbdd7c2884e8909ea8f2f59d52f7d0c699252 for why we removed such optimization
from x86_64 and if you still see issues the correct way is to fix it on
compiler).

[1] https://godbolt.org/z/7TdsY7b6v

> ---
>  sysdeps/mips/math_private.h | 56 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
>  create mode 100644 sysdeps/mips/math_private.h
> 
> diff --git a/sysdeps/mips/math_private.h b/sysdeps/mips/math_private.h
> new file mode 100644
> index 0000000000..4da8b0c2d9
> --- /dev/null
> +++ b/sysdeps/mips/math_private.h
> @@ -0,0 +1,56 @@
> +/* Copyright (C) 2024 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
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#ifndef MIPS_MATH_PRIVATE_H
> +#define MIPS_MATH_PRIVATE_H 1
> +
> +#include <math.h>
> +#include <nan-high-order-bit.h>
> +#include_next <math_private.h>
> +#include <fpu_control.h>
> +
> +#if defined(__mips_hard_float) && !defined(__mips_single_float)
> +#  undef GET_HIGH_WORD
> +#  if __mips_isa_rev >= 2
> +#    define GET_HIGH_WORD(i, d)                                               \
> +      do                                                                      \
> +	{                                                                     \
> +	  asm volatile("mfhc1  %0, %1" : "=r"(i) : "f"(d));                   \
> +	}                                                                     \
> +      while (0)
> +#  elif defined(__mips64)
> +#    define GET_HIGH_WORD(i, d)                                               \
> +      do                                                                      \
> +	{                                                                     \
> +	  long long di;                                                       \
> +	  asm volatile("dmfc1  %0, %1" : "=r"(di) : "f"(d));                  \
> +	  i = di >> 32;                                                       \
> +	}                                                                     \
> +      while (0)
> +#  else
> +#    define GET_HIGH_WORD(i, d)                                               \
> +      do                                                                      \
> +	{                                                                     \
> +	  long long tmp[1];                                                   \
> +	  asm volatile("sdc1 %1, %0" : "=m"(tmp) : "f"(d));                   \
> +	  (i) = tmp[0] >> 32;                                                 \
> +	}                                                                     \
> +      while (0)
> +#  endif
> +#endif /* __mips_hard_float && !__mips_single_float */
> +
> +#endif /* MIPS_MATH_PRIVATE_H */
  

Patch

diff --git a/sysdeps/mips/math_private.h b/sysdeps/mips/math_private.h
new file mode 100644
index 0000000000..4da8b0c2d9
--- /dev/null
+++ b/sysdeps/mips/math_private.h
@@ -0,0 +1,56 @@ 
+/* Copyright (C) 2024 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
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef MIPS_MATH_PRIVATE_H
+#define MIPS_MATH_PRIVATE_H 1
+
+#include <math.h>
+#include <nan-high-order-bit.h>
+#include_next <math_private.h>
+#include <fpu_control.h>
+
+#if defined(__mips_hard_float) && !defined(__mips_single_float)
+#  undef GET_HIGH_WORD
+#  if __mips_isa_rev >= 2
+#    define GET_HIGH_WORD(i, d)                                               \
+      do                                                                      \
+	{                                                                     \
+	  asm volatile("mfhc1  %0, %1" : "=r"(i) : "f"(d));                   \
+	}                                                                     \
+      while (0)
+#  elif defined(__mips64)
+#    define GET_HIGH_WORD(i, d)                                               \
+      do                                                                      \
+	{                                                                     \
+	  long long di;                                                       \
+	  asm volatile("dmfc1  %0, %1" : "=r"(di) : "f"(d));                  \
+	  i = di >> 32;                                                       \
+	}                                                                     \
+      while (0)
+#  else
+#    define GET_HIGH_WORD(i, d)                                               \
+      do                                                                      \
+	{                                                                     \
+	  long long tmp[1];                                                   \
+	  asm volatile("sdc1 %1, %0" : "=m"(tmp) : "f"(d));                   \
+	  (i) = tmp[0] >> 32;                                                 \
+	}                                                                     \
+      while (0)
+#  endif
+#endif /* __mips_hard_float && !__mips_single_float */
+
+#endif /* MIPS_MATH_PRIVATE_H */