From: jsing Date: Sun, 28 May 2023 17:22:04 +0000 (+0000) Subject: Provide optimised bn_addw_addw()/bn_subw_subw() for aarch64. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a3ee04998d28a97321a9074e0ade20a7c0b1a826;p=openbsd Provide optimised bn_addw_addw()/bn_subw_subw() for aarch64. --- diff --git a/lib/libcrypto/bn/arch/aarch64/bn_arch.h b/lib/libcrypto/bn/arch/aarch64/bn_arch.h index 4e16597dc3e..1b9358e710a 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.7 2023/04/17 12:51:09 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.8 2023/05/28 17:22:04 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -42,6 +42,27 @@ bn_addw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) *out_r0 = r0; } +#define HAVE_BN_ADDW_ADDW + +static inline void +bn_addw_addw(BN_ULONG a, BN_ULONG b, BN_ULONG c, BN_ULONG *out_r1, + BN_ULONG *out_r0) +{ + BN_ULONG carry, r0; + + __asm__ ( + "adds %[r0], %[a], %[b] \n" + "cset %[carry], cs \n" + "adds %[r0], %[r0], %[c] \n" + "cinc %[carry], %[carry], cs \n" + : [carry]"=&r"(carry), [r0]"=&r"(r0) + : [a]"r"(a), [b]"r"(b), [c]"r"(c) + : "cc"); + + *out_r1 = carry; + *out_r0 = r0; +} + #define HAVE_BN_MULW static inline void @@ -78,6 +99,27 @@ bn_subw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_borrow, BN_ULONG *out_r0) *out_r0 = r0; } +#define HAVE_BN_SUBW_SUBW + +static inline void +bn_subw_subw(BN_ULONG a, BN_ULONG b, BN_ULONG c, BN_ULONG *out_borrow, + BN_ULONG *out_r0) +{ + BN_ULONG borrow, r0; + + __asm__ ( + "subs %[r0], %[a], %[b] \n" + "cset %[borrow], cc \n" + "subs %[r0], %[r0], %[c] \n" + "cinc %[borrow], %[borrow], cc \n" + : [borrow]"=&r"(borrow), [r0]"=&r"(r0) + : [a]"r"(a), [b]"r"(b), [c]"r"(c) + : "cc"); + + *out_borrow = borrow; + *out_r0 = r0; +} + #endif /* __GNUC__ */ #endif