From 0e615bf55aa19d672a4c4afb823e5a29f26d42da Mon Sep 17 00:00:00 2001 From: rth Date: Wed, 21 Jan 2015 17:17:03 +0000 Subject: [PATCH] Avoid misaligned atomic operations Andrew Waterman * 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 --- libatomic/ChangeLog | 5 +++++ libatomic/fop_n.c | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/libatomic/ChangeLog b/libatomic/ChangeLog index ef5b6cd..5048725 100644 --- a/libatomic/ChangeLog +++ b/libatomic/ChangeLog @@ -1,3 +1,8 @@ +2015-01-21 Andrew Waterman + + * fop_n.c (libat_fetch_op): Align address to word boundary. + (libat_op_fetch): Likewise. + 2015-01-16 Ilya Verbin PR testsuite/64605 diff --git a/libatomic/fop_n.c b/libatomic/fop_n.c index 307184d..854d648 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); -- 2.7.4