target/mips: add missing Octeon user-mode support (first half)
v11 cover target/mips: add missing Octeon user-mode support (first half)
Respinning first half of James v10, adding tests with each patch modifying an instruction instead of all at the end. Split SEQNE/SEQNEI patch to ease review.
James Hilliard (23):
linux-user/mips: implement sysmips(MIPS_FLUSH_CACHE) linux-user/mips: implement sysmips(MIPS_ATOMIC_SET) linux-user/mips, target/mips: honor MIPS_FIXADE for unaligned accesses target/mips: expose Octeon68XX floating-point support tests/tcg/mips: add Octeon instruction smoke test target/mips: fix Octeon arithmetic destination handling target/mips: drop Octeon zero-register fast paths target/mips: split Octeon SEQ/SNE decode
target/mips: split Octeon SEQI/SNEI decode
target/mips: add Octeon LBX instruction
target/mips: add Octeon LHUX instruction
target/mips: add Octeon LWUX instruction
target/mips: add Octeon SAA instruction
target/mips: add Octeon SAAD instruction
target/mips: add Octeon ZCB and ZCBT instructions target/mips: add Octeon multiplier state
target/mips: add Octeon MTM instructions
target/mips: add Octeon MTP instructions
target/mips: add Octeon VMULU instruction
target/mips: add Octeon VMM0 instruction
target/mips: add Octeon V3MULU instruction
target/mips: add Octeon QMAC instructions
target/mips: add Octeon LA* atomic instructions
Richard Henderson (1):
tcg: Introduce tcg_gen_addN_i64
MAINTAINERS | 2 +- include/tcg/tcg-op-common.h | 1 + linux-user/mips/target_syscall.h | 3 + linux-user/mips64/target_syscall.h | 3 + target/mips/cpu.h | 16 + target/mips/tcg/translate.h | 2 + target/mips/tcg/octeon.decode | 54 ++- linux-user/mips/cpu_loop.c | 5 + linux-user/syscall.c | 56 +++ target/mips/cpu.c | 10 +- target/mips/system/machine.c | 33 ++ target/mips/tcg/octeon_translate.c | 411 +++++++++++++++--- target/mips/tcg/translate.c | 24 +- tcg/tcg-op.c | 42 ++ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 204 +++++++++ target/mips/cpu-defs.c.inc | 10 +- tests/tcg/mips64/Makefile.target | 20 + tests/tcg/mips64el/Makefile.target | 8 + 18 files changed, 844 insertions(+), 60 deletions(-) create mode 100644 tests/tcg/mips/user/isa/octeon/octeon-insns.c create mode 100644 tests/tcg/mips64/Makefile.target create mode 100644 tests/tcg/mips64el/Makefile.target
Signature · 1 line
2.53.0
PATCH v11 1/24 linux-user/mips: implement sysmips(MIPS_FLUSH_CACHE)
From: James Hilliard <[email protected]>
Add the target sysmips dispatcher and implement MIPS_FLUSH_CACHE as a successful no-op for linux-user.
Self-modifying code is handled by QEMU's normal user-mode translation invalidation machinery, so the target ABI only needs the syscall command to be accepted.
--- linux-user/mips/target_syscall.h | 1 + linux-user/mips64/target_syscall.h | 1 + linux-user/syscall.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+)
linux-user/mips/target_syscall.h +1 -0
@@ -10,6 +10,7 @@#define TARGET_MCL_ONFAULT 4#define TARGET_FORCE_SHMLBA +#define TARGET_SYSMIPS_FLUSH_CACHE 3static inline abi_ulong target_shmlba (CPUMIPSState *env) {
linux-user/mips64/target_syscall.h +1 -0
@@ -10,6 +10,7 @@#define TARGET_MCL_ONFAULT 4#define TARGET_FORCE_SHMLBA +#define TARGET_SYSMIPS_FLUSH_CACHE 3static inline abi_ulong target_shmlba (CPUMIPSState *env) {
linux-user/syscall.c +17 -0
@@ -6630,6 +6630,19 @@ static abi_long do_prctl_syscall_user_dispatch(CPUArchState *env, } } +#ifdef TARGET_NR_sysmips +static abi_long do_sysmips (CPUArchState *env,abi_long cmd,abi_long arg1, +abi_long arg2) +{ +switch (cmd) { +case TARGET_SYSMIPS_FLUSH_CACHE : +return 0 ; +default : +return -TARGET_EINVAL ; + } +} +#endif +static abi_long do_prctl (CPUArchState *env,abi_long option,abi_long arg2,abi_long arg3,abi_long arg4,abi_long arg5) {
@@ -12110,6 +12123,10 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,case TARGET_NR_prctl:return do_prctl (cpu_env, arg1, arg2, arg3, arg4, arg5);break ; +#ifdef TARGET_NR_sysmips +case TARGET_NR_sysmips: +return do_sysmips (cpu_env, arg1, arg2, arg3); +#endif #ifdef TARGET_NR_arch_prctlcase TARGET_NR_arch_prctl:return do_arch_prctl (cpu_env, arg1, arg2);
Signature · 1 line
2.53.0
PATCH v11 2/24 linux-user/mips: implement sysmips(MIPS_ATOMIC_SET)
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
Implement the MIPS_ATOMIC_SET sysmips command as an aligned 32-bit atomic exchange in target memory.
MIPS reports syscall errors through a separate register, so successful old values can overlap the errno range. Write the return value and error flag directly and return -QEMU_ESIGRETURN so the common syscall path leaves the registers unchanged.
--- linux-user/mips/target_syscall.h | 1 + linux-user/mips64/target_syscall.h | 1 + linux-user/syscall.c | 31 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+)
linux-user/mips/target_syscall.h +1 -0
@@ -11,6 +11,7 @@#define TARGET_FORCE_SHMLBA #define TARGET_SYSMIPS_FLUSH_CACHE 3 +#define TARGET_SYSMIPS_ATOMIC_SET 2001static inline abi_ulong target_shmlba (CPUMIPSState *env) {
linux-user/mips64/target_syscall.h +1 -0
@@ -11,6 +11,7 @@#define TARGET_FORCE_SHMLBA #define TARGET_SYSMIPS_FLUSH_CACHE 3 +#define TARGET_SYSMIPS_ATOMIC_SET 2001static inline abi_ulong target_shmlba (CPUMIPSState *env) {
linux-user/syscall.c +31 -0
@@ -6631,10 +6631,41 @@ static abi_long do_prctl_syscall_user_dispatch(CPUArchState *env, }#ifdef TARGET_NR_sysmips +static abi_long do_sysmips_atomic_set (CPUArchState *env,abi_ulong addr, +abi_long value) +{ +uint32_t *ptr; +abi_long old; + +if (addr &3 ) { +return -TARGET_EINVAL ; + } + + ptr =lock_user (VERIFY_WRITE , addr,sizeof (*ptr), true); +if (!ptr) { +return -TARGET_EINVAL ; + } + + old =tswap32 (qatomic_xchg (ptr,tswap32 ((uint32_t )value))); +unlock_user (ptr, addr,sizeof (*ptr)); + +/* +* MIPS uses a separate error flag, but the common linux-user syscall +* path infers that flag from the return value. Successful atomic_set +* results can overlap the target errno range, so write the result +* registers here and ask the CPU loop to leave them alone. +*/ + env->active_tc.gpr[2 ] = old; + env->active_tc.gpr[7 ] =0 ; +return -QEMU_ESIGRETURN ; +} +static abi_long do_sysmips (CPUArchState *env,abi_long cmd,abi_long arg1,abi_long arg2) {switch (cmd) { +case TARGET_SYSMIPS_ATOMIC_SET : +return do_sysmips_atomic_set (env, arg1, arg2);case TARGET_SYSMIPS_FLUSH_CACHE :return 0 ;default :
Signature · 1 line
2.53.0
PATCH v11 3/24 linux-user/mips, target/mips: honor MIPS_FIXADE for unaligned accesses
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
Linux/MIPS enables software fixups for user-mode unaligned scalar accesses by default through MIPS_FIXADE/TIF_FIXADE. QEMU linux-user did not model that ABI, so MIPS guests took fatal AdEL/AdES exceptions unless translation was forced to use unaligned host accesses.
Key MIPS translation blocks on the linux-user unaligned policy, implement sysmips(MIPS_FIXADE) to toggle that policy, and raise SIGBUS/BUS_ADRALN when fixups are disabled.
--- linux-user/mips/target_syscall.h | 1 + linux-user/mips64/target_syscall.h | 1 + target/mips/cpu.h | 4 ++++ linux-user/mips/cpu_loop.c | 5 +++++ linux-user/syscall.c | 8 ++++++++ target/mips/cpu.c | 10 ++++++++-- target/mips/tcg/translate.c | 6 +++++- 7 files changed, 32 insertions(+), 3 deletions(-)
linux-user/mips/target_syscall.h +1 -0
@@ -11,6 +11,7 @@#define TARGET_FORCE_SHMLBA #define TARGET_SYSMIPS_FLUSH_CACHE 3 +#define TARGET_SYSMIPS_FIXADE 7#define TARGET_SYSMIPS_ATOMIC_SET 2001static inline abi_ulong target_shmlba (CPUMIPSState *env)
linux-user/mips64/target_syscall.h +1 -0
@@ -11,6 +11,7 @@#define TARGET_FORCE_SHMLBA #define TARGET_SYSMIPS_FLUSH_CACHE 3 +#define TARGET_SYSMIPS_FIXADE 7#define TARGET_SYSMIPS_ATOMIC_SET 2001static inline abi_ulong target_shmlba (CPUMIPSState *env)
target/mips/cpu.h +4 -0
@@ -1161,6 +1161,10 @@ typedef struct CPUArchState {#define MIPS_HFLAG_ELPA 0x4000000#define MIPS_HFLAG_ITC_CACHE 0x8000000/* CACHE instr. operates on ITC tag */ #define MIPS_HFLAG_ERL 0x10000000/* error level flag */ +#define MIPS_HFLAG_TB_MASK (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK | \ + MIPS_HFLAG_HWRENA_ULR) + +#define TB_FLAG_MIPS_FIXADE 0x40000000target_ulong btarget;/* Jump / branch target */ target_ulong bcond;/* Branch condition (if needed) */
linux-user/mips/cpu_loop.c +5 -0
@@ -161,6 +161,11 @@ done_syscall:case EXCP_DSPDIS :force_sig (TARGET_SIGILL );break ; +case EXCP_AdEL: +case EXCP_AdES: +force_sig_fault (TARGET_SIGBUS ,TARGET_BUS_ADRALN , + env->CP0_BadVAddr); +break ;case EXCP_INTERRUPT :/* just indicate that signals should be handled asap */ break ;
linux-user/syscall.c +8 -0
@@ -6663,9 +6663,17 @@ static abi_long do_sysmips_atomic_set(CPUArchState *env, abi_ulong addr,static abi_long do_sysmips (CPUArchState *env,abi_long cmd,abi_long arg1,abi_long arg2) { +CPUState *cs =env_cpu (env); +switch (cmd) {case TARGET_SYSMIPS_ATOMIC_SET :return do_sysmips_atomic_set (env, arg1, arg2); +case TARGET_SYSMIPS_FIXADE : +if (arg1 & ~3 ) { +return -TARGET_EINVAL ; + } + cs->prctl_unalign_sigbus = !(arg1 &1 ); +return 0 ;case TARGET_SYSMIPS_FLUSH_CACHE :return 0 ;default :
target/mips/cpu.c +8 -2
@@ -565,11 +565,17 @@ static int mips_cpu_mmu_index(CPUState *cs, bool ifunc)static TCGTBCPUState mips_get_tb_cpu_state (CPUState *cs) {CPUMIPSState *env =cpu_env (cs); +uint32_t flags = env->hflags &MIPS_HFLAG_TB_MASK ; + +#ifdef CONFIG_USER_ONLY +if (!cs->prctl_unalign_sigbus) { + flags |=TB_FLAG_MIPS_FIXADE ; + } +#endif return (TCGTBCPUState ){ .pc = env->active_tc.PC, - .flags = env->hflags & (MIPS_HFLAG_TMASK |MIPS_HFLAG_BMASK | -MIPS_HFLAG_HWRENA_ULR ), + .flags = flags, }; }
target/mips/tcg/translate.c +5 -1
@@ -15070,6 +15070,7 @@ static void mips_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) {DisasContext *ctx =container_of (dcbase, DisasContext, base);CPUMIPSState *env =cpu_env (cs); +uint32_t tb_flags = ctx->base.tb->flags; ctx->page_start = ctx->base.pc_first &TARGET_PAGE_MASK ; ctx->saved_pc =-1 ;
@@ -15092,7 +15093,7 @@ static void mips_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->CP0_LLAddr_shift = env->CP0_LLAddr_shift; ctx->cmgcr = (env->CP0_Config3 >>CP0C3_CMGCR ) &1 ;/* Restore delay slot state from the tb context. */ - ctx->hflags = (uint32_t )ctx->base.tb->flags;/* FIXME: maybe use 64 bits? */ + ctx->hflags = tb_flags &MIPS_HFLAG_TB_MASK ; ctx->ulri = (env->CP0_Config3 >>CP0C3_ULRI ) &1 ; ctx->ps = ((env->active_fpu.fcr0 >>FCR0_PS ) &1 ) || (env->insn_flags & (INSN_LOONGSON2E |INSN_LOONGSON2F ));
@@ -15112,6 +15113,9 @@ static void mips_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->default_tcg_memop_mask = (!(ctx->insn_flags &ISA_NANOMIPS32 ) && (ctx->insn_flags & (ISA_MIPS_R6 |INSN_LOONGSON3A ))) ?MO_UNALN :MO_ALIGN ; +if (tb_flags &TB_FLAG_MIPS_FIXADE ) { + ctx->default_tcg_memop_mask =MO_UNALN ; + }/* * Execute a branch and its delay slot as a single instruction.
Signature · 1 line
2.53.0
PATCH v11 4/24 target/mips: expose Octeon68XX floating-point support
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
Octeon68XX cores implement CP1. Advertise that in the CPU definition by setting Config1.FP, enabling the writable Status bits, and providing the FCR0/FCR31 defaults used by this CPU model.
This lets guests observe the expected floating-point feature bits and use CP1 with -cpu Octeon68XX.
--- target/mips/cpu-defs.c.inc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
target/mips/cpu-defs.c.inc +8 -2
@@ -997,7 +997,8 @@ const mips_def_t mips_defs[] = .CP0_PRid = 0x000D9100, .CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) | (MMU_TYPE_R4000 << CP0C0_MT), - .CP0_Config1 = MIPS_CONFIG1 | (0x3F << CP0C1_MMU) | + .CP0_Config1 = MIPS_CONFIG1 | (1 << CP0C1_FP) | + (0x3F << CP0C1_MMU) | (1 << CP0C1_IS) | (4 << CP0C1_IL) | (1 << CP0C1_IA) | (1 << CP0C1_DS) | (4 << CP0C1_DL) | (1 << CP0C1_DA) | (1 << CP0C1_PC) | (1 << CP0C1_WR) | (1 << CP0C1_EP),
@@ -1011,7 +1012,12 @@ const mips_def_t mips_defs[] = .CP0_PageGrain = (1 << CP0PG_ELPA), .SYNCI_Step = 32, .CCRes = 2, - .CP0_Status_rw_bitmask = 0x12F8FFFF, + .CP0_Status_rw_bitmask = 0x36F8FFFF, + .CP1_fcr0 = (1 << FCR0_F64) | (1 << FCR0_3D) | (1 << FCR0_PS) | + (1 << FCR0_L) | (1 << FCR0_W) | (1 << FCR0_D) | + (1 << FCR0_S) | (0x00 << FCR0_PRID) | (0x0 << FCR0_REV), + .CP1_fcr31 = 0, + .CP1_fcr31_rw_bitmask = 0xFF83FFFF, .SEGBITS = 42, .PABITS = 49, .insn_flags = CPU_MIPS64R2 | INSN_OCTEON,
Signature · 1 line
2.53.0
PATCH v11 5/24 tests/tcg/mips: add Octeon instruction smoke test
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
Add a mips64/mips64el linux-user TCG smoke test for representative Octeon instruction paths.
Run the test with -cpu Octeon68XX and share the source between the mips64 and mips64el target directories.
--- MAINTAINERS | 2 +- tests/tcg/mips/user/isa/octeon/octeon-insns.c | 13 ++++++++++++ tests/tcg/mips64/Makefile.target | 20 +++++++++++++++++++ tests/tcg/mips64el/Makefile.target | 8 ++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/mips/user/isa/octeon/octeon-insns.c create mode 100644 tests/tcg/mips64/Makefile.target create mode 100644 tests/tcg/mips64el/Makefile.target
MAINTAINERS +1 -1
@@ -310,7 +310,7 @@ S: Odd Fixes F: target/mips/ F: disas/*mips.c F: docs/system/cpu-models-mips.rst.inc -F: tests/tcg/mips/ +F: tests/tcg/mips*/ OpenRISC TCG CPUs M: Stafford Horne <[email protected]>
tests/tcg/mips/user/isa/octeon/octeon-insns.c new file +13 -0
@@ -0,0 +1,13 @@ +/* +* Test Octeon-specific user-mode instructions. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include <assert.h> +#include <stdint.h> + +int main (void ) +{ +return 0 ; +}
tests/tcg/mips64/Makefile.target new file +20 -0
@@ -0,0 +1,20 @@ +# -*- Mode: makefile -*- +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# MIPS64 - included from tests/tcg/Makefile.target +# + +MIPS64_SRC=$(SRC_PATH)/tests/tcg/mips64 +MIPS_OCTEON_SRC=$(SRC_PATH)/tests/tcg/mips/user/isa/octeon + +# Set search path for all sources +VPATH += $(MIPS64_SRC) $(MIPS_OCTEON_SRC) + +MIPS64_TESTS=octeon-insns + +TESTS += $(MIPS64_TESTS) + +$(MIPS64_TESTS): CFLAGS+=-mabi=64 + +run-octeon-insns: QEMU_OPTS+=-cpu Octeon68XX
tests/tcg/mips64el/Makefile.target new file +8 -0
@@ -0,0 +1,8 @@ +# -*- Mode: makefile -*- +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# MIPS64 little-endian - included from tests/tcg/Makefile.target +# + +include $(SRC_PATH)/tests/tcg/mips64/Makefile.target
Signature · 1 line
2.53.0
Re: [PATCH v11 05/24] tests/tcg/mips: add Octeon instruction smoke test
Quoted 17 lines · Philippe Mathieu-Daudé
From: James Hilliard<[email protected]>
Add a mips64/mips64el linux-user TCG smoke test for representative Octeon instruction paths.
Run the test with -cpu Octeon68XX and share the source between the mips64 and mips64el target directories.
Signed-off-by James Hilliard<[email protected]>Reviewed-by Philippe Mathieu-Daudé<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- MAINTAINERS | 2 +- tests/tcg/mips/user/isa/octeon/octeon-insns.c | 13 ++++++++++++ tests/tcg/mips64/Makefile.target | 20 +++++++++++++++++++ tests/tcg/mips64el/Makefile.target | 8 ++++++++ 4 files changed, 42 insertions(+), 1 deletion(-)
Quoted 3 lines
create mode 100644
tests/tcg/mips/user/isa/octeon/octeon-insns.ccreate mode 100644 tests/tcg/mips64/Makefile.target create mode 100644 tests/tcg/mips64el/Makefile.target
r~
PATCH v11 6/24 target/mips: fix Octeon arithmetic destination handling
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
BADDU and DMUL write their results to rd, not rt. Route writes through gen_store_gpr() so rd == $zero is handled consistently.
--- target/mips/tcg/octeon_translate.c | 16 +++------ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 12 deletions(-)
target/mips/tcg/octeon_translate.c +4 -12
@@ -45,18 +45,14 @@ static bool trans_BADDU(DisasContext *ctx, arg_BADDU *a) {TCGv_i64 t0, t1; -if (a->rt ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 (); t1 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);gen_load_gpr (t1, a->rt);tcg_gen_add_i64 (t0, t0, t1); -tcg_gen_andi_i64 (cpu_gpr[a->rd], t0,0xff ); +tcg_gen_andi_i64 (t0, t0,0xff ); +gen_store_gpr (t0, a->rd);return true; }
@@ -64,17 +60,13 @@ static bool trans_DMUL(DisasContext *ctx, arg_DMUL *a) {TCGv_i64 t0, t1; -if (a->rt ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 (); t1 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);gen_load_gpr (t1, a->rt); -tcg_gen_mul_i64 (cpu_gpr[a->rd], t0, t1); +tcg_gen_mul_i64 (t0, t0, t1); +gen_store_gpr (t0, a->rd);return true; }
tests/tcg/mips/user/isa/octeon/octeon-insns.c +35 -0
@@ -7,7 +7,42 @@#include <assert.h> #include <stdint.h> +static uint64_t octeon_baddu (uint64_t rs,uint64_t rt) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[rs]\n\t" +"move $9, %[rt]\n\t" +".word 0x71095028\n\t" /* baddu $10, $8, $9 */ +"move %[rd], $10\n\t" + : [rd]"=r" (rd) + : [rs]"r" (rs), [rt]"r" (rt) + :"$8" ,"$9" ,"$10" ); + +return rd; +} + +static uint64_t octeon_dmul (uint64_t rs,uint64_t rt) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[rs]\n\t" +"move $9, %[rt]\n\t" +".word 0x71095003\n\t" /* dmul $10, $8, $9 */ +"move %[rd], $10\n\t" + : [rd]"=r" (rd) + : [rs]"r" (rs), [rt]"r" (rt) + :"$8" ,"$9" ,"$10" ); + +return rd; +} +int main (void ) { +assert (octeon_baddu (0x123 ,0x0f0 ) ==0x13 ); +assert (octeon_dmul (0x12345678 ,0x10 ) ==0x123456780 ); +return 0 ; }
Signature · 1 line
2.53.0
PATCH v11 7/24 target/mips: drop Octeon zero-register fast paths
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
EXTS, CINS, and POP route their destination writes through gen_store_gpr(), which already discards writes to $zero. Remove the remaining translator fast paths for destination $zero so these Octeon instructions follow the same shape as BADDU/DMUL and the generic MIPS translator helpers.
Add a mips64/mips64el linux-user TCG smoke test for representative Octeon population count instruction paths.
--- target/mips/tcg/octeon_translate.c | 15 --------------- tests/tcg/mips/user/isa/octeon/octeon-insns.c | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 15 deletions(-)
target/mips/tcg/octeon_translate.c +0 -15
@@ -74,11 +74,6 @@ static bool trans_EXTS(DisasContext *ctx, arg_EXTS *a) {TCGv_i64 t0; -if (a->rt ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);tcg_gen_sextract_i64 (t0, t0, a->p, a->lenm1 +1 );
@@ -90,11 +85,6 @@ static bool trans_CINS(DisasContext *ctx, arg_CINS *a) {TCGv_i64 t0; -if (a->rt ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);tcg_gen_deposit_z_i64 (t0, t0, a->p, a->lenm1 +1 );
@@ -106,11 +96,6 @@ static bool trans_POP(DisasContext *ctx, arg_POP *a) {TCGv_i64 t0; -if (a->rd ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);if (!a->dw) {
tests/tcg/mips/user/isa/octeon/octeon-insns.c +16 -0
@@ -39,10 +39,26 @@ static uint64_t octeon_dmul(uint64_t rs, uint64_t rt)return rd; } +static uint64_t octeon_dpop (uint64_t rs) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[rs]\n\t" +".word 0x7100502d\n\t" /* dpop $10, $8 */ +"move %[rd], $10\n\t" + : [rd]"=r" (rd) + : [rs]"r" (rs) + :"$8" ,"$10" ); + +return rd; +} +int main (void ) {assert (octeon_baddu (0x123 ,0x0f0 ) ==0x13 );assert (octeon_dmul (0x12345678 ,0x10 ) ==0x123456780 ); +assert (octeon_dpop (0xf0f0f0f0f0f0f0f0ULL ) ==32 );return 0 ; }
Signature · 1 line
2.53.0
PATCH v11 8/24 target/mips: split Octeon SEQ/SNE decode
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
Decode the equality and inequality forms as explicit SEQ/SNE instructions rather than using shared generated SEQNE entries.
The explicit decoder names match the architectural mnemonics, which makes the translator entry points and trace/debug output easier to correlate with the instruction set.
--- target/mips/tcg/octeon.decode | 3 +- target/mips/tcg/octeon_translate.c | 25 +++++++------ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 36 +++++++++++++++++++ 3 files changed, 52 insertions(+), 12 deletions(-)
target/mips/tcg/octeon.decode +2 -1
@@ -38,7 +38,8 @@ DMUL 011100 ..... ..... ..... 00000 000011 @r3 EXTS 011100 ..... ..... ..... ..... 11101 . @bitfield CINS 011100 ..... ..... ..... ..... 11001 . @bitfield POP 011100 rs:5 00000 rd:5 00000 10110 dw:1 -SEQNE 011100 rs:5 rt:5 rd:5 00000 10101 ne:1 +SEQ 011100 ..... ..... ..... 00000 101010 @r3 +SNE 011100 ..... ..... ..... 00000 101011 @r3 SEQNEI 011100 rs:5 rt:5 imm:s10 10111 ne:1 &lx base index rd
target/mips/tcg/octeon_translate.c +14 -11
@@ -106,29 +106,32 @@ static bool trans_POP(DisasContext *ctx, arg_POP *a)return true; } -static bool trans_SEQNE (DisasContext *ctx,arg_SEQNE *a) +static bool do_seq_sne (DisasContext *ctx,const arg_decode_ext_octeon1 *a, +TCGCond cond) {TCGv_i64 t0, t1; -if (a->rd ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 (); t1 =tcg_temp_new_i64 ();gen_load_gpr (t0, a->rs);gen_load_gpr (t1, a->rt); -if (a->ne) { -tcg_gen_setcond_i64 (TCG_COND_NE , cpu_gpr[a->rd], t1, t0); - }else { -tcg_gen_setcond_i64 (TCG_COND_EQ , cpu_gpr[a->rd], t1, t0); - } +tcg_gen_setcond_i64 (cond, t0, t1, t0); +gen_store_gpr (t0, a->rd);return true; } +static bool trans_SEQ (DisasContext *ctx,arg_SEQ *a) +{ +return do_seq_sne (ctx, a,TCG_COND_EQ ); +} + +static bool trans_SNE (DisasContext *ctx,arg_SNE *a) +{ +return do_seq_sne (ctx, a,TCG_COND_NE ); +} +static bool trans_SEQNEI (DisasContext *ctx,arg_SEQNEI *a) {TCGv_i64 t0;
tests/tcg/mips/user/isa/octeon/octeon-insns.c +36 -0
@@ -54,11 +54,47 @@ static uint64_t octeon_dpop(uint64_t rs)return rd; } +static uint64_t octeon_seq (uint64_t rs,uint64_t rt) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[rs]\n\t" +"move $9, %[rt]\n\t" +".word 0x7109502a\n\t" /* seq $10, $8, $9 */ +"move %[rd], $10\n\t" + : [rd]"=r" (rd) + : [rs]"r" (rs), [rt]"r" (rt) + :"$8" ,"$9" ,"$10" ); + +return rd; +} + +static uint64_t octeon_sne (uint64_t rs,uint64_t rt) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[rs]\n\t" +"move $9, %[rt]\n\t" +".word 0x7109502b\n\t" /* sne $10, $8, $9 */ +"move %[rd], $10\n\t" + : [rd]"=r" (rd) + : [rs]"r" (rs), [rt]"r" (rt) + :"$8" ,"$9" ,"$10" ); + +return rd; +} +int main (void ) {assert (octeon_baddu (0x123 ,0x0f0 ) ==0x13 );assert (octeon_dmul (0x12345678 ,0x10 ) ==0x123456780 );assert (octeon_dpop (0xf0f0f0f0f0f0f0f0ULL ) ==32 ); +assert (octeon_seq (0xabc ,0xabc ) ==1 ); +assert (octeon_seq (0xabc ,0xdef ) ==0 ); +assert (octeon_sne (0xabc ,0xabc ) ==0 ); +assert (octeon_sne (0xabc ,0xdef ) ==1 );return 0 ; }
Signature · 1 line
2.53.0
Re: [PATCH v11 08/24] target/mips: split Octeon SEQ/SNE decode
Quoted 13 lines · Philippe Mathieu-Daudé
From: James Hilliard <[email protected]>
Decode the equality and inequality forms as explicit SEQ/SNE instructions rather than using shared generated SEQNE entries.
The explicit decoder names match the architectural mnemonics, which makes the translator entry points and trace/debug output easier to correlate with the instruction set.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>[PMD: Split SEQNE (this patch) vs SEQNEI]Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 5 lines
--- target/mips/tcg/octeon.decode | 3 +- target/mips/tcg/octeon_translate.c | 25 +++++++------ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 36 +++++++++++++++++++ 3 files changed, 52 insertions(+), 12 deletions(-)
PATCH v11 9/24 target/mips: split Octeon SEQI/SNEI decode
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
Decode the equality and inequality forms as explicit SEQI/SNEI instructions rather than using shared generated SEQNEI entries.
The explicit decoder names match the architectural mnemonics, which makes the translator entry points and trace/debug output easier to correlate with the instruction set.
--- target/mips/tcg/octeon.decode | 4 +++- target/mips/tcg/octeon_translate.c | 27 +++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-)
target/mips/tcg/octeon.decode +3 -1
@@ -30,6 +30,7 @@ BBIT 11 set:1 . 10 rs:5 ..... offset:s16 p=%bbit_p # SNEI rt, rs, immediate @r3 ...... rs:5 rt:5 rd:5 ..... ...... +&cmpi rs rt imm %bitfield_p 0:1 6:5 @bitfield ...... rs:5 rt:5 lenm1:5 ..... ..... . p=%bitfield_p
@@ -40,7 +41,8 @@ CINS 011100 ..... ..... ..... ..... 11001 . @bitfield POP 011100 rs:5 00000 rd:5 00000 10110 dw:1 SEQ 011100 ..... ..... ..... 00000 101010 @r3 SNE 011100 ..... ..... ..... 00000 101011 @r3 -SEQNEI 011100 rs:5 rt:5 imm:s10 10111 ne:1 +SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi +SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx
target/mips/tcg/octeon_translate.c +13 -14
@@ -132,29 +132,28 @@ static bool trans_SNE(DisasContext *ctx, arg_SNE *a)return do_seq_sne (ctx, a,TCG_COND_NE ); } -static bool trans_SEQNEI (DisasContext *ctx,arg_SEQNEI *a) +static bool do_seqi_snei (DisasContext *ctx,const arg_cmpi *a,TCGCond cond) {TCGv_i64 t0; -if (a->rt ==0 ) { -/* nop */ -return true; - } - t0 =tcg_temp_new_i64 (); -gen_load_gpr (t0, a->rs); -/* Sign-extend to 64 bit value */ -target_ulong imm = a->imm; -if (a->ne) { -tcg_gen_setcondi_i64 (TCG_COND_NE , cpu_gpr[a->rt], t0, imm); - }else { -tcg_gen_setcondi_i64 (TCG_COND_EQ , cpu_gpr[a->rt], t0, imm); - } +tcg_gen_setcondi_i64 (cond, t0, t0, a->imm); +gen_store_gpr (t0, a->rt);return true; } +static bool trans_SEQI (DisasContext *ctx,arg_SEQI *a) +{ +return do_seqi_snei (ctx, a,TCG_COND_EQ ); +} + +static bool trans_SNEI (DisasContext *ctx,arg_SNEI *a) +{ +return do_seqi_snei (ctx, a,TCG_COND_NE ); +} +static bool trans_lx (DisasContext *ctx,arg_lx *a,MemOp mop) {gen_lx (ctx, a->rd, a->base, a->index, mop);
Signature · 1 line
2.53.0
Re: [PATCH v11 09/24] target/mips: split Octeon SEQI/SNEI decode
Quoted 9 lines · Philippe Mathieu-Daudé
From: James Hilliard <[email protected]>
Decode the equality and inequality forms as explicit SEQI/SNEI instructions rather than using shared generated SEQNEI entries.
The explicit decoder names match the architectural mnemonics, which makes the translator entry points and trace/debug output easier to correlate with the instruction set.
Quoted 8 lines
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>[PMD: Split SEQNE vs SEQNEI (this patch)]Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/octeon.decode | 4 +++- target/mips/tcg/octeon_translate.c | 27 +++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-)
PATCH v11 10/24 target/mips: add Octeon LBX instruction
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
LBX performs an indexed signed byte load from base + index and writes the sign-extended result to rd.
Wire the existing indexed-load helper to MO_SB so Octeon user-mode binaries can use the signed byte variant alongside the existing LBUX path.
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -49,4 +49,5 @@ SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi LWX 011111 ..... ..... ..... 00000 001010 @lx LHX 011111 ..... ..... ..... 00100 001010 @lx LBUX 011111 ..... ..... ..... 00110 001010 @lx +LBX 011111 ..... ..... ..... 10110 001010 @lx LDX 011111 ..... ..... ..... 01000 001010 @lx
target/mips/tcg/octeon_translate.c +1 -0
@@ -161,6 +161,7 @@ static bool trans_lx(DisasContext *ctx, arg_lx *a, MemOp mop)return true; } +TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW );TRANS (LWX , trans_lx,MO_SL );
Signature · 1 line
2.53.0
PATCH v11 11/24 target/mips: add Octeon LHUX instruction
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
LHUX performs an indexed unsigned halfword load from base + index and zero-extends the result into rd.
Add the decode entry and reuse the common indexed-load translator with MO_UW.
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -48,6 +48,7 @@ SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi @lx ...... base:5 index:5 rd:5 ...... ..... &lx LWX 011111 ..... ..... ..... 00000 001010 @lx LHX 011111 ..... ..... ..... 00100 001010 @lx +LHUX 011111 ..... ..... ..... 10100 001010 @lx LBUX 011111 ..... ..... ..... 00110 001010 @lx LBX 011111 ..... ..... ..... 10110 001010 @lx LDX 011111 ..... ..... ..... 01000 001010 @lx
target/mips/tcg/octeon_translate.c +1 -0
@@ -164,5 +164,6 @@ static bool trans_lx(DisasContext *ctx, arg_lx *a, MemOp mop)TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW ); +TRANS (LHUX , trans_lx,MO_UW );TRANS (LWX , trans_lx,MO_SL );TRANS (LDX , trans_lx,MO_UQ );
Signature · 1 line
2.53.0
PATCH v11 12/24 target/mips: add Octeon LWUX instruction
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
LWUX performs an indexed unsigned word load from base + index and zero-extends the result into rd.
Add the decode entry and route it through the common indexed-load translator with MO_UL.
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -50,5 +50,6 @@ LWX 011111 ..... ..... ..... 00000 001010 @lx LHX 011111 ..... ..... ..... 00100 001010 @lx LHUX 011111 ..... ..... ..... 10100 001010 @lx LBUX 011111 ..... ..... ..... 00110 001010 @lx +LWUX 011111 ..... ..... ..... 10000 001010 @lx LBX 011111 ..... ..... ..... 10110 001010 @lx LDX 011111 ..... ..... ..... 01000 001010 @lx
target/mips/tcg/octeon_translate.c +1 -0
@@ -166,4 +166,5 @@ TRANS(LBUX, trans_lx, MO_UB);TRANS (LHX , trans_lx,MO_SW );TRANS (LHUX , trans_lx,MO_UW );TRANS (LWX , trans_lx,MO_SL ); +TRANS (LWUX , trans_lx,MO_UL );TRANS (LDX , trans_lx,MO_UQ );
Signature · 1 line
2.53.0
PATCH v11 13/24 target/mips: add Octeon SAA instruction
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
SAA atomically adds rt to the naturally aligned 32-bit word at base and discards the old memory value.
Implement the common SAA/SAAD translator with TCG atomic_fetch_add_i64. The MemOp selects the word or doubleword transaction size. QEMU only has one Octeon CPU model today, so keep SAA/SAAD under the existing Octeon instruction feature bucket instead of adding a finer-grained Octeon+ feature bit.
--- target/mips/tcg/octeon.decode | 4 ++++ target/mips/tcg/octeon_translate.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+)
target/mips/tcg/octeon.decode +4 -0
@@ -44,6 +44,10 @@ SNE 011100 ..... ..... ..... 00000 101011 @r3 SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi +&saa base rt +@saa ...... base:5 rt:5 ................ &saa +SAA 011100 ..... ..... 00000 00000 011000 @saa + &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx LWX 011111 ..... ..... ..... 00000 001010 @lx
target/mips/tcg/octeon_translate.c +14 -0
@@ -161,6 +161,20 @@ static bool trans_lx(DisasContext *ctx, arg_lx *a, MemOp mop)return true; } +static bool trans_saa (DisasContext *ctx,arg_saa *a,MemOp mop) +{ +TCGv_i64 addr =tcg_temp_new_i64 (); +TCGv_i64 value =tcg_temp_new_i64 (); +TCGv_i64 old =tcg_temp_new_i64 (); +MemOp amo =mo_endian (ctx) | mop |MO_ALIGN ; + +gen_base_offset_addr (ctx, addr, a->base,0 ); +gen_load_gpr (value, a->rt); +tcg_gen_atomic_fetch_add_i64 (old, addr, value, ctx->mem_idx, amo); +return true; +} + +TRANS (SAA , trans_saa,MO_32 );TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW );
Signature · 1 line
2.53.0
Re: [PATCH v11 13/24] target/mips: add Octeon SAA instruction
Quoted 11 lines · Philippe Mathieu-Daudé
From: James Hilliard <[email protected]>
SAA atomically adds rt to the naturally aligned 32-bit word at base and discards the old memory value.
Implement the common SAA/SAAD translator with TCG
atomic_fetch_add_i64. The MemOp selects the word or doubleword transaction size. QEMU only has one Octeon CPU model today, so keep SAA/SAAD under the existing Octeon instruction feature bucket instead of adding a finer-grained Octeon+ feature bit.
Quoted 7 lines
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/octeon.decode | 4 ++++ target/mips/tcg/octeon_translate.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+)
PATCH v11 14/24 target/mips: add Octeon SAAD instruction
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
SAAD is the doubleword form of SAA: it atomically adds rt to the naturally aligned 64-bit doubleword at base and discards the old memory value.
Route it through the common SAA/SAAD translator so the MemOp selects the aligned doubleword transaction size.
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -47,6 +47,7 @@ SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi &saa base rt @saa ...... base:5 rt:5 ................ &saa SAA 011100 ..... ..... 00000 00000 011000 @saa +SAAD 011100 ..... ..... 00000 00000 011001 @saa &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx
target/mips/tcg/octeon_translate.c +1 -0
@@ -175,6 +175,7 @@ static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop) }TRANS (SAA , trans_saa,MO_32 ); +TRANS (SAAD , trans_saa,MO_64 );TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW );
Signature · 1 line
2.53.0
Re: [PATCH v11 14/24] target/mips: add Octeon SAAD instruction
Quoted 9 lines · Philippe Mathieu-Daudé
From: James Hilliard <[email protected]>
SAAD is the doubleword form of SAA: it atomically adds rt to the naturally aligned 64-bit doubleword at base and discards the old memory value.
Route it through the common SAA/SAAD translator so the MemOp selects the aligned doubleword transaction size.
Quoted 7 lines
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 1 + 2 files changed, 2 insertions(+)
PATCH v11 15/24 target/mips: add Octeon ZCB and ZCBT instructions
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
ZCB zeros the 128-byte cache block containing the base address. ZCBT has the same user-mode-visible memory effect for QEMU purposes.
Model both forms with a single decodetree wildcard entry, align the address down to a 128-byte line, and store eight zero 128-bit chunks to guest memory.
--- target/mips/tcg/octeon.decode | 3 +++ target/mips/tcg/octeon_translate.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
target/mips/tcg/octeon.decode +3 -0
@@ -49,6 +49,9 @@ SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi SAA 011100 ..... ..... 00000 00000 011000 @saa SAAD 011100 ..... ..... 00000 00000 011001 @saa +&zcb base +ZCB 011100 base:5 00000 00000 1110- 011111 &zcb + &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx LWX 011111 ..... ..... ..... 00000 001010 @lx
target/mips/tcg/octeon_translate.c +27 -0
@@ -176,6 +176,33 @@ static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop)TRANS (SAA , trans_saa,MO_32 );TRANS (SAAD , trans_saa,MO_64 ); + +static bool trans_ZCB (DisasContext *ctx,arg_ZCB *a) +{ +TCGv_i64 addr =tcg_temp_new_i64 (); +TCGv_i64 line =tcg_temp_new_i64 (); +TCGv_i64 zero64 =tcg_constant_i64 (0 ); +TCGv_i128 zero128 =tcg_temp_new_i128 (); +const MemOp mop =mo_endian (ctx) |MO_128 |MO_ATOM_NONE ; + +gen_base_offset_addr (ctx, addr, a->base,0 ); +tcg_gen_concat_i64_i128 (zero128, zero64, zero64); + +/* +* QEMU models ZCB/ZCBT as zeroing the containing 128-byte cache line +* in guest memory. +*/ +tcg_gen_andi_i64 (line, addr, ~0x7fULL ); + +for (int i =0 ; i <8 ; i++) { +TCGv_i64 slot =tcg_temp_new_i64 (); + +tcg_gen_addi_i64 (slot, line, i *16 ); +tcg_gen_qemu_st_i128 (zero128, slot, ctx->mem_idx, mop); + } + +return true; +}TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW );
Signature · 1 line
2.53.0
PATCH v11 16/24 tcg: Introduce tcg_gen_addN_i64
In reply to Philippe Mathieu-DaudéFrom: Richard Henderson <[email protected]>
Add a helper for multi-limb 64-bit addition. The helper emits native carry-chain TCG ops when they are available and falls back to explicit carry propagation otherwise.
This lets target translators build wider integer accumulators inline without open-coding the same add-with-carry sequence at each use site.
--- include/tcg/tcg-op-common.h | 1 + tcg/tcg-op.c | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
include/tcg/tcg-op-common.h +1 -0
@@ -251,6 +251,7 @@ void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al, TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh);void tcg_gen_addcio_i64 (TCGv_i64 r,TCGv_i64 co,TCGv_i64 a,TCGv_i64 b,TCGv_i64 ci); +void tcg_gen_addN_i64 (int n,TCGv_i64 *r,TCGv_i64 *a,TCGv_i64 *b);void tcg_gen_mulu2_i64 (TCGv_i64 rl,TCGv_i64 rh,TCGv_i64 arg1,TCGv_i64 arg2);void tcg_gen_muls2_i64 (TCGv_i64 rl,TCGv_i64 rh,TCGv_i64 arg1,TCGv_i64 arg2);void tcg_gen_mulsu2_i64 (TCGv_i64 rl,TCGv_i64 rh,TCGv_i64 arg1,TCGv_i64 arg2);
tcg/tcg-op.c +42 -0
48 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v11 16/24] tcg: Introduce tcg_gen_addN_i64
Quoted 9 lines · Philippe Mathieu-Daudé
From: Richard Henderson <[email protected]>
Add a helper for multi-limb 64-bit addition. The helper emits native carry-chain TCG ops when they are available and falls back to explicit carry propagation otherwise.
This lets target translators build wider integer accumulators inline without open-coding the same add-with-carry sequence at each use site.
Quoted 7 lines
Signed-off-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/tcg/tcg-op-common.h | 1 + tcg/tcg-op.c | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
PATCH v11 17/24 target/mips: add Octeon multiplier state
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
Add per-thread Octeon multiplier state for the MPL and P limb banks used by the VMULU/VMM0/V3MULU instruction family.
Octeon3 extends the older MPL0-MPL2/P0-P2 state with high lanes MPL3-MPL5/P3-P5, programmed by the two-source MTM/MTP forms. Represent both banks as uint64_t arrays so the TC state matches the architected 64-bit limb layout used by Octeon68XX user-mode code.
Expose MPL/P as global TCG variables so the multiplier translators can expand inline without helper calls.
Migrate the multiplier registers in an Octeon-only subsection so non-Octeon CPU models do not grow migration state.
--- target/mips/cpu.h | 12 ++++++++++++ target/mips/tcg/translate.h | 2 ++ target/mips/system/machine.c | 33 +++++++++++++++++++++++++++++++++ target/mips/tcg/translate.c | 18 ++++++++++++++++++ 4 files changed, 65 insertions(+)
target/mips/cpu.h +12 -0
@@ -459,6 +459,14 @@ typedef struct mips_def_t mips_def_t;typedef struct TCState TCState ; + +/* +* Octeon3 adds a second bank of multiplier/product limbs used by the +* two-source MTM/MTP forms: MPL0..2/P0..2 from rs and MPL3..5/P3..5 from rt. +*/ +#define OCTEON_MULTIPLIER_LANES 3 +#define OCTEON_MULTIPLIER_REGS (2 * OCTEON_MULTIPLIER_LANES) +struct TCState {target_ulong gpr[32 ];#if defined(TARGET_MIPS64 )
@@ -497,6 +505,10 @@ struct TCState {target_ulong CP0_TCScheFBack;int32_t CP0_Debug_tcstatus;target_ulong CP0_UserLocal; +struct { +uint64_t MPL[OCTEON_MULTIPLIER_REGS ]; +uint64_t P[OCTEON_MULTIPLIER_REGS ]; + } octeon;int32_t msacsr;
target/mips/tcg/translate.h +2 -0
@@ -189,6 +189,8 @@ void gen_crc32(DisasContext *ctx, int rd, int rs, int rt, int sz, int crc32c);extern TCGv cpu_gpr[32 ], cpu_PC;#if defined(TARGET_MIPS64 )extern TCGv_i64 cpu_gpr_hi[32 ]; +extern TCGv_i64 oct_mpl[OCTEON_MULTIPLIER_REGS ]; +extern TCGv_i64 oct_p[OCTEON_MULTIPLIER_REGS ];#endif extern TCGv cpu_HI[MIPS_DSP_ACC ], cpu_LO[MIPS_DSP_ACC ];extern TCGv_i32 fpu_fcr0, fpu_fcr31;
target/mips/system/machine.c +33 -0
@@ -120,6 +120,17 @@ static const VMStateDescription vmstate_inactive_tc = { .fields = vmstate_tc_fields }; +static const VMStateDescription vmstate_octeon_multiplier_tc = { + .name ="cpu/tc/octeon_multiplier" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (const VMStateField []) { +VMSTATE_UINT64_ARRAY (octeon.MPL, TCState,OCTEON_MULTIPLIER_REGS ), +VMSTATE_UINT64_ARRAY (octeon.P, TCState,OCTEON_MULTIPLIER_REGS ), +VMSTATE_END_OF_LIST () + } +}; +/* MVP state */ static const VMStateDescription vmstate_mvp = {
@@ -247,6 +258,27 @@ static const VMStateDescription mips_vmstate_timer = { } }; +static bool mips_octeon_needed (void *opaque) +{ +MIPSCPU *cpu = opaque; + +return cpu->env.insn_flags &INSN_OCTEON ; +} + +static const VMStateDescription mips_vmstate_octeon_multiplier = { + .name ="cpu/octeon_multiplier" , + .version_id =1 , + .minimum_version_id =1 , + .needed = mips_octeon_needed, + .fields = (const VMStateField []) { +VMSTATE_STRUCT (env.active_tc,MIPSCPU ,1 , + vmstate_octeon_multiplier_tc, TCState), +VMSTATE_STRUCT_ARRAY (env.tcs,MIPSCPU ,MIPS_SHADOW_SET_MAX ,1 , + vmstate_octeon_multiplier_tc, TCState), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_mips_cpu = { .name ="cpu" , .version_id =21 ,
@@ -363,6 +395,7 @@ const VMStateDescription vmstate_mips_cpu = { }, .subsections = (const VMStateDescription * const []) { &mips_vmstate_timer, + &mips_vmstate_octeon_multiplier,NULL } };
target/mips/tcg/translate.c +18 -0
@@ -1179,6 +1179,8 @@ static TCGv cpu_lladdr, cpu_llval;static TCGv_i32 hflags;TCGv_i32 fpu_fcr0, fpu_fcr31;TCGv_i64 fpu_f64[32 ]; +TCGv_i64 oct_mpl[OCTEON_MULTIPLIER_REGS ]; +TCGv_i64 oct_p[OCTEON_MULTIPLIER_REGS ];static const char regnames_HI[][4 ] = {"HI0" ,"HI1" ,"HI2" ,"HI3" ,
@@ -15276,6 +15278,22 @@ void mips_tcg_init(void) active_tc.gpr_hi[i]), rname); } + +for (unsigned i =0 ; i <OCTEON_MULTIPLIER_REGS ; ++i) { +static const char mpl_names[OCTEON_MULTIPLIER_REGS ][5 ] = { +"MPL0" ,"MPL1" ,"MPL2" ,"MPL3" ,"MPL4" ,"MPL5" , + }; +static const char p_names[OCTEON_MULTIPLIER_REGS ][3 ] = { +"P0" ,"P1" ,"P2" ,"P3" ,"P4" ,"P5" , + }; + + oct_mpl[i] =tcg_global_mem_new_i64 ( + tcg_env, offsetof(CPUMIPSState, active_tc.octeon.MPL[i]), + mpl_names[i]); + oct_p[i] =tcg_global_mem_new_i64 ( + tcg_env, offsetof(CPUMIPSState, active_tc.octeon.P[i]), + p_names[i]); + }#endif /* !TARGET_MIPS64 */ for (unsigned i =0 ; i <32 ; i++) { int off = offsetof(CPUMIPSState, active_fpu.fpr[i].wr.d[0]);
Signature · 1 line
2.53.0
PATCH v11 18/24 target/mips: add Octeon MTM instructions
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
Add the MTM0, MTM1, and MTM2 forms that load the Octeon3 multiplier operand pair from rs/rt into MPL[x] and MPL[x+3], then clear the partial products. For MPL0, also set MPL[1] to zero for backward compatibility with Octeon2 VMULU.
Legacy single-source encodings have rt encoded as $zero, so the same translator path also preserves the older Octeon behavior.
--- target/mips/tcg/octeon.decode | 7 +++++++ target/mips/tcg/octeon_translate.c | 32 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
target/mips/tcg/octeon.decode +7 -0
@@ -44,6 +44,13 @@ SNE 011100 ..... ..... ..... 00000 101011 @r3 SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi +&r2 rs rt +@r2 ...... rs:5 rt:5 ..... ..... ...... &r2 + +MTM0 011100 ..... ..... 00000 00000 001000 @r2 +MTM1 011100 ..... ..... 00000 00000 001100 @r2 +MTM2 011100 ..... ..... 00000 00000 001101 @r2 + &saa base rt @saa ...... base:5 rt:5 ................ &saa SAA 011100 ..... ..... 00000 00000 011000 @saa
target/mips/tcg/octeon_translate.c +32 -0
@@ -210,3 +210,35 @@ TRANS(LHUX, trans_lx, MO_UW);TRANS (LWX , trans_lx,MO_SL );TRANS (LWUX , trans_lx,MO_UL );TRANS (LDX , trans_lx,MO_UQ ); + +static void octeon_zero_partial_product_state (void ) +{ +for (int i =0 ; i <OCTEON_MULTIPLIER_REGS ; i++) { +tcg_gen_movi_i64 (oct_p[i],0 ); + } +} + +static bool trans_mtm (DisasContext *ctx,arg_r2 *a,unsigned int index) +{ +/* +* Octeon3 two-source MTM forms load lane index from rs and lane index + 3 +* from rt. Legacy one-source forms encode rt as $zero. +*/ +gen_load_gpr (oct_mpl[index], a->rs); +gen_load_gpr (oct_mpl[index +3 ], a->rt); + +/* +* Octeon3 clears MPL1 with MPL0 so that VMULU sequences remain +* backward compatible with Octeon2. +*/ +if (index ==0 ) { +tcg_gen_movi_i64 (oct_mpl[1 ],0 ); + } + +octeon_zero_partial_product_state (); +return true; +} + +TRANS (MTM0 , trans_mtm,0 ); +TRANS (MTM1 , trans_mtm,1 ); +TRANS (MTM2 , trans_mtm,2 );
Signature · 1 line
2.53.0
Re: [PATCH v11 18/24] target/mips: add Octeon MTM instructions
Quoted 24 lines · Philippe Mathieu-Daudé
From: James Hilliard <[email protected]>
Add the MTM0, MTM1, and MTM2 forms that load the Octeon3 multiplier operand pair from rs/rt into MPL[x] and MPL[x+3], then clear the partial products. For MPL0, also set MPL[1] to zero for backward compatibility with Octeon2 VMULU.
Legacy single-source encodings have rt encoded as $zero, so the same translator path also preserves the older Octeon behavior.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>Signed-off-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/octeon.decode | 7 +++++++ target/mips/tcg/octeon_translate.c | 32 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)target/mips/tcg/octeon.decode +0
-0
target/mips/tcg/octeon.decode SNE 011100 ..... ..... ..... 00000 101011 @r3 · line 52
Quoted 9 lines
target/mips/tcg/octeon.decode +6
-0@@ -44,6 +44,13 @@ SNE 011100 ..... ..... ..... 00000 101011 @r3 SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi +&r2 rs rt +@r2 ...... rs:5 rt:5 ..... ..... ...... &r2 + +MTM0 011100 ..... ..... 00000 00000 001000 @r2 +MTM1 011100 ..... ..... 00000 00000 001100 @r2 +MTM2 011100 ..... ..... 00000 00000 001101 @r2
I suppose you don't use a %lane argument (like later patches) due to the odd encoding.
PATCH v11 19/24 target/mips: add Octeon MTP instructions
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
Add the MTP0, MTP1, and MTP2 forms. MTP0 loads the low Octeon3 partial-product pair from rs/rt into P[0]/P[3], MTP1 loads the middle pair into P[1]/P[4], and MTP2 loads the high pair into P[2]/P[5]. For MTP0, also set P[1] to zero for backward compatibility with Octeon2 VMULU.
Legacy single-source encodings have rt encoded as $zero, so the same translator path also preserves the older Octeon behavior.
--- target/mips/tcg/octeon.decode | 4 ++++ target/mips/tcg/octeon_translate.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+)
target/mips/tcg/octeon.decode +4 -0
@@ -51,6 +51,10 @@ MTM0 011100 ..... ..... 00000 00000 001000 @r2 MTM1 011100 ..... ..... 00000 00000 001100 @r2 MTM2 011100 ..... ..... 00000 00000 001101 @r2 +MTP0 011100 ..... ..... 00000 00000 001001 @r2 +MTP1 011100 ..... ..... 00000 00000 001010 @r2 +MTP2 011100 ..... ..... 00000 00000 001011 @r2 + &saa base rt @saa ...... base:5 rt:5 ................ &saa SAA 011100 ..... ..... 00000 00000 011000 @saa
target/mips/tcg/octeon_translate.c +23 -0
@@ -242,3 +242,26 @@ static bool trans_mtm(DisasContext *ctx, arg_r2 *a, unsigned int index)TRANS (MTM0 , trans_mtm,0 );TRANS (MTM1 , trans_mtm,1 );TRANS (MTM2 , trans_mtm,2 ); + +static bool trans_mtp (DisasContext *ctx,arg_r2 *a,unsigned int index) +{ +/* +* Octeon3 two-source MTP forms load lane index from rs and lane index + 3 +* from rt. Legacy one-source forms encode rt as $zero. +*/ +gen_load_gpr (oct_p[index], a->rs); +gen_load_gpr (oct_p[index +3 ], a->rt); + +/* +* Octeon3 clears P1 with P0 so that VMULU sequences remain +* backward compatible with Octeon2. +*/ +if (index ==0 ) { +tcg_gen_movi_i64 (oct_p[1 ],0 ); + } +return true; +} + +TRANS (MTP0 , trans_mtp,0 ); +TRANS (MTP1 , trans_mtp,1 ); +TRANS (MTP2 , trans_mtp,2 );
Signature · 1 line
2.53.0
Re: [PATCH v11 19/24] target/mips: add Octeon MTP instructions
Quoted 45 lines · Philippe Mathieu-Daudé
From: James Hilliard <[email protected]>
Add the MTP0, MTP1, and MTP2 forms. MTP0 loads the low Octeon3 partial-product pair from rs/rt into P[0]/P[3], MTP1 loads the middle pair into P[1]/P[4], and MTP2 loads the high pair into P[2]/P[5]. For MTP0, also set P[1] to zero for backward compatibility with Octeon2 VMULU.
Legacy single-source encodings have rt encoded as $zero, so the same translator path also preserves the older Octeon behavior.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>Signed-off-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/octeon.decode | 4 ++++ target/mips/tcg/octeon_translate.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+)target/mips/tcg/octeon.decode +4
-0@@ -51,6 +51,10 @@ MTM0 011100 ..... ..... 00000 00000 001000 @r2 MTM1 011100 ..... ..... 00000 00000 001100 @r2 MTM2 011100 ..... ..... 00000 00000 001101 @r2 +MTP0 011100 ..... ..... 00000 00000 001001 @r2 +MTP1 011100 ..... ..... 00000 00000 001010 @r2 +MTP2 011100 ..... ..... 00000 00000 001011 @r2 + &saa base rt @saa ...... base:5 rt:5 ................ &saa SAA 011100 ..... ..... 00000 00000 011000 @saatarget/mips/tcg/octeon_translate.c +2
-0@@ -242,3 +242,26 @@ static bool trans_mtm(DisasContext *ctx, arg_r2 *a, unsigned int index)TRANS (MTM0 , trans_mtm,0 );TRANS (MTM1 , trans_mtm,1 );TRANS (MTM2 , trans_mtm,2 ); + +static bool trans_mtp (DisasContext *ctx,arg_r2 *a,unsigned int index)
target/mips/tcg/octeon_translate.c static bool trans_mtm(DisasContext *ctx, arg_r2 *a, unsigned int index) · line 256
Quoted 10 lines
target/mips/tcg/octeon_translate.c +10
-0+{ +/* +* Octeon3 two-source MTP forms load lane index from rs and lane index + 3 +* from rt. Legacy one-source forms encode rt as $zero. +*/ +gen_load_gpr (oct_p[index], a->rs); +gen_load_gpr (oct_p[index +3 ], a->rt); + +/* +* Octeon3 clears P1 with P0 so that VMULU sequences remain
I think you meant s/P0/$0/ here. Otherwise:
Quoted 11 lines
target/mips/tcg/octeon_translate.c +11
-0+* backward compatible with Octeon2. +*/ +if (index ==0 ) { +tcg_gen_movi_i64 (oct_p[1 ],0 ); + } +return true; +} + +TRANS (MTP0 , trans_mtp,0 ); +TRANS (MTP1 , trans_mtp,1 ); +TRANS (MTP2 , trans_mtp,2 );
Re: [PATCH v11 19/24] target/mips: add Octeon MTP instructions
Quoted 50 lines · Philippe Mathieu-Daudé
Quoted 49 lines · Philippe Mathieu-Daudé
From: James Hilliard <[email protected]>
Add the MTP0, MTP1, and MTP2 forms. MTP0 loads the low Octeon3 partial-product pair from rs/rt into P[0]/P[3], MTP1 loads the middle pair into P[1]/P[4], and MTP2 loads the high pair into P[2]/P[5]. For MTP0, also set P[1] to zero for backward compatibility with Octeon2 VMULU.
Legacy single-source encodings have rt encoded as $zero, so the same translator path also preserves the older Octeon behavior.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>Signed-off-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/mips/tcg/octeon.decode | 4 ++++target/mips/tcg/octeon_translate.c| 23 +++++++++++++++++++++++2 files changed, 27 insertions(+)target/mips/tcg/octeon.decode +0
-0@@ -51,6 +51,10 @@ MTM0 011100 ..... ..... 00000 00000 001000 @r2MTM1 011100 ..... ..... 00000 00000 001100 @r2 MTM2 011100 ..... ..... 00000 00000 001101 @r2
target/mips/tcg/octeon.decode +4
-0+MTP0 011100 ..... ..... 00000 00000 001001 @r2 +MTP1 011100 ..... ..... 00000 00000 001010 @r2 +MTP2 011100 ..... ..... 00000 00000 001011 @r2 +&saa base rt
@saa ...... base:5 rt:5 ................ &saa SAA 011100 ..... ..... 00000 00000 011000 @saatarget/mips/tcg/octeon_translate.c +0
-0@@ -242,3 +242,26 @@ static bool trans_mtm(DisasContext *ctx, arg_r2 *a, unsigned int index) TRANS(MTM0, trans_mtm, 0); TRANS(MTM1, trans_mtm, 1);
TRANS(MTM2, trans_mtm, 2);target/mips/tcg/octeon_translate.c +6
-0+ +static bool trans_mtp (DisasContext *ctx,arg_r2 *a,unsigned int index) +{ + /* +* Octeon3 two-source MTP forms load lane index from rs and lane index + 3 +* from rt. Legacy one-source forms encode rt as $zero.
Quoted 8 lines
Quoted 6 lines
+ */
+gen_load_gpr(oct_p[index], a->rs);
+gen_load_gpr(oct_p[index + 3], a->rt);
+
+ /*
+ * Octeon3 clears P1 with P0 so that VMULU sequences remainI think you meant s/P0/$0/ here. Otherwise:
No. MTP0 writes P0 and clears P1.
Perhaps better as "...clears P1 with a write to P0..."
r~
PATCH v11 20/24 target/mips: add Octeon VMULU instruction
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
VMULU multiplies the active Octeon multiplier state by rs, adds rt and queued partial products, returns the low result, and advances P[0]/P[1] with carry limbs.
Expand the two-limb accumulator operation inline with TCG so the result and partial-product state stay visible to the optimizer.
Add a mips64/mips64el linux-user TCG smoke test for representative Octeon multiplier instruction paths.
Include hardware-backed regression coverage for MTP0 P1 zeroing.
--- target/mips/tcg/octeon.decode | 2 + target/mips/tcg/octeon_translate.c | 35 +++++++++++++ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 49 +++++++++++++++++++ 3 files changed, 86 insertions(+)
target/mips/tcg/octeon.decode +2 -0
@@ -55,6 +55,8 @@ MTP0 011100 ..... ..... 00000 00000 001001 @r2 MTP1 011100 ..... ..... 00000 00000 001010 @r2 MTP2 011100 ..... ..... 00000 00000 001011 @r2 +VMULU 011100 ..... ..... ..... 00000 001111 @r3 + &saa base rt @saa ...... base:5 rt:5 ................ &saa SAA 011100 ..... ..... 00000 00000 011000 @saa
target/mips/tcg/octeon_translate.c +35 -0
@@ -265,3 +265,38 @@ static bool trans_mtp(DisasContext *ctx, arg_r2 *a, unsigned int index)TRANS (MTP0 , trans_mtp,0 );TRANS (MTP1 , trans_mtp,1 );TRANS (MTP2 , trans_mtp,2 ); + +static bool trans_VMULU (DisasContext *ctx,arg_VMULU *a) +{ +TCGv_i64 x[3 ], y[3 ], z[3 ]; +TCGv_i64 tmp =tcg_temp_new_i64 (); +TCGv_i64 zero =tcg_constant_i64 (0 ); + + z[0 ] = y[0 ] =tcg_temp_new_i64 (); + z[1 ] = y[1 ] =tcg_temp_new_i64 (); + z[2 ] = y[2 ] =tcg_temp_new_i64 (); + x[0 ] =tcg_temp_new_i64 (); + x[1 ] =tcg_temp_new_i64 (); + x[2 ] = zero; + +/* Z = rs * (mpl1 : mpl0) + rt */ +gen_load_gpr (tmp, a->rs); +gen_load_gpr (y[0 ], a->rt); +tcg_gen_mulu2_i64 (x[0 ], x[1 ], tmp, oct_mpl[0 ]); +tcg_gen_mulu2_i64 (y[1 ], y[2 ], tmp, oct_mpl[1 ]); +tcg_gen_addN_i64 (3 , z, y, x); + +/* X == (0 : p1 : p0) */ + x[0 ] = oct_p[0 ]; + x[1 ] = oct_p[1 ]; + +/* Y == (p1 : p0 : tmp) */ + y[0 ] = tmp; + y[1 ] = oct_p[0 ]; + y[2 ] = oct_p[1 ]; + +/* (p1 : p0 : rd) = Z + (0 : p1 : p0) */ +tcg_gen_addN_i64 (3 , y, z, x); +gen_store_gpr (tmp, a->rd); +return true; +}
tests/tcg/mips/user/isa/octeon/octeon-insns.c +49 -0
61 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v11 21/24 target/mips: add Octeon VMM0 instruction
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
VMM0 multiplies MPL[0] by rs, adds rt and the queued P[0] partial product, returns the low result, and feeds that result back into MPL[0]. It sets MPL[1] to zero and clears partial products.
Include hardware-backed regression coverage for VMM0 MPL1 zeroing.
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 16 ++++++ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 55 +++++++++++++++++++ 3 files changed, 72 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -56,6 +56,7 @@ MTP1 011100 ..... ..... 00000 00000 001010 @r2 MTP2 011100 ..... ..... 00000 00000 001011 @r2 VMULU 011100 ..... ..... ..... 00000 001111 @r3 +VMM0 011100 ..... ..... ..... 00000 010000 @r3 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +16 -0
@@ -300,3 +300,19 @@ static bool trans_VMULU(DisasContext *ctx, arg_VMULU *a)gen_store_gpr (tmp, a->rd);return true; } + +static bool trans_VMM0 (DisasContext *ctx,arg_VMM0 *a) +{ +TCGv_i64 tmp =tcg_temp_new_i64 (); + +gen_load_gpr (tmp, a->rs); +tcg_gen_mul_i64 (oct_mpl[0 ], oct_mpl[0 ], tmp); +gen_load_gpr (tmp, a->rt); +tcg_gen_add_i64 (oct_mpl[0 ], oct_mpl[0 ], tmp); +tcg_gen_add_i64 (oct_mpl[0 ], oct_mpl[0 ], oct_p[0 ]); +gen_store_gpr (oct_mpl[0 ], a->rd); + +tcg_gen_movi_i64 (oct_mpl[1 ],0 ); +octeon_zero_partial_product_state (); +return true; +}
tests/tcg/mips/user/isa/octeon/octeon-insns.c +55 -0
67 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v11 21/24] target/mips: add Octeon VMM0 instruction
Quoted 13 lines · Philippe Mathieu-Daudé
From: James Hilliard <[email protected]>
VMM0 multiplies MPL[0] by rs, adds rt and the queued P[0] partial product, returns the low result, and feeds that result back into MPL[0]. It sets MPL[1] to zero and clears partial products.
Include hardware-backed regression coverage for VMM0 MPL1 zeroing.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>Signed-off-by Richard Henderson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 5 lines
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 16 ++++++ tests/tcg/mips/user/isa/octeon/octeon-insns.c | 55 +++++++++++++++++++ 3 files changed, 72 insertions(+)
PATCH v11 22/24 target/mips: add Octeon V3MULU instruction
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
V3MULU extends VMULU across the full Octeon3 multiplier state, adding rt and queued partial products.
Return the low result while shifting the remaining accumulated limbs back into P[0] through P[5].
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 40 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
target/mips/tcg/octeon.decode +1 -0
@@ -57,6 +57,7 @@ MTP2 011100 ..... ..... 00000 00000 001011 @r2 VMULU 011100 ..... ..... ..... 00000 001111 @r3 VMM0 011100 ..... ..... ..... 00000 010000 @r3 +V3MULU 011100 ..... ..... ..... 00000 010001 @r3 &saa base rt @saa ...... base:5 rt:5 ................ &saa
target/mips/tcg/octeon_translate.c +40 -0
@@ -316,3 +316,43 @@ static bool trans_VMM0(DisasContext *ctx, arg_VMM0 *a)octeon_zero_partial_product_state ();return true; } + +static bool trans_V3MULU (DisasContext *ctx,arg_V3MULU *a) +{ +TCGv_i64 x[7 ], y[7 ], z[7 ]; +TCGv_i64 tmp =tcg_temp_new_i64 (); + +for (int i =0 ; i <7 ; ++i) { + z[i] =tcg_temp_new_i64 (); + y[i] =tcg_temp_new_i64 (); + } +memcpy (&x[0 ], z,6 *sizeof (TCGv_i64)); + x[6 ] =tcg_constant_i64 (0 ); + +/* +* Z = rs * mpl -- 64x384->448 bit multiply +* Compute even partial products into X and odd partial products into Y. +* Include RT into the odd partial products, which are 0 in bits [63:0]. +*/ +gen_load_gpr (tmp, a->rs); +gen_load_gpr (y[0 ], a->rt); +for (int i =0 ; i <6 ; i +=2 ) { +tcg_gen_mulu2_i64 (x[i +0 ], x[i +1 ], tmp, oct_mpl[i]); +tcg_gen_mulu2_i64 (y[i +1 ], y[i +2 ], tmp, oct_mpl[i +1 ]); + } + +/* Sum even and odd to produce final product, plus rt. */ +tcg_gen_addN_i64 (7 , z, x, y); + +/* X == (0 : p5 : p4 : p3 : p2 : p1 : p0) -- x[6] is still 0 */ +memcpy (&x[0 ], oct_p,6 *sizeof (TCGv_i64)); + +/* Y == (p5 : p4 : p3 : p2 : p1 : p0 : tmp) */ +memcpy (&y[1 ], oct_p,6 *sizeof (TCGv_i64)); + y[0 ] = tmp; + +/* (p* : rd) = (0 : p*) + (rs * mpl + rt) */ +tcg_gen_addN_i64 (7 , y, x, z); +gen_store_gpr (tmp, a->rd); +return true; +}
Signature · 1 line
2.53.0
PATCH v11 23/24 target/mips: add Octeon QMAC instructions
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
QMAC.0x and QMACS.0x multiply the selected signed Q15 halfword lane from rs by rt<15:0> and accumulate the Q31 product into the Octeon HI/LO accumulator state.
QMAC updates the full 64-bit HI/LO accumulator. QMACS saturates the 32-bit Q31 result in LO and keeps HI<0> as the sticky saturation flag.
--- target/mips/tcg/octeon.decode | 4 ++ target/mips/tcg/octeon_translate.c | 62 ++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+)
target/mips/tcg/octeon.decode +4 -0
@@ -28,6 +28,8 @@ BBIT 11 set:1 . 10 rs:5 ..... offset:s16 p=%bbit_p # SEQI rt, rs, immediate # SNE rd, rs, rt # SNEI rt, rs, immediate +# QMAC.0x rs, rt +# QMACS.0x rs, rt @r3 ...... rs:5 rt:5 rd:5 ..... ...... &cmpi rs rt imm
@@ -43,6 +45,8 @@ SEQ 011100 ..... ..... ..... 00000 101010 @r3 SNE 011100 ..... ..... ..... 00000 101011 @r3 SEQI 011100 rs:5 rt:5 imm:s10 101110 &cmpi SNEI 011100 rs:5 rt:5 imm:s10 101111 &cmpi +QMACS 011100 rs:5 rt:5 00000 000 lane:2 010010 +QMAC 011100 rs:5 rt:5 00000 100 lane:2 010010 &r2 rs rt @r2 ...... rs:5 rt:5 ..... ..... ...... &r2
target/mips/tcg/octeon_translate.c +62 -0
65 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v11 23/24] target/mips: add Octeon QMAC instructions
Quoted 14 lines · Philippe Mathieu-Daudé
From: James Hilliard <[email protected]>
QMAC.0x and QMACS.0x multiply the selected signed Q15 halfword lane from rs by rt<15:0> and accumulate the Q31 product into the Octeon HI/LO accumulator state.
QMAC updates the full 64-bit HI/LO accumulator. QMACS saturates the 32-bit Q31 result in LO and keeps HI<0> as the sticky saturation flag.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>Signed-off-by Richard Henderson <[email protected]>[PMD: Add min32/max32 in trans_QMACS()]Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 4 lines
--- target/mips/tcg/octeon.decode | 4 ++ target/mips/tcg/octeon_translate.c | 62 ++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+)
PATCH v11 24/24 target/mips: add Octeon LA* atomic instructions
In reply to Philippe Mathieu-DaudéFrom: James Hilliard <[email protected]>
Implement the Octeon LA* read-modify-write atomic instruction family:
LAI/LAID, LAD/LADD, LAA/LAAD, LAS/LASD, LAC/LACD, and LAW/LAWD.
These operations are architecturally distinct from SAA/SAAD and are used by existing Octeon user-mode code for atomic counters, bit operations, and exchange-style updates.
--- target/mips/tcg/octeon.decode | 17 +++++++ target/mips/tcg/octeon_translate.c | 75 ++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+)
target/mips/tcg/octeon.decode +17 -0
@@ -68,6 +68,23 @@ V3MULU 011100 ..... ..... ..... 00000 010001 @r3 SAA 011100 ..... ..... 00000 00000 011000 @saa SAAD 011100 ..... ..... 00000 00000 011001 @saa +&la base rd +&laa base add rd +@la ...... base:5 ..... rd:5 ........... &la +@laa ...... base:5 add:5 rd:5 ........... &laa +LAI 011100 ..... 00000 ..... 00010 011111 @la +LAID 011100 ..... 00000 ..... 00011 011111 @la +LAD 011100 ..... 00000 ..... 00110 011111 @la +LADD 011100 ..... 00000 ..... 00111 011111 @la +LAA 011100 ..... ..... ..... 10010 011111 @laa +LAAD 011100 ..... ..... ..... 10011 011111 @laa +LAS 011100 ..... 00000 ..... 01010 011111 @la +LASD 011100 ..... 00000 ..... 01011 011111 @la +LAC 011100 ..... 00000 ..... 01110 011111 @la +LACD 011100 ..... 00000 ..... 01111 011111 @la +LAW 011100 ..... ..... ..... 10110 011111 @laa +LAWD 011100 ..... ..... ..... 10111 011111 @laa + &zcb base ZCB 011100 base:5 00000 00000 1110- 011111 &zcb
target/mips/tcg/octeon_translate.c +75 -0
84 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v11 24/24] target/mips: add Octeon LA* atomic instructions
Quoted 98 lines · Philippe Mathieu-Daudé
From: James Hilliard <[email protected]>
Implement the Octeon LA* read-modify-write atomic instruction family:
LAI/LAID, LAD/LADD, LAA/LAAD, LAS/LASD, LAC/LACD, and LAW/LAWD.These operations are architecturally distinct from SAA/SAAD and are used by existing Octeon user-mode code for atomic counters, bit operations, and exchange-style updates.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/mips/tcg/octeon.decode | 17 +++++++ target/mips/tcg/octeon_translate.c | 75 ++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+)target/mips/tcg/octeon_translate.c +65
-0@@ -177,6 +177,68 @@ static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop)TRANS (SAA , trans_saa,MO_32 );TRANS (SAAD , trans_saa,MO_64 ); +static bool trans_la_fetch_add (DisasContext *ctx,int base,int add_reg, +int rd,int64_t imm,MemOp mop) +{ +TCGv_i64 addr =tcg_temp_new_i64 (); +TCGv_i64 value =tcg_temp_new_i64 (); +TCGv_i64 old =tcg_temp_new_i64 (); +MemOp amo =mo_endian (ctx) | mop |MO_ALIGN ; + +gen_base_offset_addr (ctx, addr, base,0 ); + +if (add_reg >=0 ) { +gen_load_gpr (value, add_reg); + }else { +tcg_gen_movi_i64 (value, imm); + } + +tcg_gen_atomic_fetch_add_i64 (old, addr, value, ctx->mem_idx, amo); +gen_store_gpr (old, rd); +return true; +} + +static bool trans_la_xchg (DisasContext *ctx,int base,int add_reg,int rd, +int64_t imm,MemOp mop) +{ +TCGv_i64 addr =tcg_temp_new_i64 (); +TCGv_i64 value =tcg_temp_new_i64 (); +TCGv_i64 old =tcg_temp_new_i64 (); +MemOp amo =mo_endian (ctx) | mop |MO_ALIGN ; + +gen_base_offset_addr (ctx, addr, base,0 ); + +if (add_reg >=0 ) { +gen_load_gpr (value, add_reg); + }else { +tcg_gen_movi_i64 (value, imm); + } + +tcg_gen_atomic_xchg_i64 (old, addr, value, ctx->mem_idx, amo); +gen_store_gpr (old, rd); +return true; +} + +static bool do_la_imm_add (DisasContext *ctx,arg_la *a,int64_t imm,MemOp mop) +{ +return trans_la_fetch_add (ctx, a->base,-1 , a->rd, imm, mop); +} + +static bool do_la_reg_add (DisasContext *ctx,arg_laa *a,MemOp mop) +{ +return trans_la_fetch_add (ctx, a->base, a->add, a->rd,0 , mop); +} + +static bool do_la_imm_xchg (DisasContext *ctx,arg_la *a,int64_t imm,MemOp mop) +{ +return trans_la_xchg (ctx, a->base,-1 , a->rd, imm, mop); +} + +static bool do_la_reg_xchg (DisasContext *ctx,arg_laa *a,MemOp mop) +{ +return trans_la_xchg (ctx, a->base, a->add, a->rd,0 , mop); +} +static bool trans_ZCB (DisasContext *ctx,arg_ZCB *a) {TCGv_i64 addr =tcg_temp_new_i64 ();@@ -418,3 +480,16 @@ static bool trans_QMACS(DisasContext *ctx, arg_QMACS *a)tcg_gen_or_i64 (cpu_HI[0 ], cpu_HI[0 ], t0);return true; } + +TRANS (LAI , do_la_imm_add,1 ,MO_SL ); +TRANS (LAID , do_la_imm_add,1 ,MO_UQ );
target/mips/tcg/octeon_translate.c static bool trans_QMACS(DisasContext *ctx, arg_QMACS *a) · line 495
Quoted 10 lines
target/mips/tcg/octeon_translate.c +10
-0+TRANS (LAD , do_la_imm_add,-1 ,MO_SL ); +TRANS (LADD , do_la_imm_add,-1 ,MO_UQ ); +TRANS (LAA , do_la_reg_add,MO_SL ); +TRANS (LAAD , do_la_reg_add,MO_UQ ); +TRANS (LAS , do_la_imm_xchg,-1 ,MO_SL ); +TRANS (LASD , do_la_imm_xchg,-1 ,MO_UQ ); +TRANS (LAC , do_la_imm_xchg,0 ,MO_SL ); +TRANS (LACD , do_la_imm_xchg,0 ,MO_UQ ); +TRANS (LAW , do_la_reg_xchg,MO_SL ); +TRANS (LAWD , do_la_reg_xchg,MO_UQ );
Alternatively passing the atomic function by argument to TRANS():
-- >8 --
+typedef void AtomicThreeOpFn(TCGv_i64, TCGv_va, TCGv_i64, TCGArg, MemOp); +
+static bool do_atomic_ld(DisasContext *ctx, AtomicThreeOpFn *atomic_fn,
+ int base, int add_reg, int rd, int64_t imm, MemOp mop)
+{
+ TCGv_i64 addr = tcg_temp_new_i64(); + TCGv_i64 value = tcg_temp_new_i64(); + TCGv_i64 old = tcg_temp_new_i64(); + MemOp amo = mo_endian(ctx) | mop | MO_ALIGN;
+
+ gen_base_offset_addr(ctx, addr, base, 0);
+
+ if (add_reg >= 0) {
+ gen_load_gpr(value, add_reg);
+ } else {
+ tcg_gen_movi_i64(value, imm);
+ }
+
+ atomic_fn(old, addr, value, ctx->mem_idx, amo); + gen_store_gpr(old, rd); + return true;
+}
+
+static bool do_atomic_la(DisasContext *ctx, arg_la *a, AtomicThreeOpFn *fn,
+ int64_t imm, MemOp mop)
+{
+ return do_atomic_ld(ctx, fn, a->base, -1, a->rd, imm, mop);
+}
+
+static bool do_atomic_laa(DisasContext *ctx, arg_laa *a, AtomicThreeOpFn *fn,
+ int64_t imm, MemOp mop)
+{
+ return do_atomic_ld(ctx, fn, a->base, a->add, a->rd, imm, mop);
+}
+
+TRANS(LAI, do_atomic_la, tcg_gen_atomic_fetch_add_i64, 1, MO_SL); +TRANS(LAID, do_atomic_la, tcg_gen_atomic_fetch_add_i64, 1, MO_UQ); +TRANS(LAD, do_atomic_la, tcg_gen_atomic_fetch_add_i64, -1, MO_SL); +TRANS(LADD, do_atomic_la, tcg_gen_atomic_fetch_add_i64, -1, MO_UQ); +TRANS(LAA, do_atomic_laa, tcg_gen_atomic_fetch_add_i64, 0, MO_SL); +TRANS(LAAD, do_atomic_laa, tcg_gen_atomic_fetch_add_i64, 0, MO_UQ); +TRANS(LAS, do_atomic_la, tcg_gen_atomic_xchg_i64, -1, MO_SL); +TRANS(LASD, do_atomic_la, tcg_gen_atomic_xchg_i64, -1, MO_UQ); +TRANS(LAC, do_atomic_la, tcg_gen_atomic_xchg_i64, 0, MO_SL); +TRANS(LACD, do_atomic_la, tcg_gen_atomic_xchg_i64, 0, MO_UQ);
+TRANS(LAW, do_atomic_laa, tcg_gen_atomic_xchg_i64, 0, MO_SL);
+TRANS(LAWD, do_atomic_laa, tcg_gen_atomic_xchg_i64, 0, MO_UQ);
---
Re: [PATCH v11 24/24] target/mips: add Octeon LA* atomic instructions
Quoted 10 lines · Philippe Mathieu-Daudé
Alternatively passing the atomic function by argument to
TRANS():-- >8 --
target/mips/tcg/octeon_translate.c +7
-0+typedef void AtomicThreeOpFn (TCGv_i64 ,TCGv_va ,TCGv_i64 ,TCGArg ,MemOp ); + +static bool do_atomic_ld (DisasContext *ctx,AtomicThreeOpFn *atomic_fn, + int base, int add_reg, int rd, int64_t imm, MemOp mop) +{ + TCGv_i64 addr = tcg_temp_new_i64(); + TCGv_i64 value = tcg_temp_new_i64();
target/mips/tcg/octeon_translate.c static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop) · line 215
Quoted 10 lines
target/mips/tcg/octeon_translate.c +10
-0+ TCGv_i64 old = tcg_temp_new_i64(); + MemOp amo = mo_endian(ctx) | mop | MO_ALIGN; + + gen_base_offset_addr(ctx, addr, base, 0); + + if (add_reg >= 0) { + gen_load_gpr(value, add_reg); + } else { + tcg_gen_movi_i64(value, imm); + }
If you're going to tweak that, you might as well do
if (add_reg >= 0) {
value = tcg_temp_new_i64();
gen_load_gpr(value, add_reg);
} else {
value = tcg_constant_i64(imm);
}r~