https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85684

            Bug ID: 85684
           Summary: output of instrinsic _xgetbv is wrongly overwritten
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gregory.hainaut at gmail dot com
  Target Milestone: ---

Hello,

GCC8.0 adds the long long _xgetbv(unsigned int), however the output isn't taken
into account. xgetbv should return values in rdx:rax (edx:eax in 32 bits).

The following code snippet

#include <cstdio>
#include <x86intrin.h>

int main()
{
        if ((_xgetbv(0) & 6) == 6)
                printf("Yes\n");
        else
                printf("No\n");
        return 0;
}

will compile as (g++ -mavx2), xgetbv in O0 build
...
xgetbv
movq %rsi, %rax
andl $6, %eax
cmpq $6, %rax
sete %al
testb %al, %al
je .L2
...

Note: the full code is optimized in -O1 as only 2 instructions !
main:
  movl $0, %ecx
  xgetbv

Best regards

Reply via email to