[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-dev
Subject:    Re: [cfe-dev] [PROPOSAL] Reintroduce guards for Intel intrinsic headers
From:       Reid Kleckner <rnk () google ! com>
Date:       2015-07-30 17:12:50
Message-ID: CACs=tyJsfCz+qBmzd1fGRjfsswdw_NRBPJSENaRbjc_NmHSFng () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I'm opposed to this. Going forward, I would really like target intrinsics
to be available regardless of the current feature set, so users don't need
hacks like these.

I see two ways to do this with different tradeoffs:
1. Diagnose missing target attributes when calling the intel intrinsics. I
was surprised to find that we don't already do this.
2. We could support some automatic transfer of the target attribute to the
caller when calling these intrinsics, but I worry that this is too
confusing.

Implicitly setting a target attribute may block inlining that the user
expected to happen, for example. Alternatively, there may be a dynamic
cpuid check in the same function between SSE2 and AVX variants of the same
algorithm, and now the SSE2 loop will unexpectedly use AVX instructions.

So we should probably settle with telling the user to add -msseNN or
__atribute__((target(("sseNN")))).

On Thu, Jul 30, 2015 at 8:53 AM, Vedant Kumar <vsk@apple.com> wrote:

> I've run into some code which no longer compiles because of two recent
> changes:
>
>   41885d3 Update the intel intrinsic headers to use the target attribute
> support.
>   695aff1 Use a define for per-file function attributes for the Intel
> intrinsic headers.
>
> Specifically, one project defines its own SSE4.1 emulation routines when
> the real intrinsics aren't available. This is a problem because they've
> reused the names of the intrinsics. E.g;
>
> > #ifndef __SSE4_1__
> > #define _mm_extract_epi8(a_, ndx) ({ ... })
> > static inline __m128i _mm_blendv_epi8(__m128i a, __m128i b, __m128i
> mask) { ... }
> > ...
> > #endif
>
> SSE4.1 intrinsics now leak into the project when it's being compiled for
> targets without SSE4.1 support. Compilation fails with "error: redefinition
> ...".
>
> When these changes were initially being discussed, I think our stance was
> that we shouldn't support code like this [1]. However, we should reconsider
> for the sake of avoiding breakage. AFAICT, we would need to revert just two
> types of changes:
>
> In lib/Headers/__wmmintrin_aes.h:
>
> > -#if defined (__SSE4_2__) || defined (__SSE4_1__)
> >  #include <smmintrin.h>
> > -#endif
>
>
> In lib/Headers/smmintrin.h:
>
> > -#ifndef __SSE4_1__
> > -#error "SSE4.1 instruction set not enabled"
> > -#else
>
> I don't see any downsides to reintroducing these guards. If everyone's OK
> with this, I can mail a patch in. The alternative is to have clients
> rewrite their emulation layers like this:
>
> > #ifdef __SSE4_1__
> > #define compat_mm_extract_epi8 _mm_extract_epi8
> > static inline __m128i combat_mm_blendv_epi8(__m128i a, __m128i b,
> __m128i mask) __attribute__((__target__(("sse4.1")))) {
> >   return _mm_blendv_epi8(a, b, mask);
> > }
> > ...
> > #else /* OK, no native SSE 4.1. Define our own. */
> > #define compat_mm_extract_epi8(a_, ndx) ({ ... })
> > static inline __m128i compat_mm_blendv_epi8(__m128i a, __m128i b,
> __m128i mask) { ... }
> > ...
> > #endif
>
> ... and then replace all calls to intrinsics with calls to the new
> compatibility routines. This seems like a lot of tedious work, and I'd love
> to help people avoid it :).
>
> Let me know what you think!
>
> vedant
>
> [1]
> http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150615/131192.html
> _______________________________________________
> cfe-dev mailing list
> cfe-dev@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>

[Attachment #5 (text/html)]

<div dir="ltr">I&#39;m opposed to this. Going forward, I would really like target \
intrinsics to be available regardless of the current feature set, so users don&#39;t \
need hacks like these.<div><br></div><div>I see two ways to do this with different \
tradeoffs:</div><div>1. Diagnose missing target attributes when calling the intel \
intrinsics. I was surprised to find that we don&#39;t already do this.</div><div>2. \
We could support some automatic transfer of the target attribute to the caller when \
calling these intrinsics, but I worry that this is too \
confusing.</div><div><br></div><div>Implicitly setting a target attribute may block \
inlining that the user expected to happen, for example. Alternatively, there may be a \
dynamic cpuid check in the same function between SSE2 and AVX variants of the same \
algorithm, and now the SSE2 loop will unexpectedly use AVX \
instructions.</div><div><br></div><div>So we should probably settle with telling the \
user to add -msseNN or __atribute__((target((&quot;sseNN&quot;)))).</div></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 30, 2015 at 8:53 AM, \
Vedant Kumar <span dir="ltr">&lt;<a href="mailto:vsk@apple.com" \
target="_blank">vsk@apple.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">I&#39;ve run into some code which no longer compiles because \
of two recent changes:<br> <br>
   41885d3 Update the intel intrinsic headers to use the target attribute \
support.<br>  695aff1 Use a define for per-file function attributes for the Intel \
intrinsic headers.<br> <br>
Specifically, one project defines its own SSE4.1 emulation routines when the real \
intrinsics aren&#39;t available. This is a problem because they&#39;ve reused the \
names of the intrinsics. E.g;<br> <br>
&gt; #ifndef __SSE4_1__<br>
&gt; #define _mm_extract_epi8(a_, ndx) ({ ... })<br>
&gt; static inline __m128i _mm_blendv_epi8(__m128i a, __m128i b, __m128i mask) { ... \
}<br> &gt; ...<br>
&gt; #endif<br>
<br>
SSE4.1 intrinsics now leak into the project when it&#39;s being compiled for targets \
without SSE4.1 support. Compilation fails with &quot;error: redefinition \
...&quot;.<br> <br>
When these changes were initially being discussed, I think our stance was that we \
shouldn&#39;t support code like this [1]. However, we should reconsider for the sake \
of avoiding breakage. AFAICT, we would need to revert just two types of changes:<br> \
<br> In lib/Headers/__wmmintrin_aes.h:<br>
<br>
&gt; -#if defined (__SSE4_2__) || defined (__SSE4_1__)<br>
&gt;   #include &lt;smmintrin.h&gt;<br>
&gt; -#endif<br>
<br>
<br>
In lib/Headers/smmintrin.h:<br>
<br>
&gt; -#ifndef __SSE4_1__<br>
&gt; -#error &quot;SSE4.1 instruction set not enabled&quot;<br>
&gt; -#else<br>
<br>
I don&#39;t see any downsides to reintroducing these guards. If everyone&#39;s OK \
with this, I can mail a patch in. The alternative is to have clients rewrite their \
emulation layers like this:<br> <br>
&gt; #ifdef __SSE4_1__<br>
&gt; #define compat_mm_extract_epi8 _mm_extract_epi8<br>
&gt; static inline __m128i combat_mm_blendv_epi8(__m128i a, __m128i b, __m128i mask) \
__attribute__((__target__((&quot;sse4.1&quot;)))) {<br> &gt;     return \
_mm_blendv_epi8(a, b, mask);<br> &gt; }<br>
&gt; ...<br>
&gt; #else /* OK, no native SSE 4.1. Define our own. */<br>
&gt; #define compat_mm_extract_epi8(a_, ndx) ({ ... })<br>
&gt; static inline __m128i compat_mm_blendv_epi8(__m128i a, __m128i b, __m128i mask) \
{ ... }<br> &gt; ...<br>
&gt; #endif<br>
<br>
... and then replace all calls to intrinsics with calls to the new compatibility \
routines. This seems like a lot of tedious work, and I&#39;d love to help people \
avoid it :).<br> <br>
Let me know what you think!<br>
<br>
vedant<br>
<br>
[1] <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150615/131192.html" \
rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20150615/131192.html</a><br>
 _______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" rel="noreferrer" \
target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br> \
</blockquote></div><br></div>



_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic