From c7bbbdd036d3dd7ae253fb13c9994215af06f073 Mon Sep 17 00:00:00 2001 From: kan Date: Fri, 11 Jul 2003 03:42:04 +0000 Subject: Gcc 3.3.1-pre 2003-07-11 C++ support bits. --- contrib/libstdc++/config/cpu/alpha/atomicity.h | 76 +++++++++++ contrib/libstdc++/config/cpu/cris/atomicity.h | 79 ++++++++++++ contrib/libstdc++/config/cpu/generic/atomicity.h | 77 +++++++++++ contrib/libstdc++/config/cpu/hppa/atomicity.h | 90 +++++++++++++ contrib/libstdc++/config/cpu/i386/atomicity.h | 75 +++++++++++ contrib/libstdc++/config/cpu/i486/atomicity.h | 57 ++++++++ contrib/libstdc++/config/cpu/ia64/atomicity.h | 51 ++++++++ contrib/libstdc++/config/cpu/m68k/atomicity.h | 158 +++++++++++++++++++++++ contrib/libstdc++/config/cpu/mips/atomicity.h | 81 ++++++++++++ contrib/libstdc++/config/cpu/powerpc/atomicity.h | 78 +++++++++++ contrib/libstdc++/config/cpu/s390/atomicity.h | 60 +++++++++ contrib/libstdc++/config/cpu/sparc/atomicity.h | 131 +++++++++++++++++++ 12 files changed, 1013 insertions(+) create mode 100644 contrib/libstdc++/config/cpu/alpha/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/cris/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/generic/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/hppa/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/i386/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/i486/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/ia64/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/m68k/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/mips/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/powerpc/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/s390/atomicity.h create mode 100644 contrib/libstdc++/config/cpu/sparc/atomicity.h (limited to 'contrib/libstdc++/config/cpu') diff --git a/contrib/libstdc++/config/cpu/alpha/atomicity.h b/contrib/libstdc++/config/cpu/alpha/atomicity.h new file mode 100644 index 0000000..895d87a --- /dev/null +++ b/contrib/libstdc++/config/cpu/alpha/atomicity.h @@ -0,0 +1,76 @@ +// Low-level functions for atomic operations: Alpha version -*- C++ -*- + +// Copyright (C) 1999, 2000, 2001 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +/* @@@ With gas we can play nice .subsection games to get the + non-predicted branch pointing forward. But Digital assemblers + don't understand those directives. This isn't a terribly + important issue, so just ignore it. */ + +typedef int _Atomic_word; + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word* __mem, int __val) +{ + register int __result, __tmp; + + __asm__ __volatile__ ( + "\n$Lxadd_%=:\n\t" + "ldl_l %0,%3\n\t" + "addl %0,%4,%1\n\t" + "stl_c %1,%2\n\t" + "beq %1,$Lxadd_%=\n\t" + "mb" + : "=&r"(__result), "=&r"(__tmp), "=m"(*__mem) + : "m" (*__mem), "r"(__val)); + + return __result; +} + +static inline void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word* __mem, int __val) +{ + register _Atomic_word __result; + + __asm__ __volatile__ ( + "\n$Ladd_%=:\n\t" + "ldl_l %0,%2\n\t" + "addl %0,%3,%0\n\t" + "stl_c %0,%1\n\t" + "beq %0,$Ladd_%=\n\t" + "mb" + : "=&r"(__result), "=m"(*__mem) + : "m" (*__mem), "r"(__val)); +} + +#endif /* atomicity.h */ diff --git a/contrib/libstdc++/config/cpu/cris/atomicity.h b/contrib/libstdc++/config/cpu/cris/atomicity.h new file mode 100644 index 0000000..55c374f --- /dev/null +++ b/contrib/libstdc++/config/cpu/cris/atomicity.h @@ -0,0 +1,79 @@ +// Low-level functions for atomic operations: CRIS version -*- C++ -*- + +// Copyright (C) 2001 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +// This entity must not cross a page boundary. +typedef int _Atomic_word __attribute__ ((__aligned__ (4))); + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (_Atomic_word* __mem, int __val) +{ + int __tmp; + _Atomic_word __result; + +#if (__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), "=m" (*__mem), "=&r" (__tmp) + : "r" (__mem), "g" (__val), "m" (*__mem) + : "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), "=m" (*__mem), "=&r" (__tmp) + : "r" (__mem), "g" (__val), "m" (*__mem) + : "memory", "r9"); +#endif + + return __result; +} + +static inline void +__attribute__ ((__unused__)) +__atomic_add (_Atomic_word* __mem, int __val) +{ + __exchange_and_add (__mem, __val); +} + +#endif /* atomicity.h */ diff --git a/contrib/libstdc++/config/cpu/generic/atomicity.h b/contrib/libstdc++/config/cpu/generic/atomicity.h new file mode 100644 index 0000000..829a77c --- /dev/null +++ b/contrib/libstdc++/config/cpu/generic/atomicity.h @@ -0,0 +1,77 @@ +// Low-level functions for atomic operations: Generic version -*- C++ -*- + +// Copyright (C) 1999, 2001, 2002, 2003 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +#include + +#define _GLIBCPP_NEED_GENERIC_MUTEX + +typedef int _Atomic_word; + +namespace __gnu_cxx +{ + extern __gthread_mutex_t _Atomic_add_mutex; + +#ifndef __GTHREAD_MUTEX_INIT + extern __gthread_once_t _Atomic_add_mutex_once; + extern void __gthread_atomic_add_mutex_once(); +#endif +} + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word* __mem, int __val) +{ +#ifndef __GTHREAD_MUTEX_INIT + __gthread_once (&__gnu_cxx::_Atomic_add_mutex_once, + __gnu_cxx::__gthread_atomic_add_mutex_once); +#endif + + _Atomic_word __result; + + __gthread_mutex_lock (&__gnu_cxx::_Atomic_add_mutex); + + __result = *__mem; + *__mem += __val; + + __gthread_mutex_unlock (&__gnu_cxx::_Atomic_add_mutex); + return __result; +} + + +static inline void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word* __mem, int __val) +{ + (void) __exchange_and_add (__mem, __val); +} + +#endif /* atomicity.h */ diff --git a/contrib/libstdc++/config/cpu/hppa/atomicity.h b/contrib/libstdc++/config/cpu/hppa/atomicity.h new file mode 100644 index 0000000..d99ac34 --- /dev/null +++ b/contrib/libstdc++/config/cpu/hppa/atomicity.h @@ -0,0 +1,90 @@ +/* Low-level functions for atomic operations. PA-RISC version. -*- C++ -*- + Copyright 2002 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +typedef int _Atomic_word; + +template +struct __Atomicity_lock +{ + static volatile int _S_atomicity_lock; +}; + +template +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 + in src/misc-inst.cc when _GLIBCPP_INST_ATOMICITY_LOCK + is defined. */ +#ifndef _GLIBCPP_INST_ATOMICITY_LOCK +template volatile int __Atomicity_lock<0>::_S_atomicity_lock; +#endif + +static inline int +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word* __mem, int __val) +{ + _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)); + + result = *__mem; + *__mem = result + __val; + /* Reset lock with PA 2.0 "ordered" store. */ + __asm__ __volatile__ ("stw,ma %1,0(%0)" + : : "r" (&lock), "r" (tmp) : "memory"); + return result; +} + +static inline void +__attribute__ ((__unused__)) +__atomic_add (_Atomic_word* __mem, int __val) +{ + 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)); + + *__mem += __val; + /* Reset lock with PA 2.0 "ordered" store. */ + __asm__ __volatile__ ("stw,ma %1,0(%0)" + : : "r" (&lock), "r" (tmp) : "memory"); +} + +#endif diff --git a/contrib/libstdc++/config/cpu/i386/atomicity.h b/contrib/libstdc++/config/cpu/i386/atomicity.h new file mode 100644 index 0000000..d619dbb --- /dev/null +++ b/contrib/libstdc++/config/cpu/i386/atomicity.h @@ -0,0 +1,75 @@ +// Low-level functions for atomic operations: x86, x >= 3 version -*- C++ -*- + +// Copyright (C) 2003 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +typedef int _Atomic_word; + +template +struct __Atomicity_lock +{ + static volatile _Atomic_word _S_atomicity_lock; +}; + +template +volatile _Atomic_word __Atomicity_lock<__inst>::_S_atomicity_lock = 0; + +template volatile _Atomic_word __Atomicity_lock<0>::_S_atomicity_lock; + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + 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)); + } while (__tmp); + + __result = *__mem; + *__mem += __val; + + /* release spin lock */ + __Atomicity_lock<0>::_S_atomicity_lock = 0; + + return __result; +} + +static inline void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word* __mem, int __val) +{ + __exchange_and_add (__mem, __val); +} + +#endif /* atomicity.h */ diff --git a/contrib/libstdc++/config/cpu/i486/atomicity.h b/contrib/libstdc++/config/cpu/i486/atomicity.h new file mode 100644 index 0000000..7c65fab --- /dev/null +++ b/contrib/libstdc++/config/cpu/i486/atomicity.h @@ -0,0 +1,57 @@ +// Low-level functions for atomic operations: x86, x >= 4 version -*- C++ -*- + +// Copyright (C) 1999, 2000, 2001 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +typedef int _Atomic_word; + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + register _Atomic_word __result; + __asm__ __volatile__ ("lock; xadd{l} {%0,%1|%1,%0}" + : "=r" (__result), "+m" (*__mem) + : "0" (__val) + : "memory"); + return __result; +} + +static inline void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word* __mem, int __val) +{ + __asm__ __volatile__ ("lock; add{l} {%1,%0|%0,%1}" + : "+m" (*__mem) : "ir" (__val) : "memory"); +} + +#endif /* atomicity.h */ + + diff --git a/contrib/libstdc++/config/cpu/ia64/atomicity.h b/contrib/libstdc++/config/cpu/ia64/atomicity.h new file mode 100644 index 0000000..e28e149 --- /dev/null +++ b/contrib/libstdc++/config/cpu/ia64/atomicity.h @@ -0,0 +1,51 @@ +// Low-level functions for atomic operations: IA64 version -*- C++ -*- + +// Copyright (C) 2000, 2001 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +#include + +typedef int _Atomic_word; + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + return __sync_fetch_and_add (__mem, __val); +} + +static inline void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word* __mem, int __val) +{ + __sync_fetch_and_add (__mem, __val); +} + +#endif /* atomicity.h */ diff --git a/contrib/libstdc++/config/cpu/m68k/atomicity.h b/contrib/libstdc++/config/cpu/m68k/atomicity.h new file mode 100644 index 0000000..db32735 --- /dev/null +++ b/contrib/libstdc++/config/cpu/m68k/atomicity.h @@ -0,0 +1,158 @@ +// Low-level functions for atomic operations: m68k version -*- C++ -*- + +// Copyright (C) 2001, 2002 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +typedef int _Atomic_word; + +#if defined(__mc68020__) || defined(__mc68030__) \ + || defined(__mc68040__) || defined(__mc68060__) +// These variants support compare-and-swap. + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + register _Atomic_word __result = *__mem; + register _Atomic_word __temp; + __asm__ __volatile__ ("1: move%.l %0,%1\n\t" + "add%.l %2,%1\n\t" + "cas%.l %0,%1,%3\n\t" + "jne 1b" + : "=d" (__result), "=&d" (__temp) + : "d" (__val), "m" (*__mem), "0" (__result) + : "memory"); + 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. + */ +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + _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; +} + +#elif !defined(__mcf5200__) && !defined(__mcf5300__) +// 68000, 68010, cpu32 and 5400 support test-and-set. + +template +struct __Atomicity_lock +{ + static volatile unsigned char _S_atomicity_lock; +}; + +template +volatile unsigned char __Atomicity_lock<__inst>::_S_atomicity_lock = 0; + +template volatile unsigned char __Atomicity_lock<0>::_S_atomicity_lock; + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + _Atomic_word __result; + + __asm__ __volatile__("1: tas %0\n\tjbne 1b" + : "=m"(__Atomicity_lock<0>::_S_atomicity_lock) + : "m"(__Atomicity_lock<0>::_S_atomicity_lock)); + + __result = *__mem; + *__mem = __result + __val; + + __Atomicity_lock<0>::_S_atomicity_lock = 0; + + return __result; +} + +#elif defined(__vxWorks__) || defined(__embedded__) +// The best we can hope for is to disable interrupts, which we +// can only do from supervisor mode. + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + _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 +// These variants do not support any atomic operations at all. + +#warning "__exchange_and_add is not atomic for this target" + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + _Atomic_word __result; + + __result = *__mem; + *__mem = __result + __val; + + return __result; +} + +#endif /* CAS / IRQ / TAS */ + +static inline void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word* __mem, int __val) +{ + // Careful: using add.l with a memory destination is not + // architecturally guaranteed to be atomic. + (void) __exchange_and_add (__mem, __val); +} + +#endif /* atomicity.h */ diff --git a/contrib/libstdc++/config/cpu/mips/atomicity.h b/contrib/libstdc++/config/cpu/mips/atomicity.h new file mode 100644 index 0000000..7bacabd --- /dev/null +++ b/contrib/libstdc++/config/cpu/mips/atomicity.h @@ -0,0 +1,81 @@ +// Low-level functions for atomic operations. + +// Copyright (C) 2001, 2002 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +typedef int _Atomic_word; + +static inline int +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + int __result, __tmp; + + __asm__ __volatile__ + ("/* Inline exchange & add */\n\t" + "1:\n\t" + ".set push\n\t" + ".set mips2\n\t" + "ll %0,%3\n\t" + "addu %1,%4,%0\n\t" + "sc %1,%2\n\t" + ".set pop\n\t" + "beqz %1,1b\n\t" + "/* End exchange & add */" + : "=&r"(__result), "=&r"(__tmp), "=m"(*__mem) + : "m" (*__mem), "r"(__val) + : "memory"); + + return __result; +} + +static inline void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word *__mem, int __val) +{ + int __result; + + __asm__ __volatile__ + ("/* Inline atomic add */\n\t" + "1:\n\t" + ".set push\n\t" + ".set mips2\n\t" + "ll %0,%2\n\t" + "addu %0,%3,%0\n\t" + "sc %0,%1\n\t" + ".set pop\n\t" + "beqz %0,1b\n\t" + "/* End atomic add */" + : "=&r"(__result), "=m"(*__mem) + : "m" (*__mem), "r"(__val) + : "memory"); +} + +#endif /* atomicity.h */ diff --git a/contrib/libstdc++/config/cpu/powerpc/atomicity.h b/contrib/libstdc++/config/cpu/powerpc/atomicity.h new file mode 100644 index 0000000..b5370fc --- /dev/null +++ b/contrib/libstdc++/config/cpu/powerpc/atomicity.h @@ -0,0 +1,78 @@ +// Low-level functions for atomic operations: PowerPC version -*- C++ -*- + +// Copyright (C) 1999, 2000, 2001 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +#ifdef __PPC405__ +#define _STWCX "sync \n\tstwcx. " +#else +#define _STWCX "stwcx. " +#endif + +typedef int _Atomic_word; + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word* __mem, int __val) +{ + _Atomic_word __tmp, __res; + __asm__ __volatile__ ( + "/* Inline exchange & add */\n" + "0:\t" + "lwarx %0,0,%2 \n\t" + "add%I3 %1,%0,%3 \n\t" + _STWCX " %1,0,%2 \n\t" + "bne- 0b \n\t" + "/* End exchange & add */" + : "=&b"(__res), "=&r"(__tmp) + : "r" (__mem), "Ir"(__val) + : "cr0", "memory"); + return __res; +} + +static inline void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word *__mem, int __val) +{ + _Atomic_word __tmp; + __asm__ __volatile__ ( + "/* Inline atomic add */\n" + "0:\t" + "lwarx %0,0,%1 \n\t" + "add%I2 %0,%0,%2 \n\t" + _STWCX " %0,0,%1 \n\t" + "bne- 0b \n\t" + "/* End atomic add */" + : "=&b"(__tmp) + : "r" (__mem), "Ir"(__val) + : "cr0", "memory"); +} + +#endif /* atomicity.h */ diff --git a/contrib/libstdc++/config/cpu/s390/atomicity.h b/contrib/libstdc++/config/cpu/s390/atomicity.h new file mode 100644 index 0000000..331c29a --- /dev/null +++ b/contrib/libstdc++/config/cpu/s390/atomicity.h @@ -0,0 +1,60 @@ +// Low-level functions for atomic operations: S/390 version -*- C++ -*- + +// Copyright (C) 2001 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +typedef int _Atomic_word; + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + register _Atomic_word __old_val, __new_val; + + __asm__ __volatile__ (" l %0,0(%2)\n" + "0: lr %1,%0\n" + " ar %1,%3\n" + " cs %0,%1,0(%2)\n" + " jl 0b" + : "=&d" (__old_val), "=&d" (__new_val) + : "a" (__mem), "d" (__val) : "cc", "memory" ); + return __old_val; +} + +static inline void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word *__mem, int __val) +{ + __exchange_and_add (__mem, __val); +} + +#endif /* atomicity.h */ + + diff --git a/contrib/libstdc++/config/cpu/sparc/atomicity.h b/contrib/libstdc++/config/cpu/sparc/atomicity.h new file mode 100644 index 0000000..23804db --- /dev/null +++ b/contrib/libstdc++/config/cpu/sparc/atomicity.h @@ -0,0 +1,131 @@ +// Low-level functions for atomic operations: Sparc version -*- C++ -*- + +// Copyright (C) 1999, 2000, 2001, 2002 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 2, 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. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#ifndef _BITS_ATOMICITY_H +#define _BITS_ATOMICITY_H 1 + +#ifdef __arch64__ + +typedef long _Atomic_word; + +static inline _Atomic_word +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word *__mem, int __val) +{ + _Atomic_word __tmp1, __tmp2; + + __asm__ __volatile__("1: ldx [%2], %0\n\t" + " add %0, %3, %1\n\t" + " casx [%2], %0, %1\n\t" + " sub %0, %1, %0\n\t" + " brnz,pn %0, 1b\n\t" + " nop" + : "=&r" (__tmp1), "=&r" (__tmp2) + : "r" (__mem), "r" (__val) + : "memory"); + return __tmp2; +} + +static inline void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word* __mem, int __val) +{ + _Atomic_word __tmp1, __tmp2; + + __asm__ __volatile__("1: ldx [%2], %0\n\t" + " add %0, %3, %1\n\t" + " casx [%2], %0, %1\n\t" + " sub %0, %1, %0\n\t" + " brnz,pn %0, 1b\n\t" + " nop" + : "=&r" (__tmp1), "=&r" (__tmp2) + : "r" (__mem), "r" (__val) + : "memory"); +} + +#else /* __arch32__ */ + +typedef int _Atomic_word; + +template +struct __Atomicity_lock +{ + static unsigned char _S_atomicity_lock; +}; + +template +unsigned char __Atomicity_lock<__inst>::_S_atomicity_lock = 0; + +template unsigned char __Atomicity_lock<0>::_S_atomicity_lock; + +static int +__attribute__ ((__unused__)) +__exchange_and_add (volatile _Atomic_word* __mem, int __val) +{ + _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; +} + +static void +__attribute__ ((__unused__)) +__atomic_add (volatile _Atomic_word* __mem, int __val) +{ + _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__ */ + +#endif /* atomicity.h */ -- cgit v1.1