add the rest of riscv bitmapip-0.93 instructions
cover add the rest of riscv bitmapip-0.93 instructions
These patches fixed some issues about srow/sroiw/clzw instructions and add the rest of riscv bitmapip-0.93 instructions except fsri/fsriw & bext/bdep & bextw/bdepw for opcode coding or name conflict problems. The problems had been fixed in riscv bitmapip-1.0 version.
I have tested these bitmapip instructions, passed by compare the results that produced by qemu and spike.
Please review and give your opinion kindly :)
Eric Tang (10):
target/riscv: rvb: fixed an error about srow/sroiw instructions target/riscv: rvb: add carry-less multiply instructions target/riscv: rvb: add cmix/cmov instructions target/riscv: rvb: add generalized shuffle instructions target/riscv: rvb: add crossbar permutation instructions target/riscv: rvb: add bfp/bfpw instructions target/riscv: rvb: add CRC instructions
target/riscv: rvb: add bit-matrix instructions target/riscv: rvb: fixed an issue about clzw instruction target/riscv: rvb: add funnel shfit instructions
target/riscv/bitmanip_helper.c | 351 ++++++++++++++++++++++++ target/riscv/helper.h | 28 ++ target/riscv/insn32.decode | 36 +++ target/riscv/insn_trans/trans_rvb.c.inc | 215 ++++++++++++++- target/riscv/translate.c | 14 + 5 files changed, 641 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
RFC 1/10 target/riscv: rvb: fixed an error about srow/sroiw instructions
According to spec, these instructions ignore the upper 32 bit of their input and sign-extend their 32 bit output values. Fixed the output's error when their input values greater than 0xffffffff.
target/riscv/insn_trans/trans_rvb.c.inc +22 -2
@@ -484,12 +484,32 @@ static bool trans_sloiw(DisasContext *ctx, arg_sloiw *a) return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_slo); } +static void gen_srow(TCGv ret, TCGv arg1, TCGv arg2) +{ + TCGv_i32 t1 = tcg_temp_new_i32(); + TCGv_i32 t2 = tcg_temp_new_i32(); + + /* truncate to 32-bits */ + tcg_gen_trunc_tl_i32(t1, arg1); + tcg_gen_trunc_tl_i32(t2, arg2); + + tcg_gen_not_i32(t1, t1); + tcg_gen_shr_i32(t1, t1, t2); + tcg_gen_not_i32(t1, t1); + + /* sign-extend 64-bits */ + tcg_gen_ext_i32_tl(ret, t1); + + tcg_temp_free_i32(t1); + tcg_temp_free_i32(t2); +} + static bool trans_srow(DisasContext *ctx, arg_srow *a) { REQUIRE_64BIT(ctx); REQUIRE_EXT(ctx, RVB); ctx->w = true; - return gen_shift(ctx, a, EXT_ZERO, gen_sro); + return gen_shift(ctx, a, EXT_ZERO, gen_srow); } static bool trans_sroiw(DisasContext *ctx, arg_sroiw *a)
@@ -497,7 +517,7 @@ static bool trans_sroiw(DisasContext *ctx, arg_sroiw *a) REQUIRE_64BIT(ctx); REQUIRE_EXT(ctx, RVB); ctx->w = true; - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_sro); + return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_srow); } static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2)
Signature · 1 line
2.17.1
RFC 2/10 target/riscv: rvb: add carry-less multiply instructions
In reply to Eric Tangtarget/riscv/bitmanip_helper.c +35 -0
@@ -88,3 +88,38 @@ target_ulong HELPER(gorcw)(target_ulong rs1, target_ulong rs2) {return do_gorc (rs1, rs2,32 ); } + +#define DO_CLMULA (NAME ,NUM ,BODY ) \ +static target_ulong do_##NAME(target_ulong rs1, \ + target_ulong rs2, \ + int bits) \ +{ \ + target_ulong x = 0; \ + int i; \ + \ + for (i = NUM; i < bits; i++) { \ + if ((rs2 >> i) & 1) { \ + x ^= BODY; \ + } \ + } \ + return x; \ +} + +DO_CLMULA(clmul, 0, (rs1 << i)) +DO_CLMULA(clmulh, 1, (rs1 >> (bits - i))) +DO_CLMULA(clmulr, 0, (rs1 >> (bits - i - 1))) + +target_ulong HELPER (clmul )(target_ulong rs1,target_ulong rs2) +{ +return do_clmul (rs1, rs2,TARGET_LONG_BITS ); +} + +target_ulong HELPER (clmulh )(target_ulong rs1,target_ulong rs2) +{ +return do_clmulh (rs1, rs2,TARGET_LONG_BITS ); +} + +target_ulong HELPER (clmulr )(target_ulong rs1,target_ulong rs2) +{ +return do_clmulr (rs1, rs2,TARGET_LONG_BITS ); +}
target/riscv/helper.h +3 -0
@@ -63,6 +63,9 @@ DEF_HELPER_FLAGS_2(grev, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(grevw, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(gorc, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(gorcw, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(clmulh, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2 (clmulr,TCG_CALL_NO_RWG_SE , tl, tl, tl) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)
target/riscv/insn32.decode +3 -0
@@ -690,6 +690,9 @@ gorc 0010100 .......... 101 ..... 0110011 @r sh1add 0010000 .......... 010 ..... 0110011 @r sh2add 0010000 .......... 100 ..... 0110011 @r sh3add 0010000 .......... 110 ..... 0110011 @r +clmul 0000101 .......... 001 ..... 0110011 @r +clmulh 0000101 .......... 011 ..... 0110011 @r +clmulr 0000101 .......... 010 ..... 0110011 @r bseti 00101. ........... 001 ..... 0010011 @sh bclri 01001. ........... 001 ..... 0010011 @sh
target/riscv/insn_trans/trans_rvb.c.inc +11 -0
@@ -321,6 +321,17 @@ static bool trans_gorci(DisasContext *ctx, arg_gorci *a) return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_helper_gorc); } +#define GEN_TRANS_CLMUL(NAME) \ +static bool trans_##NAME(DisasContext *ctx, arg_##NAME * a) \ +{ \ + REQUIRE_EXT(ctx, RVB); \ + return gen_arith(ctx, a, EXT_NONE, gen_helper_##NAME); \ +} + +GEN_TRANS_CLMUL(clmul) +GEN_TRANS_CLMUL(clmulh) +GEN_TRANS_CLMUL(clmulr) + #define GEN_SHADD(SHAMT) \ static void gen_sh##SHAMT##add(TCGv ret, TCGv arg1, TCGv arg2) \ { \
Signature · 1 line
2.17.1
RFC 3/10 target/riscv: rvb: add cmix/cmov instructions
In reply to Eric Tangtarget/riscv/insn32.decode +4 -0
@@ -43,6 +43,7 @@ &r rd rs1 rs2 &r2 rd rs1 &r2_s rs1 rs2 +&r4 rd rs1 rs2 rs3 &s imm rs1 rs2 &u imm rd &shift shamt rs1 rd
@@ -82,6 +83,7 @@ @r_wdvm ..... wd:1 vm:1 ..... ..... ... ..... ....... &rwdvm %rs2 %rs1 %rd @r2_zimm . zimm:11 ..... ... ..... ....... %rs1 %rd @r2_s ....... ..... ..... ... ..... ....... %rs2 %rs1 +@r4 ..... .. ..... ..... ... ..... ....... &r4 %rs3 %rs2 %rs1 %rd @hfence_gvma ....... ..... ..... ... ..... ....... %rs2 %rs1 @hfence_vvma ....... ..... ..... ... ..... ....... %rs2 %rs1
@@ -693,6 +695,8 @@ sh3add 0010000 .......... 110 ..... 0110011 @r clmul 0000101 .......... 001 ..... 0110011 @r clmulh 0000101 .......... 011 ..... 0110011 @r clmulr 0000101 .......... 010 ..... 0110011 @r +cmix .....11 .......... 001 ..... 0110011 @r4 +cmov .....11 .......... 101 ..... 0110011 @r4 bseti 00101. ........... 001 ..... 0010011 @sh bclri 01001. ........... 001 ..... 0010011 @sh
target/riscv/insn_trans/trans_rvb.c.inc +26 -0
@@ -332,6 +332,32 @@ GEN_TRANS_CLMUL(clmul) GEN_TRANS_CLMUL(clmulh) GEN_TRANS_CLMUL(clmulr) +static void gen_cmix(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3) +{ + tcg_gen_and_tl(arg1, arg1, arg2); + tcg_gen_not_tl(arg2, arg2); + tcg_gen_and_tl(arg3, arg3, arg2); + tcg_gen_or_tl(ret, arg1, arg3); +} + +static void gen_cmov(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3) +{ + TCGv zero = tcg_const_tl(0); + tcg_gen_movcond_tl(TCG_COND_NE, ret, arg2, zero, arg1, arg3); +} + +static bool trans_cmix(DisasContext *ctx, arg_cmix *a) +{ + REQUIRE_EXT(ctx, RVB); + return gen_quat(ctx, a, EXT_NONE, gen_cmix); +} + +static bool trans_cmov(DisasContext *ctx, arg_cmov *a) +{ + REQUIRE_EXT(ctx, RVB); + return gen_quat(ctx, a, EXT_NONE, gen_cmov); +} + #define GEN_SHADD(SHAMT) \ static void gen_sh##SHAMT##add(TCGv ret, TCGv arg1, TCGv arg2) \ { \
target/riscv/translate.c +14 -0
@@ -395,6 +395,20 @@ static bool gen_arith(DisasContext *ctx, arg_r *a, DisasExtend ext,return true; } +static bool gen_quat (DisasContext *ctx,arg_r4 *a,DisasExtend ext, +void (*func)(TCGv ,TCGv ,TCGv ,TCGv )) +{ +TCGv dest =dest_gpr (ctx, a->rd); +TCGv src1 =get_gpr (ctx, a->rs1, ext); +TCGv src2 =get_gpr (ctx, a->rs2, ext); +TCGv src3 =get_gpr (ctx, a->rs3, ext); + +func (dest, src1, src2, src3); + +gen_set_gpr (ctx, a->rd, dest); +return true; +} +static bool gen_shift_imm_fn (DisasContext *ctx,arg_shift *a,DisasExtend ext,void (*func)(TCGv ,TCGv ,target_long )) {
Signature · 1 line
2.17.1
RFC 4/10 target/riscv: rvb: add generalized shuffle instructions
In reply to Eric Tangtarget/riscv/bitmanip_helper.c +82 -0
@@ -123,3 +123,85 @@ target_ulong HELPER(clmulr)(target_ulong rs1, target_ulong rs2) {return do_clmulr (rs1, rs2,TARGET_LONG_BITS ); } + +static target_ulong shuffle_stage (target_ulong src, +uint64_t maskl, +uint64_t maskr, +int n) +{ +target_ulong x = src & ~(maskl | maskr); + x |= ((src << n) & maskl) | ((src >> n) & maskr); +return x; +} + +static target_ulong do_shfl (target_ulong rs1, +target_ulong rs2, +int bits) +{ +target_ulong x = rs1; +int shamt = rs2 & ((bits -1 ) >>1 ); + +if (shamt &16 ) { + x =shuffle_stage (x,0x0000ffff00000000LL ,0x00000000ffff0000LL ,16 ); + } +if (shamt &8 ) { + x =shuffle_stage (x,0x00ff000000ff0000LL ,0x0000ff000000ff00LL ,8 ); + } +if (shamt &4 ) { + x =shuffle_stage (x,0x0f000f000f000f00LL ,0x00f000f000f000f0LL ,4 ); + } +if (shamt &2 ) { + x =shuffle_stage (x,0x3030303030303030LL ,0x0c0c0c0c0c0c0c0cLL ,2 ); + } +if (shamt &1 ) { + x =shuffle_stage (x,0x4444444444444444LL ,0x2222222222222222LL ,1 ); + } + +return x; +} + +static target_ulong do_unshfl (target_ulong rs1, +target_ulong rs2, +int bits) +{ +target_ulong x = rs1; +int shamt = rs2 & ((bits -1 ) >>1 ); + +if (shamt &1 ) { + x =shuffle_stage (x,0x4444444444444444LL ,0x2222222222222222LL ,1 ); + } +if (shamt &2 ) { + x =shuffle_stage (x,0x3030303030303030LL ,0x0c0c0c0c0c0c0c0cLL ,2 ); + } +if (shamt &4 ) { + x =shuffle_stage (x,0x0f000f000f000f00LL ,0x00f000f000f000f0LL ,4 ); + } +if (shamt &8 ) { + x =shuffle_stage (x,0x00ff000000ff0000LL ,0x0000ff000000ff00LL ,8 ); + } +if (shamt &16 ) { + x =shuffle_stage (x,0x0000ffff00000000LL ,0x00000000ffff0000LL ,16 ); + } + +return x; +} + +target_ulong HELPER (shfl )(target_ulong rs1,target_ulong rs2) +{ +return do_shfl (rs1, rs2,TARGET_LONG_BITS ); +} + +target_ulong HELPER (unshfl )(target_ulong rs1,target_ulong rs2) +{ +return do_unshfl (rs1, rs2,TARGET_LONG_BITS ); +} + +target_ulong HELPER (shflw )(target_ulong rs1,target_ulong rs2) +{ +return do_shfl (rs1, rs2,32 ); +} + +target_ulong HELPER (unshflw )(target_ulong rs1,target_ulong rs2) +{ +return do_unshfl (rs1, rs2,32 ); +}
target/riscv/helper.h +4 -0
@@ -66,6 +66,10 @@ DEF_HELPER_FLAGS_2(gorcw, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(clmulh, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(shfl, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(unshfl, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(shflw, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2 (unshflw,TCG_CALL_NO_RWG_SE , tl, tl, tl) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)
target/riscv/insn32.decode +8 -0
@@ -23,6 +23,7 @@ %rd 7:5 %sh5 20:5 +%sh6 20:6 %sh7 20:7 %csr 20:12 %rm 12:3
@@ -63,6 +64,7 @@ @j .................... ..... ....... &j imm=%imm_j %rd @sh ...... ...... ..... ... ..... ....... &shift shamt=%sh7 %rs1 %rd +@sh6 ...... ...... ..... ... ..... ....... &shift shamt=%sh6 %rs1 %rd @csr ............ ..... ... ..... ....... %csr %rs1 %rd @atom_ld ..... aq:1 rl:1 ..... ........ ..... ....... &atomic rs2=0 %rs1 %rd
@@ -695,6 +697,8 @@ sh3add 0010000 .......... 110 ..... 0110011 @r clmul 0000101 .......... 001 ..... 0110011 @r clmulh 0000101 .......... 011 ..... 0110011 @r clmulr 0000101 .......... 010 ..... 0110011 @r +shfl 0000100 .......... 001 ..... 0110011 @r +unshfl 0000100 .......... 101 ..... 0110011 @r cmix .....11 .......... 001 ..... 0110011 @r4 cmov .....11 .......... 101 ..... 0110011 @r4
@@ -707,6 +711,8 @@ sroi 00100. ........... 101 ..... 0010011 @sh rori 01100. ........... 101 ..... 0010011 @sh grevi 01101. ........... 101 ..... 0010011 @sh gorci 00101. ........... 101 ..... 0010011 @sh +shfli 000010 ........... 001 ..... 0010011 @sh6 +unshfli 000010 ........... 101 ..... 0010011 @sh6 # *** RV64B Standard Extension (in addition to RV32B) *** clzw 0110000 00000 ..... 001 ..... 0011011 @r2
@@ -729,6 +735,8 @@ sh1add_uw 0010000 .......... 010 ..... 0111011 @r sh2add_uw 0010000 .......... 100 ..... 0111011 @r sh3add_uw 0010000 .......... 110 ..... 0111011 @r add_uw 0000100 .......... 000 ..... 0111011 @r +shflw 0000100 .......... 001 ..... 0111011 @r +unshflw 0000100 .......... 101 ..... 0111011 @r bsetiw 0010100 .......... 001 ..... 0011011 @sh5 bclriw 0100100 .......... 001 ..... 0011011 @sh5
target/riscv/insn_trans/trans_rvb.c.inc +46 -0
55 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC 5/10 target/riscv: rvb: add crossbar permutation instructions
In reply to Eric Tangtarget/riscv/bitmanip_helper.c +40 -0
@@ -205,3 +205,43 @@ target_ulong HELPER(unshflw)(target_ulong rs1, target_ulong rs2) {return do_unshfl (rs1, rs2,32 ); } + +static target_ulong do_xperm (target_ulong rs1, +target_ulong rs2, +int sz_log2, +int bits) +{ +target_ulong pos =0 ; +target_ulong r =0 ; +target_ulong sz =1LL << sz_log2; +target_ulong mask = (1LL << sz) -1 ; +int i; +for (i =0 ; i < bits; i += sz) { + pos = ((rs2 >> i) & mask) << sz_log2; +if (pos < bits) { + r |= ((rs1 >> pos) & mask) << i; + } + } + +return r; +} + +target_ulong HELPER (xperm_n )(target_ulong rs1,target_ulong rs2) +{ +return do_xperm (rs1, rs2,2 ,TARGET_LONG_BITS ); +} + +target_ulong HELPER (xperm_b )(target_ulong rs1,target_ulong rs2) +{ +return do_xperm (rs1, rs2,3 ,TARGET_LONG_BITS ); +} + +target_ulong HELPER (xperm_h )(target_ulong rs1,target_ulong rs2) +{ +return do_xperm (rs1, rs2,4 ,TARGET_LONG_BITS ); +} + +target_ulong HELPER (xperm_w )(target_ulong rs1,target_ulong rs2) +{ +return do_xperm (rs1, rs2,5 ,TARGET_LONG_BITS ); +}
target/riscv/helper.h +4 -0
@@ -70,6 +70,10 @@ DEF_HELPER_FLAGS_2(shfl, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(unshfl, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(shflw, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(unshflw, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(xperm_n, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(xperm_b, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(xperm_h, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2 (xperm_w,TCG_CALL_NO_RWG_SE , tl, tl, tl) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)
target/riscv/insn32.decode +4 -0
@@ -699,6 +699,9 @@ clmulh 0000101 .......... 011 ..... 0110011 @r clmulr 0000101 .......... 010 ..... 0110011 @r shfl 0000100 .......... 001 ..... 0110011 @r unshfl 0000100 .......... 101 ..... 0110011 @r +xperm_n 0010100 .......... 010 ..... 0110011 @r +xperm_b 0010100 .......... 100 ..... 0110011 @r +xperm_h 0010100 .......... 110 ..... 0110011 @r cmix .....11 .......... 001 ..... 0110011 @r4 cmov .....11 .......... 101 ..... 0110011 @r4
@@ -737,6 +740,7 @@ sh3add_uw 0010000 .......... 110 ..... 0111011 @r add_uw 0000100 .......... 000 ..... 0111011 @r shflw 0000100 .......... 001 ..... 0111011 @r unshflw 0000100 .......... 101 ..... 0111011 @r +xperm_w 0010100 .......... 000 ..... 0110011 @r bsetiw 0010100 .......... 001 ..... 0011011 @sh5 bclriw 0100100 .......... 001 ..... 0011011 @sh5
target/riscv/insn_trans/trans_rvb.c.inc +26 -0
@@ -351,6 +351,24 @@ static bool trans_unshfli(DisasContext *ctx, arg_unshfli *a) return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_helper_unshfl); } +static bool trans_xperm_n(DisasContext *ctx, arg_xperm_n *a) +{ + REQUIRE_EXT(ctx, RVB); + return gen_arith(ctx, a, EXT_NONE, gen_helper_xperm_n); +} + +static bool trans_xperm_b(DisasContext *ctx, arg_xperm_b *a) +{ + REQUIRE_EXT(ctx, RVB); + return gen_arith(ctx, a, EXT_NONE, gen_helper_xperm_b); +} + +static bool trans_xperm_h(DisasContext *ctx, arg_xperm_h *a) +{ + REQUIRE_EXT(ctx, RVB); + return gen_arith(ctx, a, EXT_NONE, gen_helper_xperm_h); +} + #define GEN_TRANS_CLMUL(NAME) \ static bool trans_##NAME(DisasContext *ctx, arg_##NAME * a) \ { \
@@ -749,3 +767,11 @@ static bool trans_unshflw(DisasContext *ctx, arg_unshflw *a) ctx->w = true; return gen_arith(ctx, a, EXT_ZERO, gen_helper_unshflw); } + +static bool trans_xperm_w(DisasContext *ctx, arg_xperm_w *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_EXT(ctx, RVB); + ctx->w = true; + return gen_arith(ctx, a, EXT_NONE, gen_helper_xperm_w); +}
Signature · 1 line
2.17.1
RFC 6/10 target/riscv: rvb: add bfp/bfpw instructions
In reply to Eric Tangtarget/riscv/bitmanip_helper.c +27 -0
@@ -245,3 +245,30 @@ target_ulong HELPER(xperm_w)(target_ulong rs1, target_ulong rs2) {return do_xperm (rs1, rs2,5 ,TARGET_LONG_BITS ); } + +static target_ulong do_bfp (target_ulong rs1, +target_ulong rs2, +int bits) +{ +target_ulong cfg = rs2 >> (bits /2 ); +if ((cfg >>30 ) ==2 ) { + cfg = cfg >>16 ; + } +int len = (cfg >>8 ) & ((bits /2 ) -1 ); +int off = cfg & (bits -1 ); + len = len ? len : (bits /2 ); +target_ulong mask = ~(~(target_ulong )0 << len) << off; +target_ulong data = rs2 << off; + +return (data & mask) | (rs1 & ~mask); +} + +target_ulong HELPER (bfp )(target_ulong rs1,target_ulong rs2) +{ +return do_bfp (rs1, rs2,TARGET_LONG_BITS ); +} + +target_ulong HELPER (bfpw )(target_ulong rs1,target_ulong rs2) +{ +return do_bfp (rs1, rs2,32 ); +}
target/riscv/helper.h +2 -0
@@ -74,6 +74,8 @@ DEF_HELPER_FLAGS_2(xperm_n, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(xperm_b, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(xperm_h, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(xperm_w, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(bfp, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2 (bfpw,TCG_CALL_NO_RWG_SE , tl, tl, tl) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)
target/riscv/insn32.decode +2 -0
@@ -702,6 +702,7 @@ unshfl 0000100 .......... 101 ..... 0110011 @r xperm_n 0010100 .......... 010 ..... 0110011 @r xperm_b 0010100 .......... 100 ..... 0110011 @r xperm_h 0010100 .......... 110 ..... 0110011 @r +bfp 0100100 .......... 111 ..... 0110011 @r cmix .....11 .......... 001 ..... 0110011 @r4 cmov .....11 .......... 101 ..... 0110011 @r4
@@ -741,6 +742,7 @@ add_uw 0000100 .......... 000 ..... 0111011 @r shflw 0000100 .......... 001 ..... 0111011 @r unshflw 0000100 .......... 101 ..... 0111011 @r xperm_w 0010100 .......... 000 ..... 0110011 @r +bfpw 0100100 .......... 111 ..... 0111011 @r bsetiw 0010100 .......... 001 ..... 0011011 @sh5 bclriw 0100100 .......... 001 ..... 0011011 @sh5
target/riscv/insn_trans/trans_rvb.c.inc +14 -0
@@ -369,6 +369,12 @@ static bool trans_xperm_h(DisasContext *ctx, arg_xperm_h *a) return gen_arith(ctx, a, EXT_NONE, gen_helper_xperm_h); } +static bool trans_bfp(DisasContext *ctx, arg_bfp *a) +{ + REQUIRE_EXT(ctx, RVB); + return gen_arith(ctx, a, EXT_NONE, gen_helper_bfp); +} + #define GEN_TRANS_CLMUL(NAME) \ static bool trans_##NAME(DisasContext *ctx, arg_##NAME * a) \ { \
@@ -775,3 +781,11 @@ static bool trans_xperm_w(DisasContext *ctx, arg_xperm_w *a) ctx->w = true; return gen_arith(ctx, a, EXT_NONE, gen_helper_xperm_w); } + +static bool trans_bfpw(DisasContext *ctx, arg_bfpw *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_EXT(ctx, RVB); + ctx->w = true; + return gen_arith(ctx, a, EXT_NONE, gen_helper_bfpw); +}
Signature · 1 line
2.17.1
RFC 7/10 target/riscv: rvb: add CRC instructions
In reply to Eric Tangtarget/riscv/bitmanip_helper.c +55 -0
@@ -272,3 +272,58 @@ target_ulong HELPER(bfpw)(target_ulong rs1, target_ulong rs2) {return do_bfp (rs1, rs2,32 ); } + +#define DO_CRC (NAME ,VALUE ) \ +static target_ulong do_##NAME(target_ulong rs1, \ + int nbits) \ +{ \ + int i; \ + target_ulong x = rs1; \ + for (i = 0; i < nbits; i++) { \ + x = (x >> 1) ^ ((VALUE) & ~((x & 1) - 1)); \ + } \ + return x; \ +} + +DO_CRC(crc32, 0xEDB88320) +DO_CRC(crc32c, 0x82F63B78) + +target_ulong HELPER (crc32_b )(target_ulong rs1) +{ +return do_crc32 (rs1,8 ); +} + +target_ulong HELPER (crc32_h )(target_ulong rs1) +{ +return do_crc32 (rs1,16 ); +} + +target_ulong HELPER (crc32_w )(target_ulong rs1) +{ +return do_crc32 (rs1,32 ); +} + +target_ulong HELPER (crc32_d )(target_ulong rs1) +{ +return do_crc32 (rs1,64 ); +} + +target_ulong HELPER (crc32c_b )(target_ulong rs1) +{ +return do_crc32c (rs1,8 ); +} + +target_ulong HELPER (crc32c_h )(target_ulong rs1) +{ +return do_crc32c (rs1,16 ); +} + +target_ulong HELPER (crc32c_w )(target_ulong rs1) +{ +return do_crc32c (rs1,32 ); +} + +target_ulong HELPER (crc32c_d )(target_ulong rs1) +{ +return do_crc32c (rs1,64 ); +}
target/riscv/helper.h +8 -0
@@ -76,6 +76,14 @@ DEF_HELPER_FLAGS_2(xperm_h, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(xperm_w, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(bfp, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(bfpw, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_1(crc32_b, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1(crc32_h, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1(crc32_w, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1(crc32_d, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1(crc32c_b, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1(crc32c_h, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1(crc32c_w, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1 (crc32c_d,TCG_CALL_NO_RWG_SE , tl, tl) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)
target/riscv/insn32.decode +8 -0
@@ -670,6 +670,14 @@ ctz 011000 000001 ..... 001 ..... 0010011 @r2 cpop 011000 000010 ..... 001 ..... 0010011 @r2 sext_b 011000 000100 ..... 001 ..... 0010011 @r2 sext_h 011000 000101 ..... 001 ..... 0010011 @r2 +crc32_b 0110000 10000 ..... 001 ..... 0010011 @r2 +crc32_h 0110000 10001 ..... 001 ..... 0010011 @r2 +crc32_w 0110000 10010 ..... 001 ..... 0010011 @r2 +crc32_d 0110000 10011 ..... 001 ..... 0010011 @r2 +crc32c_b 0110000 11000 ..... 001 ..... 0010011 @r2 +crc32c_h 0110000 11001 ..... 001 ..... 0010011 @r2 +crc32c_w 0110000 11010 ..... 001 ..... 0010011 @r2 +crc32c_d 0110000 11011 ..... 001 ..... 0010011 @r2 andn 0100000 .......... 111 ..... 0110011 @r orn 0100000 .......... 110 ..... 0110011 @r
target/riscv/insn_trans/trans_rvb.c.inc +16 -0
@@ -386,6 +386,22 @@ GEN_TRANS_CLMUL(clmul) GEN_TRANS_CLMUL(clmulh) GEN_TRANS_CLMUL(clmulr) +#define GEN_TRANS_CRC(NAME) \ +static bool trans_##NAME(DisasContext *ctx, arg_##NAME * a) \ +{ \ + REQUIRE_EXT(ctx, RVB); \ + return gen_unary(ctx, a, EXT_NONE, gen_helper_##NAME); \ +} \ + +GEN_TRANS_CRC(crc32_b) +GEN_TRANS_CRC(crc32_h) +GEN_TRANS_CRC(crc32_w) +GEN_TRANS_CRC(crc32_d) +GEN_TRANS_CRC(crc32c_b) +GEN_TRANS_CRC(crc32c_h) +GEN_TRANS_CRC(crc32c_w) +GEN_TRANS_CRC(crc32c_d) + static void gen_cmix(TCGv ret, TCGv arg1, TCGv arg2, TCGv arg3) { tcg_gen_and_tl(arg1, arg1, arg2);
Signature · 1 line
2.17.1
RFC 8/10 target/riscv: rvb: add bit-matrix instructions
In reply to Eric Tangtarget/riscv/bitmanip_helper.c +75 -0
@@ -327,3 +327,78 @@ target_ulong HELPER(crc32c_d)(target_ulong rs1) {return do_crc32c (rs1,64 ); } + +static target_ulong do_bmatflip (target_ulong rs1, +int bits) +{ +target_ulong x = rs1; +for (int i =0 ; i <3 ; i++) { + x =do_shfl (x,31 , bits); + } +return x; +} + +static target_ulong do_bmatxor (target_ulong rs1, +target_ulong rs2, +int bits) +{ +int i; +uint8_t u[8 ]; +uint8_t v[8 ]; +uint64_t x =0 ; + +target_ulong rs2t =do_bmatflip (rs2, bits); + +for (i =0 ; i <8 ; i++) { + u[i] = rs1 >> (i *8 ); + v[i] = rs2t >> (i *8 ); + } + +for (int i =0 ; i <64 ; i++) { +if (__builtin_popcount (u[i /8 ] & v[i %8 ]) &1 ) { + x |=1LL << i; + } + } + +return x; +} + +static target_ulong do_bmator (target_ulong rs1, +target_ulong rs2, +int bits) +{ +int i; +uint8_t u[8 ]; +uint8_t v[8 ]; +uint64_t x =0 ; + +target_ulong rs2t =do_bmatflip (rs2, bits); + +for (i =0 ; i <8 ; i++) { + u[i] = rs1 >> (i *8 ); + v[i] = rs2t >> (i *8 ); + } + +for (int i =0 ; i <64 ; i++) { +if ((u[i /8 ] & v[i %8 ]) !=0 ) { + x |=1LL << i; + } + } + +return x; +} + +target_ulong HELPER (bmatflip )(target_ulong rs1) +{ +return do_bmatflip (rs1,TARGET_LONG_BITS ); +} + +target_ulong HELPER (bmatxor )(target_ulong rs1,target_ulong rs2) +{ +return do_bmatxor (rs1, rs2,TARGET_LONG_BITS ); +} + +target_ulong HELPER (bmator )(target_ulong rs1,target_ulong rs2) +{ +return do_bmator (rs1, rs2,TARGET_LONG_BITS ); +}
target/riscv/helper.h +3 -0
@@ -84,6 +84,9 @@ DEF_HELPER_FLAGS_1(crc32c_b, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_1(crc32c_h, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_1(crc32c_w, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_1(crc32c_d, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_2(bmatxor, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(bmator, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_1 (bmatflip,TCG_CALL_NO_RWG_SE , tl, tl) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)
target/riscv/insn32.decode +3 -0
@@ -730,6 +730,7 @@ unshfli 000010 ........... 101 ..... 0010011 @sh6 clzw 0110000 00000 ..... 001 ..... 0011011 @r2 ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 +bmatflip 0110000 00011 ..... 001 ..... 0010011 @r2 packw 0000100 .......... 100 ..... 0111011 @r packuw 0100100 .......... 100 ..... 0111011 @r
@@ -751,6 +752,8 @@ shflw 0000100 .......... 001 ..... 0111011 @r unshflw 0000100 .......... 101 ..... 0111011 @r xperm_w 0010100 .......... 000 ..... 0110011 @r bfpw 0100100 .......... 111 ..... 0111011 @r +bmator 0000100 .......... 011 ..... 0110011 @r +bmatxor 0100100 .......... 011 ..... 0110011 @r bsetiw 0010100 .......... 001 ..... 0011011 @sh5 bclriw 0100100 .......... 001 ..... 0011011 @sh5
target/riscv/insn_trans/trans_rvb.c.inc +21 -0
@@ -805,3 +805,24 @@ static bool trans_bfpw(DisasContext *ctx, arg_bfpw *a) ctx->w = true; return gen_arith(ctx, a, EXT_NONE, gen_helper_bfpw); } + +static bool trans_bmatflip(DisasContext *ctx, arg_bmatflip *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_EXT(ctx, RVB); + return gen_unary(ctx, a, EXT_NONE, gen_helper_bmatflip); +} + +static bool trans_bmatxor(DisasContext *ctx, arg_bmatxor *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_EXT(ctx, RVB); + return gen_arith(ctx, a, EXT_NONE, gen_helper_bmatxor); +} + +static bool trans_bmator(DisasContext *ctx, arg_bmator *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_EXT(ctx, RVB); + return gen_arith(ctx, a, EXT_NONE, gen_helper_bmator); +}
Signature · 1 line
2.17.1
RFC 9/10 target/riscv: rvb: fixed an issue about clzw instruction
In reply to Eric Tangtarget/riscv/insn_trans/trans_rvb.c.inc +2 -1
@@ -456,7 +456,7 @@ GEN_TRANS_SHADD(3) static void gen_clzw(TCGv ret, TCGv arg1) { - tcg_gen_clzi_tl(ret, ret, 64); + tcg_gen_clzi_tl(ret, arg1, 64); tcg_gen_subi_tl(ret, ret, 32); }
@@ -464,6 +464,7 @@ static bool trans_clzw(DisasContext *ctx, arg_clzw *a) { REQUIRE_64BIT(ctx); REQUIRE_EXT(ctx, RVB); + ctx->w = true; return gen_unary(ctx, a, EXT_ZERO, gen_clzw); }
Signature · 1 line
2.17.1
RFC 10/10 target/riscv: rvb: add funnel shfit instructions
In reply to Eric TangAdd funnel shfit instructions except fsri/fsriw for opcode ecoding reason.
target/riscv/bitmanip_helper.c +37 -0
@@ -124,6 +124,43 @@ target_ulong HELPER(clmulr)(target_ulong rs1, target_ulong rs2)return do_clmulr (rs1, rs2,TARGET_LONG_BITS ); } +static target_ulong do_fsl (target_ulong rs1, +target_ulong rs2, +target_ulong rs3, +int bits) +{ +int shamt = rs2 & ((2 * bits) -1 ); +target_ulong a = rs1, b = rs3; + +if (shamt >= bits) { + shamt -= bits; + a = rs3; + b = rs1; + } + +return shamt ? (a << shamt) | (b >> (bits - shamt)) : a; +} + +target_ulong HELPER (fsl )(target_ulong rs1,target_ulong rs2,target_ulong rs3) +{ +return do_fsl (rs1, rs2, rs3,TARGET_LONG_BITS ); +} + +target_ulong HELPER (fsr )(target_ulong rs1,target_ulong rs2,target_ulong rs3) +{ +return do_fsl (rs1, -rs2, rs3,TARGET_LONG_BITS ); +} + +target_ulong HELPER (fslw )(target_ulong rs1,target_ulong rs2,target_ulong rs3) +{ +return do_fsl (rs1, rs2, rs3,32 ); +} + +target_ulong HELPER (fsrw )(target_ulong rs1,target_ulong rs2,target_ulong rs3) +{ +return do_fsl (rs1, -rs2, rs3,32 ); +} + static target_ulong shuffle_stage(target_ulong src, uint64_t maskl, uint64_t maskr,
target/riscv/helper.h +4 -0
@@ -87,6 +87,10 @@ DEF_HELPER_FLAGS_1(crc32c_d, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_2(bmatxor, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(bmator, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_1(bmatflip, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_3(fsl, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) +DEF_HELPER_FLAGS_3(fsr, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) +DEF_HELPER_FLAGS_3(fslw, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) +DEF_HELPER_FLAGS_3 (fsrw,TCG_CALL_NO_RWG_SE , tl, tl, tl, tl) /* Special functions */DEF_HELPER_2 (csrr, tl, env, int)
target/riscv/insn32.decode +4 -0
@@ -713,6 +713,8 @@ xperm_h 0010100 .......... 110 ..... 0110011 @r bfp 0100100 .......... 111 ..... 0110011 @r cmix .....11 .......... 001 ..... 0110011 @r4 cmov .....11 .......... 101 ..... 0110011 @r4 +fsl .....10 .......... 001 ..... 0110011 @r4 +fsr .....10 .......... 101 ..... 0110011 @r4 bseti 00101. ........... 001 ..... 0010011 @sh bclri 01001. ........... 001 ..... 0010011 @sh
@@ -754,6 +756,8 @@ xperm_w 0010100 .......... 000 ..... 0110011 @r bfpw 0100100 .......... 111 ..... 0111011 @r bmator 0000100 .......... 011 ..... 0110011 @r bmatxor 0100100 .......... 011 ..... 0110011 @r +fslw .....10 .......... 001 ..... 0111011 @r4 +fsrw .....10 .......... 101 ..... 0111011 @r4 bsetiw 0010100 .......... 001 ..... 0011011 @sh5 bclriw 0100100 .......... 001 ..... 0011011 @sh5
target/riscv/insn_trans/trans_rvb.c.inc +28 -0
@@ -428,6 +428,18 @@ static bool trans_cmov(DisasContext *ctx, arg_cmov *a) return gen_quat(ctx, a, EXT_NONE, gen_cmov); } +static bool trans_fsl(DisasContext *ctx, arg_fsl *a) +{ + REQUIRE_EXT(ctx, RVB); + return gen_quat(ctx, a, EXT_NONE, gen_helper_fsl); +} + +static bool trans_fsr(DisasContext *ctx, arg_fsr *a) +{ + REQUIRE_EXT(ctx, RVB); + return gen_quat(ctx, a, EXT_NONE, gen_helper_fsr); +} + #define GEN_SHADD(SHAMT) \ static void gen_sh##SHAMT##add(TCGv ret, TCGv arg1, TCGv arg2) \ { \
@@ -827,3 +839,19 @@ static bool trans_bmator(DisasContext *ctx, arg_bmator *a) REQUIRE_EXT(ctx, RVB); return gen_arith(ctx, a, EXT_NONE, gen_helper_bmator); } + +static bool trans_fslw(DisasContext *ctx, arg_fslw *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_EXT(ctx, RVB); + ctx->w = true; + return gen_quat(ctx, a, EXT_ZERO, gen_helper_fslw); +} + +static bool trans_fsrw(DisasContext *ctx, arg_fsrw *a) +{ + REQUIRE_64BIT(ctx); + REQUIRE_EXT(ctx, RVB); + ctx->w = true; + return gen_quat(ctx, a, EXT_ZERO, gen_helper_fsrw); +}
Signature · 1 line
2.17.1
Quoted 10 lines · Eric Tang
These patches fixed some issues about srow/sroiw/clzw instructions and add the rest of riscv bitmapip-0.93 instructions except fsri/fsriw & bext/bdep & bextw/bdepw for opcode coding or name conflict problems. The problems had been fixed in riscv bitmapip-1.0 version.
I have tested these bitmapip instructions, passed by compare the results that produced by qemu and spike.
Please review and give your opinion kindly :)
Hey Eric,
Thanks for the patches!
Unfortunately there is already a series "target/riscv: Update QEmu for Zb[abcs] 1.0.0"
(https://www.mail-archive.com/[email protected]/msg839086.html)
that adds support for the v1.0.0 bit manip extension. That has been reviewed and queued to be merged.
If you have fixes or features that apply on top of that please send them though :)
Alistair
Quoted 24 lines
Eric Tang (10):
target/riscv: rvb: fixed an error about srow/sroiw instructions target/riscv: rvb: add carry-less multiply instructions target/riscv: rvb: add cmix/cmov instructions target/riscv: rvb: add generalized shuffle instructions target/riscv: rvb: add crossbar permutation instructions target/riscv: rvb: add bfp/bfpw instructions target/riscv: rvb: add CRC instructions
target/riscv: rvb: add bit-matrix instructions target/riscv: rvb: fixed an issue about clzw instruction target/riscv: rvb: add funnel shfit instructionstarget/riscv/bitmanip_helper.c | 351 ++++++++++++++++++++++++ target/riscv/helper.h | 28 ++ target/riscv/insn32.decode | 36 +++ target/riscv/insn_trans/trans_rvb.c.inc | 215 ++++++++++++++- target/riscv/translate.c | 14 + 5 files changed, 641 insertions(+), 3 deletions(-)--
2.17.1
Ok, thanks. ^ ^!
Quoted 53 lines · Alistair Francis <[email protected]> 于2021年9月24日周五 下午12:39写道:
Quoted 10 lines · Eric Tang
These patches fixed some issues about srow/sroiw/clzw instructions and add the rest of riscv bitmapip-0.93 instructions except fsri/fsriw & bext/bdep & bextw/bdepw for opcode coding or name conflict problems. The problems had been fixed in riscv bitmapip-1.0 version.
I have tested these bitmapip instructions, passed by compare the results that produced by qemu and spike.
Please review and give your opinion kindly :)
Hey Eric,
Thanks for the patches!
Unfortunately there is already a series "target/riscv: Update QEmu for Zb[abcs] 1.0.0"
(https://www.mail-archive.com/[email protected]/msg839086.html)
that adds support for the v1.0.0 bit manip extension. That has been reviewed and queued to be merged.If you have fixes or features that apply on top of that please send them though :)
Alistair
Quoted 24 lines
Eric Tang (10):
target/riscv: rvb: fixed an error about srow/sroiw instructions target/riscv: rvb: add carry-less multiply instructions target/riscv: rvb: add cmix/cmov instructions target/riscv: rvb: add generalized shuffle instructions target/riscv: rvb: add crossbar permutation instructions target/riscv: rvb: add bfp/bfpw instructions target/riscv: rvb: add CRC instructions
target/riscv: rvb: add bit-matrix instructions target/riscv: rvb: fixed an issue about clzw instruction target/riscv: rvb: add funnel shfit instructionstarget/riscv/bitmanip_helper.c | 351 ++++++++++++++++++++++++ target/riscv/helper.h | 28 ++ target/riscv/insn32.decode | 36 +++ target/riscv/insn_trans/trans_rvb.c.inc | 215 ++++++++++++++- target/riscv/translate.c | 14 + 5 files changed, 641 insertions(+), 3 deletions(-)--
2.17.1