From: Henry Brausen Date: Fri, 28 Jan 2022 08:57:54 +0000 (-0700) Subject: Add BSWAP4/BSWAP8 routines for riscv64 with Zbb X-Git-Tag: openssl-3.2.0-alpha1~2647 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4fd3fc379d76d9cd33ea6699268485606447737;p=thirdparty%2Fopenssl.git Add BSWAP4/BSWAP8 routines for riscv64 with Zbb 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 Signed-off-by: Henry Brausen Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/17640) --- diff --git a/include/crypto/modes.h b/include/crypto/modes.h index 87331557fc7..f98b7056559 100644 --- a/include/crypto/modes.h +++ b/include/crypto/modes.h @@ -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