Provide optimised bn_subw() for riscv64.
authorjsing <jsing@openbsd.org>
Sun, 9 Jul 2023 10:37:32 +0000 (10:37 +0000)
committerjsing <jsing@openbsd.org>
Sun, 9 Jul 2023 10:37:32 +0000 (10:37 +0000)
lib/libcrypto/bn/arch/riscv64/bn_arch.h

index a8c50eb..e67de83 100644 (file)
@@ -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 <jsing@openbsd.org>
  *
@@ -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