public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Use BMI2 intrisic without enabling the BMI2 target for the whole translation unit
@ 2015-08-27  8:19 Ruben Laguna
  2015-08-27  8:32 ` Marc Glisse
  0 siblings, 1 reply; 3+ messages in thread
From: Ruben Laguna @ 2015-08-27  8:19 UTC (permalink / raw)
  To: gcc-help

In order for the _bzhi_u32 intrinsic to be defined when including
`x86intrinc.h` I need to compile with `-mbmi2` and that sprinkles other
BMI2 instructions all over (for bit shifting, <<).


I want to limit the BMI2 to my explicit usage of it via intrinsics because
I want to check at runtime if the BMI2 is available and dispatch to a
different function in each case (one compiled with BMI2 and explicit
intrinsics, and other without) using __attribute__((ifunc(xxx))).


I tried to manually #define __BMI2__ before including x86intrin.h and
declaring the function __attribute__((target("bmi2"))) for the function,
but that gives me a "undefined reference to _bzhi_u32".

So far the only thing that worked was to move the BMI2/BZHI function to a
separate .c file and compile that file with -mbmi2 or use #pragma GCC
target "bmi2" in that file. This alternative works but then this destroys
my ability to declare the function as static and inline.

Is there any better way to use the BZHI instruction in one static inline
function without letting gcc use BMI2 in the rest of the translation unit?

I never used inline assembly, is that the only option left?



-- 
/Rubén

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

* Re: Use BMI2 intrisic without enabling the BMI2 target for the whole translation unit
  2015-08-27  8:19 Use BMI2 intrisic without enabling the BMI2 target for the whole translation unit Ruben Laguna
@ 2015-08-27  8:32 ` Marc Glisse
  2015-08-28  8:41   ` Ruben Laguna
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Glisse @ 2015-08-27  8:32 UTC (permalink / raw)
  To: Ruben Laguna; +Cc: gcc-help

On Thu, 27 Aug 2015, Ruben Laguna wrote:

> In order for the _bzhi_u32 intrinsic to be defined when including
> `x86intrinc.h` I need to compile with `-mbmi2`

Try again with a more recent version of gcc?

-- 
Marc Glisse

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

* Re: Use BMI2 intrisic without enabling the BMI2 target for the whole translation unit
  2015-08-27  8:32 ` Marc Glisse
@ 2015-08-28  8:41   ` Ruben Laguna
  0 siblings, 0 replies; 3+ messages in thread
From: Ruben Laguna @ 2015-08-28  8:41 UTC (permalink / raw)
  To: gcc-help

Yes, that solved. the problem. I was using GCC 4.8 and I found in the
GCC 4.9 release notes that it was addressed in that version. I tried
with GCC 5.2 and it works just #include <x86intrin.h>  and declare the
function with __attribute__((target("bmi2"))).

Thanks!

On Thu, Aug 27, 2015 at 10:32 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Thu, 27 Aug 2015, Ruben Laguna wrote:
>
>> In order for the _bzhi_u32 intrinsic to be defined when including
>> `x86intrinc.h` I need to compile with `-mbmi2`
>
>
> Try again with a more recent version of gcc?
>
> --
> Marc Glisse



-- 
/Rubén

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

end of thread, other threads:[~2015-08-28  8:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-27  8:19 Use BMI2 intrisic without enabling the BMI2 target for the whole translation unit Ruben Laguna
2015-08-27  8:32 ` Marc Glisse
2015-08-28  8:41   ` Ruben Laguna

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