diff options
author | Mamone Tarsha <maamoun.tk@googlemail.com> | 2021-07-22 13:08:58 +0300 |
---|---|---|
committer | Mamone Tarsha <maamoun.tk@googlemail.com> | 2021-07-22 13:08:58 +0300 |
commit | b8054a1d0ad507812da9ba946a70d81100086252 (patch) | |
tree | 19f1b444050ebcbba9660e82e0f44c0f8ec69a13 /fat-s390x.c | |
parent | 422219fed26561363afee2639182854fe2021415 (diff) | |
download | nettle-b8054a1d0ad507812da9ba946a70d81100086252.tar.gz |
[S390x] Optimize memxor3 using vector facility with fat support
Diffstat (limited to 'fat-s390x.c')
-rw-r--r-- | fat-s390x.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/fat-s390x.c b/fat-s390x.c index 927cf837..12918cf8 100644 --- a/fat-s390x.c +++ b/fat-s390x.c @@ -49,6 +49,7 @@ #include "nettle-types.h" +#include "memxor.h" #include "aes.h" #include "gcm.h" #include "gcm-internal.h" @@ -67,6 +68,7 @@ #endif /* Facility bits */ +#define FAC_VF 129 /* vector facility */ #define FAC_MSA 17 /* message-security assist */ #define FAC_MSA_X4 77 /* message-security-assist extension 4 */ @@ -78,6 +80,7 @@ struct s390x_features { + int have_vector_facility; int have_km_aes128; int have_km_aes192; int have_km_aes256; @@ -94,6 +97,7 @@ void _nettle_kimd_status(uint64_t *status); static void get_s390x_features (struct s390x_features *features) { + features->have_vector_facility = 0; features->have_km_aes128 = 0; features->have_km_aes192 = 0; features->have_km_aes256 = 0; @@ -106,7 +110,9 @@ get_s390x_features (struct s390x_features *features) const char *sep = strchr (s, ','); size_t length = sep ? (size_t) (sep - s) : strlen(s); - if (MATCH (s, length, "msa_x1", 6)) + if (MATCH (s, length, "vf", 2)) + features->have_vector_facility = 1; + else if (MATCH (s, length, "msa_x1", 6)) { features->have_km_aes128 = 1; } @@ -132,6 +138,9 @@ get_s390x_features (struct s390x_features *features) uint64_t facilities[FACILITY_DOUBLEWORDS_MAX] = {0}; _nettle_stfle(facilities, FACILITY_DOUBLEWORDS_MAX); + if (facilities[FACILITY_INDEX(FAC_VF)] & FACILITY_BIT(FAC_VF)) + features->have_vector_facility = 1; + if (facilities[FACILITY_INDEX(FAC_MSA)] & FACILITY_BIT(FAC_MSA)) { uint64_t query_status[2] = {0}; @@ -156,6 +165,11 @@ get_s390x_features (struct s390x_features *features) } } +/* MEMXOR3 */ +DECLARE_FAT_FUNC(nettle_memxor3, memxor3_func) +DECLARE_FAT_FUNC_VAR(memxor3, memxor3_func, c) +DECLARE_FAT_FUNC_VAR(memxor3, memxor3_func, s390x) + /* AES128 */ DECLARE_FAT_FUNC(nettle_aes128_set_encrypt_key, aes128_set_key_func) DECLARE_FAT_FUNC_VAR(aes128_set_encrypt_key, aes128_set_key_func, c) @@ -227,6 +241,18 @@ fat_init (void) get_s390x_features (&features); verbose = getenv (ENV_VERBOSE) != NULL; + /* MEMXOR3 */ + if (features.have_vector_facility) + { + if (verbose) + fprintf (stderr, "libnettle: enabling vectorized memxor3.\n"); + nettle_memxor3_vec = _nettle_memxor3_s390x; + } + else + { + nettle_memxor3_vec = _nettle_memxor3_c; + } + /* AES128 */ if (features.have_km_aes128) { @@ -302,6 +328,11 @@ fat_init (void) } } +/* MEMXOR3 */ +DEFINE_FAT_FUNC(nettle_memxor3, void *, + (void *dst_in, const void *a_in, const void *b_in, size_t n), + (dst_in, a_in, b_in, n)) + /* AES128 */ DEFINE_FAT_FUNC(nettle_aes128_set_encrypt_key, void, (struct aes128_ctx *ctx, const uint8_t *key), |