1209523Srpaulo// Low-level functions for atomic operations: CRIS version -*- C++ -*- 2209523Srpaulo 3209523Srpaulo// Copyright (C) 2001, 2003, 2004, 2005 Free Software Foundation, Inc. 4209523Srpaulo// 5209523Srpaulo// This file is part of the GNU ISO C++ Library. This library is free 6209523Srpaulo// software; you can redistribute it and/or modify it under the 7209523Srpaulo// terms of the GNU General Public License as published by the 8209523Srpaulo// Free Software Foundation; either version 2, or (at your option) 9209523Srpaulo// any later version. 10209523Srpaulo 11209523Srpaulo// This library is distributed in the hope that it will be useful, 12209523Srpaulo// but WITHOUT ANY WARRANTY; without even the implied warranty of 13209523Srpaulo// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14209523Srpaulo// GNU General Public License for more details. 15209523Srpaulo 16209523Srpaulo// You should have received a copy of the GNU General Public License along 17209523Srpaulo// with this library; see the file COPYING. If not, write to the Free 18209523Srpaulo// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19209523Srpaulo// USA. 20209523Srpaulo 21209523Srpaulo// As a special exception, you may use this file as part of a free software 22209523Srpaulo// library without restriction. Specifically, if other files instantiate 23209523Srpaulo// templates or use macros or inline functions from this file, or you compile 24209523Srpaulo// this file and link it with other files to produce an executable, this 25209523Srpaulo// file does not by itself cause the resulting executable to be covered by 26209523Srpaulo// the GNU General Public License. This exception does not however 27209523Srpaulo// invalidate any other reasons why the executable file might be covered by 28209523Srpaulo// the GNU General Public License. 29209523Srpaulo 30209523Srpaulo#include <ext/atomicity.h> 31209523Srpaulo 32209523Srpaulo_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 33209523Srpaulo 34209523Srpaulo _Atomic_word 35209523Srpaulo __exchange_and_add(volatile _Atomic_word* __mem, int __val) 36209523Srpaulo { 37209523Srpaulo int __tmp; 38209523Srpaulo _Atomic_word __result; 39209523Srpaulo 40209523Srpaulo#if (__CRIS_arch_version >= 10) 41209523Srpaulo __asm__ __volatile__ (" clearf \n" 42209523Srpaulo "0: \n" 43209523Srpaulo " move.d %4,%2 \n" 44209523Srpaulo " move.d [%3],%0 \n" 45209523Srpaulo " add.d %0,%2 \n" 46209523Srpaulo " ax \n" 47209523Srpaulo " move.d %2,[%3] \n" 48209523Srpaulo " bwf 0b \n" 49209523Srpaulo " clearf \n" 50209523Srpaulo : "=&r" (__result), "=Q" (*__mem), "=&r" (__tmp) 51209523Srpaulo : "r" (__mem), "g" (__val), "Q" (*__mem) 52209523Srpaulo /* The memory clobber must stay, regardless of 53209523Srpaulo current uses of this function. */ 54209523Srpaulo : "memory"); 55209523Srpaulo#else 56209523Srpaulo __asm__ __volatile__ (" move $ccr,$r9 \n" 57209523Srpaulo " di \n" 58209523Srpaulo " move.d %4,%2 \n" 59209523Srpaulo " move.d [%3],%0 \n" 60209523Srpaulo " add.d %0,%2 \n" 61209523Srpaulo " move.d %2,[%3] \n" 62209523Srpaulo " move $r9,$ccr \n" 63209523Srpaulo : "=&r" (__result), "=Q" (*__mem), "=&r" (__tmp) 64209523Srpaulo : "r" (__mem), "g" (__val), "Q" (*__mem) 65209523Srpaulo : "r9", 66209523Srpaulo /* The memory clobber must stay, regardless of 67209523Srpaulo current uses of this function. */ 68209523Srpaulo "memory"); 69209523Srpaulo#endif 70209523Srpaulo 71209523Srpaulo return __result; 72209523Srpaulo } 73209523Srpaulo 74209523Srpaulo void 75209523Srpaulo __atomic_add(volatile _Atomic_word* __mem, int __val) 76209523Srpaulo { __exchange_and_add(__mem, __val); } 77209523Srpaulo 78209523Srpaulo_GLIBCXX_END_NAMESPACE 79209523Srpaulo