Re: powerpc64: filling in a few more HWCAP flags

George Koehler <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
On Sun, 3 May 2026 09:42:33 -0400
Brad Smith <[email protected]> wrote:

> PPC_FEATURE2_ARCH_2_07
> 
> Noticed in FFmpeg for Power8 VSX code within libswscale and devel/orc
> and probably others.
> 
> PPC_FEATURE2_HAS_VEC_CRYPTO
> 
> OpenSSL, NSS, Nettle, and Botan

Thanks for looking for these flags.  I had a diff to add some flags,
but didn't commit it, because I forgot to finish checking it.

Some ports would do faster AES and SHA-2 if elf_aux_info(3) AT_HWCAP2
had the crypto flag.  Some ports will need a patch to start calling
elf_aux_info, but at least security/libgcrypt already calls it.  The
flag has 2 names,
  PPC_FEATURE2_HAS_VEC_CRYPTO
  PPC_FEATURE2_VEC_CRYPTO      /* no HAS_ */
Ports like the 2nd name, so my diff adds it.  (If we don't add it,
most ports will #ifndef it then #define it.)

https://www.kernel.org/doc/html/next/arch/powerpc/elf_hwcaps.html says
to set 2.06 but not 2.05.  My diff sets 2.06, 2.07, isel and crypto
for both POWER8 and POWER9.  I saw PPC_FEATURE2_ISEL in qemu.  An
example of isel in C is
  /* r = c < d ? a : b; */
  __asm ("cmpw %3, %4; isellt %0, %1, %2":
      "=r"(r): "r"(a), "r"(b), "r"(c), "r"(d): "cr0");

--gkoehler

Index: arch/powerpc/include/elf.h
===================================================================
RCS file: /cvs/src/sys/arch/powerpc/include/elf.h,v
diff -u -p -r1.3 elf.h
--- arch/powerpc/include/elf.h	19 Feb 2025 18:25:03 -0000	1.3
+++ arch/powerpc/include/elf.h	13 Jul 2026 00:32:09 -0000
@@ -54,6 +54,7 @@ extern unsigned long hwcap2;
 #define	PPC_FEATURE2_ISEL	0x08000000
 #define	PPC_FEATURE2_TAR	0x04000000
 #define	PPC_FEATURE2_HAS_VEC_CRYPTO	0x02000000
+#define	PPC_FEATURE2_VEC_CRYPTO	0x02000000
 #define	PPC_FEATURE2_HTM_NOSC	0x01000000
 #define	PPC_FEATURE2_ARCH_3_00	0x00800000
 #define	PPC_FEATURE2_HAS_IEEE128	0x00400000
Index: arch/powerpc64/include/elf.h
===================================================================
RCS file: /cvs/src/sys/arch/powerpc64/include/elf.h,v
diff -u -p -r1.3 elf.h
--- arch/powerpc64/include/elf.h	19 Feb 2025 18:25:03 -0000	1.3
+++ arch/powerpc64/include/elf.h	13 Jul 2026 00:32:09 -0000
@@ -54,6 +54,7 @@ extern unsigned long hwcap2;
 #define	PPC_FEATURE2_ISEL	0x08000000
 #define	PPC_FEATURE2_TAR	0x04000000
 #define	PPC_FEATURE2_HAS_VEC_CRYPTO	0x02000000
+#define	PPC_FEATURE2_VEC_CRYPTO	0x02000000
 #define	PPC_FEATURE2_HTM_NOSC	0x01000000
 #define	PPC_FEATURE2_ARCH_3_00	0x00800000
 #define	PPC_FEATURE2_HAS_IEEE128	0x00400000
Index: arch/powerpc64/powerpc64/cpu.c
===================================================================
RCS file: /cvs/src/sys/arch/powerpc64/powerpc64/cpu.c,v
diff -u -p -r1.30 cpu.c
--- arch/powerpc64/powerpc64/cpu.c	28 Nov 2024 18:54:36 -0000	1.30
+++ arch/powerpc64/powerpc64/cpu.c	13 Jul 2026 00:32:09 -0000
@@ -224,9 +224,11 @@ cpu_init_features(void)
 {
 	uint32_t pvr = mfpvr();
 
-	hwcap = PPC_FEATURE_32 | PPC_FEATURE_64 | PPC_FEATURE_HAS_FPU |
-	    PPC_FEATURE_HAS_MMU | PPC_FEATURE_HAS_ALTIVEC |
-	    PPC_FEATURE_HAS_VSX;
+	hwcap = PPC_FEATURE_32 | PPC_FEATURE_64 | PPC_FEATURE_HAS_ALTIVEC |
+	    PPC_FEATURE_HAS_FPU | PPC_FEATURE_HAS_MMU |
+	    PPC_FEATURE_ARCH_2_06 | PPC_FEATURE_HAS_VSX;
+	hwcap2 = PPC_FEATURE2_ARCH_2_07 | PPC_FEATURE2_ISEL |
+	    PPC_FEATURE2_VEC_CRYPTO;
 
 	switch (CPU_VERSION(pvr)) {
 	case CPU_IBMPOWER9:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.