HClib
0.3
Documentation for Habanero-C Library API
Main Page
Modules
Data Structures
Files
File List
All
Data Structures
Functions
Typedefs
Enumerations
Groups
src
inc
hc_sysdep.h
1
/* Copyright (c) 2013, Rice University
2
3
Redistribution and use in source and binary forms, with or without
4
modification, are permitted provided that the following conditions are
5
met:
6
7
1. Redistributions of source code must retain the above copyright
8
notice, this list of conditions and the following disclaimer.
9
2. Redistributions in binary form must reproduce the above
10
copyright notice, this list of conditions and the following
11
disclaimer in the documentation and/or other materials provided
12
with the distribution.
13
3. Neither the name of Rice University
14
nor the names of its contributors may be used to endorse or
15
promote products derived from this software without specific
16
prior written permission.
17
18
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
*/
31
32
#ifndef HC_SYSDEP_H_
33
#define HC_SYSDEP_H_
34
35
//
36
// amd_64
37
//
38
39
#ifdef __x86_64
40
41
#define HC_CACHE_LINE 64
42
43
static
__inline__
int
hc_atomic_inc(
volatile
int
*ptr) {
44
unsigned
char
c;
45
__asm__ __volatile__(
46
47
"lock ;\n"
48
"incl %0; sete %1"
49
:
"+m"
(*(ptr)),
"=qm"
(c)
50
: :
"memory"
51
);
52
return
c!= 0;
53
}
54
55
/* return 1 if the *ptr becomes 0 after decremented, otherwise return 0
56
*/
57
static
__inline__
int
hc_atomic_dec(
volatile
int
*ptr) {
58
unsigned
char
rt;
59
__asm__ __volatile__(
60
"lock;\n"
61
"decl %0; sete %1"
62
:
"+m"
(*(ptr)),
"=qm"
(rt)
63
: :
"memory"
64
);
65
return
rt != 0;
66
}
67
68
69
#endif
/* __x86_64 */
70
71
#endif
/* HC_SYSDEP_H_ */
Generated on Thu Jun 12 2014 12:49:26 for HClib by
1.8.3.1