Merged revisions 7797-7917 via svnmerge from
[cacao.git] / src / vm / jit / s390 / machine-instr.h
1 #ifndef _MACHINE_INSTR_H
2 #define _MACHINE_INSTR_H
3
4 /*  Taken from linux kernel source 
5  *  include/asm-s390/atomic.h
6  *
7  *  S390 version
8  *    Copyright (C) 1999-2005 IBM Deutschland Entwicklung GmbH, IBM Corporation
9  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
10  *               Denis Joseph Barrow,
11  *               Arnd Bergmann (arndb@de.ibm.com)
12  *
13  *  Derived from "include/asm-i386/bitops.h"
14  *    Copyright (C) 1992, Linus Torvalds
15  */
16
17 #define __CS_LOOP(ptr, op_val, op_string) ({                            \
18         int old_val, new_val;                           \
19         __asm__ __volatile__("   l     %0,0(%3)\n"                      \
20                              "0: lr    %1,%0\n"                         \
21                              op_string "  %1,%4\n"                      \
22                              "   cs    %0,%1,0(%3)\n"                   \
23                              "   jl    0b"                              \
24                              : "=&d" (old_val), "=&d" (new_val),        \
25                                "=m" (*ptr)      \
26                              : "a" (ptr), "d" (op_val),                 \
27                                "m" (*ptr)       \
28                              : "cc", "memory" );                        \
29         new_val;                                                        \
30 })
31
32 static inline void
33 atomic_add (volatile int *mem, int val)
34 {
35         __CS_LOOP(mem, val, "ar");
36 }
37
38 static inline long
39 compare_and_swap (volatile long *p, long oldval, long newval)
40 {
41         __asm__ __volatile__("  cs   %0,%3,0(%2)\n"
42                              : "+d" (oldval), "=m" (*p)
43                              : "a" (p), "d" (newval), "m" (*p)
44                              : "cc", "memory" );
45         return oldval;
46 }
47
48 /*
49  *  Taken from linux kerenl source
50  *  include/asm-s390/system.h
51  *
52  *  S390 version
53  *    Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
54  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
55  *
56  *  Derived from "include/asm-i386/system.h"
57  */
58
59 /*
60  * Force strict CPU ordering.
61  * And yes, this is required on UP too when we're talking
62  * to devices.
63  *
64  * This is very similar to the ppc eieio/sync instruction in that is
65  * does a checkpoint syncronisation & makes sure that 
66  * all memory ops have completed wrt other CPU's ( see 7-15 POP  DJB ).
67  */
68
69 #define eieio()  __asm__ __volatile__ ( "bcr 15,0" : : : "memory" ) 
70
71 #define STORE_ORDER_BARRIER() eieio()
72 #define MEMORY_BARRIER() eieio()
73
74 /* TODO not sure if the following two can't be just empty. */
75
76 #define MEMORY_BARRIER_BEFORE_ATOMIC() eieio()
77 #define MEMORY_BARRIER_AFTER_ATOMIC() eieio()
78
79 #endif