Qore Programming Language
0.8.11
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
include
qore
macros-x86_64.h
1
/* -*- mode: c++; indent-tabs-mode: nil -*- */
2
/*
3
Qore Programming Language
4
5
Copyright 2003 - 2013 David Nichols
6
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Lesser General Public
9
License as published by the Free Software Foundation; either
10
version 2.1 of the License, or (at your option) 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 GNU
15
Lesser General Public License for more details.
16
17
You should have received a copy of the GNU Lesser General Public
18
License along with this library; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
22
#ifndef _QORE_MACHINE_MACROS_H
23
#define _QORE_MACHINE_MACROS_H
24
25
#define STACK_DIRECTION_DOWN 1
26
27
#ifdef __GNUC__
28
29
#define HAVE_ATOMIC_MACROS
30
#define HAVE_CHECK_STACK_POS
31
32
// returns 1 when counter reaches zero, 0 if not
33
static
inline
int
atomic_dec(
volatile
int
*a) {
34
unsigned
char
rc;
35
36
__asm(
37
"lock; decl %0; sete %1"
38
:
"=m"
(*a),
"=qm"
(rc)
39
:
"m"
(*a) :
"memory"
40
);
41
return
rc != 0;
42
}
43
44
static
inline
void
atomic_inc(
volatile
int
*a) {
45
__asm(
46
"lock; incl %0"
47
:
"=m"
(*a)
48
);
49
}
50
51
static
inline
size_t
get_stack_pos() {
52
size_t
addr;
53
__asm(
"movq %%rsp, %0"
:
"=g"
(addr) );
54
return
addr;
55
}
56
57
#endif // #ifdef __GNUC__
58
59
#ifdef __SUNPRO_CC
60
61
#define HAVE_ATOMIC_MACROS
62
#define HAVE_CHECK_STACK_POS
63
64
// these routines are implemented in assembler
65
extern
"C"
int
atomic_dec(
volatile
int
*a);
66
extern
"C"
void
atomic_inc(
volatile
int
*a);
67
68
extern
"C"
size_t
get_stack_pos();
69
70
#endif // #ifdef __SUNPRO_CC
71
72
#endif // #ifndef _QORE_MACHINE_MACROS_H
73