summaryrefslogtreecommitdiff
path: root/libatomic
diff options
context:
space:
mode:
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-21 17:17:03 +0000
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>2015-01-21 17:17:03 +0000
commit0e615bf55aa19d672a4c4afb823e5a29f26d42da (patch)
tree789c86c5c0fcde33931533dbfc334718e3029274 /libatomic
parentb0418f7882574b8fd858fd8a1810ede42a1ff21d (diff)
downloadgcc-0e615bf55aa19d672a4c4afb823e5a29f26d42da.tar.gz
Avoid misaligned atomic operations
Andrew Waterman <waterman@cs.berkeley.edu> * fop_n.c (libat_fetch_op): Align address to word boundary. (libat_op_fetch): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219954 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libatomic')
-rw-r--r--libatomic/ChangeLog5
-rw-r--r--libatomic/fop_n.c12
2 files changed, 11 insertions, 6 deletions
diff --git a/libatomic/ChangeLog b/libatomic/ChangeLog
index ef5b6cdf0bf..50487255105 100644
--- a/libatomic/ChangeLog
+++ b/libatomic/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-21 Andrew Waterman <waterman@cs.berkeley.edu>
+
+ * fop_n.c (libat_fetch_op): Align address to word boundary.
+ (libat_op_fetch): Likewise.
+
2015-01-16 Ilya Verbin <ilya.verbin@intel.com>
PR testsuite/64605
diff --git a/libatomic/fop_n.c b/libatomic/fop_n.c
index 307184d429a..854d648638d 100644
--- a/libatomic/fop_n.c
+++ b/libatomic/fop_n.c
@@ -112,9 +112,9 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel)
pre_barrier (smodel);
- wptr = (UWORD *)mptr;
- shift = 0;
- mask = -1;
+ wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
+ shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK);
+ mask = SIZE(MASK) << shift;
wopval = (UWORD)opval << shift;
woldval = __atomic_load_n (wptr, __ATOMIC_RELAXED);
@@ -136,9 +136,9 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel)
pre_barrier (smodel);
- wptr = (UWORD *)mptr;
- shift = 0;
- mask = -1;
+ wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
+ shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK);
+ mask = SIZE(MASK) << shift;
wopval = (UWORD)opval << shift;
woldval = __atomic_load_n (wptr, __ATOMIC_RELAXED);