Skip to content

s_has_vpclmulqdq() is not checking correct bit to detect VPCLMULQDQ #1084

@pbadari

Description

@pbadari

Describe the bug

s_has_vpclmulqdq() is not checking the correct bit to detect VPCLMULQDQ.
According to the documentation it is bit 10. (code is checking bit 20).

Input Output
EAX=07H, ECX=0 ECX[bit 10] VPCLMULQDQ
EAX=07H, ECX=0 EBX[bit 16] AVX512F
EAX=07H, ECX=0 EBX[bit 31] AVX512VL

https://en.wikichip.org/wiki/x86/vpclmulqdq

Expected Behavior

s_has_vpclmulqdq() should return TRUE if the CPU supports it.

Current Behavior

s_has_vpclmulqdq() returns FALSE incorrectly.

Reproduction Steps

call s_has_vpclmulqdq() on any modern IA system.

Possible Solution

diff --git a/source/arch/intel/cpuid.c b/source/arch/intel/cpuid.c
index 44fdff0..465fccd 100644
--- a/source/arch/intel/cpuid.c
+++ b/source/arch/intel/cpuid.c
@@ -116,8 +116,8 @@ static bool s_has_bmi2(void) {
 static bool s_has_vpclmulqdq(void) {
     uint32_t abcd[4];
     /* Check VPCLMULQDQ:
-     * CPUID.(EAX=07H, ECX=0H):ECX.VPCLMULQDQ[bit 20]==1 */
-    uint32_t vpclmulqdq_mask = (1 << 20);
+     * CPUID.(EAX=07H, ECX=0H):ECX.VPCLMULQDQ[bit 10]==1 */
+    uint32_t vpclmulqdq_mask = (1 << 10);
     aws_run_cpuid(7, 0, abcd);
     if ((abcd[2] & vpclmulqdq_mask) != vpclmulqdq_mask) {
         return false;

Additional Information/Context

No response

aws-c-common version used

latest mainline branch

Compiler and version used

gcc version 11.4.1 20231218

Operating System and version

CentOS9

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.needs-reviewThis issue or pull request needs review from a core team member.p2This is a standard priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions