1132720Skan// Low-level functions for atomic operations: MIPS version -*- C++ -*- 2117397Skan 3169691Skan// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 4169691Skan// Free Software Foundation, Inc. 5117397Skan// 6117397Skan// This file is part of the GNU ISO C++ Library. This library is free 7117397Skan// software; you can redistribute it and/or modify it under the 8117397Skan// terms of the GNU General Public License as published by the 9117397Skan// Free Software Foundation; either version 2, or (at your option) 10117397Skan// any later version. 11117397Skan 12117397Skan// This library is distributed in the hope that it will be useful, 13117397Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of 14117397Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15117397Skan// GNU General Public License for more details. 16117397Skan 17117397Skan// You should have received a copy of the GNU General Public License along 18117397Skan// with this library; see the file COPYING. If not, write to the Free 19169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 20117397Skan// USA. 21117397Skan 22117397Skan// As a special exception, you may use this file as part of a free software 23117397Skan// library without restriction. Specifically, if other files instantiate 24117397Skan// templates or use macros or inline functions from this file, or you compile 25117397Skan// this file and link it with other files to produce an executable, this 26117397Skan// file does not by itself cause the resulting executable to be covered by 27117397Skan// the GNU General Public License. This exception does not however 28117397Skan// invalidate any other reasons why the executable file might be covered by 29117397Skan// the GNU General Public License. 30117397Skan 31169691Skan#include <ext/atomicity.h> 32117397Skan 33169691Skan_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) 34169691Skan 35169691Skan // NB: MIPS II or above required. 36132720Skan _Atomic_word 37132720Skan __attribute__ ((__unused__)) 38132720Skan __exchange_and_add(volatile _Atomic_word* __mem, int __val) 39132720Skan { 40132720Skan _Atomic_word __result, __tmp; 41132720Skan 42132720Skan __asm__ __volatile__ 43132720Skan ("/* Inline exchange & add */\n\t" 44132720Skan "1:\n\t" 45132720Skan ".set push\n\t" 46132720Skan#if _MIPS_SIM == _ABIO32 47132720Skan ".set mips2\n\t" 48132720Skan#endif 49169691Skan "ll %0,0(%2)\n\t" 50169691Skan "addu %1,%3,%0\n\t" 51169691Skan "sc %1,0(%2)\n\t" 52132720Skan ".set pop\n\t" 53132720Skan "beqz %1,1b\n\t" 54132720Skan "/* End exchange & add */" 55169691Skan : "=&r"(__result), "=&r"(__tmp) 56169691Skan : "r"(__mem), "r"(__val) 57169691Skan : "memory" ); 58132720Skan 59132720Skan return __result; 60132720Skan } 61132720Skan 62132720Skan void 63132720Skan __attribute__ ((__unused__)) 64132720Skan __atomic_add(volatile _Atomic_word* __mem, int __val) 65132720Skan { 66132720Skan _Atomic_word __result; 67132720Skan 68132720Skan __asm__ __volatile__ 69132720Skan ("/* Inline atomic add */\n\t" 70132720Skan "1:\n\t" 71132720Skan ".set push\n\t" 72132720Skan#if _MIPS_SIM == _ABIO32 73132720Skan ".set mips2\n\t" 74132720Skan#endif 75169691Skan "ll %0,0(%1)\n\t" 76169691Skan "addu %0,%2,%0\n\t" 77169691Skan "sc %0,0(%1)\n\t" 78132720Skan ".set pop\n\t" 79132720Skan "beqz %0,1b\n\t" 80132720Skan "/* End atomic add */" 81169691Skan : "=&r"(__result) 82169691Skan : "r"(__mem), "r"(__val) 83169691Skan : "memory" ); 84132720Skan } 85169691Skan 86169691Skan_GLIBCXX_END_NAMESPACE 87