1117397Skan// Low-level functions for atomic operations: CRIS version  -*- C++ -*-
2117397Skan
3169691Skan// Copyright (C) 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
4117397Skan//
5117397Skan// This file is part of the GNU ISO C++ Library.  This library is free
6117397Skan// software; you can redistribute it and/or modify it under the
7117397Skan// terms of the GNU General Public License as published by the
8117397Skan// Free Software Foundation; either version 2, or (at your option)
9117397Skan// any later version.
10117397Skan
11117397Skan// This library is distributed in the hope that it will be useful,
12117397Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of
13117397Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14117397Skan// GNU General Public License for more details.
15117397Skan
16117397Skan// You should have received a copy of the GNU General Public License along
17117397Skan// with this library; see the file COPYING.  If not, write to the Free
18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19117397Skan// USA.
20117397Skan
21117397Skan// As a special exception, you may use this file as part of a free software
22117397Skan// library without restriction.  Specifically, if other files instantiate
23117397Skan// templates or use macros or inline functions from this file, or you compile
24117397Skan// this file and link it with other files to produce an executable, this
25117397Skan// file does not by itself cause the resulting executable to be covered by
26117397Skan// the GNU General Public License.  This exception does not however
27117397Skan// invalidate any other reasons why the executable file might be covered by
28117397Skan// the GNU General Public License.
29117397Skan
30169691Skan#include <ext/atomicity.h>
31117397Skan
32169691Skan_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
33169691Skan
34132720Skan  _Atomic_word
35132720Skan  __exchange_and_add(volatile _Atomic_word* __mem, int __val)
36132720Skan  {
37132720Skan    int __tmp;
38132720Skan    _Atomic_word __result;
39117397Skan
40117397Skan#if (__CRIS_arch_version >= 10)
41132720Skan    __asm__ __volatile__ (" clearf		\n"
42117397Skan			"0:			\n"
43117397Skan			" move.d %4,%2		\n"
44117397Skan			" move.d [%3],%0	\n"
45117397Skan			" add.d %0,%2		\n"
46117397Skan			" ax			\n"
47117397Skan			" move.d %2,[%3]	\n"
48117397Skan			" bwf 0b		\n"
49117397Skan			" clearf		\n"
50169691Skan			:  "=&r" (__result), "=Q" (*__mem), "=&r" (__tmp)
51169691Skan			: "r" (__mem), "g" (__val), "Q" (*__mem)
52132720Skan			/* The memory clobber must stay, regardless of
53132720Skan			   current uses of this function.  */
54117397Skan			: "memory");
55117397Skan#else
56132720Skan    __asm__ __volatile__ (" move $ccr,$r9	\n"
57117397Skan			" di			\n"
58117397Skan			" move.d %4,%2		\n"
59117397Skan			" move.d [%3],%0	\n"
60117397Skan			" add.d %0,%2		\n"
61117397Skan			" move.d %2,[%3]	\n"
62117397Skan			" move $r9,$ccr		\n"
63169691Skan			:  "=&r" (__result), "=Q" (*__mem), "=&r" (__tmp)
64169691Skan			: "r" (__mem), "g" (__val), "Q" (*__mem)
65132720Skan			: "r9",
66132720Skan			  /* The memory clobber must stay, regardless of
67132720Skan			     current uses of this function.  */
68132720Skan			  "memory");
69117397Skan#endif
70117397Skan
71132720Skan    return __result;
72132720Skan  }
73117397Skan
74132720Skan  void
75132720Skan  __atomic_add(volatile _Atomic_word* __mem, int __val)
76132720Skan  { __exchange_and_add(__mem, __val); }
77169691Skan
78169691Skan_GLIBCXX_END_NAMESPACE
79