Skip to content

Commit 6a6082c

Browse files
committed
Try to fix memory barriers on x86_64.
%esp is no good; must use %rsp there.
1 parent a2822fb commit 6a6082c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/include/storage/barrier.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,32 @@ extern slock_t dummy_spinlock;
6262
/* This works on any architecture, since it's only talking to GCC itself. */
6363
#define pg_compiler_barrier() __asm__ __volatile__("" : : : "memory")
6464

65-
#if defined(__i386__) || defined(__x86_64__) /* 32 or 64 bit x86 */
65+
#if defined(__i386__)
6666

6767
/*
68-
* x86 and x86_64 do not allow loads to be reorded with other loads, or
69-
* stores to be reordered with other stores, but a load can be performed
70-
* before a subsequent store.
68+
* i386 does not allow loads to be reorded with other loads, or stores to be
69+
* reordered with other stores, but a load can be performed before a subsequent
70+
* store.
7171
*
7272
* "lock; addl" has worked for longer than "mfence".
73+
*/
74+
#define pg_memory_barrier() \
75+
__asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory")
76+
#define pg_read_barrier() pg_compiler_barrier()
77+
#define pg_write_barrier() pg_compiler_barrier()
78+
79+
#elif defined(__x86_64__) /* 64 bit x86 */
80+
81+
/*
82+
* x86_64 has similar ordering characteristics to i386.
7383
*
7484
* Technically, some x86-ish chips support uncached memory access and/or
7585
* special instructions that are weakly ordered. In those cases we'd need
7686
* the read and write barriers to be lfence and sfence. But since we don't
7787
* do those things, a compiler barrier should be enough.
7888
*/
7989
#define pg_memory_barrier() \
80-
__asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory")
90+
__asm__ __volatile__ ("lock; addl $0,0(%%rsp)" : : : "memory")
8191
#define pg_read_barrier() pg_compiler_barrier()
8292
#define pg_write_barrier() pg_compiler_barrier()
8393

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy