target/arm: Split helper_crypto_sm3tt

Rather than passing an opcode to a helper, fully decode the
operation at translate time. Use clear_tail_16 to zap the
balance of the SVE register with the AdvSIMD write.

Backports commit 43fa36c96c24349145497adc1b451f9caf74e344 from qemu
This commit is contained in:
Richard Henderson 2020-06-14 23:22:41 -04:00 committed by Lioncash
parent 5ca8caf656
commit 1d95dd1c89
19 changed files with 93 additions and 51 deletions

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_aarch64
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_aarch64
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_aarch64
#define helper_crypto_sm3tt helper_crypto_sm3tt_aarch64
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_aarch64
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_aarch64
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_aarch64
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_aarch64
#define helper_crypto_sm4e helper_crypto_sm4e_aarch64
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_aarch64
#define helper_dc_zva helper_dc_zva_aarch64

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_aarch64eb
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_aarch64eb
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_aarch64eb
#define helper_crypto_sm3tt helper_crypto_sm3tt_aarch64eb
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_aarch64eb
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_aarch64eb
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_aarch64eb
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_aarch64eb
#define helper_crypto_sm4e helper_crypto_sm4e_aarch64eb
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_aarch64eb
#define helper_dc_zva helper_dc_zva_aarch64eb

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_arm
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_arm
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_arm
#define helper_crypto_sm3tt helper_crypto_sm3tt_arm
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_arm
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_arm
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_arm
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_arm
#define helper_crypto_sm4e helper_crypto_sm4e_arm
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_arm
#define helper_dc_zva helper_dc_zva_arm

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_armeb
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_armeb
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_armeb
#define helper_crypto_sm3tt helper_crypto_sm3tt_armeb
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_armeb
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_armeb
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_armeb
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_armeb
#define helper_crypto_sm4e helper_crypto_sm4e_armeb
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_armeb
#define helper_dc_zva helper_dc_zva_armeb

View file

@ -1101,7 +1101,10 @@ symbols = (
'helper_crypto_sha512su1',
'helper_crypto_sm3partw1',
'helper_crypto_sm3partw2',
'helper_crypto_sm3tt',
'helper_crypto_sm3tt1a',
'helper_crypto_sm3tt1b',
'helper_crypto_sm3tt2a',
'helper_crypto_sm3tt2b',
'helper_crypto_sm4e',
'helper_crypto_sm4ekey',
'helper_dc_zva',

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_m68k
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_m68k
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_m68k
#define helper_crypto_sm3tt helper_crypto_sm3tt_m68k
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_m68k
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_m68k
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_m68k
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_m68k
#define helper_crypto_sm4e helper_crypto_sm4e_m68k
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_m68k
#define helper_dc_zva helper_dc_zva_m68k

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_mips
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_mips
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_mips
#define helper_crypto_sm3tt helper_crypto_sm3tt_mips
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_mips
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_mips
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_mips
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_mips
#define helper_crypto_sm4e helper_crypto_sm4e_mips
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_mips
#define helper_dc_zva helper_dc_zva_mips

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_mips64
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_mips64
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_mips64
#define helper_crypto_sm3tt helper_crypto_sm3tt_mips64
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_mips64
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_mips64
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_mips64
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_mips64
#define helper_crypto_sm4e helper_crypto_sm4e_mips64
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_mips64
#define helper_dc_zva helper_dc_zva_mips64

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_mips64el
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_mips64el
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_mips64el
#define helper_crypto_sm3tt helper_crypto_sm3tt_mips64el
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_mips64el
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_mips64el
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_mips64el
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_mips64el
#define helper_crypto_sm4e helper_crypto_sm4e_mips64el
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_mips64el
#define helper_dc_zva helper_dc_zva_mips64el

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_mipsel
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_mipsel
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_mipsel
#define helper_crypto_sm3tt helper_crypto_sm3tt_mipsel
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_mipsel
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_mipsel
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_mipsel
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_mipsel
#define helper_crypto_sm4e helper_crypto_sm4e_mipsel
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_mipsel
#define helper_dc_zva helper_dc_zva_mipsel

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_powerpc
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_powerpc
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_powerpc
#define helper_crypto_sm3tt helper_crypto_sm3tt_powerpc
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_powerpc
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_powerpc
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_powerpc
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_powerpc
#define helper_crypto_sm4e helper_crypto_sm4e_powerpc
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_powerpc
#define helper_dc_zva helper_dc_zva_powerpc

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_riscv32
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_riscv32
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_riscv32
#define helper_crypto_sm3tt helper_crypto_sm3tt_riscv32
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_riscv32
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_riscv32
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_riscv32
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_riscv32
#define helper_crypto_sm4e helper_crypto_sm4e_riscv32
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_riscv32
#define helper_dc_zva helper_dc_zva_riscv32

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_riscv64
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_riscv64
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_riscv64
#define helper_crypto_sm3tt helper_crypto_sm3tt_riscv64
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_riscv64
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_riscv64
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_riscv64
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_riscv64
#define helper_crypto_sm4e helper_crypto_sm4e_riscv64
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_riscv64
#define helper_dc_zva helper_dc_zva_riscv64

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_sparc
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_sparc
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_sparc
#define helper_crypto_sm3tt helper_crypto_sm3tt_sparc
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_sparc
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_sparc
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_sparc
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_sparc
#define helper_crypto_sm4e helper_crypto_sm4e_sparc
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_sparc
#define helper_dc_zva helper_dc_zva_sparc

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_sparc64
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_sparc64
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_sparc64
#define helper_crypto_sm3tt helper_crypto_sm3tt_sparc64
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_sparc64
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_sparc64
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_sparc64
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_sparc64
#define helper_crypto_sm4e helper_crypto_sm4e_sparc64
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_sparc64
#define helper_dc_zva helper_dc_zva_sparc64

View file

@ -681,26 +681,16 @@ void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm, uint32_t desc)
clear_tail_16(vd, desc);
}
void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2,
uint32_t opcode)
static inline void
crypto_sm3tt(uint64_t *rd, uint64_t *rn, uint64_t *rm,
uint32_t desc, uint32_t opcode)
{
uint64_t *rd = vd;
uint64_t *rn = vn;
uint64_t *rm = vm;
union CRYPTO_STATE d;
union CRYPTO_STATE n;
union CRYPTO_STATE m;
union CRYPTO_STATE d = { .l = { rd[0], rd[1] } };
union CRYPTO_STATE n = { .l = { rn[0], rn[1] } };
union CRYPTO_STATE m = { .l = { rm[0], rm[1] } };
uint32_t imm2 = simd_data(desc);
uint32_t t;
d.l[0] = rd[0];
d.l[1] = rd[1];
n.l[0] = rn[0];
n.l[1] = rn[1];
m.l[0] = rm[0];
m.l[1] = rm[1];
assert(imm2 < 4);
if (opcode == 0 || opcode == 2) {
@ -738,8 +728,21 @@ void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2,
rd[0] = d.l[0];
rd[1] = d.l[1];
clear_tail_16(rd, desc);
}
#define DO_SM3TT(NAME, OPCODE) \
void HELPER(NAME)(void *vd, void *vn, void *vm, uint32_t desc) \
{ crypto_sm3tt(vd, vn, vm, desc, OPCODE); }
DO_SM3TT(crypto_sm3tt1a, 0)
DO_SM3TT(crypto_sm3tt1b, 1)
DO_SM3TT(crypto_sm3tt2a, 2)
DO_SM3TT(crypto_sm3tt2b, 3)
#undef DO_SM3TT
static uint8_t const sm4_sbox[] = {
0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7,
0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05,

View file

@ -527,7 +527,10 @@ DEF_HELPER_FLAGS_3(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
DEF_HELPER_FLAGS_4(crypto_sha512su1, TCG_CALL_NO_RWG,
void, ptr, ptr, ptr, i32)
DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32)
DEF_HELPER_FLAGS_4(crypto_sm3tt1a, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
DEF_HELPER_FLAGS_4(crypto_sm3tt1b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
DEF_HELPER_FLAGS_4(crypto_sm3tt2a, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
DEF_HELPER_FLAGS_4(crypto_sm3tt2b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
DEF_HELPER_FLAGS_4(crypto_sm3partw1, TCG_CALL_NO_RWG,
void, ptr, ptr, ptr, i32)
DEF_HELPER_FLAGS_4(crypto_sm3partw2, TCG_CALL_NO_RWG,

View file

@ -14173,14 +14173,15 @@ static void disas_crypto_xar(DisasContext *s, uint32_t insn)
*/
static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn)
{
TCGContext *tcg_ctx = s->uc->tcg_ctx;
static gen_helper_gvec_3 * const fns[4] = {
gen_helper_crypto_sm3tt1a, gen_helper_crypto_sm3tt1b,
gen_helper_crypto_sm3tt2a, gen_helper_crypto_sm3tt2b,
};
int opcode = extract32(insn, 10, 2);
int imm2 = extract32(insn, 12, 2);
int rm = extract32(insn, 16, 5);
int rn = extract32(insn, 5, 5);
int rd = extract32(insn, 0, 5);
TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
TCGv_i32 tcg_imm2, tcg_opcode;
if (!dc_isar_feature(aa64_sm3, s)) {
unallocated_encoding(s);
@ -14191,20 +14192,7 @@ static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn)
return;
}
tcg_rd_ptr = vec_full_reg_ptr(s, rd);
tcg_rn_ptr = vec_full_reg_ptr(s, rn);
tcg_rm_ptr = vec_full_reg_ptr(s, rm);
tcg_imm2 = tcg_const_i32(tcg_ctx, imm2);
tcg_opcode = tcg_const_i32(tcg_ctx, opcode);
gen_helper_crypto_sm3tt(tcg_ctx, tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr, tcg_imm2,
tcg_opcode);
tcg_temp_free_ptr(tcg_ctx, tcg_rd_ptr);
tcg_temp_free_ptr(tcg_ctx, tcg_rn_ptr);
tcg_temp_free_ptr(tcg_ctx, tcg_rm_ptr);
tcg_temp_free_i32(tcg_ctx, tcg_imm2);
tcg_temp_free_i32(tcg_ctx, tcg_opcode);
gen_gvec_op3_ool(s, true, rd, rn, rm, imm2, fns[opcode]);
}
/* C3.6 Data processing - SIMD, inc Crypto

View file

@ -1095,7 +1095,10 @@
#define helper_crypto_sha512su1 helper_crypto_sha512su1_x86_64
#define helper_crypto_sm3partw1 helper_crypto_sm3partw1_x86_64
#define helper_crypto_sm3partw2 helper_crypto_sm3partw2_x86_64
#define helper_crypto_sm3tt helper_crypto_sm3tt_x86_64
#define helper_crypto_sm3tt1a helper_crypto_sm3tt1a_x86_64
#define helper_crypto_sm3tt1b helper_crypto_sm3tt1b_x86_64
#define helper_crypto_sm3tt2a helper_crypto_sm3tt2a_x86_64
#define helper_crypto_sm3tt2b helper_crypto_sm3tt2b_x86_64
#define helper_crypto_sm4e helper_crypto_sm4e_x86_64
#define helper_crypto_sm4ekey helper_crypto_sm4ekey_x86_64
#define helper_dc_zva helper_dc_zva_x86_64