Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Check if xsave is enabled by OS before calling xgetbv in XmmYmmStateSupport #8939

Merged
merged 2 commits into from
Jan 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/pal/src/arch/amd64/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ Return value:
extern "C" unsigned int XmmYmmStateSupport()
{
unsigned int eax;
__asm(" xgetbv\n" \
: "=a"(eax) /*output in eax*/\
: "c"(0) /*inputs - 0 in ecx*/\
: "eax", "edx" /* registers that are clobbered*/
__asm(" mov $1, %%eax\n" \
" cpuid\n" \
" xor %%eax, %%eax\n" \
" and $0x18000000, %%ecx\n" /* check for xsave feature set and that it is enabled by the OS */ \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit - if you do xor %%eax, %%eax right after the cpuid and at line 61 do jne end, you can get rid of the jmp and xor after xgetbv.

" cmp $0x18000000, %%ecx\n" \
" jne end\n" \
" xor %%ecx, %%ecx\n" \
" xgetbv\n" \
"end:\n" \
: "=a"(eax) /* output in eax */ \
: /* no inputs */ \
: "eax", "ebx", "ecx", "edx" /* registers that are clobbered */
);
// Check OS has enabled both XMM and YMM state support
return ((eax & 0x06) == 0x06) ? 1 : 0;
Expand Down