-/* $OpenBSD: bn_arch.h,v 1.1 2023/01/20 10:04:33 jsing Exp $ */
+/* $OpenBSD: bn_arch.h,v 1.2 2023/01/31 05:53:49 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <openssl/bn.h>
+
#ifndef HEADER_BN_ARCH_H
#define HEADER_BN_ARCH_H
#ifndef OPENSSL_NO_ASM
+#if defined(__GNUC__)
+#define HAVE_BN_UMUL_HILO
+
+static inline void
+bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l)
+{
+ BN_ULONG h, l;
+
+ /* Unsigned multiplication using a umulh/mul pair. */
+ __asm__ ("umulh %0, %2, %3; mul %1, %2, %3"
+ : "=r"(h), "=r"(l)
+ : "r"(a), "r"(b));
+
+ *out_h = h;
+ *out_l = l;
+}
+#endif /* __GNUC__ */
+
#endif
#endif
-/* $OpenBSD: bn_arch.h,v 1.8 2023/01/28 16:33:34 jsing Exp $ */
+/* $OpenBSD: bn_arch.h,v 1.9 2023/01/31 05:53:49 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
}
#endif /* __GNUC__ */
+#if defined(__GNUC__)
+#define HAVE_BN_UMUL_HILO
+
+static inline void
+bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l)
+{
+ BN_ULONG h, l;
+
+ /*
+ * Unsigned multiplication of %rax, with the double word result being
+ * stored in %rdx:%rax.
+ */
+ __asm__ ("mulq %3"
+ : "=d"(h), "=a"(l)
+ : "a"(a), "rm"(b)
+ : "cc");
+
+ *out_h = h;
+ *out_l = l;
+}
+#endif /* __GNUC__ */
+
#endif
#endif
-/* $OpenBSD: bn_arch.h,v 1.7 2023/01/28 16:33:34 jsing Exp $ */
+/* $OpenBSD: bn_arch.h,v 1.8 2023/01/31 05:53:49 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
}
#endif /* __GNUC__ */
+#if defined(__GNUC__)
+#define HAVE_BN_UMUL_HILO
+
+static inline void
+bn_umul_hilo(BN_ULONG a, BN_ULONG b, BN_ULONG *out_h, BN_ULONG *out_l)
+{
+ BN_ULONG h, l;
+
+ /*
+ * Unsigned multiplication of %eax, with the double word result being
+ * stored in %edx:%eax.
+ */
+ __asm__ ("mull %3"
+ : "=d"(h), "=a"(l)
+ : "a"(a), "rm"(b)
+ : "cc");
+
+ *out_h = h;
+ *out_l = l;
+}
+#endif /* __GNUC__ */
+
#endif
#endif