From: jsing Date: Fri, 17 Feb 2023 05:46:57 +0000 (+0000) Subject: Provide optimised versions of bn_addw() and bn_subw() for aarch64. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f4d370f79396aa7557c1503b9caf368c9240ef95;p=openbsd Provide optimised versions of bn_addw() and bn_subw() for aarch64. --- diff --git a/lib/libcrypto/bn/arch/aarch64/bn_arch.h b/lib/libcrypto/bn/arch/aarch64/bn_arch.h index cc456848c97..9d61bc9114b 100644 --- a/lib/libcrypto/bn/arch/aarch64/bn_arch.h +++ b/lib/libcrypto/bn/arch/aarch64/bn_arch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.h,v 1.4 2023/02/16 10:41:03 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.5 2023/02/17 05:46:57 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -23,6 +23,23 @@ #ifndef OPENSSL_NO_ASM #if defined(__GNUC__) + +#define HAVE_BN_ADDW + +static inline void +bn_addw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) +{ + BN_ULONG carry, r0; + + __asm__ ("adds %1, %2, %3; cset %0, cs" + : "=r"(carry), "=r"(r0) + : "r"(a), "r"(b) + : "cc"); + + *out_r1 = carry; + *out_r0 = r0; +} + #define HAVE_BN_MULW static inline void @@ -38,6 +55,23 @@ bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) *out_r1 = r1; *out_r0 = r0; } + +#define HAVE_BN_SUBW + +static inline void +bn_subw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_borrow, BN_ULONG *out_r0) +{ + BN_ULONG borrow, r0; + + __asm__ ("subs %1, %2, %3; cset %0, cc" + : "=r"(borrow), "=r"(r0) + : "r"(a), "r"(b) + : "cc"); + + *out_borrow = borrow; + *out_r0 = r0; +} + #endif /* __GNUC__ */ #endif