]> sourceware.org Git - glibc.git/blob - sysdeps/sparc/sparc32/sparcv9/atomicity.h
Update.
[glibc.git] / sysdeps / sparc / sparc32 / sparcv9 / atomicity.h
1 /* Low-level functions for atomic operations. Sparc32+v9 version.
2 Copyright (C) 1999 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #ifndef _ATOMICITY_H
21 #define _ATOMICITY_H 1
22
23 #include <inttypes.h>
24
25 static inline int
26 __attribute__ ((unused))
27 exchange_and_add (volatile uint32_t *mem, int val)
28 {
29 uint32_t tmp1, tmp2;
30
31 __asm__ __volatile__("1: lduw [%2], %0\n\t"
32 " add %0, %3, %1\n\t"
33 " cas [%2], %0, %1\n\t"
34 " sub %0, %1, %0\n\t"
35 " brnz,pn %0, 1b\n\t"
36 " nop"
37 : "=&r" (tmp1), "=&r" (tmp2)
38 : "r" (mem), "r" (val)
39 : "memory");
40 return tmp2;
41 }
42
43 static inline void
44 __attribute__ ((unused))
45 atomic_add (volatile uint32_t *mem, int val)
46 {
47 uint32_t tmp1, tmp2;
48
49 __asm__ __volatile__("1: lduw [%2], %0\n\t"
50 " add %0, %3, %1\n\t"
51 " cas [%2], %0, %1\n\t"
52 " sub %0, %1, %0\n\t"
53 " brnz,pn %0, 1b\n\t"
54 " nop"
55 : "=&r" (tmp1), "=&r" (tmp2)
56 : "r" (mem), "r" (val)
57 : "memory");
58 }
59
60 static inline int
61 __attribute__ ((unused))
62 compare_and_swap (volatile long int *p, long int oldval, long int newval)
63 {
64 register long int tmp, tmp2;
65
66 __asm__ __volatile__("1: lduw [%4], %0\n\t"
67 " mov %2, %1\n\t"
68 " cmp %0, %3\n\t"
69 " bne,a,pn %%xcc, 2f\n\t"
70 " mov 0, %0\n\t"
71 " cas [%4], %0, %1\n\t"
72 " sub %0, %1, %0\n\t"
73 " brnz,pn %0, 1b\n\t"
74 " mov 1, %0\n\t"
75 "2:"
76 : "=&r" (tmp), "=&r" (tmp2)
77 : "r" (newval), "r" (oldval), "r" (p)
78 : "memory");
79 return tmp;
80 }
81
82 #endif /* atomicity.h */
This page took 0.038732 seconds and 5 git commands to generate.