public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] x86-64: Don't inline atof without SSE2 [BZ #27600]
@ 2021-03-18  1:54 H.J. Lu
  2021-03-18  5:03 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2021-03-18  1:54 UTC (permalink / raw)
  To: libc-alpha

Since without SSE2, inlined atof fails with

/usr/include/bits/stdlib-float.h: In function ‘atof’:
/usr/include/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
   26 | {
      | ^

don't inline atof without SSE2 for x86-64.
---
 include/bits/stdlib-float.h     |  4 ++--
 sysdeps/x86/Makefile            |  7 +++++++
 sysdeps/x86/bits/stdlib-float.h | 29 +++++++++++++++++++++++++++++
 sysdeps/x86/tst-stdlib.c        | 27 +++++++++++++++++++++++++++
 4 files changed, 65 insertions(+), 2 deletions(-)
 create mode 100644 sysdeps/x86/bits/stdlib-float.h
 create mode 100644 sysdeps/x86/tst-stdlib.c

diff --git a/include/bits/stdlib-float.h b/include/bits/stdlib-float.h
index 54ab571981..4474d1d2dc 100644
--- a/include/bits/stdlib-float.h
+++ b/include/bits/stdlib-float.h
@@ -1,8 +1,8 @@
 /* No floating-point inline functions in rtld and for the conform tests.  */
 #ifdef _ISOMAC
-# include <stdlib/bits/stdlib-float.h>
+# include_next <bits/stdlib-float.h>
 #else
 # if !IS_IN (rtld)
-#  include <stdlib/bits/stdlib-float.h>
+#  include_next <bits/stdlib-float.h>
 # endif
 #endif
diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index 3ca7bfefe4..d6381e73af 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -221,3 +221,10 @@ tests += \
 tests-static += \
   tst-sysconf-cache-linesize-static
 endif
+
+ifeq ($(subdir),stdlib)
+tests += \
+  tst-stdlib
+
+CFLAGS-tst-stdlib.c += -mno-sse
+endif
diff --git a/sysdeps/x86/bits/stdlib-float.h b/sysdeps/x86/bits/stdlib-float.h
new file mode 100644
index 0000000000..17be04b927
--- /dev/null
+++ b/sysdeps/x86/bits/stdlib-float.h
@@ -0,0 +1,29 @@
+/* Floating-point inline functions for stdlib.h.
+   Copyright (C) 2012-2021 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 _STDLIB_H
+# error "Never use <bits/stdlib-float.h> directly; include <stdlib.h> instead."
+#endif
+
+#if defined __USE_EXTERN_INLINES && (!defined __x86_64__ || defined __SSE2__)
+__extern_inline double
+__NTH (atof (const char *__nptr))
+{
+  return strtod (__nptr, (char **) NULL);
+}
+#endif /* Optimizing and Inlining.  */
diff --git a/sysdeps/x86/tst-stdlib.c b/sysdeps/x86/tst-stdlib.c
new file mode 100644
index 0000000000..226eb35a5d
--- /dev/null
+++ b/sysdeps/x86/tst-stdlib.c
@@ -0,0 +1,27 @@
+/* Test <stdlib.h> with -mno-sse.
+   Copyright (C) 2021 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/>.  */
+
+#include <stdlib.h>
+
+static int
+do_test (void)
+{
+  return 0;
+}
+
+#include <support/test-driver.c>
-- 
2.30.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86-64: Don't inline atof without SSE2 [BZ #27600]
  2021-03-18  1:54 [PATCH] x86-64: Don't inline atof without SSE2 [BZ #27600] H.J. Lu
@ 2021-03-18  5:03 ` Florian Weimer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2021-03-18  5:03 UTC (permalink / raw)
  To: H.J. Lu via Libc-alpha

* H. J. Lu via Libc-alpha:

> Since without SSE2, inlined atof fails with
>
> /usr/include/bits/stdlib-float.h: In function ‘atof’:
> /usr/include/bits/stdlib-float.h:26:1: error: SSE register return with SSE disabled
>    26 | {
>       | ^
>
> don't inline atof without SSE2 for x86-64.

Could you say publicly why you want to make this change, given that SSE2
is a mandatory part of x86-64?

> +#if defined __USE_EXTERN_INLINES && (!defined __x86_64__ || defined __SSE2__)
> +__extern_inline double
> +__NTH (atof (const char *__nptr))
> +{
> +  return strtod (__nptr, (char **) NULL);
> +}

This is just an inline function that is using the double type, not
something that uses an SSE2 type.  It's not even always_inline.  Many
other headers will have the same problem, especially for C++.  I think
you should teach GCC not to issue a diagnostic for inline functions
whose definitions are not used in a compilation.  This is how
-mgeneral-regs-only behaves on AArch64 already, if I'm not mistaken.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-18  5:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18  1:54 [PATCH] x86-64: Don't inline atof without SSE2 [BZ #27600] H.J. Lu
2021-03-18  5:03 ` Florian Weimer

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).