RandomX optimizations
- Optimized soft AES code, up to +30% hashrate on CPU without AES support - Added prefetch for the first dataset access, up to +0.1% hashrate
This commit is contained in:
parent
a8c2e908a2
commit
d3f98ef7bc
5 changed files with 171 additions and 335 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright (c) 2018-2019, tevador <tevador@gmail.com>
|
||||
Copyright (c) 2019 SChernykh <https://github.com/SChernykh>
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
@ -31,16 +32,80 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <stdint.h>
|
||||
#include "crypto/randomx/intrin_portable.h"
|
||||
|
||||
rx_vec_i128 soft_aesenc(rx_vec_i128 in, rx_vec_i128 key);
|
||||
extern uint32_t lutEnc0[256];
|
||||
extern uint32_t lutEnc1[256];
|
||||
extern uint32_t lutEnc2[256];
|
||||
extern uint32_t lutEnc3[256];
|
||||
extern uint32_t lutDec0[256];
|
||||
extern uint32_t lutDec1[256];
|
||||
extern uint32_t lutDec2[256];
|
||||
extern uint32_t lutDec3[256];
|
||||
|
||||
rx_vec_i128 soft_aesdec(rx_vec_i128 in, rx_vec_i128 key);
|
||||
template<bool soft> rx_vec_i128 aesenc(rx_vec_i128 in, rx_vec_i128 key);
|
||||
template<bool soft> rx_vec_i128 aesdec(rx_vec_i128 in, rx_vec_i128 key);
|
||||
|
||||
template<bool soft>
|
||||
inline rx_vec_i128 aesenc(rx_vec_i128 in, rx_vec_i128 key) {
|
||||
return soft ? soft_aesenc(in, key) : rx_aesenc_vec_i128(in, key);
|
||||
template<>
|
||||
FORCE_INLINE rx_vec_i128 aesenc<true>(rx_vec_i128 in, rx_vec_i128 key) {
|
||||
volatile uint8_t s[16];
|
||||
memcpy((void*) s, &in, 16);
|
||||
|
||||
uint32_t s0 = lutEnc0[s[ 0]];
|
||||
uint32_t s1 = lutEnc0[s[ 4]];
|
||||
uint32_t s2 = lutEnc0[s[ 8]];
|
||||
uint32_t s3 = lutEnc0[s[12]];
|
||||
|
||||
s0 ^= lutEnc1[s[ 5]];
|
||||
s1 ^= lutEnc1[s[ 9]];
|
||||
s2 ^= lutEnc1[s[13]];
|
||||
s3 ^= lutEnc1[s[ 1]];
|
||||
|
||||
s0 ^= lutEnc2[s[10]];
|
||||
s1 ^= lutEnc2[s[14]];
|
||||
s2 ^= lutEnc2[s[ 2]];
|
||||
s3 ^= lutEnc2[s[ 6]];
|
||||
|
||||
s0 ^= lutEnc3[s[15]];
|
||||
s1 ^= lutEnc3[s[ 3]];
|
||||
s2 ^= lutEnc3[s[ 7]];
|
||||
s3 ^= lutEnc3[s[11]];
|
||||
|
||||
return rx_xor_vec_i128(rx_set_int_vec_i128(s3, s2, s1, s0), key);
|
||||
}
|
||||
|
||||
template<bool soft>
|
||||
inline rx_vec_i128 aesdec(rx_vec_i128 in, rx_vec_i128 key) {
|
||||
return soft ? soft_aesdec(in, key) : rx_aesdec_vec_i128(in, key);
|
||||
template<>
|
||||
FORCE_INLINE rx_vec_i128 aesdec<true>(rx_vec_i128 in, rx_vec_i128 key) {
|
||||
volatile uint8_t s[16];
|
||||
memcpy((void*) s, &in, 16);
|
||||
|
||||
uint32_t s0 = lutDec0[s[ 0]];
|
||||
uint32_t s1 = lutDec0[s[ 4]];
|
||||
uint32_t s2 = lutDec0[s[ 8]];
|
||||
uint32_t s3 = lutDec0[s[12]];
|
||||
|
||||
s0 ^= lutDec1[s[13]];
|
||||
s1 ^= lutDec1[s[ 1]];
|
||||
s2 ^= lutDec1[s[ 5]];
|
||||
s3 ^= lutDec1[s[ 9]];
|
||||
|
||||
s0 ^= lutDec2[s[10]];
|
||||
s1 ^= lutDec2[s[14]];
|
||||
s2 ^= lutDec2[s[ 2]];
|
||||
s3 ^= lutDec2[s[ 6]];
|
||||
|
||||
s0 ^= lutDec3[s[ 7]];
|
||||
s1 ^= lutDec3[s[11]];
|
||||
s2 ^= lutDec3[s[15]];
|
||||
s3 ^= lutDec3[s[ 3]];
|
||||
|
||||
return rx_xor_vec_i128(rx_set_int_vec_i128(s3, s2, s1, s0), key);
|
||||
}
|
||||
|
||||
template<>
|
||||
FORCE_INLINE rx_vec_i128 aesenc<false>(rx_vec_i128 in, rx_vec_i128 key) {
|
||||
return rx_aesenc_vec_i128(in, key);
|
||||
}
|
||||
|
||||
template<>
|
||||
FORCE_INLINE rx_vec_i128 aesdec<false>(rx_vec_i128 in, rx_vec_i128 key) {
|
||||
return rx_aesdec_vec_i128(in, key);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue