Skip to content

Commit

Permalink
cpu-features: Fix the AVX2 detection
Browse files Browse the repository at this point in the history
We were looking for the XSAVE bits in the wrong place.

Co-authored-by: Stefano Moioli <[email protected]>
  • Loading branch information
oleavr and smx-smx committed Nov 15, 2023
1 parent 04f7fd7 commit c4aa189
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions gum/gum.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2022 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2008-2023 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2023 Stefano Moioli <[email protected]>
*
* Licence: wxWindows Library Licence, Version 3.1
Expand Down Expand Up @@ -729,15 +729,14 @@ gum_do_query_cpu_features (void)
GumCpuFeatures features = 0;
guint a, b, c, d;

if (gum_get_cpuid (7, &a, &b, &c, &d))
if (gum_get_cpuid (1, &a, &b, &c, &d))
{
gboolean cpu_has_avx2, cpu_has_xsave, os_enabled_xsave;
gboolean cpu_supports_avx2, os_enabled_xsave;

cpu_has_avx2 = (b & (1 << 5)) != 0;
cpu_has_xsave = (c & (1 << 27)) != 0;
os_enabled_xsave = (c & (1 << 28)) != 0;
cpu_supports_avx2 = (c & (1 << 28)) != 0;
os_enabled_xsave = (c & (1 << 27)) != 0;

if (cpu_has_avx2 && cpu_has_xsave && os_enabled_xsave)
if (cpu_supports_avx2 && os_enabled_xsave)
features |= GUM_CPU_AVX2;
}

Expand Down

0 comments on commit c4aa189

Please sign in to comment.