aboutsummaryrefslogtreecommitdiff
path: root/libatomic/config
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2020-09-07 10:47:25 +0200
committerTom de Vries <tdevries@suse.de>2020-09-11 12:06:15 +0200
commit15545563128f0240192c263522d4a36b7f86250f (patch)
tree746bb4c9e006aa697779062ec38bfd6e35ff6fea /libatomic/config
parent8ae0de5621120b16295fe6b73ca044d4c576af6d (diff)
downloadgcc-15545563128f0240192c263522d4a36b7f86250f.zip
gcc-15545563128f0240192c263522d4a36b7f86250f.tar.gz
gcc-15545563128f0240192c263522d4a36b7f86250f.tar.bz2
[libatomic] Add nvptx support
Add nvptx support to libatomic. Given that atomic_test_and_set is not implemented for nvptx (PR96964), the compiler translates __atomic_test_and_set falling back onto the "Failing all else, assume a single threaded environment and simply perform the operation" case in expand_atomic_test_and_set, so it doesn't map onto an actual atomic operation. Still, that counts as supported for the configure test of libatomic, so we end up with HAVE_ATOMIC_TAS_1/2/4/8/16 == 1, and the corresponding __atomic_test_and_set_1/2/4/8/16 in libatomic all using that non-atomic implementation. Fix this by adding an atomic_test_and_set expansion for nvptx, that uses libatomics __atomic_test_and_set_1. This again makes the configure tests for HAVE_ATOMIC_TAS_1/2/4/8/16 fail, so instead we use this case in tas_n.c: ... /* If this type is smaller than word-sized, fall back to a word-sized compare-and-swap loop. */ bool SIZE(libat_test_and_set) (UTYPE *mptr, int smodel) ... which for __atomic_test_and_set_8 uses INVERT_MASK_8. Add INVERT_MASK_8 in libatomic_i.h, as well as MASK_8. Tested libatomic testsuite on nvptx. gcc/ChangeLog: PR target/96964 * config/nvptx/nvptx.md (define_expand "atomic_test_and_set"): New expansion. libatomic/ChangeLog: PR target/96898 * configure.tgt: Add nvptx. * libatomic_i.h (MASK_8, INVERT_MASK_8): New macro definition. * config/nvptx/host-config.h: New file. * config/nvptx/lock.c: New file.
Diffstat (limited to 'libatomic/config')
-rw-r--r--libatomic/config/nvptx/host-config.h56
-rw-r--r--libatomic/config/nvptx/lock.c56
2 files changed, 112 insertions, 0 deletions
diff --git a/libatomic/config/nvptx/host-config.h b/libatomic/config/nvptx/host-config.h
new file mode 100644
index 0000000..eb9de81
--- /dev/null
+++ b/libatomic/config/nvptx/host-config.h
@@ -0,0 +1,56 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This file is part of the GNU Atomic Library (libatomic).
+
+ Libatomic is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Libatomic 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 General Public License for
+ more details.
+
+ Under Section 7 of GPL version 3, you are granted additional
+ permissions described in the GCC Runtime Library Exception, version
+ 3.1, as published by the Free Software Foundation.
+
+ You should have received a copy of the GNU General Public License and
+ a copy of the GCC Runtime Library Exception along with this program;
+ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Copied from libatomic/config/posix/host-config.h. */
+
+/* Included after all more target-specific host-config.h. */
+
+
+#ifndef protect_start_end
+# ifdef HAVE_ATTRIBUTE_VISIBILITY
+# pragma GCC visibility push(hidden)
+# endif
+
+void libat_lock_1 (void *ptr);
+void libat_unlock_1 (void *ptr);
+
+static inline UWORD
+protect_start (void *ptr)
+{
+ libat_lock_1 (ptr);
+ return 0;
+}
+
+static inline void
+protect_end (void *ptr, UWORD dummy UNUSED)
+{
+ libat_unlock_1 (ptr);
+}
+
+# define protect_start_end 1
+# ifdef HAVE_ATTRIBUTE_VISIBILITY
+# pragma GCC visibility pop
+# endif
+#endif /* protect_start_end */
+
+#include_next <host-config.h>
diff --git a/libatomic/config/nvptx/lock.c b/libatomic/config/nvptx/lock.c
new file mode 100644
index 0000000..dea85a3
--- /dev/null
+++ b/libatomic/config/nvptx/lock.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This file is part of the GNU Atomic Library (libatomic).
+
+ Libatomic is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ Libatomic 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 General Public License for
+ more details.
+
+ Under Section 7 of GPL version 3, you are granted additional
+ permissions described in the GCC Runtime Library Exception, version
+ 3.1, as published by the Free Software Foundation.
+
+ You should have received a copy of the GNU General Public License and
+ a copy of the GCC Runtime Library Exception along with this program;
+ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Functions libat_lock_n/libat_unlock_n based on GOMP_atomic_start/end in
+ libgomp/atomic.c. */
+
+#include "libatomic_i.h"
+
+static int atomic_lock;
+
+void
+libat_lock_n (void *ptr __attribute__((unused)),
+ size_t n __attribute__((unused)))
+{
+ while (__sync_lock_test_and_set (&atomic_lock, 1))
+ ; /* Spin. */
+}
+
+void
+libat_unlock_n (void *ptr __attribute__((unused)),
+ size_t n __attribute__((unused)))
+{
+ __sync_lock_release (&atomic_lock);
+}
+
+void
+libat_lock_1 (void *ptr)
+{
+ libat_lock_n (ptr, 1);
+}
+
+void
+libat_unlock_1 (void *ptr)
+{
+ libat_unlock_n (ptr, 1);
+}