Qore Programming Language  0.8.11.1
macros-powerpc.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  Qore Programming Language
4 
5  Copyright (C) 2003 - 2014 David Nichols
6 
7  Permission is hereby granted, free of charge, to any person obtaining a
8  copy of this software and associated documentation files (the "Software"),
9  to deal in the Software without restriction, including without limitation
10  the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  and/or sell copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following conditions:
13 
14  The above copyright notice and this permission notice shall be included in
15  all copies or substantial portions of the Software.
16 
17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  DEALINGS IN THE SOFTWARE.
24 
25  Note that the Qore library is released under a choice of three open-source
26  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
27  information.
28 */
29 
30 #ifndef _QORE_CONFIG_MACHINE_MACROS_H
31 
32 #define _QORE_CONFIG_MACHINE_MACROS_H
33 
34 // only have support for 32-bit ppc for now
35 #ifndef __ppc64
36 
37 #define HAVE_ATOMIC_MACROS
38 
39 static inline int atomic_inc(int *v) {
40  int t;
41 
42  asm volatile(
43  "1: lwarx %0,0,%1\n"
44  " addic %0,%0,1\n"
45  " stwcx. %0,0,%1\n"
46  " bne- 1b"
47  : "=&r" (t)
48  : "r" (v)
49  : "cc", "memory");
50  return t;
51 }
52 
53 static inline int atomic_dec(int *v) {
54  int t;
55 
56  asm volatile(
57  "1: lwarx %0,0,%1\n"
58  " addic %0,%0,-1\n"
59  " stwcx. %0,0,%1\n"
60  " bne- 1b"
61  : "=&r" (t)
62  : "r" (v)
63  : "cc", "memory");
64  return !t;
65 }
66 
67 #define HAVE_CHECK_STACK_POS
68 #define STACK_DIRECTION_DOWN 1
69 
70 static inline size_t get_stack_pos() {
71  size_t addr;
72  __asm("mr %0, r1" : "=r" (addr) );
73  return addr;
74 }
75 
76 #endif
77 
78 #endif