Skip to content

Commit

Permalink
Bug 1623184 - Clear ECX prior to cpuid, fixing query for Extended Fea…
Browse files Browse the repository at this point in the history
…tures r=bbeurdouche

While trying to benchmark the recent HACL* AVX2 code, I noticed that it was not being called on two machines (that both support AVX2), instead using only the AVX version.

In order to query for Extended Features (cpuid with EAX=7), we also need to set ECX to 0: https://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-software-developer-vol-2a-manual.html. The current code fails to do this, resulting in flags that show no support.

Initially, I wrote a separate `freebl_cpuid_ex` function that accepted a value for ECX as a separate input argument. However, some definitions of `freebl_cpuid` already zero ECX, so making this consistent is the simplest way to get the desired behavior.

With this patch, the two test machines (MacOS and Linux x64) correctly use the AVX2 ChaCha20Poly1305 code.

Differential Revision: https://phabricator.services.mozilla.com/D67235

--HG--
extra : moz-landing-system : lando
  • Loading branch information
Kevin Jacobs committed Mar 18, 2020
1 parent ba93119 commit ccfefef
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/freebl/mpi/mpcpucache.c
Expand Up @@ -39,7 +39,8 @@ freebl_cpuid(unsigned long op, unsigned long *eax,
unsigned long *ebx, unsigned long *ecx,
unsigned long *edx)
{
__asm__("cpuid\n\t"
__asm__("xor %%ecx, %%ecx\n\t"
"cpuid\n\t"
: "=a"(*eax),
"=b"(*ebx),
"=c"(*ecx),
Expand Down

0 comments on commit ccfefef

Please sign in to comment.