81ac4b77a779cc8300cfbfbfe8bccc968944e126
[sbcl.git] / src / runtime / x86-64-arch.h
1 /* FIXME: Aren't preprocessor symbols with underscore prefixes
2  * reserved for the system libraries? If so, it would be tidy to
3  * rename flags like _X86_ARCH_H so their names are in a part of the
4  * namespace that we control. */
5 #ifndef _X86_64_ARCH_H
6 #define _X86_64_ARCH_H
7
8 #ifndef SBCL_GENESIS_CONFIG
9 #error genesis/config.h (or sbcl.h) must be included before this file
10 #endif
11
12 #include "interr.h"                     /* for declaration of lose() */
13
14 #define ARCH_HAS_STACK_POINTER
15
16 /* FIXME: Do we also want
17  *   #define ARCH_HAS_FLOAT_REGISTERS
18  * here? (The answer wasn't obvious to me when merging the
19  * architecture-abstracting patches for CSR's SPARC port. -- WHN 2002-02-15) */
20
21 #define COMPILER_BARRIER \
22     do { __asm__ __volatile__ ( "" : : : "memory"); } while (0)
23
24 static inline void
25 get_spinlock(volatile lispobj *word, unsigned long value)
26 {
27 #ifdef LISP_FEATURE_SB_THREAD
28     u64 rax=0;
29     if(*word==value)
30         lose("recursive get_spinlock: 0x%x,%ld\n",word,value);
31     do {
32 #if defined(LISP_FEATURE_DARWIN)
33         asm volatile
34             ("xor %0,%0\n\
35               lock/cmpxchg %1,%2"
36              : "=a" (rax)
37              : "r" (value), "m" (*word)
38              : "memory", "cc");
39 #else
40         asm volatile
41             ("xor %0,%0\n\
42               lock cmpxchg %1,%2"
43              : "=a" (rax)
44              : "r" (value), "m" (*word)
45              : "memory", "cc");
46 #endif
47     } while(rax!=0);
48 #else
49     *word=value;
50 #endif
51 }
52
53 static inline void
54 release_spinlock(volatile lispobj *word)
55 {
56     /* See comment in RELEASE-SPINLOCK in target-thread.lisp. */
57     COMPILER_BARRIER;
58     *word=0;
59     COMPILER_BARRIER;
60 }
61
62 static inline lispobj
63 swap_lispobjs(volatile lispobj *dest, lispobj value)
64 {
65     lispobj old_value;
66     asm volatile
67         ("lock xchg %0,(%1)"
68          : "=r" (old_value)
69          : "r" (dest), "0" (value)
70          : "memory");
71     return old_value;
72 }
73
74 #endif /* _X86_64_ARCH_H */