public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: libc-alpha@sourceware.org
Subject: [PATCH] x86-64: Don't inline atof without SSE2 [BZ #27600]
Date: Wed, 17 Mar 2021 18:54:14 -0700	[thread overview]
Message-ID: <20210318015414.902129-1-hjl.tools@gmail.com> (raw)

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


             reply	other threads:[~2021-03-18  1:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18  1:54 H.J. Lu [this message]
2021-03-18  5:03 ` Florian Weimer

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=20210318015414.902129-1-hjl.tools@gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /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).