public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/47895] New: usage of __attribute__ ((__target__ ("xyz"))) with buitins
@ 2011-02-25 14:00 vincenzo.innocente at cern dot ch
  2011-02-25 15:40 ` [Bug middle-end/47895] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2011-02-25 14:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47895

           Summary: usage of __attribute__ ((__target__ ("xyz"))) with
                    buitins
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vincenzo.innocente@cern.ch


I would like to generate code for multiple targets from the same source when
using builtins
(
I think that this issue has been discussed before for instance in
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39840
) 


I have code as in the example below that compiles only with -mavx.
In such a case it will use AVX instruction for all functions including the one
"targetted" for sse3
while I would like to obtain an object file that I can run on multiple
platform.
This problem occurs only when builtins are used: standard c code is correctly
emitted accordingly to the target provided that the minimal -m is used.

Is there any preprocessor flag to "activate" all intrinsics and builtins in
x86intrin.h?

-----------------------------
example

#include <x86intrin.h>

float  __attribute__ ((__target__ ("sse3"))) sum3(float const * __restrict__ x,
float const * __restrict__ y, float const * __restrict__ z) {
  __m128 sum = _mm_setzero_ps();
  for (int i=0; i!=1024; i+=4)
    sum  += _mm_add_ps(_mm_loadu_ps(z+i),
                       _mm_mul_ps(_mm_loadu_ps(x+i),_mm_loadu_ps(y+i)) );
    sum = _mm_hadd_ps(sum,sum);
    sum = _mm_hadd_ps(sum,sum);
  float ret;
  _mm_store_ss(&ret,sum);
  return ret;
}

float  __attribute__ ((__target__ ("avx"))) sumv(float const * __restrict__ x,
float const * __restrict__ y, float const * __restrict__ z) {
  __m256 sum = _mm256_setzero_ps();
  for (int i=0; i!=1024; i+=8)
    sum  += _mm256_add_ps(_mm256_loadu_ps(z+i),
                       _mm256_mul_ps(_mm256_loadu_ps(x+i),_mm256_loadu_ps(y+i))
);
    sum = _mm256_hadd_ps(sum,sum);
    sum = _mm256_hadd_ps(sum,sum);
    sum = _mm256_hadd_ps(sum,sum);
  float ret[8];
  _mm256_store_ps(ret,sum);
  return ret[0];
}


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

end of thread, other threads:[~2021-08-05 22:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-25 14:00 [Bug middle-end/47895] New: usage of __attribute__ ((__target__ ("xyz"))) with buitins vincenzo.innocente at cern dot ch
2011-02-25 15:40 ` [Bug middle-end/47895] " rguenth at gcc dot gnu.org
2011-02-26 11:09 ` vincenzo.innocente at cern dot ch
2021-08-05 22:12 ` pinskia at gcc dot gnu.org
2021-08-05 22:19 ` pinskia at gcc dot gnu.org

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).