OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [config/] [cpu/] [sparc/] [atomicity.h] - Blame information for rev 866

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// Low-level functions for atomic operations: Sparc version  -*- C++ -*-
2
 
3
// Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2009
4
// Free Software Foundation, Inc.
5
//
6
// This file is part of the GNU ISO C++ Library.  This library is free
7
// software; you can redistribute it and/or modify it under the
8
// terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 3, or (at your option)
10
// any later version.
11
 
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
 
17
// Under Section 7 of GPL version 3, you are granted additional
18
// permissions described in the GCC Runtime Library Exception, version
19
// 3.1, as published by the Free Software Foundation.
20
 
21
// You should have received a copy of the GNU General Public License and
22
// a copy of the GCC Runtime Library Exception along with this program;
23
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24
// <http://www.gnu.org/licenses/>.
25
 
26
#include <ext/atomicity.h>
27
 
28
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
29
{
30
_GLIBCXX_BEGIN_NAMESPACE_VERSION
31
 
32
#ifdef __arch64__
33
  _Atomic_word
34
  __attribute__ ((__unused__))
35
  __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw ()
36
  {
37
    _Atomic_word __tmp1, __tmp2;
38
    _Atomic_word __val_extended = __val;
39
 
40
    __asm__ __volatile__("1:    ldx     [%3], %0\n\t"
41
                         "      add     %0, %4, %1\n\t"
42
                         "      casx    [%3], %0, %1\n\t"
43
                         "      sub     %0, %1, %0\n\t"
44
                         "      brnz,pn %0, 1b\n\t"
45
                         "       nop"
46
                         : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__mem)
47
                         : "r" (__mem), "r" (__val_extended), "m" (*__mem));
48
    return __tmp2;
49
  }
50
 
51
  void
52
  __attribute__ ((__unused__))
53
  __atomic_add(volatile _Atomic_word* __mem, int __val) throw ()
54
  {
55
    _Atomic_word __tmp1, __tmp2;
56
    _Atomic_word __val_extended = __val;
57
 
58
    __asm__ __volatile__("1:    ldx     [%3], %0\n\t"
59
                         "      add     %0, %4, %1\n\t"
60
                         "      casx    [%3], %0, %1\n\t"
61
                         "      sub     %0, %1, %0\n\t"
62
                         "      brnz,pn %0, 1b\n\t"
63
                         "       nop"
64
                         : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__mem)
65
                         : "r" (__mem), "r" (__val_extended), "m" (*__mem));
66
  }
67
 
68
#else /* __arch32__ */
69
 
70
  template<int __inst>
71
    struct _Atomicity_lock
72
    {
73
      static unsigned char _S_atomicity_lock;
74
    };
75
 
76
  template<int __inst>
77
  unsigned char _Atomicity_lock<__inst>::_S_atomicity_lock = 0;
78
 
79
  template unsigned char _Atomicity_lock<0>::_S_atomicity_lock;
80
 
81
  _Atomic_word
82
  __attribute__ ((__unused__))
83
  __exchange_and_add(volatile _Atomic_word* __mem, int __val) throw ()
84
  {
85
    _Atomic_word __result, __tmp;
86
 
87
    __asm__ __volatile__("1:    ldstub  [%1], %0\n\t"
88
                         "      cmp     %0, 0\n\t"
89
                         "      bne     1b\n\t"
90
                         "       nop"
91
                         : "=&r" (__tmp)
92
                         : "r" (&_Atomicity_lock<0>::_S_atomicity_lock)
93
                         : "memory");
94
    __result = *__mem;
95
    *__mem += __val;
96
    __asm__ __volatile__("stb   %%g0, [%0]"
97
                         : /* no outputs */
98
                         : "r" (&_Atomicity_lock<0>::_S_atomicity_lock)
99
                         : "memory");
100
    return __result;
101
  }
102
 
103
  void
104
  __attribute__ ((__unused__))
105
  __atomic_add(volatile _Atomic_word* __mem, int __val) throw ()
106
  {
107
    _Atomic_word __tmp;
108
 
109
    __asm__ __volatile__("1:    ldstub  [%1], %0\n\t"
110
                         "      cmp     %0, 0\n\t"
111
                         "      bne     1b\n\t"
112
                         "       nop"
113
                         : "=&r" (__tmp)
114
                         : "r" (&_Atomicity_lock<0>::_S_atomicity_lock)
115
                         : "memory");
116
    *__mem += __val;
117
    __asm__ __volatile__("stb   %%g0, [%0]"
118
                         : /* no outputs */
119
                         : "r" (&_Atomicity_lock<0>::_S_atomicity_lock)
120
                         : "memory");
121
  }
122
#endif /* __arch32__ */
123
 
124
_GLIBCXX_END_NAMESPACE_VERSION
125
} // namespace

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.