Add BSWAP4/BSWAP8 routines for riscv64 with Zbb
authorHenry Brausen <henry.brausen@vrull.eu>
Fri, 28 Jan 2022 08:57:54 +0000 (01:57 -0700)
committerPauli <pauli@openssl.org>
Thu, 19 May 2022 06:32:49 +0000 (16:32 +1000)
These routines make use of the rev8 instruction in the Zbb extension
to accelerate byte-swapping when OpenSSL is built specifically for
a machine that supports Zbb.

Reviewed-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Signed-off-by: Henry Brausen <henry.brausen@vrull.eu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17640)

include/crypto/modes.h

index 87331557fc7ee2ade190040cd5aed35f83f10a47..f98b7056559a20481a618d8580e6b679ee266446 100644 (file)
@@ -74,6 +74,13 @@ typedef unsigned char u8;
                         asm ("rev %0,%1"                \
                         : "=r"(ret_) : "r"((u32)(x)));  \
                         ret_;                           })
+#  elif defined(__riscv_zbb) && __riscv_xlen == 64
+#   define BSWAP8(x) ({ u64 ret_=(x);                   \
+                        asm ("rev8 %0,%0"               \
+                        : "+r"(ret_));   ret_;          })
+#   define BSWAP4(x) ({ u32 ret_=(x);                   \
+                        asm ("rev8 %0,%0; srli %0,%0,32"\
+                        : "+r"(ret_));   ret_;          })
 #  endif
 # elif defined(_MSC_VER)
 #  if _MSC_VER>=1300