* Re: [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
@ 2007-05-18 5:33 Uros Bizjak
2007-05-18 9:09 ` Paolo Carlini
0 siblings, 1 reply; 11+ messages in thread
From: Uros Bizjak @ 2007-05-18 5:33 UTC (permalink / raw)
To: GCC Patches; +Cc: Paolo Carlini, Mark Mitchell
Hello!
> In short, in order to take advantage in the C++ library of
> __sync_*_compare_and_swap (in shared_ptr<> for instance) we need a runtime
> feature macro. In that thread it was decided that such macros should begin with
> __GCC_HAVE_*, and here we are adding 4 of them, for that specific builtin and 1,
> 2, 4, 8 bytes types. This fine grained approach seems optimal, more accurate than
> lumping everything under a yes or no __GCC_HAVE_ATOMIC_BUILTINS.
Could __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 for cmpxchg16b also be added
to these checks? For testing, you need -mcx16 compile flag on x86_64.
Uros.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
2007-05-18 5:33 [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_* Uros Bizjak
@ 2007-05-18 9:09 ` Paolo Carlini
2007-05-18 9:28 ` Uros Bizjak
0 siblings, 1 reply; 11+ messages in thread
From: Paolo Carlini @ 2007-05-18 9:09 UTC (permalink / raw)
To: Uros Bizjak; +Cc: GCC Patches, Paolo Bonzini
Uros Bizjak wrote:
> Could __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 for cmpxchg16b also be added
> to these checks? For testing, you need -mcx16 compile flag on x86_64.
Isn't completely trivial, because HAVE_sync_compare_and_swapti is not
defined on i386... Paolo, or Uros, can you suggest a quick solution for
this extension?
Thanks,
Paolo.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
2007-05-18 9:09 ` Paolo Carlini
@ 2007-05-18 9:28 ` Uros Bizjak
2007-05-18 9:30 ` Paolo Carlini
0 siblings, 1 reply; 11+ messages in thread
From: Uros Bizjak @ 2007-05-18 9:28 UTC (permalink / raw)
To: Paolo Carlini; +Cc: GCC Patches, Paolo Bonzini
On 5/18/07, Paolo Carlini <pcarlini@suse.de> wrote:
> > Could __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 for cmpxchg16b also be added
> > to these checks? For testing, you need -mcx16 compile flag on x86_64.
>
> Isn't completely trivial, because HAVE_sync_compare_and_swapti is not
> defined on i386... Paolo, or Uros, can you suggest a quick solution for
> this extension?
+#include "insn-codes.h"
IMO you should #include "insn-flags.h". HAVE_ macros are defined there.
Perhaps adding
#ifdef HAVE_sync_compare_and_swapqi
+ if (HAVE_sync_compare_and_swapqi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
#endif
could solve this problem?
Uros.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
2007-05-18 9:28 ` Uros Bizjak
@ 2007-05-18 9:30 ` Paolo Carlini
2007-05-18 9:44 ` Uros Bizjak
0 siblings, 1 reply; 11+ messages in thread
From: Paolo Carlini @ 2007-05-18 9:30 UTC (permalink / raw)
To: Uros Bizjak; +Cc: GCC Patches, Paolo Bonzini
Uros Bizjak wrote:
> +#include "insn-codes.h"
>
> IMO you should #include "insn-flags.h". HAVE_ macros are defined there.
Ok...
> Perhaps adding
>
> #ifdef HAVE_sync_compare_and_swapqi
> + if (HAVE_sync_compare_and_swapqi)
> + cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
> #endif
>
> could solve this problem?
Indeed ;)
Stay tuned...
Paolo.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
2007-05-18 9:30 ` Paolo Carlini
@ 2007-05-18 9:44 ` Uros Bizjak
2007-05-18 12:15 ` Paolo Carlini
0 siblings, 1 reply; 11+ messages in thread
From: Uros Bizjak @ 2007-05-18 9:44 UTC (permalink / raw)
To: Paolo Carlini; +Cc: GCC Patches, Paolo Bonzini
On 5/18/07, Paolo Carlini <pcarlini@suse.de> wrote:
> > +#include "insn-codes.h"
> >
> > IMO you should #include "insn-flags.h". HAVE_ macros are defined there.
>
> Ok...
Actually, it looks that insn-flags.h have been included elsewhere
(since it worked), so no need to include it at all...
> > Perhaps adding
> >
> > #ifdef HAVE_sync_compare_and_swapqi
> > + if (HAVE_sync_compare_and_swapqi)
> > + cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
> > #endif
> >
> > could solve this problem?
>
> Indeed ;)
I think that you need #ifdef wraps everywhere.
BTW:
+/* { dg-do preprocess { target i?86-*-* } } */
+/* { dg-options "-march=i586" } */
We should also preprocess for x86_64 target, so:
/* { dg-do preprocess { target i?86-*-* target x86_64-*-* } } */
/* { dg-options "-march=i586" { target { { i?86-*-* x86_64-*-* } &&
ilp32 } } } */
and to check SWAP_16:
/* { dg-do preprocess { target { { i?86-*-* x86_64-*-* } && lp64 } */
/* { dg-options "-mcx16" } */
Uros.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
2007-05-18 9:44 ` Uros Bizjak
@ 2007-05-18 12:15 ` Paolo Carlini
2007-05-18 12:42 ` Uros Bizjak
0 siblings, 1 reply; 11+ messages in thread
From: Paolo Carlini @ 2007-05-18 12:15 UTC (permalink / raw)
To: Uros Bizjak; +Cc: GCC Patches, Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 533 bytes --]
Uros Bizjak wrote:
> On 5/18/07, Paolo Carlini <pcarlini@suse.de> wrote:
>
>> > +#include "insn-codes.h"
>> >
>> > IMO you should #include "insn-flags.h". HAVE_ macros are defined
>> there.
>>
>> Ok...
>
> Actually, it looks that insn-flags.h have been included elsewhere
> (since it worked), so no need to include it at all...
Agreed about everything, thanks for your help. I think the attached
(tested x86_64-linux multilib, and x86-linux) implements all your
suggestions.
Ok for mainline now?
Paolo.
/////////////////////
[-- Attachment #2: CL_gcc_have_compare_and_swap_4 --]
[-- Type: text/plain, Size: 832 bytes --]
2007-05-18 Paolo Bonzini <bonzini@gnu.org>
Paolo Carlini <pcarlini@suse.de>
Uros Bizjak <ubizjak@gmail.com>
* c-cppbuiltin.c (c_cpp_builtins): Define
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2,
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8,
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16, if appropriate.
* doc/cpp.texi [Standard Predefined Macros]: Document.
2007-05-18 Paolo Bonzini <bonzini@gnu.org>
Paolo Carlini <pcarlini@suse.de>
Uros Bizjak <ubizjak@gmail.com>
* gcc.dg/gcc-have-sync-compare-and-swap.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-1.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-2.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-3.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-4.c,
New testcases.
[-- Attachment #3: patch_gcc_have_compare_and_swap_4b --]
[-- Type: text/plain, Size: 6291 bytes --]
Index: doc/cpp.texi
===================================================================
--- doc/cpp.texi (revision 124776)
+++ doc/cpp.texi (working copy)
@@ -2179,6 +2179,14 @@
(once per compilation) and @code{__TIMESTAMP__} will expand to
@code{@w{"??? ??? ?? ??:??:?? ????"}}.
+@item __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+These macros are defined when the target processor supports atomic compare
+and swap operations on operands 1, 2, 4, 8 or 16 bytes in length, respectively.
+
@end table
@node System-specific Predefined Macros
Index: c-cppbuiltin.c
===================================================================
--- c-cppbuiltin.c (revision 124776)
+++ c-cppbuiltin.c (working copy)
@@ -547,6 +547,33 @@
if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node))
cpp_define (pfile, "__WCHAR_UNSIGNED__");
+ /* Tell source code if the compiler makes sync_compare_and_swap
+ builtins available. */
+#ifdef HAVE_sync_compare_and_swapqi
+ if (HAVE_sync_compare_and_swapqi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+#endif
+
+#ifdef HAVE_sync_compare_and_swaphi
+ if (HAVE_sync_compare_and_swaphi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+#endif
+
+#ifdef HAVE_sync_compare_and_swapsi
+ if (HAVE_sync_compare_and_swapsi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+#endif
+
+#ifdef HAVE_sync_compare_and_swapdi
+ if (HAVE_sync_compare_and_swapdi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
+#endif
+
+#ifdef HAVE_sync_compare_and_swapti
+ if (HAVE_sync_compare_and_swapti)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
+#endif
+
/* Make the choice of ObjC runtime visible to source code. */
if (c_dialect_objc () && flag_next_runtime)
cpp_define (pfile, "__NEXT_RUNTIME__");
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-1.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-1.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-1.c (revision 0)
@@ -0,0 +1,18 @@
+/* { dg-do preprocess { target i?86-*-* } } */
+/* { dg-options "-march=i386" } */
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#error nonono
+#endif
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-2.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-2.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-2.c (revision 0)
@@ -0,0 +1,14 @@
+/* { dg-do preprocess { target i?86-*-* } } */
+/* { dg-options "-march=i486" } */
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-3.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-3.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-3.c (revision 0)
@@ -0,0 +1,18 @@
+/* { dg-do preprocess { target i?86-*-* x86_64-*-* } } */
+/* { dg-options "-march=i586" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#error nonono
+#endif
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-4.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-4.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-4.c (revision 0)
@@ -0,0 +1,22 @@
+/* { dg-do preprocess { target { { i?86-*-* x86_64-*-* } && lp64 } } } */
+/* { dg-options "-mcx16" } */
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+#error nonono
+#endif
Index: testsuite/gcc.dg/gcc-have-sync-compare-and-swap.c
===================================================================
--- testsuite/gcc.dg/gcc-have-sync-compare-and-swap.c (revision 0)
+++ testsuite/gcc.dg/gcc-have-sync-compare-and-swap.c (revision 0)
@@ -0,0 +1,56 @@
+/* { dg-do link } */
+
+void f1()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+ typedef int __attribute__ ((__mode__ (__QI__))) qi_int_type;
+ qi_int_type qi_int;
+ __sync_bool_compare_and_swap (&qi_int, (qi_int_type)0, (qi_int_type)1);
+#endif
+}
+
+void f2()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+ typedef int __attribute__ ((__mode__ (__HI__))) hi_int_type;
+ hi_int_type hi_int;
+ __sync_bool_compare_and_swap (&hi_int, (hi_int_type)0, (hi_int_type)1);
+#endif
+}
+
+void f4()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+ typedef int __attribute__ ((__mode__ (__SI__))) si_int_type;
+ si_int_type si_int;
+ __sync_bool_compare_and_swap (&si_int, (si_int_type)0, (si_int_type)1);
+#endif
+}
+
+void f8()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+ typedef int __attribute__ ((__mode__ (__DI__))) di_int_type;
+ di_int_type di_int;
+ __sync_bool_compare_and_swap (&di_int, (di_int_type)0, (di_int_type)1);
+#endif
+}
+
+void f16()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+ typedef int __attribute__ ((__mode__ (__TI__))) ti_int_type;
+ ti_int_type ti_int;
+ __sync_bool_compare_and_swap (&ti_int, (ti_int_type)0, (ti_int_type)1);
+#endif
+}
+
+int main()
+{
+ f1();
+ f2();
+ f4();
+ f8();
+ f16();
+ return 0;
+}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
2007-05-18 12:15 ` Paolo Carlini
@ 2007-05-18 12:42 ` Uros Bizjak
2007-05-18 14:35 ` Paolo Carlini
0 siblings, 1 reply; 11+ messages in thread
From: Uros Bizjak @ 2007-05-18 12:42 UTC (permalink / raw)
To: Paolo Carlini; +Cc: GCC Patches, Paolo Bonzini
On 5/18/07, Paolo Carlini <pcarlini@suse.de> wrote:
> Agreed about everything, thanks for your help. I think the attached
> (tested x86_64-linux multilib, and x86-linux) implements all your
> suggestions.
>
> Ok for mainline now?
I would add also
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
to ..._swap-1.c,
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
to ..._swap-2.c and
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
to ..._swap-3.c
just to cover all cases... Anyway, the i386 part (tests) are OK, and
althoug I can't approve cpp part it looks pretty safe to me, having
all these #ifdefs around.
Thanks,
Uros.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
2007-05-18 12:42 ` Uros Bizjak
@ 2007-05-18 14:35 ` Paolo Carlini
2007-05-21 21:12 ` Mark Mitchell
0 siblings, 1 reply; 11+ messages in thread
From: Paolo Carlini @ 2007-05-18 14:35 UTC (permalink / raw)
To: Uros Bizjak; +Cc: GCC Patches, Paolo Bonzini
[-- Attachment #1: Type: text/plain, Size: 638 bytes --]
Uros Bizjak wrote:
> I would add also
>
> +#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
>
> to ..._swap-1.c,
>
> +#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
> +#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
>
> to ..._swap-2.c and
>
> +#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
>
> to ..._swap-3.c
Ok, added in the attahed, tested x86-linux and x86_64-linux multilib, as
usual.
> just to cover all cases... Anyway, the i386 part (tests) are OK, and
> althoug I can't approve cpp part it looks pretty safe to me, having
> all these #ifdefs around.
Excellent. I'm looking for approval of the c-cppbuiltin.c bits...
Paolo.
////////////////
[-- Attachment #2: CL_gcc_have_compare_and_swap_5 --]
[-- Type: text/plain, Size: 832 bytes --]
2007-05-18 Paolo Bonzini <bonzini@gnu.org>
Paolo Carlini <pcarlini@suse.de>
Uros Bizjak <ubizjak@gmail.com>
* c-cppbuiltin.c (c_cpp_builtins): Define
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2,
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8,
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16, if appropriate.
* doc/cpp.texi [Standard Predefined Macros]: Document.
2007-05-18 Paolo Bonzini <bonzini@gnu.org>
Paolo Carlini <pcarlini@suse.de>
Uros Bizjak <ubizjak@gmail.com>
* gcc.dg/gcc-have-sync-compare-and-swap.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-1.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-2.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-3.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-4.c,
New testcases.
[-- Attachment #3: patch_gcc_have_compare_and_swap_5 --]
[-- Type: text/plain, Size: 6624 bytes --]
Index: doc/cpp.texi
===================================================================
--- doc/cpp.texi (revision 124776)
+++ doc/cpp.texi (working copy)
@@ -2179,6 +2179,14 @@
(once per compilation) and @code{__TIMESTAMP__} will expand to
@code{@w{"??? ??? ?? ??:??:?? ????"}}.
+@item __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+These macros are defined when the target processor supports atomic compare
+and swap operations on operands 1, 2, 4, 8 or 16 bytes in length, respectively.
+
@end table
@node System-specific Predefined Macros
Index: c-cppbuiltin.c
===================================================================
--- c-cppbuiltin.c (revision 124776)
+++ c-cppbuiltin.c (working copy)
@@ -547,6 +547,33 @@
if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node))
cpp_define (pfile, "__WCHAR_UNSIGNED__");
+ /* Tell source code if the compiler makes sync_compare_and_swap
+ builtins available. */
+#ifdef HAVE_sync_compare_and_swapqi
+ if (HAVE_sync_compare_and_swapqi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+#endif
+
+#ifdef HAVE_sync_compare_and_swaphi
+ if (HAVE_sync_compare_and_swaphi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+#endif
+
+#ifdef HAVE_sync_compare_and_swapsi
+ if (HAVE_sync_compare_and_swapsi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+#endif
+
+#ifdef HAVE_sync_compare_and_swapdi
+ if (HAVE_sync_compare_and_swapdi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
+#endif
+
+#ifdef HAVE_sync_compare_and_swapti
+ if (HAVE_sync_compare_and_swapti)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
+#endif
+
/* Make the choice of ObjC runtime visible to source code. */
if (c_dialect_objc () && flag_next_runtime)
cpp_define (pfile, "__NEXT_RUNTIME__");
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-1.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-1.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-1.c (revision 0)
@@ -0,0 +1,22 @@
+/* { dg-do preprocess { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
+/* { dg-options "-march=i386" } */
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+#error nonono
+#endif
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-2.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-2.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-2.c (revision 0)
@@ -0,0 +1,23 @@
+/* { dg-do preprocess { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
+/* { dg-options "-march=i486" } */
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+#error nonono
+#endif
+
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-3.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-3.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-3.c (revision 0)
@@ -0,0 +1,22 @@
+/* { dg-do preprocess { target i?86-*-* x86_64-*-* } } */
+/* { dg-options "-march=i586" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+#error nonono
+#endif
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-4.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-4.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-4.c (revision 0)
@@ -0,0 +1,22 @@
+/* { dg-do preprocess { target { { i?86-*-* x86_64-*-* } && lp64 } } } */
+/* { dg-options "-mcx16" } */
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+#error nonono
+#endif
Index: testsuite/gcc.dg/gcc-have-sync-compare-and-swap.c
===================================================================
--- testsuite/gcc.dg/gcc-have-sync-compare-and-swap.c (revision 0)
+++ testsuite/gcc.dg/gcc-have-sync-compare-and-swap.c (revision 0)
@@ -0,0 +1,56 @@
+/* { dg-do link } */
+
+void f1()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+ typedef int __attribute__ ((__mode__ (__QI__))) qi_int_type;
+ qi_int_type qi_int;
+ __sync_bool_compare_and_swap (&qi_int, (qi_int_type)0, (qi_int_type)1);
+#endif
+}
+
+void f2()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+ typedef int __attribute__ ((__mode__ (__HI__))) hi_int_type;
+ hi_int_type hi_int;
+ __sync_bool_compare_and_swap (&hi_int, (hi_int_type)0, (hi_int_type)1);
+#endif
+}
+
+void f4()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+ typedef int __attribute__ ((__mode__ (__SI__))) si_int_type;
+ si_int_type si_int;
+ __sync_bool_compare_and_swap (&si_int, (si_int_type)0, (si_int_type)1);
+#endif
+}
+
+void f8()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+ typedef int __attribute__ ((__mode__ (__DI__))) di_int_type;
+ di_int_type di_int;
+ __sync_bool_compare_and_swap (&di_int, (di_int_type)0, (di_int_type)1);
+#endif
+}
+
+void f16()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16
+ typedef int __attribute__ ((__mode__ (__TI__))) ti_int_type;
+ ti_int_type ti_int;
+ __sync_bool_compare_and_swap (&ti_int, (ti_int_type)0, (ti_int_type)1);
+#endif
+}
+
+int main()
+{
+ f1();
+ f2();
+ f4();
+ f8();
+ f16();
+ return 0;
+}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
2007-05-18 14:35 ` Paolo Carlini
@ 2007-05-21 21:12 ` Mark Mitchell
2007-05-21 22:52 ` Paolo Carlini
0 siblings, 1 reply; 11+ messages in thread
From: Mark Mitchell @ 2007-05-21 21:12 UTC (permalink / raw)
To: Paolo Carlini; +Cc: Uros Bizjak, GCC Patches, Paolo Bonzini
Paolo Carlini wrote:
> Excellent. I'm looking for approval of the c-cppbuiltin.c bits...
I apologize for arriving late to this party, especially since you
invited me early.
The c-cppbuiltin.c changes are OK.
Thanks,
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
2007-05-21 21:12 ` Mark Mitchell
@ 2007-05-21 22:52 ` Paolo Carlini
0 siblings, 0 replies; 11+ messages in thread
From: Paolo Carlini @ 2007-05-21 22:52 UTC (permalink / raw)
To: Mark Mitchell; +Cc: Uros Bizjak, GCC Patches, Paolo Bonzini
Mark Mitchell wrote:
>>Excellent. I'm looking for approval of the c-cppbuiltin.c bits...
>>
>>
>I apologize for arriving late to this party, especially since you
>invited me early.
>
>
:) You didn't miss much, I learned a lot from Uros, but only trivial
things for real compiler people...
>The c-cppbuiltin.c changes are OK.
>
>
Thanks a lot, committed!
Paolo.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_*
@ 2007-05-18 1:46 Paolo Carlini
0 siblings, 0 replies; 11+ messages in thread
From: Paolo Carlini @ 2007-05-18 1:46 UTC (permalink / raw)
To: 'gcc-patches@gcc.gnu.org'; +Cc: Mark Mitchell
[-- Attachment #1: Type: text/plain, Size: 694 bytes --]
Hi,
this patch follows-up to an old thread:
http://gcc.gnu.org/ml/libstdc++/2006-07/msg00106.html
In short, in order to take advantage in the C++ library of
__sync_*_compare_and_swap (in shared_ptr<> for instance) we need a
runtime feature macro. In that thread it was decided that such macros
should begin with __GCC_HAVE_*, and here we are adding 4 of them, for
that specific builtin and 1, 2, 4, 8 bytes types. This fine grained
approach seems optimal, more accurate than lumping everything under a
yes or no __GCC_HAVE_ATOMIC_BUILTINS.
This patch, a joint work with Paolo Bonzini, has been tested on
x86-linux and x86_64-linux.
Ok for mainline?
Paolo.
///////////////////
[-- Attachment #2: CL_gcc_have_compare_and_swap --]
[-- Type: text/plain, Size: 690 bytes --]
2007-05-17 Paolo Bonzini <bonzini@gnu.org>
Paolo Carlini <pcarlini@suse.de>
* c-cppbuiltin.c (c_cpp_builtins): Define
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2,
__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4, __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8,
if appropriate.
* Makefile.in: Adjust.
* doc/cpp.texi [Standard Predefined Macros]: Document.
2007-05-17 Paolo Bonzini <bonzini@gnu.org>
Paolo Carlini <pcarlini@suse.de>
* gcc.dg/gcc-have-sync-compare-and-swap.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-1.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-2.c,
gcc.target/i386/gcc-have-sync-compare-and-swap-3.c:
New testcases.
[-- Attachment #3: patch_gcc_have_compare_and_swap --]
[-- Type: text/plain, Size: 5559 bytes --]
Index: doc/cpp.texi
===================================================================
--- doc/cpp.texi (revision 124776)
+++ doc/cpp.texi (working copy)
@@ -2179,6 +2179,13 @@
(once per compilation) and @code{__TIMESTAMP__} will expand to
@code{@w{"??? ??? ?? ??:??:?? ????"}}.
+@item __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+@itemx __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+These macros are defined when the target processor supports atomic compare
+and swap operations on operands 1, 2, 4 or 8 bytes in length, respectively.
+
@end table
@node System-specific Predefined Macros
Index: c-cppbuiltin.c
===================================================================
--- c-cppbuiltin.c (revision 124776)
+++ c-cppbuiltin.c (working copy)
@@ -34,6 +34,7 @@
#include "toplev.h"
#include "tm_p.h" /* Target prototypes. */
#include "target.h"
+#include "insn-codes.h"
#ifndef TARGET_OS_CPP_BUILTINS
# define TARGET_OS_CPP_BUILTINS()
@@ -547,6 +548,20 @@
if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node))
cpp_define (pfile, "__WCHAR_UNSIGNED__");
+ /* Tell source code if the compiler makes sync_compare_and_swap
+ builtins available. */
+ if (HAVE_sync_compare_and_swapqi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+
+ if (HAVE_sync_compare_and_swaphi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+
+ if (HAVE_sync_compare_and_swapsi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+
+ if (HAVE_sync_compare_and_swapdi)
+ cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
+
/* Make the choice of ObjC runtime visible to source code. */
if (c_dialect_objc () && flag_next_runtime)
cpp_define (pfile, "__NEXT_RUNTIME__");
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-1.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-1.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-1.c (revision 0)
@@ -0,0 +1,18 @@
+/* { dg-do preprocess { target i?86-*-* } } */
+/* { dg-options "-march=i386" } */
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
+
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#error nonono
+#endif
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-2.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-2.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-2.c (revision 0)
@@ -0,0 +1,14 @@
+/* { dg-do preprocess { target i?86-*-* } } */
+/* { dg-options "-march=i486" } */
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
Index: testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-3.c
===================================================================
--- testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-3.c (revision 0)
+++ testsuite/gcc.target/i386/gcc-have-sync-compare-and-swap-3.c (revision 0)
@@ -0,0 +1,18 @@
+/* { dg-do preprocess { target i?86-*-* } } */
+/* { dg-options "-march=i586" } */
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#error nonono
+#endif
+
+#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#error nonono
+#endif
Index: testsuite/gcc.dg/gcc-have-sync-compare-and-swap.c
===================================================================
--- testsuite/gcc.dg/gcc-have-sync-compare-and-swap.c (revision 0)
+++ testsuite/gcc.dg/gcc-have-sync-compare-and-swap.c (revision 0)
@@ -0,0 +1,46 @@
+/* { dg-do link } */
+
+void f1()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
+ typedef int __attribute__ ((__mode__ (__QI__))) qi_int_type;
+ qi_int_type qi_int;
+ __sync_bool_compare_and_swap (&qi_int, (qi_int_type)0, (qi_int_type)1);
+#endif
+}
+
+void f2()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2
+ typedef int __attribute__ ((__mode__ (__HI__))) hi_int_type;
+ hi_int_type hi_int;
+ __sync_bool_compare_and_swap (&hi_int, (hi_int_type)0, (hi_int_type)1);
+#endif
+}
+
+void f4()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+ typedef int __attribute__ ((__mode__ (__SI__))) si_int_type;
+ si_int_type si_int;
+ __sync_bool_compare_and_swap (&si_int, (si_int_type)0, (si_int_type)1);
+#endif
+}
+
+void f8()
+{
+#ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+ typedef int __attribute__ ((__mode__ (__DI__))) di_int_type;
+ di_int_type di_int;
+ __sync_bool_compare_and_swap (&di_int, (di_int_type)0, (di_int_type)1);
+#endif
+}
+
+int main()
+{
+ f1();
+ f2();
+ f4();
+ f8();
+ return 0;
+}
Index: Makefile.in
===================================================================
--- Makefile.in (revision 124776)
+++ Makefile.in (working copy)
@@ -1739,7 +1739,7 @@
c-cppbuiltin.o : c-cppbuiltin.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) version.h $(C_COMMON_H) $(C_PRAGMA_H) $(FLAGS_H) toplev.h \
- output.h except.h $(REAL_H) $(TARGET_H) $(TM_P_H)
+ output.h except.h $(REAL_H) $(TARGET_H) $(TM_P_H) insn-codes.h
# A file used by all variants of C and some other languages.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-05-21 22:52 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-18 5:33 [PATCH] Add __GCC_HAVE_SYNC_COMPARE_AND_SWAP_* Uros Bizjak
2007-05-18 9:09 ` Paolo Carlini
2007-05-18 9:28 ` Uros Bizjak
2007-05-18 9:30 ` Paolo Carlini
2007-05-18 9:44 ` Uros Bizjak
2007-05-18 12:15 ` Paolo Carlini
2007-05-18 12:42 ` Uros Bizjak
2007-05-18 14:35 ` Paolo Carlini
2007-05-21 21:12 ` Mark Mitchell
2007-05-21 22:52 ` Paolo Carlini
-- strict thread matches above, loose matches on Subject: below --
2007-05-18 1:46 Paolo Carlini
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).