public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [libatomic PATCH] Fix libatomic behavior for big endian toolchain
@ 2014-10-17  7:28 Shiva Chen
  2014-10-17 15:48 ` Joseph S. Myers
  0 siblings, 1 reply; 3+ messages in thread
From: Shiva Chen @ 2014-10-17  7:28 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 686 bytes --]

Hi,

I noticed that libatomic implementation for builtin function parameter
smaller than word.
It would shift the parameter value to word and then store word.
However, the shift amount for big endian would be wrong.
This patch fix libatomic builtin function behavior for big endian toolchain.

Is it ok for trunk ?

Shiva


2014-10-17     Shiva Chen <shiva0217@gmail.com>

Fix libatomic behavior for big endian toolchain
* libatomic/cas_n.c: Fix shift amount for big endian toolchain
* libatomic/config/arm/exch_n.c: Fix shift amount for big endian toolchain
* libatomic/exch_n.c: Fix shift amount for big endian toolchain
* libatomic/fop_n.c: Fix shift amount for big endian toolchain

[-- Attachment #2: libatomic-big-endian-patch.diff --]
[-- Type: text/plain, Size: 2506 bytes --]

diff --git a/libatomic/cas_n.c b/libatomic/cas_n.c
index 801262d..aea49f0 100644
--- a/libatomic/cas_n.c
+++ b/libatomic/cas_n.c
@@ -60,7 +60,11 @@ SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval,
   if (N < WORDSIZE)
     {
       wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
-      shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK);
+#ifdef __ARMEB__
+      shift = ((WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT);
+#else
+      shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT);
+#endif
       mask = SIZE(MASK) << shift;
     }
   else
diff --git a/libatomic/config/arm/exch_n.c b/libatomic/config/arm/exch_n.c
index c90d57f..0d71c5a 100644
--- a/libatomic/config/arm/exch_n.c
+++ b/libatomic/config/arm/exch_n.c
@@ -88,7 +88,11 @@ SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel)
   __atomic_thread_fence (__ATOMIC_SEQ_CST);
 
   wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
-  shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ INVERT_MASK_1;
+#ifdef __ARMEB__
+  shift = ((WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT);
+#else
+  shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT);
+#endif
   mask = MASK_1 << shift;
   wnewval = newval << shift;
 
diff --git a/libatomic/exch_n.c b/libatomic/exch_n.c
index 23558b0..e293d0b 100644
--- a/libatomic/exch_n.c
+++ b/libatomic/exch_n.c
@@ -77,7 +77,11 @@ SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel)
   if (N < WORDSIZE)
     {
       wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
-      shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK);
+#ifdef __ARMEB__
+      shift = ((WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT);
+#else
+      shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT);
+#endif
       mask = SIZE(MASK) << shift;
     }
   else
diff --git a/libatomic/fop_n.c b/libatomic/fop_n.c
index 4a18da9..b3184b7 100644
--- a/libatomic/fop_n.c
+++ b/libatomic/fop_n.c
@@ -113,7 +113,11 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel)
   pre_barrier (smodel);
 
   wptr = (UWORD *)mptr;
+#ifdef __ARMEB__
+  shift = (WORDSIZE - N) * CHAR_BIT;
+#else
   shift = 0;
+#endif
   mask = -1;
 
   wopval = (UWORD)opval << shift;
@@ -137,7 +141,11 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel)
   pre_barrier (smodel);
 
   wptr = (UWORD *)mptr;
+#ifdef __ARMEB__
+  shift = (WORDSIZE - N) * CHAR_BIT;
+#else
   shift = 0;
+#endif
   mask = -1;
 
   wopval = (UWORD)opval << shift;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [libatomic PATCH] Fix libatomic behavior for big endian toolchain
  2014-10-17  7:28 [libatomic PATCH] Fix libatomic behavior for big endian toolchain Shiva Chen
@ 2014-10-17 15:48 ` Joseph S. Myers
  2014-10-17 16:36   ` Shiva Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph S. Myers @ 2014-10-17 15:48 UTC (permalink / raw)
  To: Shiva Chen; +Cc: gcc-patches

Changes to architecture-independent files must use 
architecture-independent conditionals, so __BYTE_ORDER__ not __ARMEB__.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [libatomic PATCH] Fix libatomic behavior for big endian toolchain
  2014-10-17 15:48 ` Joseph S. Myers
@ 2014-10-17 16:36   ` Shiva Chen
  0 siblings, 0 replies; 3+ messages in thread
From: Shiva Chen @ 2014-10-17 16:36 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 495 bytes --]

Hi, Joseph

I have been modify the patch as your suggestion
use # if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
in architecture-independent files

Is it ok for trunk ?

And I don't have svn write access
Could you help me to commit this patch?

Shiva

2014-10-17 23:41 GMT+08:00 Joseph S. Myers <joseph@codesourcery.com>:
> Changes to architecture-independent files must use
> architecture-independent conditionals, so __BYTE_ORDER__ not __ARMEB__.
>
> --
> Joseph S. Myers
> joseph@codesourcery.com

[-- Attachment #2: libatomic-big-endian-patch.diff --]
[-- Type: text/plain, Size: 2610 bytes --]

diff --git a/libatomic/cas_n.c b/libatomic/cas_n.c
index 801262d..5b5b8d7 100644
--- a/libatomic/cas_n.c
+++ b/libatomic/cas_n.c
@@ -60,7 +60,11 @@ SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval,
   if (N < WORDSIZE)
     {
       wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
-      shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK);
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+      shift = ((WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT);
+#else
+      shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT);
+#endif
       mask = SIZE(MASK) << shift;
     }
   else
diff --git a/libatomic/config/arm/exch_n.c b/libatomic/config/arm/exch_n.c
index c90d57f..0d71c5a 100644
--- a/libatomic/config/arm/exch_n.c
+++ b/libatomic/config/arm/exch_n.c
@@ -88,7 +88,11 @@ SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel)
   __atomic_thread_fence (__ATOMIC_SEQ_CST);
 
   wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
-  shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ INVERT_MASK_1;
+#ifdef __ARMEB__
+  shift = ((WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT);
+#else
+  shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT);
+#endif
   mask = MASK_1 << shift;
   wnewval = newval << shift;
 
diff --git a/libatomic/exch_n.c b/libatomic/exch_n.c
index 23558b0..4418f1f 100644
--- a/libatomic/exch_n.c
+++ b/libatomic/exch_n.c
@@ -77,7 +77,11 @@ SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel)
   if (N < WORDSIZE)
     {
       wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
-      shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK);
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+      shift = ((WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT);
+#else
+      shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT);
+#endif
       mask = SIZE(MASK) << shift;
     }
   else
diff --git a/libatomic/fop_n.c b/libatomic/fop_n.c
index 4a18da9..5d26cde 100644
--- a/libatomic/fop_n.c
+++ b/libatomic/fop_n.c
@@ -113,7 +113,11 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel)
   pre_barrier (smodel);
 
   wptr = (UWORD *)mptr;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+  shift = (WORDSIZE - N) * CHAR_BIT;
+#else
   shift = 0;
+#endif
   mask = -1;
 
   wopval = (UWORD)opval << shift;
@@ -137,7 +141,11 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel)
   pre_barrier (smodel);
 
   wptr = (UWORD *)mptr;
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+  shift = (WORDSIZE - N) * CHAR_BIT;
+#else
   shift = 0;
+#endif
   mask = -1;
 
   wopval = (UWORD)opval << shift;

[-- Attachment #3: Changelog --]
[-- Type: application/octet-stream, Size: 367 bytes --]

2014-10-17     Shiva Chen <shiva0217@gmail.com>

	Fix libatomic behavior for big endian toolchain
	* libatomic/cas_n.c: Fix shift amount for big endian toolchain
	* libatomic/config/arm/exch_n.c: Fix shift amount for big endian toolchain
	* libatomic/exch_n.c: Fix shift amount for big endian toolchain
	* libatomic/fop_n.c: Fix shift amount for big endian toolchain

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-10-17 16:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-17  7:28 [libatomic PATCH] Fix libatomic behavior for big endian toolchain Shiva Chen
2014-10-17 15:48 ` Joseph S. Myers
2014-10-17 16:36   ` Shiva Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).