]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
lib: add support for Hygon Genuine CPUs in x86 acceleration
authorxinpeng.wang <wangxinpeng@uniontech.com>
Wed, 14 Jan 2026 05:19:46 +0000 (13:19 +0800)
committerxinpeng.wang <wangxinpeng@uniontech.com>
Wed, 14 Jan 2026 05:19:46 +0000 (13:19 +0800)
Hygon CPUs (HygonGenuine) share the same AES-NI and other crypto
instruction sets with AMD Zen architecture. However, they were previously
falling back to the generic software provider because the vendor check
only recognized Intel and AMD.

This fallback to the software provider (Nettle wrapper) could lead to
numerical issues or crashes (e.g., divide-by-zero) in certain
environments like Photoshop.

This patch:
1. Adds X86_CPU_VENDOR_HYGON to x86_cpu_vendor enum.
2. Updates check_x86_cpu_vendor() to recognize Hygon CPUs.
3. Enables hardware acceleration for Hygon CPUs.

Signed-off-by: xinpeng.wang <wangxinpeng@uniontech.com>
lib/accelerated/x86/x86-common.c

index 57144e9e0c4a32ca2e68734c14eae3defd3be2fc..aaa74782c6599ebf0394ef1fc9db7598681474bb 100644 (file)
@@ -779,6 +779,7 @@ enum x86_cpu_vendor {
        X86_CPU_VENDOR_OTHER,
        X86_CPU_VENDOR_INTEL,
        X86_CPU_VENDOR_AMD,
+       X86_CPU_VENDOR_HYGON,
 };
 
 static enum x86_cpu_vendor check_x86_cpu_vendor(void)
@@ -799,6 +800,11 @@ static enum x86_cpu_vendor check_x86_cpu_vendor(void)
                return X86_CPU_VENDOR_AMD;
        }
 
+       if (memcmp(&b, "Hygo", 4) == 0 && memcmp(&d, "nGen", 4) == 0 &&
+           memcmp(&c, "uine", 4) == 0) {
+               return X86_CPU_VENDOR_HYGON;
+       }
+
        return X86_CPU_VENDOR_OTHER;
 }