aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/config/nvptx/nvptx.md16
-rw-r--r--libatomic/config/nvptx/host-config.h56
-rw-r--r--libatomic/config/nvptx/lock.c56
-rw-r--r--libatomic/configure.tgt3
-rw-r--r--libatomic/libatomic_i.h2
5 files changed, 133 insertions, 0 deletions
diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md
index 4168190..6178e6a 100644
--- a/gcc/config/nvptx/nvptx.md
+++ b/gcc/config/nvptx/nvptx.md
@@ -1667,6 +1667,22 @@
"%.\\tatom%A1.b%T0.<logic>\\t%0, %1, %2;"
[(set_attr "atomic" "true")])
+(define_expand "atomic_test_and_set"
+ [(match_operand:SI 0 "nvptx_register_operand") ;; bool success output
+ (match_operand:QI 1 "memory_operand") ;; memory
+ (match_operand:SI 2 "const_int_operand")] ;; model
+ ""
+{
+ rtx libfunc;
+ rtx addr;
+ libfunc = init_one_libfunc ("__atomic_test_and_set_1");
+ addr = convert_memory_address (ptr_mode, XEXP (operands[1], 0));
+ emit_library_call_value (libfunc, operands[0], LCT_NORMAL, SImode,
+ addr, ptr_mode,
+ operands[2], SImode);
+ DONE;
+})
+
(define_insn "nvptx_barsync"
[(unspec_volatile [(match_operand:SI 0 "nvptx_nonmemory_operand" "Ri")
(match_operand:SI 1 "const_int_operand")]
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);
+}
diff --git a/libatomic/configure.tgt b/libatomic/configure.tgt
index efb3b1e..7834e0a 100644
--- a/libatomic/configure.tgt
+++ b/libatomic/configure.tgt
@@ -174,6 +174,9 @@ case "${target}" in
UNSUPPORTED=1
;;
+ nvptx*-*-*)
+ ;;
+
*)
# Who are you?
UNSUPPORTED=1
diff --git a/libatomic/libatomic_i.h b/libatomic/libatomic_i.h
index 081b154..37de992 100644
--- a/libatomic/libatomic_i.h
+++ b/libatomic/libatomic_i.h
@@ -109,9 +109,11 @@ typedef unsigned UWORD __attribute__((mode(word)));
#define MASK_1 ((UWORD)0xff)
#define MASK_2 ((UWORD)0xffff)
#define MASK_4 ((UWORD)0xffffffff)
+#define MASK_8 ((UWORD)0xffffffffffffffff)
#define INVERT_MASK_1 ((UWORD)WORDS_BIGENDIAN << ((WORDSIZE - 1) * CHAR_BIT))
#define INVERT_MASK_2 ((UWORD)WORDS_BIGENDIAN << ((WORDSIZE - 2) * CHAR_BIT))
#define INVERT_MASK_4 ((UWORD)WORDS_BIGENDIAN << ((WORDSIZE - 4) * CHAR_BIT))
+#define INVERT_MASK_8 ((UWORD)WORDS_BIGENDIAN << ((WORDSIZE - 8) * CHAR_BIT))
/* Most of the files in this library are compiled multiple times with
N defined to be a power of 2 between 1 and 16. The SIZE macro is