bn_subw() will be used more widely in an upcoming change.
-/* $OpenBSD: bn_arch.h,v 1.13 2023/02/16 11:13:05 jsing Exp $ */
+/* $OpenBSD: bn_arch.h,v 1.14 2024/03/26 06:09:25 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
#define HAVE_BN_WORD_CLZ
#if defined(__GNUC__)
+
#define HAVE_BN_DIV_REM_WORDS_INLINE
static inline void
*out_q = q;
*out_r = r;
}
-#endif /* __GNUC__ */
-#if defined(__GNUC__)
#define HAVE_BN_MULW
static inline void
*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__ (
+ "subq %3, %1 \n"
+ "setb %b0 \n"
+ "and $1, %0 \n"
+ : "=r"(borrow), "=r"(r0)
+ : "1"(a), "rm"(b)
+ : "cc");
+
+ *out_borrow = borrow;
+ *out_r0 = r0;
+}
+
#endif /* __GNUC__ */
#endif