diff options
Diffstat (limited to 'libstdc++-v3/config/cpu')
20 files changed, 1287 insertions, 0 deletions
diff --git a/libstdc++-v3/config/cpu/alpha/atomic_word.h b/libstdc++-v3/config/cpu/alpha/atomic_word.h new file mode 100644 index 000000000..266b3855e --- /dev/null +++ b/libstdc++-v3/config/cpu/alpha/atomic_word.h @@ -0,0 +1,33 @@ +// Low-level type for atomic operations -*- C++ -*- + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#ifndef _GLIBCXX_ATOMIC_WORD_H +#define _GLIBCXX_ATOMIC_WORD_H 1 + +typedef int _Atomic_word; + +#define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("mb":::"memory") +#define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("wmb":::"memory") + +#endif diff --git a/libstdc++-v3/config/cpu/arm/cxxabi_tweaks.h b/libstdc++-v3/config/cpu/arm/cxxabi_tweaks.h new file mode 100644 index 000000000..2ac349dfc --- /dev/null +++ b/libstdc++-v3/config/cpu/arm/cxxabi_tweaks.h @@ -0,0 +1,82 @@ +// Control various target specific ABI tweaks. ARM version. + +// Copyright (C) 2004, 2006, 2008, 2009, 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +/** @file bits/cxxabi_tweaks.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{cxxabi.h} + */ + +#ifndef _CXXABI_TWEAKS_H +#define _CXXABI_TWEAKS_H 1 + +#ifdef __cplusplus +namespace __cxxabiv1 +{ + extern "C" + { +#endif + +#ifdef __ARM_EABI__ + // The ARM EABI uses the least significant bit of a 32-bit + // guard variable. */ +#define _GLIBCXX_GUARD_TEST(x) ((*(x) & 1) != 0) +#define _GLIBCXX_GUARD_SET(x) *(x) = 1 +#define _GLIBCXX_GUARD_BIT 1 +#define _GLIBCXX_GUARD_PENDING_BIT __guard_test_bit (1, 1) +#define _GLIBCXX_GUARD_WAITING_BIT __guard_test_bit (2, 1) + typedef int __guard; + + // We also want the element size in array cookies. +#define _GLIBCXX_ELTSIZE_IN_COOKIE 1 + + // __cxa_vec_ctor should return a pointer to the array. + typedef void * __cxa_vec_ctor_return_type; +#define _GLIBCXX_CXA_VEC_CTOR_RETURN(x) return x + // Constructors and destructors return the "this" pointer. + typedef void * __cxa_cdtor_return_type; + +#else // __ARM_EABI__ + + // The generic ABI uses the first byte of a 64-bit guard variable. +#define _GLIBCXX_GUARD_TEST(x) (*(char *) (x) != 0) +#define _GLIBCXX_GUARD_SET(x) *(char *) (x) = 1 +#define _GLIBCXX_GUARD_BIT __guard_test_bit (0, 1) +#define _GLIBCXX_GUARD_PENDING_BIT __guard_test_bit (1, 1) +#define _GLIBCXX_GUARD_WAITING_BIT __guard_test_bit (2, 1) + __extension__ typedef int __guard __attribute__((mode (__DI__))); + + // __cxa_vec_ctor has void return type. + typedef void __cxa_vec_ctor_return_type; +#define _GLIBCXX_CXA_VEC_CTOR_RETURN(x) return + // Constructors and destructors do not return a value. + typedef void __cxa_cdtor_return_type; + +#endif //!__ARM_EABI__ + +#ifdef __cplusplus + } +} // namespace __cxxabiv1 +#endif + +#endif diff --git a/libstdc++-v3/config/cpu/cris/atomic_word.h b/libstdc++-v3/config/cpu/cris/atomic_word.h new file mode 100644 index 000000000..369b7b0c5 --- /dev/null +++ b/libstdc++-v3/config/cpu/cris/atomic_word.h @@ -0,0 +1,31 @@ +// Low-level type for atomic operations -*- C++ -*- + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#ifndef _GLIBCXX_ATOMIC_WORD_H +#define _GLIBCXX_ATOMIC_WORD_H 1 + +// This entity must not cross a page boundary. +typedef int _Atomic_word __attribute__ ((__aligned__ (4))); + +#endif diff --git a/libstdc++-v3/config/cpu/cris/atomicity.h b/libstdc++-v3/config/cpu/cris/atomicity.h new file mode 100644 index 000000000..148a8b61c --- /dev/null +++ b/libstdc++-v3/config/cpu/cris/atomicity.h @@ -0,0 +1,89 @@ +// Low-level functions for atomic operations: CRIS version -*- C++ -*- + +// Copyright (C) 2001, 2003, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#include <ext/atomicity.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + _Atomic_word + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + int __tmp; + _Atomic_word __result; + +#if (__CRIS_arch_version >= 32) + __asm__ __volatile__ (" clearf p \n" + "0: \n" + " move.d %4,%2 \n" + " move.d [%3],%0 \n" + " add.d %0,%2 \n" + " ax \n" + " move.d %2,[%3] \n" + " bcs 0b \n" + " clearf p \n" + : "=&r" (__result), "=Q" (*__mem), "=&r" (__tmp) + : "r" (__mem), "g" (__val), "Q" (*__mem) + : "memory"); +#elif (__CRIS_arch_version >= 10) + __asm__ __volatile__ (" clearf \n" + "0: \n" + " move.d %4,%2 \n" + " move.d [%3],%0 \n" + " add.d %0,%2 \n" + " ax \n" + " move.d %2,[%3] \n" + " bwf 0b \n" + " clearf \n" + : "=&r" (__result), "=Q" (*__mem), "=&r" (__tmp) + : "r" (__mem), "g" (__val), "Q" (*__mem) + /* The memory clobber must stay, regardless of + current uses of this function. */ + : "memory"); +#else + __asm__ __volatile__ (" move $ccr,$r9 \n" + " di \n" + " move.d %4,%2 \n" + " move.d [%3],%0 \n" + " add.d %0,%2 \n" + " move.d %2,[%3] \n" + " move $r9,$ccr \n" + : "=&r" (__result), "=Q" (*__mem), "=&r" (__tmp) + : "r" (__mem), "g" (__val), "Q" (*__mem) + : "r9", + /* The memory clobber must stay, regardless of + current uses of this function. */ + "memory"); +#endif + + return __result; + } + + void + __atomic_add(volatile _Atomic_word* __mem, int __val) throw () + { __exchange_and_add(__mem, __val); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/libstdc++-v3/config/cpu/generic/atomic_word.h b/libstdc++-v3/config/cpu/generic/atomic_word.h new file mode 100644 index 000000000..f2bdbbc96 --- /dev/null +++ b/libstdc++-v3/config/cpu/generic/atomic_word.h @@ -0,0 +1,47 @@ +// Low-level type for atomic operations -*- C++ -*- + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +/** @file atomic_word.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _GLIBCXX_ATOMIC_WORD_H +#define _GLIBCXX_ATOMIC_WORD_H 1 + +typedef int _Atomic_word; + +// Define these two macros using the appropriate memory barrier for the target. +// The commented out versions below are the defaults. +// See ia64/atomic_word.h for an alternative approach. + +// This one prevents loads from being hoisted across the barrier; +// in other words, this is a Load-Load acquire barrier. +// This is necessary iff TARGET_RELAXED_ORDERING is defined in tm.h. +// #define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("":::"memory") + +// This one prevents stores from being sunk across the barrier; in other +// words, a Store-Store release barrier. +// #define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("":::"memory") + +#endif diff --git a/libstdc++-v3/config/cpu/generic/atomicity_builtins/atomicity.h b/libstdc++-v3/config/cpu/generic/atomicity_builtins/atomicity.h new file mode 100644 index 000000000..581c41fda --- /dev/null +++ b/libstdc++-v3/config/cpu/generic/atomicity_builtins/atomicity.h @@ -0,0 +1,44 @@ +// Low-level functions for atomic operations: version for CPUs providing +// atomic builtins -*- C++ -*- + +// Copyright (C) 2006, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#include <bits/c++config.h> +#include <bits/atomic_word.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { return __sync_fetch_and_add(__mem, __val); } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) throw () + { __sync_fetch_and_add(__mem, __val); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/libstdc++-v3/config/cpu/generic/atomicity_mutex/atomicity.h b/libstdc++-v3/config/cpu/generic/atomicity_mutex/atomicity.h new file mode 100644 index 000000000..dc0a5a065 --- /dev/null +++ b/libstdc++-v3/config/cpu/generic/atomicity_mutex/atomicity.h @@ -0,0 +1,60 @@ +// Low-level functions for atomic operations: Generic version -*- C++ -*- + +// Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#include <ext/atomicity.h> +#include <ext/concurrence.h> + +namespace +{ + __gnu_cxx::__mutex& + get_atomic_mutex() + { + static __gnu_cxx::__mutex atomic_mutex; + return atomic_mutex; + } +} // anonymous namespace + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + __gnu_cxx::__scoped_lock sentry(get_atomic_mutex()); + _Atomic_word __result; + __result = *__mem; + *__mem += __val; + return __result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) throw () + { __exchange_and_add(__mem, __val); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/libstdc++-v3/config/cpu/generic/cpu_defines.h b/libstdc++-v3/config/cpu/generic/cpu_defines.h new file mode 100644 index 000000000..c1b986337 --- /dev/null +++ b/libstdc++-v3/config/cpu/generic/cpu_defines.h @@ -0,0 +1,33 @@ +// Specific definitions for generic platforms -*- C++ -*- + +// Copyright (C) 2005, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +/** @file bits/cpu_defines.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{iosfwd} + */ + +#ifndef _GLIBCXX_CPU_DEFINES +#define _GLIBCXX_CPU_DEFINES 1 + +#endif diff --git a/libstdc++-v3/config/cpu/generic/cxxabi_tweaks.h b/libstdc++-v3/config/cpu/generic/cxxabi_tweaks.h new file mode 100644 index 000000000..f48f73e00 --- /dev/null +++ b/libstdc++-v3/config/cpu/generic/cxxabi_tweaks.h @@ -0,0 +1,59 @@ +// Control various target specific ABI tweaks. Generic version. + +// Copyright (C) 2004, 2006, 2008, 2009, 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +/** @file bits/cxxabi_tweaks.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{cxxabi.h} + */ + +#ifndef _CXXABI_TWEAKS_H +#define _CXXABI_TWEAKS_H 1 + +#ifdef __cplusplus +namespace __cxxabiv1 +{ + extern "C" + { +#endif + + // The generic ABI uses the first byte of a 64-bit guard variable. +#define _GLIBCXX_GUARD_TEST(x) (*(char *) (x) != 0) +#define _GLIBCXX_GUARD_SET(x) *(char *) (x) = 1 +#define _GLIBCXX_GUARD_BIT __guard_test_bit (0, 1) +#define _GLIBCXX_GUARD_PENDING_BIT __guard_test_bit (1, 1) +#define _GLIBCXX_GUARD_WAITING_BIT __guard_test_bit (2, 1) + __extension__ typedef int __guard __attribute__((mode (__DI__))); + + // __cxa_vec_ctor has void return type. + typedef void __cxa_vec_ctor_return_type; +#define _GLIBCXX_CXA_VEC_CTOR_RETURN(x) return + // Constructors and destructors do not return a value. + typedef void __cxa_cdtor_return_type; + +#ifdef __cplusplus + } +} // namespace __cxxabiv1 +#endif + +#endif diff --git a/libstdc++-v3/config/cpu/hppa/atomicity.h b/libstdc++-v3/config/cpu/hppa/atomicity.h new file mode 100644 index 000000000..a2ec4f2e9 --- /dev/null +++ b/libstdc++-v3/config/cpu/hppa/atomicity.h @@ -0,0 +1,94 @@ +// Low-level functions for atomic operations: PA-RISC version -*- C++ -*- + +// Copyright (C) 2002, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#include <bits/c++config.h> +#include <ext/atomicity.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template<int _Inst> + struct _Atomicity_lock + { + static volatile int _S_atomicity_lock; + }; + + template<int _Inst> + volatile int + _Atomicity_lock<_Inst>::_S_atomicity_lock __attribute__ ((aligned (16))) = 1; + + // Because of the lack of weak support when using the hpux som + // linker, we explicitly instantiate the atomicity lock. + template volatile int _Atomicity_lock<0>::_S_atomicity_lock; + + int + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + _Atomic_word result; + int tmp; + volatile int& lock = _Atomicity_lock<0>::_S_atomicity_lock; + + __asm__ __volatile__ ("ldcw 0(%1),%0\n\t" + "cmpib,<>,n 0,%0,.+20\n\t" + "ldw 0(%1),%0\n\t" + "cmpib,= 0,%0,.-4\n\t" + "nop\n\t" + "b,n .-20" + : "=&r" (tmp) + : "r" (&lock) + : "memory"); + + result = *__mem; + *__mem = result + __val; + __asm__ __volatile__ ("stw %1,0(%0)" + : : "r" (&lock), "r" (tmp) : "memory"); + return result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) throw () + { + int tmp; + volatile int& lock = _Atomicity_lock<0>::_S_atomicity_lock; + + __asm__ __volatile__ ("ldcw 0(%1),%0\n\t" + "cmpib,<>,n 0,%0,.+20\n\t" + "ldw 0(%1),%0\n\t" + "cmpib,= 0,%0,.-4\n\t" + "nop\n\t" + "b,n .-20" + : "=&r" (tmp) + : "r" (&lock) + : "memory"); + + *__mem += __val; + __asm__ __volatile__ ("stw %1,0(%0)" + : : "r" (&lock), "r" (tmp) : "memory"); + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/libstdc++-v3/config/cpu/i386/atomicity.h b/libstdc++-v3/config/cpu/i386/atomicity.h new file mode 100644 index 000000000..97205e42f --- /dev/null +++ b/libstdc++-v3/config/cpu/i386/atomicity.h @@ -0,0 +1,73 @@ +// Low-level functions for atomic operations: x86, x >= 3 version -*- C++ -*- + +// Copyright (C) 2003, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#include <ext/atomicity.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template<int __inst> + struct _Atomicity_lock + { + static volatile _Atomic_word _S_atomicity_lock; + }; + + template<int __inst> + volatile _Atomic_word _Atomicity_lock<__inst>::_S_atomicity_lock = 0; + + template volatile _Atomic_word _Atomicity_lock<0>::_S_atomicity_lock; + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + register _Atomic_word __result, __tmp = 1; + + // Obtain the atomic exchange/add spin lock. + do + { + __asm__ __volatile__ ("xchg{l} {%0,%1|%1,%0}" + : "=m" (_Atomicity_lock<0>::_S_atomicity_lock), + "+r" (__tmp) + : "m" (_Atomicity_lock<0>::_S_atomicity_lock)); + } + while (__tmp); + + __result = *__mem; + *__mem += __val; + + // Release spin lock. + _Atomicity_lock<0>::_S_atomicity_lock = 0; + + return __result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) throw () + { __exchange_and_add(__mem, __val); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/libstdc++-v3/config/cpu/i486/atomicity.h b/libstdc++-v3/config/cpu/i486/atomicity.h new file mode 100644 index 000000000..602cbb711 --- /dev/null +++ b/libstdc++-v3/config/cpu/i486/atomicity.h @@ -0,0 +1,52 @@ +// Low-level functions for atomic operations: x86, x >= 4 version -*- C++ -*- + +// Copyright (C) 1999, 2000, 2001, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#include <ext/atomicity.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + register _Atomic_word __result; + __asm__ __volatile__ ("lock; xadd{l} {%0,%1|%1,%0}" + : "=r" (__result), "=m" (*__mem) + : "0" (__val), "m" (*__mem)); + return __result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) throw () + { + __asm__ __volatile__ ("lock; add{l} {%1,%0|%0,%1}" + : "=m" (*__mem) : "ir" (__val), "m" (*__mem)); + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + diff --git a/libstdc++-v3/config/cpu/ia64/atomic_word.h b/libstdc++-v3/config/cpu/ia64/atomic_word.h new file mode 100644 index 000000000..9dfbf00ec --- /dev/null +++ b/libstdc++-v3/config/cpu/ia64/atomic_word.h @@ -0,0 +1,64 @@ +// Low-level type for atomic operations -*- C++ -*- + +// Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#ifndef _GLIBCXX_ATOMIC_WORD_H +#define _GLIBCXX_ATOMIC_WORD_H 1 + +#include <bits/cxxabi_tweaks.h> + +typedef int _Atomic_word; + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ + // Test the first byte of __g and ensure that no loads are hoisted across + // the test. + inline bool + __test_and_acquire (__cxxabiv1::__guard *__g) + { + unsigned char __c; + unsigned char *__p = reinterpret_cast<unsigned char *>(__g); + // ldN.acq is a load with an implied hoist barrier. + // would ld8+mask be faster than just doing an ld1? + __asm __volatile ("ld1.acq %0 = %1" : "=r"(__c) : "m"(*__p) : "memory"); + return __c != 0; + } + + // Set the first byte of __g to 1 and ensure that no stores are sunk + // across the store. + inline void + __set_and_release (__cxxabiv1::__guard *__g) + { + unsigned char *__p = reinterpret_cast<unsigned char *>(__g); + // stN.rel is a store with an implied sink barrier. + // could load word, set flag, and CAS it back + __asm __volatile ("st1.rel %0 = %1" : "=m"(*__p) : "r"(1) : "memory"); + } + + // We don't define the _BARRIER macros on ia64 because the barriers are + // included in the test and set, above. +#define _GLIBCXX_GUARD_TEST_AND_ACQUIRE(G) __gnu_cxx::__test_and_acquire (G) +#define _GLIBCXX_GUARD_SET_AND_RELEASE(G) __gnu_cxx::__set_and_release (G) +} + +#endif diff --git a/libstdc++-v3/config/cpu/m68k/atomicity.h b/libstdc++-v3/config/cpu/m68k/atomicity.h new file mode 100644 index 000000000..571125584 --- /dev/null +++ b/libstdc++-v3/config/cpu/m68k/atomicity.h @@ -0,0 +1,132 @@ +// Low-level functions for atomic operations: m68k version -*- C++ -*- + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#include <ext/atomicity.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +#if ( defined(__mc68020__) || defined(__mc68030__) \ + || defined(__mc68040__) || defined(__mc68060__) ) \ + && !defined(__mcpu32__) + // These variants support compare-and-swap. + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + register _Atomic_word __result = *__mem; + register _Atomic_word __temp; + __asm__ __volatile__ ("1: move%.l %0,%1\n\t" + "add%.l %3,%1\n\t" + "cas%.l %0,%1,%2\n\t" + "jne 1b" + : "=d" (__result), "=&d" (__temp), "=m" (*__mem) + : "d" (__val), "0" (__result), "m" (*__mem)); + return __result; + } + +#elif defined(__rtems__) + // TAS/JBNE is unsafe on systems with strict priority-based scheduling. + // Disable interrupts, which we can do only from supervisor mode. + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + _Atomic_word __result; + short __level, __tmpsr; + __asm__ __volatile__ ("move%.w %%sr,%0\n\tor%.l %0,%1\n\tmove%.w %1,%%sr" + : "=d"(__level), "=d"(__tmpsr) : "1"(0x700)); + + __result = *__mem; + *__mem = __result + __val; + __asm__ __volatile__ ("move%.w %0,%%sr" : : "d"(__level)); + + return __result; + } + +#else + + template<int __inst> + struct _Atomicity_lock + { + static volatile unsigned char _S_atomicity_lock; + }; + + template<int __inst> + volatile unsigned char _Atomicity_lock<__inst>::_S_atomicity_lock = 0; + + template volatile unsigned char _Atomicity_lock<0>::_S_atomicity_lock; + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + _Atomic_word __result; + + // bset with no immediate addressing (not SMP-safe) +#if defined(__mcfisaa__) || defined(__mcfisaaplus__) + __asm__ __volatile__("1: bset.b #7,%0@\n\tjbne 1b" + : /* no outputs */ + : "a"(&_Atomicity_lock<0>::_S_atomicity_lock) + : "cc", "memory"); + + // CPU32 and CF ISAs B & C support test-and-set (SMP-safe). +#elif defined(__mcpu32__) || defined(__mcfisab__) || defined (__mcfisac__) + __asm__ __volatile__("1: tas %0\n\tjbne 1b" + : "+m"(_Atomicity_lock<0>::_S_atomicity_lock) + : /* none */ + : "cc"); + + // Use bset with immediate addressing for 68000/68010 (not SMP-safe) + // NOTE: TAS is available on the 68000, but unsupported by some Amiga + // memory controllers. +#else + __asm__ __volatile__("1: bset.b #7,%0\n\tjbne 1b" + : "+m"(_Atomicity_lock<0>::_S_atomicity_lock) + : /* none */ + : "cc"); +#endif + + __result = *__mem; + *__mem = __result + __val; + + _Atomicity_lock<0>::_S_atomicity_lock = 0; + + return __result; + } + +#endif /* TAS / BSET */ + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) throw () + { + // Careful: using add.l with a memory destination is not + // architecturally guaranteed to be atomic. + __exchange_and_add(__mem, __val); + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/libstdc++-v3/config/cpu/microblaze/cpu_defines.h b/libstdc++-v3/config/cpu/microblaze/cpu_defines.h new file mode 100644 index 000000000..320e980bd --- /dev/null +++ b/libstdc++-v3/config/cpu/microblaze/cpu_defines.h @@ -0,0 +1,39 @@ +// Specific definitions for Xilinx MicroBlaze platforms -*- C++ -*- + +// Copyright (C) 2009, 2010 Free Software Foundation, Inc. +// +// Contributed by Michael Eager <eager@eagercon.com>. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +/** @file bits/cpu_defines.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{iosfwd} + */ + +#ifndef _GLIBCXX_CPU_DEFINES +#define _GLIBCXX_CPU_DEFINES 1 + +// Optimize memory size for embedded systems +// -- Use abort for eh terminate +#define _GLIBCXX_NO_VERBOSE_TERMINATE 1 + +#endif diff --git a/libstdc++-v3/config/cpu/powerpc/atomic_word.h b/libstdc++-v3/config/cpu/powerpc/atomic_word.h new file mode 100644 index 000000000..2c7bd8232 --- /dev/null +++ b/libstdc++-v3/config/cpu/powerpc/atomic_word.h @@ -0,0 +1,37 @@ +// Low-level type for atomic operations -*- C++ -*- + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#ifndef _GLIBCXX_ATOMIC_WORD_H +#define _GLIBCXX_ATOMIC_WORD_H 1 + +typedef int _Atomic_word; + +#define _GLIBCXX_READ_MEM_BARRIER __asm __volatile ("isync":::"memory") +#ifdef __NO_LWSYNC__ +#define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("sync":::"memory") +#else +#define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("lwsync":::"memory") +#endif + +#endif diff --git a/libstdc++-v3/config/cpu/powerpc/cpu_defines.h b/libstdc++-v3/config/cpu/powerpc/cpu_defines.h new file mode 100644 index 000000000..3985b6c10 --- /dev/null +++ b/libstdc++-v3/config/cpu/powerpc/cpu_defines.h @@ -0,0 +1,36 @@ +// Specific definitions for generic platforms -*- C++ -*- + +// Copyright (C) 2005, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +/** @file bits/cpu_defines.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{iosfwd} + */ + +#ifndef _GLIBCXX_CPU_DEFINES +#define _GLIBCXX_CPU_DEFINES 1 + +// Integer divide instructions don't trap on PowerPC. +#define __glibcxx_integral_traps false + +#endif diff --git a/libstdc++-v3/config/cpu/sh/atomicity.h b/libstdc++-v3/config/cpu/sh/atomicity.h new file mode 100644 index 000000000..ece63ce2a --- /dev/null +++ b/libstdc++-v3/config/cpu/sh/atomicity.h @@ -0,0 +1,109 @@ +// Low-level functions for atomic operations: sh version -*- C++ -*- + +// Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#ifdef __SH4A__ + +#include <ext/atomicity.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + typedef int _Atomic_word; + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add (volatile _Atomic_word* __mem, int __val) throw () + { + _Atomic_word __result; + + __asm__ __volatile__ + ("0:\n" + "\tmovli.l\t@%2,r0\n" + "\tmov\tr0,%1\n" + "\tadd\t%3,r0\n" + "\tmovco.l\tr0,@%2\n" + "\tbf\t0b" + : "+m" (*__mem), "=&r" (__result) + : "r" (__mem), "rI08" (__val) + : "r0"); + + return __result; + } + + + void + __attribute__ ((__unused__)) + __atomic_add (volatile _Atomic_word* __mem, int __val) throw () + { + asm("0:\n" + "\tmovli.l\t@%1,r0\n" + "\tadd\t%2,r0\n" + "\tmovco.l\tr0,@%1\n" + "\tbf\t0b" + : "+m" (*__mem) + : "r" (__mem), "rI08" (__val) + : "r0"); + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#else /* !__SH4A__ */ + +/* This is generic/atomicity.h */ + +#include <ext/atomicity.h> +#include <ext/concurrence.h> + +namespace +{ + __gnu_cxx::__mutex atomic_mutex; +} // anonymous namespace + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + __gnu_cxx::__scoped_lock sentry(atomic_mutex); + _Atomic_word __result; + __result = *__mem; + *__mem += __val; + return __result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) throw () + { __exchange_and_add(__mem, __val); } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace + +#endif /* !__SH4A__ */ diff --git a/libstdc++-v3/config/cpu/sparc/atomic_word.h b/libstdc++-v3/config/cpu/sparc/atomic_word.h new file mode 100644 index 000000000..41e7bd4df --- /dev/null +++ b/libstdc++-v3/config/cpu/sparc/atomic_word.h @@ -0,0 +1,48 @@ +// Low-level type for atomic operations -*- C++ -*- + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#ifndef _GLIBCXX_ATOMIC_WORD_H +#define _GLIBCXX_ATOMIC_WORD_H 1 + +#ifdef __arch64__ + typedef long _Atomic_word; +#else + typedef int _Atomic_word; +#endif + +#if defined(__sparc_v9__) +// These are necessary under the V9 RMO model, though it is almost never +// used in userspace. +#define _GLIBCXX_READ_MEM_BARRIER \ + __asm __volatile ("membar #LoadLoad":::"memory") +#define _GLIBCXX_WRITE_MEM_BARRIER \ + __asm __volatile ("membar #StoreStore":::"memory") + +#elif defined(__sparc_v8__) +// This is necessary under the PSO model. +#define _GLIBCXX_WRITE_MEM_BARRIER __asm __volatile ("stbar":::"memory") + +#endif + +#endif diff --git a/libstdc++-v3/config/cpu/sparc/atomicity.h b/libstdc++-v3/config/cpu/sparc/atomicity.h new file mode 100644 index 000000000..c032e540e --- /dev/null +++ b/libstdc++-v3/config/cpu/sparc/atomicity.h @@ -0,0 +1,125 @@ +// Low-level functions for atomic operations: Sparc version -*- C++ -*- + +// Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library 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, or (at your option) +// any later version. + +// This 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 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/>. + +#include <ext/atomicity.h> + +namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +#ifdef __arch64__ + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + _Atomic_word __tmp1, __tmp2; + _Atomic_word __val_extended = __val; + + __asm__ __volatile__("1: ldx [%3], %0\n\t" + " add %0, %4, %1\n\t" + " casx [%3], %0, %1\n\t" + " sub %0, %1, %0\n\t" + " brnz,pn %0, 1b\n\t" + " nop" + : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__mem) + : "r" (__mem), "r" (__val_extended), "m" (*__mem)); + return __tmp2; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) throw () + { + _Atomic_word __tmp1, __tmp2; + _Atomic_word __val_extended = __val; + + __asm__ __volatile__("1: ldx [%3], %0\n\t" + " add %0, %4, %1\n\t" + " casx [%3], %0, %1\n\t" + " sub %0, %1, %0\n\t" + " brnz,pn %0, 1b\n\t" + " nop" + : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__mem) + : "r" (__mem), "r" (__val_extended), "m" (*__mem)); + } + +#else /* __arch32__ */ + + template<int __inst> + struct _Atomicity_lock + { + static unsigned char _S_atomicity_lock; + }; + + template<int __inst> + unsigned char _Atomicity_lock<__inst>::_S_atomicity_lock = 0; + + template unsigned char _Atomicity_lock<0>::_S_atomicity_lock; + + _Atomic_word + __attribute__ ((__unused__)) + __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw () + { + _Atomic_word __result, __tmp; + + __asm__ __volatile__("1: ldstub [%1], %0\n\t" + " cmp %0, 0\n\t" + " bne 1b\n\t" + " nop" + : "=&r" (__tmp) + : "r" (&_Atomicity_lock<0>::_S_atomicity_lock) + : "memory"); + __result = *__mem; + *__mem += __val; + __asm__ __volatile__("stb %%g0, [%0]" + : /* no outputs */ + : "r" (&_Atomicity_lock<0>::_S_atomicity_lock) + : "memory"); + return __result; + } + + void + __attribute__ ((__unused__)) + __atomic_add(volatile _Atomic_word* __mem, int __val) throw () + { + _Atomic_word __tmp; + + __asm__ __volatile__("1: ldstub [%1], %0\n\t" + " cmp %0, 0\n\t" + " bne 1b\n\t" + " nop" + : "=&r" (__tmp) + : "r" (&_Atomicity_lock<0>::_S_atomicity_lock) + : "memory"); + *__mem += __val; + __asm__ __volatile__("stb %%g0, [%0]" + : /* no outputs */ + : "r" (&_Atomicity_lock<0>::_S_atomicity_lock) + : "memory"); + } +#endif /* __arch32__ */ + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace |