runtime: yield with _mm_pause instead of __builtin_ia32... (issue 100810044)

1,324 views
Skip to first unread message

p...@google.com

unread,
May 27, 2014, 6:02:16 PM5/27/14
to ia...@golang.org, gofront...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: iant,

Description:
runtime: yield with _mm_pause instead of __builtin_ia32_pause when built
with Clang

The former is more portable than the latter, being supported by at
least GCC and Clang, but we need to continue using __builtin_ia32_pause
with GCC to work around a bug preventing us from using _mm_pause
with GCC when targeting 32-bit x86.

Please review this at https://codereview.appspot.com/100810044/

Affected files (+9, -0 lines):
M libgo/runtime/yield.c


Index: libgo/runtime/yield.c
===================================================================
--- a/libgo/runtime/yield.c
+++ b/libgo/runtime/yield.c
@@ -14,6 +14,10 @@
#include <sys/select.h>
#endif

+#if defined (__clang__) && (defined (__i386__) || defined (__x86_64__))
+#include "xmmintrin.h"
+#endif
+
#include "runtime.h"

/* Spin wait. */
@@ -26,8 +30,13 @@
for (i = 0; i < cnt; ++i)
{
#if defined (__i386__) || defined (__x86_64__)
+#ifdef __clang__
+ _mm_pause ();
+#else
+ // TODO: fix GCC bug preventing us from using _mm_pause.
__builtin_ia32_pause ();
#endif
+#endif
}
}



ia...@golang.org

unread,
May 28, 2014, 8:37:52 PM5/28/14
to p...@google.com, gofront...@googlegroups.com, re...@codereview-hr.appspotmail.com
The problem with calling _mm_pause is that the default 32-bit x86 target
does not support SSE. Of course _mm_pause does not actually require SSE
support. On the other hand <xmmintrin.h> should only be used for
targets with SSE support. So it's not clear whether this is a bug or
not.

What is clear is that the <ia32intrin.h> header file defines __pause,
which has the same effect and does work. Does it work with clang to
#include <ia32intrin.h> and use __pause?

https://codereview.appspot.com/100810044/

p...@google.com

unread,
May 28, 2014, 11:55:23 PM5/28/14
to ia...@golang.org, gofront...@googlegroups.com, re...@codereview-hr.appspotmail.com
Clang does not support __pause. Maybe the simplest thing to do is to use
inline asm, which both compilers should support.

https://codereview.appspot.com/100810044/

p...@google.com

unread,
May 29, 2014, 6:27:15 PM5/29/14
to ia...@golang.org, gofront...@googlegroups.com, re...@codereview-hr.appspotmail.com

ia...@golang.org

unread,
May 29, 2014, 6:52:59 PM5/29/14
to p...@google.com, gofront...@googlegroups.com, re...@codereview-hr.appspotmail.com
I'm working on getting GCC to support _mm_pause while building libgo for
older 32-bit processors
(https://gcc.gnu.org/ml/gcc-patches/2014-05/msg02560.html). Let's see
what happens with that.

https://codereview.appspot.com/100810044/

ia...@golang.org

unread,
May 30, 2014, 9:54:33 AM5/30/14
to p...@google.com, gofront...@googlegroups.com, re...@codereview-hr.appspotmail.com
I've committed a version of this. You can abandon this CL (hg change -d
100810044).

https://codereview.appspot.com/100810044/
Reply all
Reply to author
Forward
0 new messages