~clint-fewbar/ubuntu/precise/erlang/merge-15b

« back to all changes in this revision

Viewing changes to erts/include/internal/i386/ethr_membar.h

  • Committer: Package Import Robot
  • Author(s): Sergei Golovan
  • Date: 2011-12-15 19:20:10 UTC
  • mfrom: (1.1.18) (3.5.15 sid)
  • mto: (3.5.16 sid)
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20111215192010-jnxcfe3tbrpp0big
Tags: 1:15.b-dfsg-1
* New upstream release.
* Upload to experimental because this release breaks external drivers
  API along with ABI, so several applications are to be fixed.
* Removed SSL patch because the old SSL implementation is removed from
  the upstream distribution.
* Removed never used patch which added native code to erlang beam files.
* Removed the erlang-docbuilder binary package because the docbuilder
  application was dropped by upstream.
* Documented dropping ${erlang-docbuilder:Depends} substvar in
  erlang-depends(1) manpage.
* Made erlang-base and erlang-base-hipe provide virtual package
  erlang-abi-15.b (the number means the first erlang version, which
  provides current ABI).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * %CopyrightBegin%
 
3
 *
 
4
 * Copyright Ericsson AB 2011. All Rights Reserved.
 
5
 *
 
6
 * The contents of this file are subject to the Erlang Public License,
 
7
 * Version 1.1, (the "License"); you may not use this file except in
 
8
 * compliance with the License. You should have received a copy of the
 
9
 * Erlang Public License along with this software. If not, it can be
 
10
 * retrieved online at http://www.erlang.org/.
 
11
 *
 
12
 * Software distributed under the License is distributed on an "AS IS"
 
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
 * the License for the specific language governing rights and limitations
 
15
 * under the License.
 
16
 *
 
17
 * %CopyrightEnd%
 
18
 */
 
19
 
 
20
/*
 
21
 * Description: Memory barriers for x86/x86-64
 
22
 * Author: Rickard Green
 
23
 */
 
24
 
 
25
#ifndef ETHR_X86_MEMBAR_H__
 
26
#define ETHR_X86_MEMBAR_H__
 
27
 
 
28
#define ETHR_LoadLoad   (1 << 0)
 
29
#define ETHR_LoadStore  (1 << 1)
 
30
#define ETHR_StoreLoad  (1 << 2)
 
31
#define ETHR_StoreStore (1 << 3)
 
32
 
 
33
#define ETHR_NO_SSE2_MEMORY_BARRIER__                   \
 
34
do {                                                    \
 
35
    volatile ethr_sint32_t x__ = 0;                     \
 
36
    __asm__ __volatile__ ("lock; orl $0x0, %0\n\t"      \
 
37
                          : "=m"(x__)                   \
 
38
                          : "m"(x__)                    \
 
39
                          : "memory");                  \
 
40
} while (0)
 
41
 
 
42
static __inline__ void
 
43
ethr_cfence__(void)
 
44
{
 
45
    __asm__ __volatile__ ("" : : : "memory");
 
46
}
 
47
 
 
48
static __inline__ void
 
49
ethr_mfence__(void)
 
50
{
 
51
#if ETHR_SIZEOF_PTR == 4
 
52
    if (ETHR_X86_RUNTIME_CONF_HAVE_NO_SSE2__)
 
53
        ETHR_NO_SSE2_MEMORY_BARRIER__;
 
54
    else
 
55
#endif
 
56
        __asm__ __volatile__ ("mfence\n\t" : : : "memory");
 
57
}
 
58
 
 
59
static __inline__ void
 
60
ethr_sfence__(void)
 
61
{
 
62
#if ETHR_SIZEOF_PTR == 4
 
63
    if (ETHR_X86_RUNTIME_CONF_HAVE_NO_SSE2__)
 
64
        ETHR_NO_SSE2_MEMORY_BARRIER__;
 
65
    else
 
66
#endif
 
67
        __asm__ __volatile__ ("sfence\n\t" : : : "memory");
 
68
}
 
69
 
 
70
static __inline__ void
 
71
ethr_lfence__(void)
 
72
{
 
73
#if ETHR_SIZEOF_PTR == 4
 
74
    if (ETHR_X86_RUNTIME_CONF_HAVE_NO_SSE2__)
 
75
        ETHR_NO_SSE2_MEMORY_BARRIER__;
 
76
    else
 
77
#endif
 
78
        __asm__ __volatile__ ("lfence\n\t" : : : "memory");
 
79
}
 
80
 
 
81
#define ETHR_X86_OUT_OF_ORDER_MEMBAR(B)                         \
 
82
  ETHR_CHOOSE_EXPR((B) == ETHR_StoreStore,                      \
 
83
                   ethr_sfence__(),                             \
 
84
                   ETHR_CHOOSE_EXPR((B) == ETHR_LoadLoad,       \
 
85
                                    ethr_lfence__(),            \
 
86
                                    ethr_mfence__()))
 
87
 
 
88
#ifdef ETHR_X86_OUT_OF_ORDER
 
89
 
 
90
#define ETHR_MEMBAR(B) \
 
91
  ETHR_X86_OUT_OF_ORDER_MEMBAR((B))
 
92
 
 
93
#else /* !ETHR_X86_OUT_OF_ORDER (the default) */
 
94
 
 
95
/*
 
96
 * We assume that only stores before loads may be reordered. That is,
 
97
 * we assume that *no* instructions like these are used:
 
98
 * - CLFLUSH,
 
99
 * - streaming stores executed with non-temporal move,
 
100
 * - string operations, or
 
101
 * - other instructions which aren't LoadLoad, LoadStore, and StoreStore
 
102
 *   ordered by themselves
 
103
 * If such instructions are used, either insert memory barriers
 
104
 * using ETHR_X86_OUT_OF_ORDER_MEMBAR() at appropriate places, or
 
105
 * define ETHR_X86_OUT_OF_ORDER. For more info see Intel 64 and IA-32
 
106
 * Architectures Software Developer's Manual; Vol 3A; Chapter 8.2.2.
 
107
 */
 
108
 
 
109
#define ETHR_MEMBAR(B) \
 
110
  ETHR_CHOOSE_EXPR((B) & ETHR_StoreLoad, ethr_mfence__(), ethr_cfence__())
 
111
 
 
112
#endif /* !ETHR_X86_OUT_OF_ORDER */
 
113
 
 
114
#endif /* ETHR_X86_MEMBAR_H__ */