From 75bb8d3034d8e40b76dfa1377325b829cc58a395 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sun, 28 May 2023 17:22:04 +0000 Subject: Provide optimised bn_addw_addw()/bn_subw_subw() for aarch64. --- src/lib/libcrypto/bn/arch/aarch64/bn_arch.h | 44 ++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h b/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h index 4e16597dc3..1b9358e710 100644 --- a/src/lib/libcrypto/bn/arch/aarch64/bn_arch.h +++ b/src/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 -- cgit v1.2.3-55-g6feb