From: jsing Date: Sun, 9 Jul 2023 10:37:32 +0000 (+0000) Subject: Provide optimised bn_subw() for riscv64. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c6b817c5bbc1cc7268260d27e0db2999c4e52fdc;p=openbsd Provide optimised bn_subw() for riscv64. --- diff --git a/lib/libcrypto/bn/arch/riscv64/bn_arch.h b/lib/libcrypto/bn/arch/riscv64/bn_arch.h index a8c50eb06d2..e67de835cf1 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.6 2023/07/09 10:36:53 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.7 2023/07/09 10:37:32 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -63,6 +63,23 @@ bn_mulw(BN_ULONG a, BN_ULONG b, BN_ULONG *out_r1, BN_ULONG *out_r0) *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__ ( + "sub %[r0], %[a], %[b] \n" + "sltu %[borrow], %[a], %[r0] \n" + : [borrow]"=r"(borrow), [r0]"=&r"(r0) + : [a]"r"(a), [b]"r"(b)); + + *out_borrow = borrow; + *out_r0 = r0; +} + #endif /* __GNUC__ */ #endif