tcg/riscv: Add support for vector
v2 cover tcg/riscv: Add support for vector
From: TANG Tiancheng <[email protected]>
This patch set introduces support for the RISC-V vector extension in TCG backend for RISC-V targets.
v2:
1. Remove [PATCH v1 03/15] and use a simpler approach with fixed constraints at initialization in the backend instead of modifying register allocation constraints in tcg.c. See details in 2.
2. Change the available vector registers, and the constraint registers which are defined in "tcg-target-con-str.h", to the minimum for all vector instructions; for TCG_TYPE_V256 (vlen=64, lmul=4, omitting v0), max 7 registers, and TCG_TYPE_V128/64 also use only 7.
3. Remove all inline markers; let the compiler decide.
4. Merge thread variables to use only prev_vtype.
5. Increase use of whole load/store instructions when bit width ≥ vlen.
6. Add vmv<nr>r.v to move registers when bit width ≥ vlen.
7. Configure vtype with separate operation length (vl) and element width (SEW); IRs not changing SEW should inherit SEW from the previous IR (e.g., load/store/move/dup/dupm, and/or/xor/not). Place set_vec_config in the switch.
8. Change vlen detection to include element width.
9. Use neg instead of sub in cmp_vec expand.
10. Complete all expansions in cmp_vec's expand function, not in tcg_out_vec_op.
11. Move some asserts into tcg_out_opc_*.
12. Remove the check for riscv_vlen >= 64 when enabling vector support.
13. Move not_vec to patch 7.
14. Change OPC_VRSUB_VX to OPC_VRSUB_VI
15. Move the vsetvli out of the SIGILL probe.
16. Move the initialization of the riscv_vlen to the cpuinfo_init.
v1:
https://lists.gnu.org/archive/html/qemu-riscv/2024-08/msg00205.html
Swung0x48 (1):
tcg/riscv: Add basic support for vector
TANG Tiancheng (13):
tcg/op-gvec: Fix iteration step in 32-bit operation
util: Add RISC-V vector extension probe in cpuinfo tcg/riscv: Add riscv vset{i}vli support tcg/riscv: Implement vector load/store tcg/riscv: Implement vector mov/dup{m/i} tcg/riscv: Add support for basic vector opcodes tcg/riscv: Implement vector cmp ops tcg/riscv: Implement vector neg ops tcg/riscv: Implement vector sat/mul ops tcg/riscv: Implement vector min/max ops tcg/riscv: Implement vector shs/v ops tcg/riscv: Implement vector roti/v/x shi ops tcg/riscv: Enable native vector support for TCG host
host/include/riscv/host/cpuinfo.h | 2 + tcg/riscv/tcg-target-con-set.h | 9 + tcg/riscv/tcg-target-con-str.h | 2 + tcg/riscv/tcg-target.c.inc | 961 ++++++++++++++++++++++++++++-- tcg/riscv/tcg-target.h | 80 ++- tcg/riscv/tcg-target.opc.h | 20 + tcg/tcg-op-gvec.c | 2 +- util/cpuinfo-riscv.c | 26 +- 8 files changed, 1032 insertions(+), 70 deletions(-) create mode 100644 tcg/riscv/tcg-target.opc.h
Signature · 1 line
2.43.0
PATCH v2 1/14 tcg/op-gvec: Fix iteration step in 32-bit operation
From: TANG Tiancheng <[email protected]>
The loop in the 32-bit case of the vector compare operation was incorrectly incrementing by 8 bytes per iteration instead of 4 bytes. This caused the function to process only half of the intended elements.
--- tcg/tcg-op-gvec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/tcg-op-gvec.c +1 -1
@@ -3939,7 +3939,7 @@ void tcg_gen_gvec_cmps(TCGCond cond, unsigned vece, uint32_t dofs,uint32_t i;tcg_gen_extrl_i64_i32 (t1, c); -for (i =0 ; i < oprsz; i +=8 ) { +for (i =0 ; i < oprsz; i +=4 ) {tcg_gen_ld_i32 (t0, tcg_env, aofs + i);tcg_gen_negsetcond_i32 (cond, t0, t0, t1);tcg_gen_st_i32 (t0, tcg_env, dofs + i);
Signature · 1 line
2.43.0
Re: [PATCH v2 01/14] tcg/op-gvec: Fix iteration step in 32-bit operation
Quoted 7 lines · LIU Zhiwei
From: TANG Tiancheng <[email protected]>
The loop in the 32-bit case of the vector compare operation was incorrectly incrementing by 8 bytes per iteration instead of 4 bytes. This caused the function to process only half of the intended elements.
Quoted 6 lines
Signed-off-by TANG Tiancheng <[email protected]>Fixes 9622c697d1 (tcg: Add gvec compare with immediate and scalar operand)Reviewed-by Liu Zhiwei <[email protected]>--- tcg/tcg-op-gvec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
Quoted 14 lines
tcg/tcg-op-gvec.c +1
-1@@ -3939,7 +3939,7 @@ void tcg_gen_gvec_cmps(TCGCond cond, unsigned vece, uint32_t dofs,uint32_t i;tcg_gen_extrl_i64_i32 (t1, c); -for (i =0 ; i < oprsz; i +=8 ) { +for (i =0 ; i < oprsz; i +=4 ) {tcg_gen_ld_i32 (t0, tcg_env, aofs + i);tcg_gen_negsetcond_i32 (cond, t0, t0, t1);tcg_gen_st_i32 (t0, tcg_env, dofs + i);
PATCH v2 2/14 util: Add RISC-V vector extension probe in cpuinfo
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
Add support for probing RISC-V vector extension availability in the backend. This information will be used when deciding whether to use vector instructions in code generation.
While the compiler doesn't support RISCV_HWPROBE_EXT_ZVE64X, we use RISCV_HWPROBE_IMA_V instead.
--- host/include/riscv/host/cpuinfo.h | 2 ++ util/cpuinfo-riscv.c | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-)
host/include/riscv/host/cpuinfo.h +2 -0
@@ -10,9 +10,11 @@#define CPUINFO_ZBA (1u << 1)#define CPUINFO_ZBB (1u << 2)#define CPUINFO_ZICOND (1u << 3) +#define CPUINFO_ZVE64X (1u << 4)/* Initialized with a constructor. */ extern unsigned cpuinfo; +extern unsigned riscv_vlen;/* * We cannot rely on constructor ordering, so other constructors must
util/cpuinfo-riscv.c +24 -2
@@ -12,6 +12,7 @@#endif unsigned cpuinfo; +unsigned riscv_vlen;static volatile sig_atomic_t got_sigill;static void sigill_handler (int signo,siginfo_t *si,void *data)
@@ -33,7 +34,7 @@ static void sigill_handler(int signo, siginfo_t *si, void *data)/* Called both as constructor and (possibly) via other constructors. */ unsigned __attribute__((constructor))cpuinfo_init (void ) { -unsigned left =CPUINFO_ZBA |CPUINFO_ZBB |CPUINFO_ZICOND ; +unsigned left =CPUINFO_ZBA |CPUINFO_ZBB |CPUINFO_ZICOND |CPUINFO_ZVE64X ;unsigned info = cpuinfo;if (info) {
@@ -49,6 +50,9 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)#endif #if defined(__riscv_arch_test) && defined(__riscv_zicond) info |=CPUINFO_ZICOND ; +#endif +#if defined(__riscv_arch_test) && defined(__riscv_zve64x) + info |=CPUINFO_ZVE64X ;#endif left &= ~info;
@@ -64,7 +68,8 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) && pair.key >= 0) { info |= pair.value &RISCV_HWPROBE_EXT_ZBA ?CPUINFO_ZBA :0 ; info |= pair.value &RISCV_HWPROBE_EXT_ZBB ?CPUINFO_ZBB :0 ; - left &= ~(CPUINFO_ZBA |CPUINFO_ZBB ); + info |= pair.value &RISCV_HWPROBE_IMA_V ?CPUINFO_ZVE64X :0 ; + left &= ~(CPUINFO_ZBA |CPUINFO_ZBB |CPUINFO_ZVE64X );#ifdef RISCV_HWPROBE_EXT_ZICOND info |= pair.value &RISCV_HWPROBE_EXT_ZICOND ?CPUINFO_ZICOND :0 ; left &= ~CPUINFO_ZICOND ;
@@ -112,6 +117,23 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)assert (left ==0 ); } +if (info &CPUINFO_ZVE64X ) { +/* +* Get vlen for Vector. +* VLMAX = LMUL * VLEN / SEW. +* The "vsetvli rd, x0, e64" means "LMUL = 1, SEW = 64, rd = VLMAX", +* so "vlen = VLMAX * 64". +*/ +unsigned long vlmax =0 ; + asm("vsetvli %0, x0, e64" :"=r" (vlmax)); +if (vlmax) { + riscv_vlen = vlmax *64 ; +assert (riscv_vlen >=64 && !(riscv_vlen & (riscv_vlen -1 ))); + }else { + info &= ~CPUINFO_ZVE64X ; + } + } + info |=CPUINFO_ALWAYS ; cpuinfo = info;return info;
Signature · 1 line
2.43.0
Re: [PATCH v2 02/14] util: Add RISC-V vector extension probe in cpuinfo
Quoted 1 line · LIU Zhiwei
+extern unsigned
riscv_vlen;
Do you really want to store vlen and not vlenb?
It seems that would simplify some of your computation in the tcg backend.
Quoted 23 lines
util/cpuinfo-riscv.c +5
-1@@ -49,6 +50,9 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)#endif #if defined(__riscv_arch_test) && defined(__riscv_zicond) info |=CPUINFO_ZICOND ; +#endif +#if defined(__riscv_arch_test) && defined(__riscv_zve64x) + info |=CPUINFO_ZVE64X ;#endif left &= ~info;@@ -64,7 +68,8 @@ unsigned __attribute__((constructor)) cpuinfo_init(void) && pair.key >= 0) { info |= pair.value &RISCV_HWPROBE_EXT_ZBA ?CPUINFO_ZBA :0 ; info |= pair.value &RISCV_HWPROBE_EXT_ZBB ?CPUINFO_ZBB :0 ; - left &= ~(CPUINFO_ZBA |CPUINFO_ZBB ); + info |= pair.value &RISCV_HWPROBE_IMA_V ?CPUINFO_ZVE64X :0 ; + left &= ~(CPUINFO_ZBA |CPUINFO_ZBB |CPUINFO_ZVE64X );#ifdef RISCV_HWPROBE_EXT_ZICOND info |= pair.value &RISCV_HWPROBE_EXT_ZICOND ?CPUINFO_ZICOND :0 ; left &= ~CPUINFO_ZICOND ;@@ -112,6 +117,23 @@ unsigned __attribute__((constructor)) cpuinfo_init(void)assert (left ==0 ); }
util/cpuinfo-riscv.c unsigned __attribute__((constructor)) cpuinfo_init(void) · line 128
Quoted 10 lines
util/cpuinfo-riscv.c +9
-0+if (info &CPUINFO_ZVE64X ) { +/* +* Get vlen for Vector. +* VLMAX = LMUL * VLEN / SEW. +* The "vsetvli rd, x0, e64" means "LMUL = 1, SEW = 64, rd = VLMAX", +* so "vlen = VLMAX * 64". +*/ +unsigned long vlmax =0 ; + asm("vsetvli %0, x0, e64" :"=r" (vlmax));
This doesn't compile, surely.
s/x0/zero/ is surely the minimum change, but this still won't work unless V is enabled at compile-time.
You need to use the .insn form, like we do for the Zba probe above:
.insn i 0x57, 7, %0, zero, 3 << 3
I have verified that RISCV_HWPROBE_IMA_V went into the linux kernel at the same time as vector support, so this probing is complete and sufficient.
r~
PATCH v2 3/14 tcg/riscv: Add basic support for vector
In reply to LIU ZhiweiFrom: Swung0x48 <[email protected]>
The RISC-V vector instruction set utilizes the LMUL field to group multiple registers, enabling variable-length vector registers. This implementation uses only the first register number of each group while reserving the other register numbers within the group.
In TCG, each VEC_IR can have 3 types (TCG_TYPE_V64/128/256), and the host runtime needs to adjust LMUL based on the type to use different register groups.
This presents challenges for TCG's register allocation. Currently, we avoid modifying the register allocation part of TCG and only expose the minimum number of vector registers.
For example, when the host vlen is 64 bits and type is TCG_TYPE_V256, with LMUL equal to 4, we use 4 vector registers as one register group. We can use a maximum of 8 register groups, but the V0 register number is reserved as a mask register, so we can effectively use at most 7 register groups. Moreover, when type is smaller than TCG_TYPE_V256, only 7 registers are forced to be used. This is because TCG cannot yet dynamically constrain registers with type; likewise, when the host vlen is 128 bits and TCG_TYPE_V256, we can use at most 15 registers.
There is not much pressure on vector register allocation in TCG now, so using 7 registers is feasible and will not have a major impact on code generation.
This patch:
1. Reserves vector register 0 for use as a mask register.
2. When using register groups, reserves the additional registers within each group.
--- tcg/riscv/tcg-target-con-str.h | 1 + tcg/riscv/tcg-target.c.inc | 131 +++++++++++++++++++++++++-------- tcg/riscv/tcg-target.h | 78 +++++++++++--------- tcg/riscv/tcg-target.opc.h | 12 +++ 4 files changed, 157 insertions(+), 65 deletions(-) create mode 100644 tcg/riscv/tcg-target.opc.h
tcg/riscv/tcg-target-con-str.h +1 -0
@@ -9,6 +9,7 @@* REGS(letter, register_mask) */ REGS('r', ALL_GENERAL_REGS) +REGS ('v' ,GET_VREG_SET (riscv_vlen))/* * Define constraint letters for constants:
tcg/riscv/tcg-target.c.inc +99 -32
173 lines not on this page · raw message
tcg/riscv/tcg-target.h +45 -33
93 lines not on this page · raw message
tcg/riscv/tcg-target.opc.h new file +12 -0
@@ -0,0 +1,12 @@ +/* +* Copyright (c) C-SKY Microsystems Co., Ltd. +* +* This work is licensed under the terms of the GNU GPL, version 2 or +* (at your option) any later version. +* +* See the COPYING file in the top-level directory for details. +* +* Target-specific opcodes for host vector expansion. These will be +* emitted by tcg_expand_vec_op. For those familiar with GCC internals, +* consider these to be UNSPEC with names. +*/
Signature · 1 line
2.43.0
Re: [PATCH v2 03/14] tcg/riscv: Add basic support for vector
Quoted 48 lines · LIU Zhiwei
From: Swung0x48 <[email protected]>
The RISC-V vector instruction set utilizes the LMUL field to group multiple registers, enabling variable-length vector registers. This implementation uses only the first register number of each group while reserving the other register numbers within the group.
In TCG, each
VEC_IRcan have 3 types (TCG_TYPE_V64/128/256), and the host runtime needs to adjust LMUL based on the type to use different register groups.This presents challenges for TCG's register allocation. Currently, we avoid modifying the register allocation part of TCG and only expose the minimum number of vector registers.
For example, when the host vlen is 64 bits and type is
TCG_TYPE_V256, with LMUL equal to 4, we use 4 vector registers as one register group. We can use a maximum of 8 register groups, but the V0 register number is reserved as a mask register, so we can effectively use at most 7 register groups. Moreover, when type is smaller thanTCG_TYPE_V256, only 7 registers are forced to be used. This is because TCG cannot yet dynamically constrain registers with type; likewise, when the host vlen is 128 bits andTCG_TYPE_V256, we can use at most 15 registers.There is not much pressure on vector register allocation in TCG now, so using 7 registers is feasible and will not have a major impact on code generation.
This patch:
1. Reserves vector register 0 for use as a mask register.
2. When using register groups, reserves the additional registers within each group.Signed-off-by TANG Tiancheng <[email protected]>Reviewed-by Liu Zhiwei <[email protected]>--- tcg/riscv/tcg-target-con-str.h | 1 + tcg/riscv/tcg-target.c.inc | 131 +++++++++++++++++++++++++-------- tcg/riscv/tcg-target.h | 78 +++++++++++--------- tcg/riscv/tcg-target.opc.h | 12 +++ 4 files changed, 157 insertions(+), 65 deletions(-)create mode 100644
tcg/riscv/tcg-target.opc.htcg/riscv/tcg-target-con-str.h +0
-0
tcg/riscv/tcg-target-con-str.h line 12
Quoted 4 lines
tcg/riscv/tcg-target-con-str.h +1
-0@@ -9,6 +9,7 @@* REGS(letter, register_mask) */ REGS('r', ALL_GENERAL_REGS) +REGS ('v' ,GET_VREG_SET (riscv_vlen))
Perhaps too complicated. Make this MAKE_64BIT_MASK(32, 32); everything else will be handled by tcg_target_available_regs[] and reserved_regs.
tcg/riscv/tcg-target-con-str.h static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot) · line 118
Quoted 7 lines
tcg/riscv/tcg-target-con-str.h +3
-0@@ -127,6 +113,12 @@ static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot)#define TCG_CT_CONST_J12 0x1000#define ALL_GENERAL_REGS MAKE_64BIT_MASK(0, 32) +#define ALL_VECTOR_REGS MAKE_64BIT_MASK(33, 31) +#define ALL_DVECTOR_REG_GROUPS 0x5555555400000000 +#define ALL_QVECTOR_REG_GROUPS 0x1111111000000000
V0 is still a vector register, even if it is reserved. I think you should include it in these masks.
tcg/riscv/tcg-target-con-str.h static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot) · line 121
Quoted 3 lines
tcg/riscv/tcg-target-con-str.h +3
-0+#define GET_VREG_SET (vlen) (vlen == 64 ? ALL_QVECTOR_REG_GROUPS : \ + (vlen == 128 ? ALL_DVECTOR_REG_GROUPS : \ + ALL_VECTOR_REGS))
I think you will not need this macro.
Quoted 5 lines
tcg/riscv/tcg-target-con-str.h +5
-0+/* +* RISC-V vector instruction emitters +*/ + +/* Vector registers uses the same 5 lower bits as GPR registers. */
tcg/riscv/tcg-target-con-str.h static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot)
Quoted 10 lines
tcg/riscv/tcg-target-con-str.h +10
-0+static void tcg_out_opc_reg_vec (TCGContext *s,RISCVInsn opc, +TCGReg d,TCGReg s1,TCGReg s2,bool vm) +{ +tcg_out32 (s,encode_r (opc, d, s1, s2) | (vm <<25 )); +} + +static void tcg_out_opc_reg_vec_i (TCGContext *s,RISCVInsn opc, +TCGReg rd,TCGArg imm,TCGReg vs2,bool vm) +{ +tcg_out32 (s,encode_r (opc, rd, (imm &0x1f ), vs2) | (vm <<25 ));
I think you want to create new encode_* functions, not abuse the integer ones.
Quoted 11 lines
tcg/riscv/tcg-target-con-str.h +11
-0+} + +/* vm=0 (vm = false) means vector masking ENABLED. */ +#define tcg_out_opc_vv (s, opc, vd, vs2, vs1, vm) \ + tcg_out_opc_reg_vec(s, opc, vd, vs1, vs2, vm); + +/* +* In RISC-V, vs2 is the first operand, while rs1/imm is the +* second operand. +*/ +#define tcg_out_opc_vx (s, opc, vd, vs2, rs1, vm) \
tcg/riscv/tcg-target-con-str.h
Quoted 10 lines
tcg/riscv/tcg-target-con-str.h +10
-0+tcg_out_opc_reg_vec (s, opc, vd, rs1, vs2, vm); + +#define tcg_out_opc_vi (s, opc, vd, vs2, imm, vm) \ + tcg_out_opc_reg_vec_i(s, opc, vd, imm, vs2, vm); + +/* +* Only unit-stride addressing implemented; may extend in future. +*/ +#define tcg_out_opc_ldst_vec (s, opc, vs3_vd, rs1, vm) \ + tcg_out_opc_reg_vec(s, opc, vs3_vd, rs1, 0, vm);
I don't understand the need for any of these #defines. Why are we not simply creating functions of the correct name?
tcg/riscv/tcg-target-con-str.h static void tcg_target_init(TCGContext *s) · line 2164
Quoted 6 lines
tcg/riscv/tcg-target-con-str.h +2
-0@@ -2101,6 +2160,13 @@ static void tcg_target_init(TCGContext *s) tcg_target_available_regs[TCG_TYPE_I32 ] =0xffffffff ; tcg_target_available_regs[TCG_TYPE_I64 ] =0xffffffff ; +if (cpuinfo &CPUINFO_ZVE64X ) { +TCGRegSet vector_regs =GET_VREG_SET (riscv_vlen);
This ought to be the only usage of GET_VREG_SET, so I think you should inline that code with a switch on riscv_vlen/vlenb.
r~
PATCH v2 4/14 tcg/riscv: Add riscv vset{i}vli support
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
In RISC-V, vector operations require initial configuration using the vset{i}vl{i} instruction.
This instruction:
1. Sets the vector length (vl) in bytes
2. Configures the vtype register, which includes:
SEW (Single Element Width)
LMUL (vector register group multiplier) Other vector operation parameters
This configuration is crucial for defining subsequent vector operation behavior. To optimize performance, the configuration process is managed dynamically:
1. Reconfiguration using vset{i}vl{i} is necessary when SEW or vector register group width changes.
2. The vset instruction can be omitted when configuration remains unchanged.
This optimization is only effective within a single TB. Each TB requires reconfiguration at its start, as the current state cannot be obtained from hardware.
--- tcg/riscv/tcg-target.c.inc | 104 +++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+)
tcg/riscv/tcg-target.c.inc +104 -0
@@ -119,6 +119,7 @@ static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot) #define GET_VREG_SET(vlen) (vlen == 64 ? ALL_QVECTOR_REG_GROUPS : \ (vlen == 128 ? ALL_DVECTOR_REG_GROUPS : \ ALL_VECTOR_REGS)) +#define riscv_vlenb (riscv_vlen / 8) #define sextreg sextract64
@@ -168,6 +169,18 @@ static bool tcg_target_const_match(int64_t val, int ct, * RISC-V Base ISA opcodes (IM) */ +#define V_OPIVV (0x0 << 12) +#define V_OPFVV (0x1 << 12) +#define V_OPMVV (0x2 << 12) +#define V_OPIVI (0x3 << 12) +#define V_OPIVX (0x4 << 12) +#define V_OPFVF (0x5 << 12) +#define V_OPMVX (0x6 << 12) +#define V_OPCFG (0x7 << 12) + +#define V_SUMOP (0x0 << 20) +#define V_LUMOP (0x0 << 20) + typedef enum { OPC_ADD = 0x33, OPC_ADDI = 0x13,
@@ -263,6 +276,11 @@ typedef enum { /* Zicond: integer conditional operations */ OPC_CZERO_EQZ = 0x0e005033, OPC_CZERO_NEZ = 0x0e007033, + + /* V: Vector extension 1.0 */ + OPC_VSETVLI = 0x57 | V_OPCFG, + OPC_VSETIVLI = 0xc0000057 | V_OPCFG, + OPC_VSETVL = 0x80000057 | V_OPCFG, } RISCVInsn; /*
@@ -355,6 +373,35 @@ static int32_t encode_uj(RISCVInsn opc, TCGReg rd, uint32_t imm) return opc | (rd & 0x1f) << 7 | encode_ujimm20(imm); } +typedef enum { + VTA_TU = 0, + VTA_TA, +} RISCVVta; + +typedef enum { + VMA_MU = 0, + VMA_MA, +} RISCVVma; + +typedef enum { + VLMUL_M1 = 0, /* LMUL=1 */ + VLMUL_M2, /* LMUL=2 */ + VLMUL_M4, /* LMUL=4 */ + VLMUL_M8, /* LMUL=8 */ + VLMUL_RESERVED, + VLMUL_MF8, /* LMUL=1/8 */ + VLMUL_MF4, /* LMUL=1/4 */ + VLMUL_MF2, /* LMUL=1/2 */ +} RISCVVlmul; +#define LMUL_MAX 8 + +static int32_t encode_vtypei(RISCVVta vta, RISCVVma vma, + unsigned vsew, RISCVVlmul vlmul) +{ + return (vma & 0x1) << 7 | (vta & 0x1) << 6 | (vsew & 0x7) << 3 | + (vlmul & 0x7); +} + /* * RISC-V instruction emitters */
@@ -484,6 +531,12 @@ static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, tcg_out32(s, encode_r(opc, rd, (imm & 0x1f), vs2) | (vm << 25)); } +static void tcg_out_opc_vec_config(TCGContext *s, RISCVInsn opc, + TCGReg rd, uint32_t avl, int32_t vtypei) +{ + tcg_out32(s, encode_i(opc, rd, avl, vtypei)); +} + /* vm=0 (vm = false) means vector masking ENABLED. */ #define tcg_out_opc_vv(s, opc, vd, vs2, vs1, vm) \ tcg_out_opc_reg_vec(s, opc, vd, vs1, vs2, vm);
@@ -498,12 +551,62 @@ static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, #define tcg_out_opc_vi(s, opc, vd, vs2, imm, vm) \ tcg_out_opc_reg_vec_i(s, opc, vd, imm, vs2, vm); +#define tcg_out_opc_vconfig(s, opc, rd, avl, vtypei) \ + tcg_out_opc_vec_config(s, opc, rd, avl, vtypei); + /* * Only unit-stride addressing implemented; may extend in future. */ #define tcg_out_opc_ldst_vec(s, opc, vs3_vd, rs1, vm) \ tcg_out_opc_reg_vec(s, opc, vs3_vd, rs1, 0, vm); +static void tcg_out_vsetvl(TCGContext *s, uint32_t avl, int vtypei) +{ + if (avl < 32) { + tcg_out_opc_vconfig(s, OPC_VSETIVLI, TCG_REG_ZERO, avl, vtypei); + } else { + tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_TMP0, TCG_REG_ZERO, avl); + tcg_out_opc_vconfig(s, OPC_VSETVLI, TCG_REG_ZERO, TCG_REG_TMP0, vtypei); + } +} + +/* + * TODO: If the vtype value is not supported by the implementation, + * then the vill bit is set in vtype, the remaining bits in + * vtype are set to zero, and the vl register is also set to zero + */ + +static __thread int prev_vtypei; + +#define get_vlmax(vsew) (riscv_vlen / (8 << vsew) * (LMUL_MAX)) +#define get_vec_type_bytes(type) (type >= TCG_TYPE_V64 ? \ + (8 << (type - TCG_TYPE_V64)) : 0) +#define calc_vlmul(oprsz) (ctzl(oprsz / riscv_vlenb)) + +static void tcg_target_set_vec_config(TCGContext *s, TCGType type, + unsigned vece) +{ + unsigned vsew, oprsz, avl; + int vtypei; + RISCVVlmul vlmul; + + vsew = vece; + oprsz = get_vec_type_bytes(type); + avl = oprsz / (1 << vece); + vlmul = oprsz > riscv_vlenb ? + calc_vlmul(oprsz) : VLMUL_M1; + vtypei = encode_vtypei(VTA_TA, VMA_MA, vsew, vlmul); + + tcg_debug_assert(avl <= get_vlmax(vsew)); + tcg_debug_assert(vlmul <= VLMUL_RESERVED); + tcg_debug_assert(vsew <= MO_64); + + if (vtypei != prev_vtypei) { + prev_vtypei = vtypei; + tcg_out_vsetvl(s, avl, vtypei); + } +} + /* * TCG intrinsics */
@@ -2152,6 +2255,7 @@ static void tcg_target_qemu_prologue(TCGContext *s) static void tcg_out_tb_start(TCGContext *s) { + prev_vtypei = -1; /* nothing to do */ }
Signature · 1 line
2.43.0
Re: [PATCH v2 04/14] tcg/riscv: Add riscv vset{i}vli support
Quoted 77 lines · LIU Zhiwei
From: TANG Tiancheng <[email protected]>
In RISC-V, vector operations require initial configuration using the vset{i}vl{i} instruction.
This instruction:
1. Sets the vector length (vl) in bytes
2. Configures the vtype register, which includes:
SEW (Single Element Width)
LMUL (vector register group multiplier) Other vector operation parametersThis configuration is crucial for defining subsequent vector operation behavior. To optimize performance, the configuration process is managed dynamically:
1. Reconfiguration using vset{i}vl{i} is necessary when SEW or vector register group width changes.
2. The vset instruction can be omitted when configuration remains unchanged.This optimization is only effective within a single TB. Each TB requires reconfiguration at its start, as the current state cannot be obtained from hardware.
Signed-off-by TANG Tiancheng <[email protected]>Signed-off-by Weiwei Li <[email protected]>Reviewed-by Liu Zhiwei <[email protected]>--- tcg/riscv/tcg-target.c.inc | 104 +++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+)tcg/riscv/tcg-target.c.inc +18
-0@@ -119,6 +119,7 @@ static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot) #define GET_VREG_SET(vlen) (vlen == 64 ? ALL_QVECTOR_REG_GROUPS : \ (vlen == 128 ? ALL_DVECTOR_REG_GROUPS : \ ALL_VECTOR_REGS)) +#define riscv_vlenb (riscv_vlen / 8) #define sextreg sextract64@@ -168,6 +169,18 @@ static bool tcg_target_const_match(int64_t val, int ct, * RISC-V Base ISA opcodes (IM) */ +#define V_OPIVV (0x0 << 12) +#define V_OPFVV (0x1 << 12) +#define V_OPMVV (0x2 << 12) +#define V_OPIVI (0x3 << 12) +#define V_OPIVX (0x4 << 12) +#define V_OPFVF (0x5 << 12) +#define V_OPMVX (0x6 << 12) +#define V_OPCFG (0x7 << 12) + +#define V_SUMOP (0x0 << 20) +#define V_LUMOP (0x0 << 20) + typedef enum { OPC_ADD = 0x33, OPC_ADDI = 0x13,@@ -263,6 +276,11 @@ typedef enum { /* Zicond: integer conditional operations */ OPC_CZERO_EQZ = 0x0e005033, OPC_CZERO_NEZ = 0x0e007033, + + /* V: Vector extension 1.0 */ + OPC_VSETVLI = 0x57 | V_OPCFG, + OPC_VSETIVLI = 0xc0000057 | V_OPCFG, + OPC_VSETVL = 0x80000057 | V_OPCFG, } RISCVInsn; /*@@ -355,6 +373,35 @@ static int32_t encode_uj(RISCVInsn opc, TCGReg rd, uint32_t imm) return opc | (rd & 0x1f) << 7 | encode_ujimm20(imm); }
tcg/riscv/tcg-target.c.inc static int32_t encode_uj(RISCVInsn opc, TCGReg rd, uint32_t imm) · line 384
Quoted 10 lines
tcg/riscv/tcg-target.c.inc +9
-0+typedef enum { + VTA_TU = 0, + VTA_TA, +} RISCVVta; + +typedef enum { + VMA_MU = 0, + VMA_MA, +} RISCVVma;
Do these really need enumerators, or would 'bool' be sufficient?
tcg/riscv/tcg-target.c.inc static int32_t encode_uj(RISCVInsn opc, TCGReg rd, uint32_t imm) · line 403
Quoted 6 lines
tcg/riscv/tcg-target.c.inc +6
-0+static int32_t encode_vtypei(RISCVVta vta, RISCVVma vma, + unsigned vsew, RISCVVlmul vlmul) +{ + return (vma & 0x1) << 7 | (vta & 0x1) << 6 | (vsew & 0x7) << 3 | + (vlmul & 0x7); +}
s/vtypei/vtype/g? vtype is only immediate in specific contexts, and you'll match the manual better if you talk about vtype the CSR rather than the vset*vli argument.
Assert values in range rather than masking.
Use MemOp vsew, since you're using MO_64, etc.
tcg/riscv/tcg-target.c.inc static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, · line 555
Quoted 6 lines
tcg/riscv/tcg-target.c.inc +2
-0@@ -498,12 +551,62 @@ static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, #define tcg_out_opc_vi(s, opc, vd, vs2, imm, vm) \ tcg_out_opc_reg_vec_i(s, opc, vd, imm, vs2, vm); +#define tcg_out_opc_vconfig(s, opc, rd, avl, vtypei) \ + tcg_out_opc_vec_config(s, opc, rd, avl, vtypei);
Why the extra define?
tcg/riscv/tcg-target.c.inc static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, · line 577
Quoted 6 lines
tcg/riscv/tcg-target.c.inc +6
-0+ +/* + * TODO: If the vtype value is not supported by the implementation, + * then the vill bit is set in vtype, the remaining bits in + * vtype are set to zero, and the vl register is also set to zero + */
Why is this a TODO?
Are you suggesting that we might need to probe *all* of the cases at startup?
tcg/riscv/tcg-target.c.inc static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, · line 579
Quoted 1 line
tcg/riscv/tcg-target.c.inc +1
-0+static __thread int prev_vtypei;
I think we should put this into TCGContext.
We don't currently have any host-specific values there, but there's no reason we can't have any.
tcg/riscv/tcg-target.c.inc static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, · line 581
Quoted 1 line
tcg/riscv/tcg-target.c.inc +1
-0+#define get_vlmax(vsew) (riscv_vlen / (8 << vsew) * (LMUL_MAX))
Given that we know that LMUL_MAX is 8, doesn't this cancel out?
tcg/riscv/tcg-target.c.inc static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, · line 583
Quoted 2 lines
tcg/riscv/tcg-target.c.inc +2
-0+#define get_vec_type_bytes(type) (type >= TCG_TYPE_V64 ? \ + (8 << (type - TCG_TYPE_V64)) : 0)
Again, assert not produce nonsense results. And this doesn't need hiding in a macro.
tcg/riscv/tcg-target.c.inc static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, · line 584
Quoted 1 line
tcg/riscv/tcg-target.c.inc +1
-0+#define calc_vlmul(oprsz) (ctzl(oprsz / riscv_vlenb))
I think it's clearer to do this inline, where we can see that oprsz > vlenb.
tcg/riscv/tcg-target.c.inc static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, · line 593
Quoted 9 lines
tcg/riscv/tcg-target.c.inc +9
-0+ +static void tcg_target_set_vec_config(TCGContext *s, TCGType type, + unsigned vece) +{ + unsigned vsew, oprsz, avl; + int vtypei; + RISCVVlmul vlmul; + + vsew = vece;
You can just name the argument vsew...
tcg/riscv/tcg-target.c.inc static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, · line 597
Quoted 4 lines
tcg/riscv/tcg-target.c.inc +4
-0+ oprsz = get_vec_type_bytes(type); + avl = oprsz / (1 << vece); + vlmul = oprsz > riscv_vlenb ? + calc_vlmul(oprsz) : VLMUL_M1;
I guess it is always the case that full register operations are preferred over fractional?
tcg/riscv/tcg-target.c.inc static void tcg_out_opc_reg_vec_i(TCGContext *s, RISCVInsn opc, · line 602
Quoted 5 lines
tcg/riscv/tcg-target.c.inc +5
-0+ vtypei = encode_vtypei(VTA_TA, VMA_MA, vsew, vlmul); + + tcg_debug_assert(avl <= get_vlmax(vsew)); + tcg_debug_assert(vlmul <= VLMUL_RESERVED); + tcg_debug_assert(vsew <= MO_64);
These asserts should be moved higher, above their first uses.
r~
PATCH v2 5/14 tcg/riscv: Implement vector load/store
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
--- tcg/riscv/tcg-target-con-set.h | 2 + tcg/riscv/tcg-target.c.inc | 169 ++++++++++++++++++++++++++++++++- 2 files changed, 167 insertions(+), 4 deletions(-)
tcg/riscv/tcg-target-con-set.h +2 -0
@@ -21,3 +21,5 @@ C_O1_I2(r, rZ, rZ) C_N1_I2(r, r, rM) C_O1_I4(r, r, rI, rM, rM) C_O2_I4(r, r, rZ, rZ, rM, rM) +C_O0_I2(v, r) +C_O1_I1 (v, r)
tcg/riscv/tcg-target.c.inc +165 -4
224 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v2 05/14] tcg/riscv: Implement vector load/store
Quoted 8 lines · LIU Zhiwei
tcg/riscv/tcg-target.c.inc +4
-0@@ -799,6 +834,17 @@ static void tcg_out_ldst(TCGContext *s, RISCVInsn opc, TCGReg data, case OPC_SD: tcg_out_opc_store(s, opc, addr, data, imm12); break; + case OPC_VSE8_V: + case OPC_VSE16_V: + case OPC_VSE32_V: + case OPC_VSE64_V:
tcg/riscv/tcg-target.c.inc static void tcg_out_ldst(TCGContext *s, RISCVInsn opc, TCGReg data, · line 850
Quoted 10 lines
tcg/riscv/tcg-target.c.inc +7
-0+ case OPC_VS1R_V: + case OPC_VS2R_V: + case OPC_VS4R_V: + case OPC_VS8R_V: + tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_TMP0, addr, imm12); + tcg_out_opc_ldst_vec(s, opc, data, TCG_REG_TMP0, true); + break; case OPC_LB: case OPC_LBU: case OPC_LH:
I think you shouldn't try to handle vector load/store in this same function. You'll want something like
if (offset != 0) {
if (offset == sextreg(offset, 12)) {
tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_TMP0, addr, offset);
} else {
tcg_out_movi(s, TCG_REG_TMP0, offset);
tcg_out_opc_reg(s, TCG_REG_TMP0, TCG_REG_TMP0, addr);
}
addr = TCG_REG_TMP0;
}at the top, instead of the imm12 split currently at the top of tcg_out_ldst.
r~
PATCH v2 6/14 tcg/riscv: Implement vector mov/dup{m/i}
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
--- tcg/riscv/tcg-target.c.inc | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
tcg/riscv/tcg-target.c.inc +54 -0
@@ -303,6 +303,12 @@ typedef enum { OPC_VS2R_V = 0x2000027 | V_UNIT_STRIDE_WHOLE_REG | V_NF(1), OPC_VS4R_V = 0x2000027 | V_UNIT_STRIDE_WHOLE_REG | V_NF(3), OPC_VS8R_V = 0x2000027 | V_UNIT_STRIDE_WHOLE_REG | V_NF(7), + + OPC_VMV_V_V = 0x5e000057 | V_OPIVV, + OPC_VMV_V_I = 0x5e000057 | V_OPIVI, + OPC_VMV_V_X = 0x5e000057 | V_OPIVX, + + OPC_VMVNR_V = 0x9e000057 | V_OPIVI, } RISCVInsn; /*
@@ -544,6 +550,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, static void tcg_out_opc_reg_vec(TCGContext *s, RISCVInsn opc, TCGReg d, TCGReg s1, TCGReg s2, bool vm) { + tcg_debug_assert(d >= TCG_REG_V0 && d >= TCG_REG_V0); tcg_out32(s, encode_r(opc, d, s1, s2) | (vm << 25)); }
@@ -656,6 +663,21 @@ static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg) case TCG_TYPE_I64: tcg_out_opc_imm(s, OPC_ADDI, ret, arg, 0); break; + case TCG_TYPE_V64: + case TCG_TYPE_V128: + case TCG_TYPE_V256: + { + int nf = get_vec_type_bytes(type) / riscv_vlenb; + + if (nf != 0) { + tcg_debug_assert(is_power_of_2(nf) && nf <= 8); + tcg_out_opc_vi(s, OPC_VMVNR_V, ret, arg, nf - 1, true); + } else { + riscv_set_vec_config_vl(s, type); + tcg_out_opc_vv(s, OPC_VMV_V_V, ret, TCG_REG_V0, arg, true); + } + } + break; default: g_assert_not_reached(); }
@@ -1042,6 +1064,33 @@ static void tcg_out_addsub2(TCGContext *s, } } +static bool tcg_out_dup_vec(TCGContext *s, TCGType type, unsigned vece, + TCGReg dst, TCGReg src) +{ + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vx(s, OPC_VMV_V_X, dst, TCG_REG_V0, src, true); + return true; +} + +static bool tcg_out_dupm_vec(TCGContext *s, TCGType type, unsigned vece, + TCGReg dst, TCGReg base, intptr_t offset) +{ + tcg_out_ld(s, TCG_TYPE_REG, TCG_REG_TMP0, base, offset); + return tcg_out_dup_vec(s, type, vece, dst, TCG_REG_TMP0); +} + +static void tcg_out_dupi_vec(TCGContext *s, TCGType type, unsigned vece, + TCGReg dst, int64_t arg) +{ + if (arg < 16 && arg >= -16) { + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vi(s, OPC_VMV_V_I, dst, TCG_REG_V0, arg, true); + return; + } + tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_TMP0, arg); + tcg_out_dup_vec(s, type, vece, dst, TCG_REG_TMP0); +} + static const struct { RISCVInsn op; bool swap;
@@ -2170,6 +2219,9 @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, a2 = args[2]; switch (opc) { + case INDEX_op_dupm_vec: + tcg_out_dupm_vec(s, type, vece, a0, a1, a2); + break; case INDEX_op_ld_vec: tcg_out_ld(s, type, a0, a1, a2); break;
@@ -2341,6 +2393,8 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_st_vec: return C_O0_I2(v, r); + case INDEX_op_dup_vec: + case INDEX_op_dupm_vec: case INDEX_op_ld_vec: return C_O1_I1(v, r); default:
Signature · 1 line
2.43.0
Re: [PATCH v2 06/14] tcg/riscv: Implement vector mov/dup{m/i}
Quoted 7 lines · LIU Zhiwei
From: TANG Tiancheng<[email protected]>
Signed-off-by TANG Tiancheng<[email protected]>Reviewed-by Liu Zhiwei<[email protected]>--- tcg/riscv/tcg-target.c.inc | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
r~
PATCH v2 7/14 tcg/riscv: Add support for basic vector opcodes
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
--- tcg/riscv/tcg-target-con-set.h | 2 ++ tcg/riscv/tcg-target-con-str.h | 1 + tcg/riscv/tcg-target.c.inc | 54 ++++++++++++++++++++++++++++++++++ tcg/riscv/tcg-target.h | 2 +- 4 files changed, 58 insertions(+), 1 deletion(-)
tcg/riscv/tcg-target-con-set.h +2 -0
@@ -22,4 +22,6 @@ C_N1_I2(r, r, rM) C_O1_I4(r, r, rI, rM, rM) C_O2_I4(r, r, rZ, rZ, rM, rM) C_O0_I2(v, r) +C_O0_I2(v, vK) C_O1_I1(v, r) +C_O1_I1 (v, v)
tcg/riscv/tcg-target-con-str.h +1 -0
@@ -17,6 +17,7 @@ REGS('v', GET_VREG_SET(riscv_vlen))*/ CONST('I', TCG_CT_CONST_S12) CONST('J', TCG_CT_CONST_J12) +CONST('K', TCG_CT_CONST_S5) CONST('N', TCG_CT_CONST_N12) CONST('M', TCG_CT_CONST_M12)CONST ('Z' ,TCG_CT_CONST_ZERO )
tcg/riscv/tcg-target.c.inc +54 -0
90 lines not on this page · raw message
tcg/riscv/tcg-target.h +1 -1
@@ -151,7 +151,7 @@ typedef enum {#define TCG_TARGET_HAS_nand_vec 0#define TCG_TARGET_HAS_nor_vec 0#define TCG_TARGET_HAS_eqv_vec 0 -#define TCG_TARGET_HAS_not_vec 0 +#define TCG_TARGET_HAS_not_vec 1#define TCG_TARGET_HAS_neg_vec 0#define TCG_TARGET_HAS_abs_vec 0#define TCG_TARGET_HAS_roti_vec 0
Signature · 1 line
2.43.0
Re: [PATCH v2 07/14] tcg/riscv: Add support for basic vector opcodes
Quoted 39 lines · LIU Zhiwei
From: TANG Tiancheng<[email protected]>
Signed-off-by TANG Tiancheng<[email protected]>Reviewed-by Liu Zhiwei<[email protected]>--- tcg/riscv/tcg-target-con-set.h | 2 ++ tcg/riscv/tcg-target-con-str.h | 1 + tcg/riscv/tcg-target.c.inc | 54 ++++++++++++++++++++++++++++++++++ tcg/riscv/tcg-target.h | 2 +- 4 files changed, 58 insertions(+), 1 deletion(-)tcg/riscv/tcg-target-con-set.h +2
-0@@ -22,4 +22,6 @@ C_N1_I2(r, r, rM) C_O1_I4(r, r, rI, rM, rM) C_O2_I4(r, r, rZ, rZ, rM, rM) C_O0_I2(v, r) +C_O0_I2(v, vK) C_O1_I1(v, r) +C_O1_I1 (v, v)tcg/riscv/tcg-target-con-str.h +1
-0@@ -17,6 +17,7 @@ REGS('v', GET_VREG_SET(riscv_vlen))*/ CONST('I', TCG_CT_CONST_S12) CONST('J', TCG_CT_CONST_J12) +CONST('K', TCG_CT_CONST_S5) CONST('N', TCG_CT_CONST_N12) CONST('M', TCG_CT_CONST_M12)CONST ('Z' ,TCG_CT_CONST_ZERO )tcg/riscv/tcg-target.c.inc +0
-0
tcg/riscv/tcg-target.c.inc static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot) · line 115
Quoted 5 lines
tcg/riscv/tcg-target.c.inc +1
-0@@ -111,6 +111,7 @@ static TCGReg tcg_target_call_oarg_reg(TCGCallReturnKind kind, int slot) #define TCG_CT_CONST_N12 0x400 #define TCG_CT_CONST_M12 0x800 #define TCG_CT_CONST_J12 0x1000 +#define TCG_CT_CONST_S5 0x2000
Added, but not used in this patch?
r~
PATCH v2 8/14 tcg/riscv: Implement vector cmp ops
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
1.Address immediate value constraints in RISC-V Vector Extension 1.0 for comparison instructions.
2.Extend comparison results from mask registers to SEW-width elements,
following recommendations in The RISC-V SPEC Volume I (Version 20240411).
This aligns with TCG's cmp_vec behavior by expanding compare results to full element width: all 1s for true, all 0s for false.
--- tcg/riscv/tcg-target-con-set.h | 6 +- tcg/riscv/tcg-target.c.inc | 240 +++++++++++++++++++++++++++++++++ tcg/riscv/tcg-target.opc.h | 5 + 3 files changed, 250 insertions(+), 1 deletion(-)
tcg/riscv/tcg-target-con-set.h +5 -1
@@ -21,7 +21,11 @@ C_O1_I2(r, rZ, rZ) C_N1_I2(r, r, rM) C_O1_I4(r, r, rI, rM, rM) C_O2_I4(r, r, rZ, rZ, rM, rM) +C_O0_I1(v) +C_O0_I2(v, v) C_O0_I2(v, r) -C_O0_I2(v, vK) C_O1_I1(v, r) C_O1_I1(v, v) +C_O1_I2(v, v, v) +C_O1_I2(v, v, vi) +C_O1_I2(v, v, vK)
tcg/riscv/tcg-target.c.inc +240 -0
295 lines not on this page · raw message
tcg/riscv/tcg-target.opc.h +5 -0
@@ -10,3 +10,8 @@* emitted by tcg_expand_vec_op. For those familiar with GCC internals, * consider these to be UNSPEC with names. */ + +DEF(rvv_cmp_vi, 0, 1, 2, IMPLVEC) +DEF(rvv_cmp_vx, 0, 2, 1, IMPLVEC) +DEF(rvv_cmp_vv, 0, 2, 1, IMPLVEC) +DEF (rvv_merge_vec,1 ,2 ,0 ,IMPLVEC )
Signature · 1 line
2.43.0
Re: [PATCH v2 08/14] tcg/riscv: Implement vector cmp ops
Quoted 24 lines · LIU Zhiwei
From: TANG Tiancheng<[email protected]>
1.Address immediate value constraints in RISC-V Vector Extension 1.0 for comparison instructions.
2.Extend comparison results from mask registers to SEW-width elements,
following recommendations in The RISC-V SPEC Volume I (Version 20240411).This aligns with TCG's
cmp_vecbehavior by expanding compare results to full element width: all 1s for true, all 0s for false.Signed-off-by TANG Tiancheng<[email protected]>Reviewed-by Liu Zhiwei<[email protected]>--- tcg/riscv/tcg-target-con-set.h | 6 +- tcg/riscv/tcg-target.c.inc | 240 +++++++++++++++++++++++++++++++++ tcg/riscv/tcg-target.opc.h | 5 + 3 files changed, 250 insertions(+), 1 deletion(-)tcg/riscv/tcg-target-con-set.h +0
-0
tcg/riscv/tcg-target-con-set.h C_O1_I2(r, rZ, rZ) · line 25
Quoted 7 lines
tcg/riscv/tcg-target-con-set.h +2
-1@@ -21,7 +21,11 @@ C_O1_I2(r, rZ, rZ) C_N1_I2(r, r, rM) C_O1_I4(r, r, rI, rM, rM) C_O2_I4(r, r, rZ, rZ, rM, rM) +C_O0_I1(v) +C_O0_I2(v, v) C_O0_I2(v, r) -C_O0_I2 (v, vK)
Removing vK, just added in the previous patch.
Quoted 7 lines
tcg/riscv/tcg-target-con-set.h +7
-0+static bool expand_vec_cmp_vi (TCGType type,unsigned vece, +TCGv_vec v1,TCGArg a2,TCGCond cond) +{ +int64_t arg2 =arg_temp (a2)->val; +bool invert = false; + +if (!tcg_vec_cmp_can_do_vi (cond, arg2)) {
...
tcg/riscv/tcg-target-con-set.h
Quoted 8 lines
tcg/riscv/tcg-target-con-set.h +8
-0+static bool expand_vec_cmp_noinv (TCGType type,unsigned vece,TCGv_vec v1, +TCGArg a2,TCGCond cond) +{ +bool invert = false; +TCGTemp *t1 =arg_temp (a2); + +if (t1->kind ==TEMP_CONST ) { + invert =expand_vec_cmp_vi (type, vece, v1, a2, cond);
This will not work as you intend, primarily because vector constants are stored in expanded form. E.g. MO_8 1 is stored as 0x0101010101010101.
This is handled transparently *if* you use tcg_target_const_match instead.
Otherwise one must (sign)extract the low vece bits, and then double-check that the replication of the low bits matches the complete 'a2' value.
I agree that we should be prepared for more vector x scalar operations, but that needs to happen during generic expansion rather than very late in the backend.
I think the first implementation should be simpler:
CONST('C', TCG_CT_CONST_CMP_VI)
tcg_target_const_match()
{
...
if ((ct & TCG_CT_CONST_CMP_VI) &&
val >= tcg_cmpcond_to_rvv_vi[cond].min &&
val <= tcg_cmpcond_to_rvv_vi[cond].max) {
return true;
}
} case INDEX_op_cmp_vec:
riscv_set_vec_config_vl_vece(s, type, vece);
cond = args[3];
if (c2) {
tcg_out_opc_vi(s, tcg_cmpcond_to_rvv_vi[cond].op, a0, a1,
a2 - tcg_cmpcond_to_rvv_vi[cond].adjust);
} else if (tcg_cmpcond_to_rvv_vv[cond].swap) {
tcg_out_opc_vv(s, tcg_cmpcond_to_rvv_vv[cond].op, a0, a2, a1);
} else {
tcg_out_opc_vv(s, tcg_cmpcond_to_rvv_vv[cond].op, a0, a1, a2);
}
break;This appears to not require any expansion in tcg_expand_vec_op at all.
r~
Re: [PATCH v2 08/14] tcg/riscv: Implement vector cmp ops
Quoted 27 lines · Richard Henderson
I think the first implementation should be simpler:
CONST('C', TCG_CT_CONST_CMP_VI)
tcg_target_const_match()
{
...
if ((ct &TCG_CT_CONST_CMP_VI) &&
val >= tcg_cmpcond_to_rvv_vi[cond].min && val <= tcg_cmpcond_to_rvv_vi[cond].max) { return true;
}
}case
INDEX_op_cmp_vec:
riscv_set_vec_config_vl_vece(s, type, vece);
cond = args[3];
if (c2) {
tcg_out_opc_vi(s, tcg_cmpcond_to_rvv_vi[cond].op, a0, a1, a2 - tcg_cmpcond_to_rvv_vi[cond].adjust); } else if (tcg_cmpcond_to_rvv_vv[cond].swap) {tcg_out_opc_vv(s, tcg_cmpcond_to_rvv_vv[cond].op, a0, a2, a1); } else {
tcg_out_opc_vv(s, tcg_cmpcond_to_rvv_vv[cond].op, a0, a1, a2); }
break;
Quoted 1 line
This appears to not require any expansion in
tcg_expand_vec_opat all.
I knew I should have slept on that answer.
Of course you need expansion, because riscv cmp_vv produces a mask.
However, I think we should simply model this as INDEX_op_cmpsel_vec:
case INDEX_op_cmpsel_vec:
riscv_set_vec_config_vl_vece(s, type, vece);
a3 = args[3];
a4 = args[4];
cond = args[5];
/* Use only vmerge_vim if possible, by inverting the test. */
if (const_args[4] && !const_args[3]) {
cond = tcg_cond_inv(cond);
a3 = a4;
a4 = args[3];
const_args[3] = true;
const_args[4] = false;
}
/* Perform the comparison into V0 mask. */
if (const_args[2]) {
tcg_out_opc_vi(s, tcg_cmpcond_to_rvv_vi[cond].op,
TCG_REG_V0, a1,
a2 - tcg_cmpcond_to_rvv_vi[cond].adjust);
} else if (tcg_cmpcond_to_rvv_vv[cond].swap) {
tcg_out_opc_vv(s, tcg_cmpcond_to_rvv_vv[cond].op,
TCG_REG_V0, a2, a1);
} else {
tcg_out_opc_vv(s, tcg_cmpcond_to_rvv_vv[cond].op,
TCG_REG_V0, a1, a2);
}
if (const_args[3]) {
if (const_args[4]) {
tcg_out_opc_vi(s, OPC_VMV_V_I, a0, TCG_REG_V0, a4, true);
a4 = a0;
}
tcg_out_opc_vim_mask(s, OPC_VMERGE_VIM, a0, a3, a4);
} else {
tcg_out_opc_vvm_mask(s, OPC_VMERGE_VVM, a0, a3, a4);
}
break;Then INDEX_op_cmp_vec should be expanded to
INDEX_op_cmpsel_vec a0, a1, a2, -1, 0, a3
r~
PATCH v2 9/14 tcg/riscv: Implement vector neg ops
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
--- tcg/riscv/tcg-target.c.inc | 8 ++++++++ tcg/riscv/tcg-target.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)
tcg/riscv/tcg-target.c.inc +8 -0
@@ -322,6 +322,7 @@ typedef enum { OPC_VXOR_VV = 0x2c000057 | V_OPIVV, OPC_VXOR_VI = 0x2c000057 | V_OPIVI, + OPC_VRSUB_VI = 0xc000057 | V_OPIVI, OPC_VMSEQ_VV = 0x60000057 | V_OPIVV, OPC_VMSEQ_VI = 0x60000057 | V_OPIVI, OPC_VMSEQ_VX = 0x60000057 | V_OPIVX,
@@ -2394,6 +2395,10 @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, riscv_set_vec_config_vl(s, type); tcg_out_opc_vi(s, OPC_VXOR_VI, a0, a1, -1, true); break; + case INDEX_op_neg_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vi(s, OPC_VRSUB_VI, a0, a1, 0, true); + break; case INDEX_op_rvv_cmp_vx: riscv_set_vec_config_vl_vece(s, type, vece); tcg_out_cmp_vec_vx(s, a2, a0, a1);
@@ -2408,6 +2413,7 @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, tcg_out_cmp_vec_vv(s, a2, a0, a1); break; case INDEX_op_rvv_merge_vec: + riscv_set_vec_config_vl_vece(s, type, vece); if (const_args[2]) { /* vd[i] == v0.mask[i] ? imm : vs2[i] */ tcg_out_opc_vim_mask(s, OPC_VMERGE_VIM, a0, a1, a2);
@@ -2520,6 +2526,7 @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) case INDEX_op_or_vec: case INDEX_op_xor_vec: case INDEX_op_not_vec: + case INDEX_op_neg_vec: return 1; case INDEX_op_cmp_vec: return -1;
@@ -2673,6 +2680,7 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_dupm_vec: case INDEX_op_ld_vec: return C_O1_I1(v, r); + case INDEX_op_neg_vec: case INDEX_op_not_vec: return C_O1_I1(v, v); case INDEX_op_add_vec:
tcg/riscv/tcg-target.h +1 -1
@@ -152,7 +152,7 @@ typedef enum {#define TCG_TARGET_HAS_nor_vec 0#define TCG_TARGET_HAS_eqv_vec 0#define TCG_TARGET_HAS_not_vec 1 -#define TCG_TARGET_HAS_neg_vec 0 +#define TCG_TARGET_HAS_neg_vec 1#define TCG_TARGET_HAS_abs_vec 0#define TCG_TARGET_HAS_roti_vec 0#define TCG_TARGET_HAS_rots_vec 0
Signature · 1 line
2.43.0
Re: [PATCH v2 09/14] tcg/riscv: Implement vector neg ops
Quoted 8 lines · LIU Zhiwei
From: TANG Tiancheng<[email protected]>
Signed-off-by TANG Tiancheng<[email protected]>Reviewed-by Liu Zhiwei<[email protected]>--- tcg/riscv/tcg-target.c.inc | 8 ++++++++ tcg/riscv/tcg-target.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)
r~
PATCH v2 10/14 tcg/riscv: Implement vector sat/mul ops
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
--- tcg/riscv/tcg-target.c.inc | 36 ++++++++++++++++++++++++++++++++++++ tcg/riscv/tcg-target.h | 4 ++-- 2 files changed, 38 insertions(+), 2 deletions(-)
tcg/riscv/tcg-target.c.inc +36 -0
@@ -323,6 +323,12 @@ typedef enum { OPC_VXOR_VI = 0x2c000057 | V_OPIVI, OPC_VRSUB_VI = 0xc000057 | V_OPIVI, + OPC_VMUL_VV = 0x94000057 | V_OPMVV, + OPC_VSADD_VV = 0x84000057 | V_OPIVV, + OPC_VSSUB_VV = 0x8c000057 | V_OPIVV, + OPC_VSADDU_VV = 0x80000057 | V_OPIVV, + OPC_VSSUBU_VV = 0x88000057 | V_OPIVV, + OPC_VMSEQ_VV = 0x60000057 | V_OPIVV, OPC_VMSEQ_VI = 0x60000057 | V_OPIVI, OPC_VMSEQ_VX = 0x60000057 | V_OPIVX,
@@ -2399,6 +2405,26 @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, riscv_set_vec_config_vl_vece(s, type, vece); tcg_out_opc_vi(s, OPC_VRSUB_VI, a0, a1, 0, true); break; + case INDEX_op_mul_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vv(s, OPC_VMUL_VV, a0, a1, a2, true); + break; + case INDEX_op_ssadd_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vv(s, OPC_VSADD_VV, a0, a1, a2, true); + break; + case INDEX_op_sssub_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vv(s, OPC_VSSUB_VV, a0, a1, a2, true); + break; + case INDEX_op_usadd_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vv(s, OPC_VSADDU_VV, a0, a1, a2, true); + break; + case INDEX_op_ussub_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vv(s, OPC_VSSUBU_VV, a0, a1, a2, true); + break; case INDEX_op_rvv_cmp_vx: riscv_set_vec_config_vl_vece(s, type, vece); tcg_out_cmp_vec_vx(s, a2, a0, a1);
@@ -2527,6 +2553,11 @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) case INDEX_op_xor_vec: case INDEX_op_not_vec: case INDEX_op_neg_vec: + case INDEX_op_mul_vec: + case INDEX_op_ssadd_vec: + case INDEX_op_sssub_vec: + case INDEX_op_usadd_vec: + case INDEX_op_ussub_vec: return 1; case INDEX_op_cmp_vec: return -1;
@@ -2688,6 +2719,11 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_and_vec: case INDEX_op_or_vec: case INDEX_op_xor_vec: + case INDEX_op_mul_vec: + case INDEX_op_ssadd_vec: + case INDEX_op_sssub_vec: + case INDEX_op_usadd_vec: + case INDEX_op_ussub_vec: return C_O1_I2(v, v, v); case INDEX_op_rvv_merge_vec: return C_O1_I2(v, v, vK);
tcg/riscv/tcg-target.h +2 -2
@@ -160,8 +160,8 @@ typedef enum {#define TCG_TARGET_HAS_shi_vec 0#define TCG_TARGET_HAS_shs_vec 0#define TCG_TARGET_HAS_shv_vec 0 -#define TCG_TARGET_HAS_mul_vec 0 -#define TCG_TARGET_HAS_sat_vec 0 +#define TCG_TARGET_HAS_mul_vec 1 +#define TCG_TARGET_HAS_sat_vec 1#define TCG_TARGET_HAS_minmax_vec 0#define TCG_TARGET_HAS_bitsel_vec 0#define TCG_TARGET_HAS_cmpsel_vec 0
Signature · 1 line
2.43.0
Re: [PATCH v2 10/14] tcg/riscv: Implement vector sat/mul ops
Quoted 8 lines · LIU Zhiwei
From: TANG Tiancheng<[email protected]>
Signed-off-by TANG Tiancheng<[email protected]>Reviewed-by Liu Zhiwei<[email protected]>--- tcg/riscv/tcg-target.c.inc | 36 ++++++++++++++++++++++++++++++++++++ tcg/riscv/tcg-target.h | 4 ++-- 2 files changed, 38 insertions(+), 2 deletions(-)
r~
PATCH v2 11/14 tcg/riscv: Implement vector min/max ops
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
--- tcg/riscv/tcg-target.c.inc | 29 +++++++++++++++++++++++++++++ tcg/riscv/tcg-target.h | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-)
tcg/riscv/tcg-target.c.inc +29 -0
@@ -329,6 +329,11 @@ typedef enum { OPC_VSADDU_VV = 0x80000057 | V_OPIVV, OPC_VSSUBU_VV = 0x88000057 | V_OPIVV, + OPC_VMAX_VV = 0x1c000057 | V_OPIVV, + OPC_VMAXU_VV = 0x18000057 | V_OPIVV, + OPC_VMIN_VV = 0x14000057 | V_OPIVV, + OPC_VMINU_VV = 0x10000057 | V_OPIVV, + OPC_VMSEQ_VV = 0x60000057 | V_OPIVV, OPC_VMSEQ_VI = 0x60000057 | V_OPIVI, OPC_VMSEQ_VX = 0x60000057 | V_OPIVX,
@@ -2425,6 +2430,22 @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, riscv_set_vec_config_vl_vece(s, type, vece); tcg_out_opc_vv(s, OPC_VSSUBU_VV, a0, a1, a2, true); break; + case INDEX_op_smax_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vv(s, OPC_VMAX_VV, a0, a1, a2, true); + break; + case INDEX_op_smin_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vv(s, OPC_VMIN_VV, a0, a1, a2, true); + break; + case INDEX_op_umax_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vv(s, OPC_VMAXU_VV, a0, a1, a2, true); + break; + case INDEX_op_umin_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vv(s, OPC_VMINU_VV, a0, a1, a2, true); + break; case INDEX_op_rvv_cmp_vx: riscv_set_vec_config_vl_vece(s, type, vece); tcg_out_cmp_vec_vx(s, a2, a0, a1);
@@ -2558,6 +2579,10 @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) case INDEX_op_sssub_vec: case INDEX_op_usadd_vec: case INDEX_op_ussub_vec: + case INDEX_op_smax_vec: + case INDEX_op_smin_vec: + case INDEX_op_umax_vec: + case INDEX_op_umin_vec: return 1; case INDEX_op_cmp_vec: return -1;
@@ -2724,6 +2749,10 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_sssub_vec: case INDEX_op_usadd_vec: case INDEX_op_ussub_vec: + case INDEX_op_smax_vec: + case INDEX_op_smin_vec: + case INDEX_op_umax_vec: + case INDEX_op_umin_vec: return C_O1_I2(v, v, v); case INDEX_op_rvv_merge_vec: return C_O1_I2(v, v, vK);
tcg/riscv/tcg-target.h +1 -1
@@ -162,7 +162,7 @@ typedef enum {#define TCG_TARGET_HAS_shv_vec 0#define TCG_TARGET_HAS_mul_vec 1#define TCG_TARGET_HAS_sat_vec 1 -#define TCG_TARGET_HAS_minmax_vec 0 +#define TCG_TARGET_HAS_minmax_vec 1#define TCG_TARGET_HAS_bitsel_vec 0#define TCG_TARGET_HAS_cmpsel_vec 0
Signature · 1 line
2.43.0
Re: [PATCH v2 11/14] tcg/riscv: Implement vector min/max ops
Quoted 8 lines · LIU Zhiwei
From: TANG Tiancheng<[email protected]>
Signed-off-by TANG Tiancheng<[email protected]>Reviewed-by Liu Zhiwei<[email protected]>--- tcg/riscv/tcg-target.c.inc | 29 +++++++++++++++++++++++++++++ tcg/riscv/tcg-target.h | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-)
r~
PATCH v2 12/14 tcg/riscv: Implement vector shs/v ops
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
--- tcg/riscv/tcg-target-con-set.h | 1 + tcg/riscv/tcg-target.c.inc | 44 ++++++++++++++++++++++++++++++++++ tcg/riscv/tcg-target.h | 4 ++-- 3 files changed, 47 insertions(+), 2 deletions(-)
tcg/riscv/tcg-target-con-set.h +1 -0
@@ -29,3 +29,4 @@ C_O1_I1(v, v) C_O1_I2(v, v, v) C_O1_I2(v, v, vi) C_O1_I2(v, v, vK) +C_O1_I2 (v, v, r)
tcg/riscv/tcg-target.c.inc +44 -0
69 lines not on this page · raw message
tcg/riscv/tcg-target.h +2 -2
@@ -158,8 +158,8 @@ typedef enum {#define TCG_TARGET_HAS_rots_vec 0#define TCG_TARGET_HAS_rotv_vec 0#define TCG_TARGET_HAS_shi_vec 0 -#define TCG_TARGET_HAS_shs_vec 0 -#define TCG_TARGET_HAS_shv_vec 0 +#define TCG_TARGET_HAS_shs_vec 1 +#define TCG_TARGET_HAS_shv_vec 1#define TCG_TARGET_HAS_mul_vec 1#define TCG_TARGET_HAS_sat_vec 1#define TCG_TARGET_HAS_minmax_vec 1
Signature · 1 line
2.43.0
Re: [PATCH v2 12/14] tcg/riscv: Implement vector shs/v ops
Quoted 9 lines · LIU Zhiwei
From: TANG Tiancheng<[email protected]>
Signed-off-by TANG Tiancheng<[email protected]>Reviewed-by Liu Zhiwei<[email protected]>--- tcg/riscv/tcg-target-con-set.h | 1 + tcg/riscv/tcg-target.c.inc | 44 ++++++++++++++++++++++++++++++++++ tcg/riscv/tcg-target.h | 4 ++-- 3 files changed, 47 insertions(+), 2 deletions(-)
r~
PATCH v2 13/14 tcg/riscv: Implement vector roti/v/x shi ops
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
--- tcg/riscv/tcg-target.c.inc | 98 +++++++++++++++++++++++++++++++++++++- tcg/riscv/tcg-target.h | 8 ++-- tcg/riscv/tcg-target.opc.h | 3 ++ 3 files changed, 104 insertions(+), 5 deletions(-)
tcg/riscv/tcg-target.c.inc +97 -1
@@ -358,10 +358,13 @@ typedef enum { OPC_VMSGT_VX = 0x7c000057 | V_OPIVX, OPC_VSLL_VV = 0x94000057 | V_OPIVV, + OPC_VSLL_VI = 0x94000057 | V_OPIVI, OPC_VSLL_VX = 0x94000057 | V_OPIVX, OPC_VSRL_VV = 0xa0000057 | V_OPIVV, + OPC_VSRL_VI = 0xa0000057 | V_OPIVI, OPC_VSRL_VX = 0xa0000057 | V_OPIVX, OPC_VSRA_VV = 0xa4000057 | V_OPIVV, + OPC_VSRA_VI = 0xa4000057 | V_OPIVI, OPC_VSRA_VX = 0xa4000057 | V_OPIVX, OPC_VMV_V_V = 0x5e000057 | V_OPIVV,
@@ -2477,6 +2480,18 @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, riscv_set_vec_config_vl_vece(s, type, vece); tcg_out_opc_vv(s, OPC_VSRA_VV, a0, a1, a2, true); break; + case INDEX_op_rvv_shli_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vi(s, OPC_VSLL_VI, a0, a1, a2, true); + break; + case INDEX_op_rvv_shri_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vi(s, OPC_VSRL_VI, a0, a1, a2, true); + break; + case INDEX_op_rvv_sari_vec: + riscv_set_vec_config_vl_vece(s, type, vece); + tcg_out_opc_vi(s, OPC_VSRA_VI, a0, a1, a2, true); + break; case INDEX_op_rvv_cmp_vx: riscv_set_vec_config_vl_vece(s, type, vece); tcg_out_cmp_vec_vx(s, a2, a0, a1);
@@ -2561,7 +2576,8 @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, TCGArg a0, ...) { va_list va; - TCGv_vec v0, v1; + TCGv_vec v0, v1, v2, t1; + TCGv_i32 t2; TCGArg a2, a3; va_start(va, a0);
@@ -2589,6 +2605,69 @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, } } break; + case INDEX_op_shli_vec: + if (a2 > 31) { + tcg_gen_shls_vec(vece, v0, v1, tcg_constant_i32(a2)); + } else { + vec_gen_3(INDEX_op_rvv_shli_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), a2); + } + break; + case INDEX_op_shri_vec: + if (a2 > 31) { + tcg_gen_shrs_vec(vece, v0, v1, tcg_constant_i32(a2)); + } else { + vec_gen_3(INDEX_op_rvv_shri_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), a2); + } + break; + case INDEX_op_sari_vec: + if (a2 > 31) { + tcg_gen_sars_vec(vece, v0, v1, tcg_constant_i32(a2)); + } else { + vec_gen_3(INDEX_op_rvv_sari_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), a2); + } + break; + case INDEX_op_rotli_vec: + t1 = tcg_temp_new_vec(type); + tcg_gen_shli_vec(vece, t1, v1, a2); + tcg_gen_shri_vec(vece, v0, v1, (8 << vece) - a2); + tcg_gen_or_vec(vece, v0, v0, t1); + tcg_temp_free_vec(t1); + break; + case INDEX_op_rotls_vec: + t1 = tcg_temp_new_vec(type); + t2 = tcg_temp_new_i32(); + tcg_gen_neg_i32(t2, temp_tcgv_i32(arg_temp(a2))); + tcg_gen_shrs_vec(vece, v0, v1, t2); + tcg_gen_shls_vec(vece, t1, v1, temp_tcgv_i32(arg_temp(a2))); + tcg_gen_or_vec(vece, v0, v0, t1); + tcg_temp_free_vec(t1); + tcg_temp_free_i32(t2); + break; + case INDEX_op_rotlv_vec: + v2 = temp_tcgv_vec(arg_temp(a2)); + t1 = tcg_temp_new_vec(type); + tcg_gen_neg_vec(vece, t1, v2); + vec_gen_3(INDEX_op_shrv_vec, type, vece, tcgv_vec_arg(t1), + tcgv_vec_arg(v1), tcgv_vec_arg(t1)); + vec_gen_3(INDEX_op_shlv_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), tcgv_vec_arg(v2)); + tcg_gen_or_vec(vece, v0, v0, t1); + tcg_temp_free_vec(t1); + break; + case INDEX_op_rotrv_vec: + v2 = temp_tcgv_vec(arg_temp(a2)); + t1 = tcg_temp_new_vec(type); + tcg_gen_neg_vec(vece, t1, v2); + vec_gen_3(INDEX_op_shlv_vec, type, vece, tcgv_vec_arg(t1), + tcgv_vec_arg(v1), tcgv_vec_arg(t1)); + vec_gen_3(INDEX_op_shrv_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), tcgv_vec_arg(v2)); + tcg_gen_or_vec(vece, v0, v0, t1); + tcg_temp_free_vec(t1); + break; default: g_assert_not_reached(); }
@@ -2622,6 +2701,13 @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) case INDEX_op_sarv_vec: return 1; case INDEX_op_cmp_vec: + case INDEX_op_shri_vec: + case INDEX_op_shli_vec: + case INDEX_op_sari_vec: + case INDEX_op_rotls_vec: + case INDEX_op_rotlv_vec: + case INDEX_op_rotrv_vec: + case INDEX_op_rotli_vec: return -1; default: return 0;
@@ -2775,6 +2861,13 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) return C_O1_I1(v, r); case INDEX_op_neg_vec: case INDEX_op_not_vec: + case INDEX_op_rotli_vec: + case INDEX_op_shli_vec: + case INDEX_op_shri_vec: + case INDEX_op_sari_vec: + case INDEX_op_rvv_shli_vec: + case INDEX_op_rvv_shri_vec: + case INDEX_op_rvv_sari_vec: return C_O1_I1(v, v); case INDEX_op_add_vec: case INDEX_op_sub_vec:
@@ -2793,10 +2886,13 @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) case INDEX_op_shlv_vec: case INDEX_op_shrv_vec: case INDEX_op_sarv_vec: + case INDEX_op_rotlv_vec: + case INDEX_op_rotrv_vec: return C_O1_I2(v, v, v); case INDEX_op_shls_vec: case INDEX_op_shrs_vec: case INDEX_op_sars_vec: + case INDEX_op_rotls_vec: return C_O1_I2(v, v, r); case INDEX_op_rvv_merge_vec: return C_O1_I2(v, v, vK);
tcg/riscv/tcg-target.h +4 -4
@@ -154,10 +154,10 @@ typedef enum {#define TCG_TARGET_HAS_not_vec 1#define TCG_TARGET_HAS_neg_vec 1#define TCG_TARGET_HAS_abs_vec 0 -#define TCG_TARGET_HAS_roti_vec 0 -#define TCG_TARGET_HAS_rots_vec 0 -#define TCG_TARGET_HAS_rotv_vec 0 -#define TCG_TARGET_HAS_shi_vec 0 +#define TCG_TARGET_HAS_roti_vec -1 +#define TCG_TARGET_HAS_rots_vec -1 +#define TCG_TARGET_HAS_rotv_vec -1 +#define TCG_TARGET_HAS_shi_vec -1#define TCG_TARGET_HAS_shs_vec 1#define TCG_TARGET_HAS_shv_vec 1#define TCG_TARGET_HAS_mul_vec 1
tcg/riscv/tcg-target.opc.h +3 -0
@@ -15,3 +15,6 @@ DEF(rvv_cmp_vi, 0, 1, 2, IMPLVEC) DEF(rvv_cmp_vx, 0, 2, 1, IMPLVEC) DEF(rvv_cmp_vv, 0, 2, 1, IMPLVEC) DEF(rvv_merge_vec, 1, 2, 0, IMPLVEC) +DEF(rvv_shli_vec, 1, 1, 1, IMPLVEC) +DEF(rvv_shri_vec, 1, 1, 1, IMPLVEC) +DEF (rvv_sari_vec,1 ,1 ,1 ,IMPLVEC )
Signature · 1 line
2.43.0
Re: [PATCH v2 13/14] tcg/riscv: Implement vector roti/v/x shi ops
Quoted 35 lines · LIU Zhiwei
tcg/riscv/tcg-target.c.inc +31
-0@@ -2589,6 +2605,69 @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, } } break; + case INDEX_op_shli_vec: + if (a2 > 31) { + tcg_gen_shls_vec(vece, v0, v1, tcg_constant_i32(a2)); + } else { + vec_gen_3(INDEX_op_rvv_shli_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), a2); + } + break; + case INDEX_op_shri_vec: + if (a2 > 31) { + tcg_gen_shrs_vec(vece, v0, v1, tcg_constant_i32(a2)); + } else { + vec_gen_3(INDEX_op_rvv_shri_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), a2); + } + break; + case INDEX_op_sari_vec: + if (a2 > 31) { + tcg_gen_sars_vec(vece, v0, v1, tcg_constant_i32(a2)); + } else { + vec_gen_3(INDEX_op_rvv_sari_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), a2); + } + break; + case INDEX_op_rotli_vec: + t1 = tcg_temp_new_vec(type); + tcg_gen_shli_vec(vece, t1, v1, a2); + tcg_gen_shri_vec(vece, v0, v1, (8 << vece) - a2); + tcg_gen_or_vec(vece, v0, v0, t1); + tcg_temp_free_vec(t1); + break;
tcg/riscv/tcg-target.c.inc void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, · line 2648
Quoted 10 lines
tcg/riscv/tcg-target.c.inc +10
-0+ case INDEX_op_rotls_vec: + t1 = tcg_temp_new_vec(type); + t2 = tcg_temp_new_i32(); + tcg_gen_neg_i32(t2, temp_tcgv_i32(arg_temp(a2))); + tcg_gen_shrs_vec(vece, v0, v1, t2); + tcg_gen_shls_vec(vece, t1, v1, temp_tcgv_i32(arg_temp(a2))); + tcg_gen_or_vec(vece, v0, v0, t1); + tcg_temp_free_vec(t1); + tcg_temp_free_i32(t2); + break;
I'm trying to work out how much benefit there is here of expanding these early, as opposed to simply using TCG_REG_TMP0 when the immediate doesn't fit, or for rotls_vec negation.
Quoted 12 lines
tcg/riscv/tcg-target.c.inc +12
-0+ case INDEX_op_rotlv_vec: + v2 = temp_tcgv_vec(arg_temp(a2)); + t1 = tcg_temp_new_vec(type); + tcg_gen_neg_vec(vece, t1, v2); + vec_gen_3(INDEX_op_shrv_vec, type, vece, tcgv_vec_arg(t1), + tcgv_vec_arg(v1), tcgv_vec_arg(t1)); + vec_gen_3(INDEX_op_shlv_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), tcgv_vec_arg(v2)); + tcg_gen_or_vec(vece, v0, v0, t1); + tcg_temp_free_vec(t1); + break; + case INDEX_op_rotrv_vec:
tcg/riscv/tcg-target.c.inc void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, · line 2670
Quoted 10 lines
tcg/riscv/tcg-target.c.inc +10
-0+ v2 = temp_tcgv_vec(arg_temp(a2)); + t1 = tcg_temp_new_vec(type); + tcg_gen_neg_vec(vece, t1, v2); + vec_gen_3(INDEX_op_shlv_vec, type, vece, tcgv_vec_arg(t1), + tcgv_vec_arg(v1), tcgv_vec_arg(t1)); + vec_gen_3(INDEX_op_shrv_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), tcgv_vec_arg(v2)); + tcg_gen_or_vec(vece, v0, v0, t1); + tcg_temp_free_vec(t1); + break;
And here we can use TCG_REG_V0 as the temporary, both for negation and shift intermediate.
vrsub_vi V0, a2, 0
vshlv_vv V0, a1, V0
vshrv_vv a0, a1, a2
vor_vv a0, a0, V0r~
Re: [PATCH v2 13/14] tcg/riscv: Implement vector roti/v/x shi ops
Quoted 44 lines · Richard Henderson
Quoted 43 lines · LIU Zhiwei
tcg/riscv/tcg-target.c.inc +21
-0@@ -2589,6 +2605,69 @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, } } break; + case INDEX_op_shli_vec: + if (a2 > 31) { + tcg_gen_shls_vec(vece, v0, v1, tcg_constant_i32(a2)); + } else { + vec_gen_3(INDEX_op_rvv_shli_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), a2); + } + break; + case INDEX_op_shri_vec: + if (a2 > 31) { + tcg_gen_shrs_vec(vece, v0, v1, tcg_constant_i32(a2)); + } else { + vec_gen_3(INDEX_op_rvv_shri_vec, type, vece, tcgv_vec_arg(v0), + tcgv_vec_arg(v1), a2); + } + break; + case INDEX_op_sari_vec: + if (a2 > 31) { + tcg_gen_sars_vec(vece, v0, v1, tcg_constant_i32(a2)); + } else { + vec_gen_3(INDEX_op_rvv_sari_vec, type, vece,
tcgv_vec_arg(v0),
+tcgv_vec_arg(v1), a2);
+ }
+ break;
+ caseINDEX_op_rotli_vec:
+ t1 =tcg_temp_new_vec(type);
+tcg_gen_shli_vec(vece, t1, v1, a2);
+tcg_gen_shri_vec(vece, v0, v1, (8 << vece) - a2); +tcg_gen_or_vec(vece, v0, v0, t1);
+tcg_temp_free_vec(t1);
+ break;
+ caseINDEX_op_rotls_vec:
+ t1 =tcg_temp_new_vec(type);
+ t2 =tcg_temp_new_i32();
+tcg_gen_neg_i32(t2, temp_tcgv_i32(arg_temp(a2)));
Quoted 8 lines
Quoted 6 lines
+
tcg_gen_shrs_vec(vece, v0, v1, t2);
+tcg_gen_shls_vec(vece, t1, v1, temp_tcgv_i32(arg_temp(a2))); +tcg_gen_or_vec(vece, v0, v0, t1);
+tcg_temp_free_vec(t1);
+tcg_temp_free_i32(t2);
+ break;I'm trying to work out how much benefit there is here of expanding these early, as opposed to simply using
TCG_REG_TMP0when the immediate doesn't fit,
We find for rotli, it just copied code from the implementation of INDEX_op_shli_vec and INDEX_op_shri_vec if we don't expand it.
case INDEX_op_rotli_vec:
if (a2 > 31) {
tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_TMP0, TCG_REG_ZERO, a2);
tcg_out_opc_vx(s, OPC_VSLL_VX, TCG_REG_V0, a1, TCG_REG_TMP0, true);
} else {
tcg_out_opc_vi(s, OPC_VSLL_VI, TCG_REG_V0, a1, a2, true);
} if ((8 << vece) - a2) > 31) {
tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_TMP0, TCG_REG_ZERO, 8 << vece) - a2);
tcg_out_opc_vx(s, OPC_VSRL_VX, a0, a1, TCG_REG_TMP0, true);
} else {
tcg_out_opc_vi(s, OPC_VSRL_VI, a0, a1, 8 << vece) - a2, true);
}
tcg_out_opc_vv(s, OPC_VOR_VV, a0, a0, TCG_REG_V0, true);
break;Thus, I prefer to expand it early, at least for rotli_vec.
Thanks,
Zhiwei
Quoted 34 lines
or for
rotls_vecnegation.Quoted 14 lines
+ case
INDEX_op_rotlv_vec:
+ v2 = temp_tcgv_vec(arg_temp(a2));
+ t1 =tcg_temp_new_vec(type);
+tcg_gen_neg_vec(vece, t1, v2);
+ vec_gen_3(INDEX_op_shrv_vec, type, vece,tcgv_vec_arg(t1), +tcgv_vec_arg(v1),tcgv_vec_arg(t1)); + vec_gen_3(INDEX_op_shlv_vec, type, vece,tcgv_vec_arg(v0), +tcgv_vec_arg(v1),tcgv_vec_arg(v2)); +tcg_gen_or_vec(vece, v0, v0, t1);
+tcg_temp_free_vec(t1);
+ break;
+ caseINDEX_op_rotrv_vec:
+ v2 = temp_tcgv_vec(arg_temp(a2));
+ t1 =tcg_temp_new_vec(type);Quoted 8 lines
+
tcg_gen_neg_vec(vece, t1, v2);
+ vec_gen_3(INDEX_op_shlv_vec, type, vece,tcgv_vec_arg(t1), +tcgv_vec_arg(v1),tcgv_vec_arg(t1)); + vec_gen_3(INDEX_op_shrv_vec, type, vece,tcgv_vec_arg(v0), +tcgv_vec_arg(v1),tcgv_vec_arg(v2)); +tcg_gen_or_vec(vece, v0, v0, t1);
+tcg_temp_free_vec(t1);
+ break;And here we can use
TCG_REG_V0as the temporary, both for negation and shift intermediate.vrsub_vi V0, a2, 0
vshlv_vv V0, a1, V0
vshrv_vv a0, a1, a2
vor_vv a0, a0, V0r~
Re: [PATCH v2 13/14] tcg/riscv: Implement vector roti/v/x shi ops
Quoted 21 lines · LIU Zhiwei
Quoted 1 line
I'm trying to work out how much benefit there is here of expanding these early, as opposed to simply using
TCG_REG_TMP0when the immediate doesn't fit,We find for rotli, it just copied code from the implementation of
INDEX_op_shli_vecandINDEX_op_shri_vecif we don't expand it.case INDEX_op_rotli_vec: if (a2 > 31) { tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_TMP0, TCG_REG_ZERO, a2); tcg_out_opc_vx(s, OPC_VSLL_VX, TCG_REG_V0, a1, TCG_REG_TMP0, true); } else { tcg_out_opc_vi(s, OPC_VSLL_VI, TCG_REG_V0, a1, a2, true); }if ((8 << vece) - a2) > 31) { tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_TMP0, TCG_REG_ZERO, 8 << vece) - a2); tcg_out_opc_vx(s, OPC_VSRL_VX, a0, a1, TCG_REG_TMP0, true); } else { tcg_out_opc_vi(s, OPC_VSRL_VI, a0, a1, 8 << vece) - a2, true); } tcg_out_opc_vv(s, OPC_VOR_VV, a0, a0, TCG_REG_V0, true); break;
Quoted 1 line
Thus, I prefer to expand it early, at least for
rotli_vec.
static void tcg_out_vshifti(TCGContext *s, RISCVInsn op_vi, RISCVInsn op_vx,
TCGReg dst, TCGReg src, unsigned imm)
{
if (imm < 32) {
tcg_out_opc_vi(s, op_vi, dst, src, imm);
} else {
tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_TMP0, imm);
tcg_out_opc_vx(s, op_vx, dst, src, TCG_REG_TMP0);
}
} case INDEX_op_shli_vec:
set_vconfig_vl_sew(s, type, vece);
tcg_out_vshifti(s, OPC_VSLL_VI, OPC_VSLL_VX, a0, a1, a2);
break;
case INDEX_op_rotli_vec:
set_vconfig_vl_sew(s, type, vece);
tcg_out_vshifti(s, OPC_VSLL_VI, OPC_VSLL_VX, TCG_REG_V0, a1, a2);
a2 = -a2 & ((8 << vece) - 1);
tcg_out_vshifti(s, OPC_VSRL_VI, OPC_VSRL_VX, a0, a1, a2);
tcg_out_opc_vv(s, OPC_VOR_VV, a0, a0, TCG_REG_V0);
break;r~
Re: [PATCH v2 13/14] tcg/riscv: Implement vector roti/v/x shi ops
Quoted 24 lines · Richard Henderson
Quoted 21 lines · LIU Zhiwei
Quoted 1 line
I'm trying to work out how much benefit there is here of expanding these early, as opposed to simply using
TCG_REG_TMP0when the immediate doesn't fit,We find for rotli, it just copied code from the implementation of
INDEX_op_shli_vecandINDEX_op_shri_vecif we don't expand it.case
INDEX_op_rotli_vec:
if (a2 > 31) {
tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_TMP0, TCG_REG_ZERO, a2);tcg_out_opc_vx(s, OPC_VSLL_VX, TCG_REG_V0, a1, TCG_REG_TMP0, true); } else {
tcg_out_opc_vi(s, OPC_VSLL_VI, TCG_REG_V0, a1, a2, true); }if ((8 << vece) - a2) > 31) {
tcg_out_opc_imm(s, OPC_ADDI, TCG_REG_TMP0, TCG_REG_ZERO, 8 << vece)- a2);tcg_out_opc_vx(s, OPC_VSRL_VX, a0, a1, TCG_REG_TMP0, true); } else {
tcg_out_opc_vi(s, OPC_VSRL_VI, a0, a1, 8 << vece)- a2, true); }
tcg_out_opc_vv(s, OPC_VOR_VV, a0, a0, TCG_REG_V0, true);
break;Quoted 1 line
Thus, I prefer to expand it early, at least for
rotli_vec.
Quoted 12 lines
static void
tcg_out_vshifti(TCGContext *s, RISCVInsn op_vi, RISCVInsn op_vx, TCGReg dst, TCGReg src, unsigned imm){
if (imm < 32) {
tcg_out_opc_vi(s, op_vi, dst, src, imm);
} else {
tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_TMP0, imm);tcg_out_opc_vx(s, op_vx, dst, src, TCG_REG_TMP0);
}
}
Thanks for the guide.
Quoted 5 lines
case
INDEX_op_shli_vec:
set_vconfig_vl_sew(s, type, vece);tcg_out_vshifti(s, OPC_VSLL_VI, OPC_VSLL_VX, a0, a1, a2); break;
Quoted 7 lines
case
INDEX_op_rotli_vec:
set_vconfig_vl_sew(s, type, vece);
tcg_out_vshifti(s, OPC_VSLL_VI, OPC_VSLL_VX, TCG_REG_V0, a1, a2); a2 = -a2 & ((8 << vece) - 1);
tcg_out_vshifti(s, OPC_VSRL_VI, OPC_VSRL_VX, a0, a1, a2);tcg_out_opc_vv(s, OPC_VOR_VV, a0, a0, TCG_REG_V0); break;
OK. We will take this way.
Thanks,
Zhiwei
Quoted 2 lines
r~
PATCH v2 14/14 tcg/riscv: Enable native vector support for TCG host
In reply to LIU ZhiweiFrom: TANG Tiancheng <[email protected]>
--- tcg/riscv/tcg-target.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tcg/riscv/tcg-target.h +5 -3
@@ -143,9 +143,11 @@ typedef enum {#define TCG_TARGET_HAS_tst 0/* vector instructions */ -#define TCG_TARGET_HAS_v64 0 -#define TCG_TARGET_HAS_v128 0 -#define TCG_TARGET_HAS_v256 0 +#define have_rvv (cpuinfo & CPUINFO_ZVE64X) + +#define TCG_TARGET_HAS_v64 have_rvv +#define TCG_TARGET_HAS_v128 have_rvv +#define TCG_TARGET_HAS_v256 have_rvv#define TCG_TARGET_HAS_andc_vec 0#define TCG_TARGET_HAS_orc_vec 0#define TCG_TARGET_HAS_nand_vec 0
Signature · 1 line
2.43.0
Re: [PATCH v2 14/14] tcg/riscv: Enable native vector support for TCG host
Quoted 7 lines · LIU Zhiwei
From: TANG Tiancheng<[email protected]>
Signed-off-by TANG Tiancheng<[email protected]>Reviewed-by Liu Zhiwei<[email protected]>--- tcg/riscv/tcg-target.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
r~