From: jsing Date: Tue, 31 Jan 2023 05:57:08 +0000 (+0000) Subject: Provide inline assembly bn_umul_hilo() for alpha/powerpc64/riscv64. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=872b6eb842235e22bfefc40415ca7a7e71e75d65;p=openbsd Provide inline assembly bn_umul_hilo() for alpha/powerpc64/riscv64. These should work, but are currently untested and disabled. ok tb@ --- diff --git a/lib/libcrypto/bn/arch/alpha/bn_arch.h b/lib/libcrypto/bn/arch/alpha/bn_arch.h index 136adf0e977..9bc00911ab0 100644 --- a/lib/libcrypto/bn/arch/alpha/bn_arch.h +++ b/lib/libcrypto/bn/arch/alpha/bn_arch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.h,v 1.1 2023/01/20 10:04:33 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:57:08 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -20,5 +20,25 @@ #ifndef OPENSSL_NO_ASM +#if 0 /* Needs testing and enabling. */ +#if defined(__GNUC__) +#define HAVE_BN_UMUL_HILO + +static inline void +bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) +{ + BN_ULONG h, l; + + /* Unsigned multiplication using a umulh/mulq pair. */ + __asm__ ("umulh %2, %3, %0; mulq %2, %3, %1" + : "=r"(h), "=r"(l) + : "r"(a), "r"(b)); + + *out_h = h; + *out_l = l; +} +#endif /* __GNUC__ */ +#endif + #endif #endif diff --git a/lib/libcrypto/bn/arch/powerpc64/bn_arch.h b/lib/libcrypto/bn/arch/powerpc64/bn_arch.h index 4d6571f9cb4..1b8bd61138e 100644 --- a/lib/libcrypto/bn/arch/powerpc64/bn_arch.h +++ b/lib/libcrypto/bn/arch/powerpc64/bn_arch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.h,v 1.1 2023/01/20 10:04:34 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:57:08 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -20,5 +20,25 @@ #ifndef OPENSSL_NO_ASM +#if 0 /* Needs testing and enabling. */ +#if defined(__GNUC__) +#define HAVE_BN_UMUL_HILO + +static inline void +bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) +{ + BN_ULONG h, l; + + /* Unsigned multiplication using a mulhdu/mul pair. */ + __asm__ ("mulhdu %0, %2, %3; mul %1, %2, %3" + : "=r"(h), "=r"(l) + : "r"(a), "r"(b)); + + *out_h = h; + *out_l = l; +} +#endif /* __GNUC__ */ +#endif + #endif #endif diff --git a/lib/libcrypto/bn/arch/riscv64/bn_arch.h b/lib/libcrypto/bn/arch/riscv64/bn_arch.h index 4d6571f9cb4..1b4267acc01 100644 --- a/lib/libcrypto/bn/arch/riscv64/bn_arch.h +++ b/lib/libcrypto/bn/arch/riscv64/bn_arch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.h,v 1.1 2023/01/20 10:04:34 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:57:08 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -20,5 +20,29 @@ #ifndef OPENSSL_NO_ASM +#if 0 /* Needs testing and enabling. */ +#if defined(__GNUC__) +#define HAVE_BN_UMUL_HILO + +static inline void +bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l) +{ + BN_ULONG h, l; + + /* + * Unsigned multiplication using a mulh/mul pair. Note that the order + * of these instructions is important, as they can potentially be fused + * into a single operation. + */ + __asm__ ("mulh %0, %2, %3; mul %1, %2, %3" + : "=r"(h), "=r"(l) + : "r"(a), "r"(b)); + + *out_h = h; + *out_l = l; +} +#endif /* __GNUC__ */ +#endif + #endif #endif