target/mips: add missing Octeon user-mode support
v9 cover target/mips: add missing Octeon user-mode support
This series updates MIPS linux-user unaligned-access behavior and fills in missing Octeon user-mode instruction support used by existing Octeon binaries.
The first patches model the Linux/MIPS sysmips ABI pieces needed by linux-user, including MIPS_FLUSH_CACHE, MIPS_ATOMIC_SET, and the MIPS_FIXADE policy used to control unaligned scalar access fixups. User-mode unaligned scalar accesses default to software fixups and sysmips(MIPS_FIXADE) can toggle SIGBUS/BUS_ADRALN behavior.
Richard Henderson's v7.5 multiplier/QMAC rework is incorporated directly as nine patches: two TCG preparatory patches and seven Octeon multiplier/QMAC patches. The Octeon multiplier and QMAC translations now expand inline in TCG.
The remaining Octeon patches add integer, indexed memory, atomic, COP2 crypto, CHORD, LLM, and CvmCount RDHWR support. The COP2 work is split into state, helper plumbing, per-engine helper batches, explicit selector decode, CHORD/LLM, and smoke-test coverage so each functional block can be reviewed independently. The series also adds a small mips64/mips64el TCG guest test covering representative Octeon integer, fixed-point, multiplier, RDHWR, and COP2 selector paths. The final patch corrects the Octeon68XX CP1 feature bits and FCR defaults.
Changes since v1:
- Split BADDU/DMUL destination fixes into a separate patch.
- Split the SEQ/SNE decode refactoring into a separate patch.
- Moved Octeon multiplier state to uint64_t arrays and updated VMState.
- Switched Octeon helper ABIs to i64/uint64_t where applicable.
- Moved COP2 selector decode/support logic into octeon_translate.c.
- Added in-tree TCG tests for mips64 and mips64el linux-user.
- Used switch ranges and g_assert_not_reached() for SHA3/ZUC shared selector handling.
- Dropped Octeon prefixes from generic Camellia helper routines.
- Replaced the reflected GFM 64-bit carryless multiply loop with crypto/clmul.h.
- Moved the Octeon68XX CP1 CPU-model correction to the end of the series.
- Added migration coverage for Octeon COP2 crypto and LLM sparse state.
- Split COP2 helper implementation by functional subcategory and added helper.h declarations alongside the side-effecting selector operations.
- Removed the shared COP2 selector enum; selectors are now either decoded by decodetree or kept as helper-local constants for shared register-window arithmetic.
- Used signed 32-bit DMFC2 direct loads for 32-bit COP2 register readback.
---
Changes in v9:
- Used MO_ATOM_NONE for the 128-bit ZCB/ZCBT zero stores.
- Reused octeon_zero_partial_product_state() in the VMM0 translator.
- Removed the shared MIPSOcteonCop2Sel enum from CPU state headers.
- Replaced generic selector-dispatch COP2 helpers with per-operation
helper functions.
- Split COP2 helper implementation into smaller functional subcategory
patches: plumbing, CRC, GFM, SHA3, ZUC, SNOW3G, AES, SMS4, 3DES/KASUMI,
Camellia, HSH, and CHORD/LLM.
- Added COP2 helper declarations to helper.h alongside the per-engine
helper implementation commits.
- Used signed 32-bit DMFC2 direct loads for 32-bit COP2 register
readback.
- Documented the AESRESINP input/readback state split in the translator.
- Combined COP2 selector readback with QMAC/CvmCount smoke coverage.
- Link to v8: https://lore.kernel.org/qemu-devel/20260517-mips-octeon-missing-insns-v2-v8-0-206151ee77ec@gmail.com
Changes in v8:
- Incorporated Richard Henderson's v7.5 9-patch multiplier/QMAC rework
directly into the stack rather than as a follow-up cleanup.
- Added the two v7.5 TCG prep patches as standalone patches:
tcg_gen_addN_i64 and mul[us]2 zero/one optimization.
- Replaced the helper-backed Octeon multiplier/QMAC sequence with the
seven v7.5-shaped patches: multiplier state, MTM, MTP, VMULU, VMM0,
V3MULU, and QMAC.
- Split Octeon COP2 crypto core support into state/migration, helper
implementation, explicit selector decode, and selector readback test
patches.
- Decoded Octeon COP2 selectors explicitly in decodetree and used direct
TCG loads/stores for simple COP2 register moves.
- Kept COP2 helper calls for operation selectors and shared-window state
that require side effects.
- Folded ZCB/ZCBT into one patch so the decodetree wildcard is
introduced in final form.
- Added new Reviewed-by tags from Richard Henderson for MTM/MTP, LA*,
CvmCount, and QMAC/CvmCount test patches.
- Link to v7: https://lore.kernel.org/qemu-devel/20260514-mips-octeon-missing-insns-v2-v7-0-226686be4ce1@gmail.com
Changes in v7:
- Rebased on current qemu.git staging (edcc429e9e).
- Reordered the zero-register cleanup after the BADDU/DMUL destination fix
and moved the multiplier-state patch next to the MTM/MTP instruction
patches.
- Applied Philippe's MIPS_FIXADE TB-flag readability tweak.
- Used explicit MO_32/MO_64 MemOps for SAA/SAAD atomic transaction sizes.
- Folded ZCB/ZCBT decode with a decodetree wildcard and zero the cache
block with 128-bit stores.
- Added new Reviewed-by tags from Philippe Mathieu-Daudé and Richard
Henderson.
- Link to v6: https://lore.kernel.org/qemu-devel/20260511-mips-octeon-missing-insns-v2-v6-0-5062889c4d3c@gmail.com
Changes in v6:
- Added Octeon QMAC/QMACS fixed-point accumulator support and smoke
coverage.
- Added Octeon RDHWR $31/CvmCount support and smoke coverage.
- Clarified MTM0/VMM0 reset behavior against the CN71XX
register-state tables.
- Fixed MTP0 to zero P1 per the CN71XX register-state table and added
smoke coverage.
- Fixed VMM0 MPL1 reset handling and added smoke coverage for MPL1.
- Cleaned up internal VMUL, LA*, COP2 payload/state, and COP2 selector
naming to better match hardware register/selector terminology.
- Renamed the MIPS_FIXADE TB flag, HSH register word-packing helpers,
and sparse LLM backing fields to match ABI and hardware terminology.
- Link to v5: https://lore.kernel.org/qemu-devel/20260510-mips-octeon-missing-insns-v2-v5-0-d5d2668d15ab@gmail.com
Changes in v5:
- Added Richard Henderson's Reviewed-by tags for LBX, LHUX, LWUX, SAA,
and SAAD, plus Acked-by tags for ZCB and ZCBT.
- Dropped the separate Octeon+ feature bit; QEMU has a single Octeon CPU
model today, so SAA/SAAD stay under the existing Octeon feature bucket.
- Folded ZCBT into the ZCB decodetree entry with a selector comment.
- Link to v4: https://lore.kernel.org/qemu-devel/20260509-mips-octeon-missing-insns-v2-v4-0-d669dcd05c2f@gmail.com
Changes in v4:
- Added Richard Henderson's Reviewed-by tags to the reviewed sysmips and
Octeon translator cleanup patches.
- Kept the Octeon3 MPL3-MPL5/P3-P5 high-lane multiplier state
documented by Cavium SDK/toolchain sources.
- Documented the Octeon3 two-source MTM/MTP forms and preserved the rt
high-lane operands while legacy one-source encodings use rt == $zero.
- Simplified SAA/SAAD translation to use the i64 TCG atomic add path for
both word and doubleword sizes.
- Marked SAA/SAAD as Octeon+ instructions and gated them behind a
separate Octeon+ feature bit.
- Simplified LA* translation to use i64 TCG atomic helpers for word and
doubleword operations, with MO_SL selecting word result sign-extension.
- Link to v3: https://lore.kernel.org/qemu-devel/20260508-mips-octeon-missing-insns-v2-v3-0-bcbec96357d9@gmail.com
Changes in v3:
- Rebased on current qemu.git master.
- Split sysmips support into separate MIPS_FLUSH_CACHE, MIPS_ATOMIC_SET,
and MIPS_FIXADE patches.
- Made MIPS_ATOMIC_SET always use the MIPS separate error-result register
path for successful returns.
- Removed redundant Octeon MIPS64 checks and target-long guards from the
translator paths.
- Removed zero-register fast paths where gen_store_gpr() already handles
discarded writes.
- Reworked SEQ/SNE decode and LA* translator helpers as requested.
- Split the Octeon arithmetic/memory patch into narrower state, indexed
load, SAA/SAAD, ZCB/ZCBT, multiplier, and test patches.
- Reworked Octeon multiplier limb accumulation as requested.
- Link to v2: https://lore.kernel.org/qemu-devel/20260421-mips-octeon-missing-insns-v2-v2-0-a0791df188c9@gmail.com
To: [email protected]
Cc: Laurent Vivier <[email protected]>
Cc: Helge Deller <[email protected]>
Cc: Pierrick Bouvier <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Cc: Jiaxun Yang <[email protected]>
Cc: Aurelien Jarno <[email protected]>
Cc: Aleksandar Rikalo <[email protected]>
Cc: Huacai Chen <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Paolo Bonzini <[email protected]>
---
James Hilliard (38):
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: fix Octeon arithmetic destination handling target/mips: drop Octeon zero-register fast paths target/mips: split Octeon SEQ/SNE 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
tests/tcg/mips: add Octeon instruction smoke test target/mips: add Octeon LA* atomic instructions target/mips: add Octeon COP2 crypto state
target/mips: add Octeon COP2 crypto helper plumbing target/mips: add Octeon CRC COP2 helpers
target/mips: add Octeon GFM COP2 helpers
target/mips: add Octeon SHA3 COP2 helpers
target/mips: add Octeon ZUC COP2 helpers
target/mips: add Octeon SNOW3G COP2 helpers
target/mips: add Octeon AES COP2 helpers
target/mips: add Octeon SMS4 COP2 helpers
target/mips: add Octeon 3DES and KASUMI COP2 helpers target/mips: add Octeon Camellia COP2 helpers
target/mips: add Octeon HSH COP2 helpers
target/mips: add Octeon CHORD and LLM COP2 helpers target/mips: decode Octeon COP2 selectors explicitly target/mips: add Octeon CvmCount RDHWR support tests/tcg/mips: cover Octeon COP2, QMAC and CvmCount target/mips: expose Octeon68XX floating-point support
Richard Henderson (2):
tcg: Introduce tcg_gen_addN_i64
tcg: Optimize INDEX_op_mul[us]2 for 0 and 1
MAINTAINERS | 2 + include/tcg/tcg-op-common.h | 1 + linux-user/mips/cpu_loop.c | 5 + linux-user/mips/target_syscall.h | 3 + linux-user/mips64/target_syscall.h | 3 + linux-user/syscall.c | 56 + target/mips/cpu-defs.c.inc | 10 +- target/mips/cpu.c | 78 +- target/mips/cpu.h | 70 + target/mips/helper.h | 123 ++ target/mips/internal.h | 3 + target/mips/system/machine.c | 142 ++ target/mips/tcg/meson.build | 1 + target/mips/tcg/octeon.decode | 259 ++- target/mips/tcg/octeon_crypto.c | 2543 +++++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 751 +++++++- target/mips/tcg/op_helper.c | 19 +- target/mips/tcg/translate.c | 43 +- target/mips/tcg/translate.h | 2 + tcg/optimize.c | 92 +- tcg/tcg-op.c | 42 + tests/tcg/mips/user/isa/octeon/octeon-insns.c | 332 ++++ tests/tcg/mips64/Makefile.target | 20 + tests/tcg/mips64el/Makefile.target | 8 + 24 files changed, 4516 insertions(+), 92 deletions(-)
---
base-commit: 6d17fd91f6cf88df5cb2205e578640d72605cc43
change-id: 20260420-mips-octeon-missing-insns-v2-5e693770cf2c
Best regards,
Signature · 1 line
James Hilliard <[email protected]>
PATCH v9 1/40 linux-user/mips: implement sysmips(MIPS_FLUSH_CACHE)
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.
---
Changes v2 -> v3:
- Split MIPS_FLUSH_CACHE out of the combined sysmips/MIPS_FIXADE patch. (suggested by Richard Henderson)
--- 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) {
@@ -12102,6 +12115,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.54.0
PATCH v9 2/40 linux-user/mips: implement sysmips(MIPS_ATOMIC_SET)
In reply to James HilliardImplement 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.
---
Changes v2 -> v3:
- Split MIPS_ATOMIC_SET out of the combined sysmips/MIPS_FIXADE patch. (suggested by Richard Henderson)
- Always use the explicit MIPS return-register path for successful atomic_set results. (suggested by Richard Henderson)
--- 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.54.0
PATCH v9 3/40 linux-user/mips, target/mips: honor MIPS_FIXADE for unaligned accesses
In reply to James HilliardLinux/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.
---
Changes v6 -> v7:
- Replace the compact TB_FLAG_MIPS_FIXADE multiplication with an explicit conditional branch for readability. (suggested by Philippe Mathieu-Daudé)
Changes v5 -> v6:
- Rename the TB flag from TB_FLAG_UNALIGN to TB_FLAG_MIPS_FIXADE to match the MIPS_FIXADE ABI policy.
Changes v2 -> v3:
- Split MIPS_FLUSH_CACHE and MIPS_ATOMIC_SET into preparatory sysmips patches. (suggested by Richard Henderson)
--- linux-user/mips/cpu_loop.c | 5 +++++ linux-user/mips/target_syscall.h | 1 + linux-user/mips64/target_syscall.h | 1 + linux-user/syscall.c | 8 ++++++++ target/mips/cpu.c | 10 ++++++++-- target/mips/cpu.h | 4 ++++ target/mips/tcg/translate.c | 6 +++++- 7 files changed, 32 insertions(+), 3 deletions(-)
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/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)
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/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) */
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.54.0
PATCH v9 4/40 target/mips: fix Octeon arithmetic destination handling
In reply to James HilliardBADDU and DMUL write their results to rd, not rt. Route writes through gen_store_gpr() so rd == $zero is handled consistently.
---
Changes v1 -> v2:
- Split the BADDU/DMUL destination handling fix out of the Octeon arithmetic instruction patch. (suggested by Philippe Mathieu-Daudé)
Changes v2 -> v3:
- Remove the rd == $zero fast paths and let gen_store_gpr() discard writes to $zero. (suggested by Richard Henderson)
--- target/mips/tcg/octeon_translate.c | 16 ++++------------ 1 file changed, 4 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; }
Signature · 1 line
2.54.0
PATCH v9 5/40 target/mips: drop Octeon zero-register fast paths
In reply to James HilliardEXTS, 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.
---
Changes v2 -> v3:
- Remove the remaining destination $zero fast paths and let gen_store_gpr() discard writes to $zero. (suggested by Richard Henderson)
--- target/mips/tcg/octeon_translate.c | 15 --------------- 1 file changed, 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) {
Signature · 1 line
2.54.0
PATCH v9 6/40 target/mips: split Octeon SEQ/SNE decode
In reply to James HilliardDecode the equality and inequality forms as explicit SEQ/SNE and SEQI/SNEI instructions rather than using shared generated SEQNE/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.
---
Changes v1 -> v2:
- Split the SEQ/SNE decode cleanup out of the Octeon arithmetic instruction patch. (suggested by Philippe Mathieu-Daudé)
Changes v2 -> v3:
- Remove the decoded ne field now that the instructions are split.
- Reuse @r3 for SEQ/SNE and pass the TCG condition into a shared translator helper. (suggested by Richard Henderson)
--- target/mips/tcg/octeon.decode | 7 +++-- target/mips/tcg/octeon_translate.c | 52 ++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 27 deletions(-)
target/mips/tcg/octeon.decode +5 -2
@@ -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
@@ -38,8 +39,10 @@ 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 -SEQNEI 011100 rs:5 rt:5 imm:s10 10111 ne:1 +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 &lx base index rd @lx ...... base:5 index:5 rd:5 ...... ..... &lx
target/mips/tcg/octeon_translate.c +27 -25
79 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v9 7/40 target/mips: add Octeon LBX instruction
In reply to James HilliardLBX 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.
---
Changes v2 -> v3:
- Split LBX out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- 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.54.0
PATCH v9 8/40 target/mips: add Octeon LHUX instruction
In reply to James HilliardLHUX 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.
---
Changes v2 -> v3:
- Split LHUX out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- 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.54.0
PATCH v9 9/40 target/mips: add Octeon LWUX instruction
In reply to James HilliardLWUX 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.
---
Changes v2 -> v3:
- Split LWUX out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- 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.54.0
PATCH v9 10/40 target/mips: add Octeon SAA instruction
In reply to James HilliardSAA 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.
---
Changes v6 -> v7:
- Use MO_32 for the word-size atomic transaction; the signedness bits are irrelevant for a discarded fetch-add result. (suggested by Philippe Mathieu-Daudé)
Changes v2 -> v3:
- Split SAA out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
Changes v3 -> v4:
- Gate SAA/SAAD behind an Octeon+ feature bit. (reported by Richard Henderson)
- Use the i64 TCG atomic add path for both word and doubleword sizes. (suggested by Richard Henderson)
Changes v4 -> v5:
- Drop the separate Octeon+ feature bit; QEMU only has one Octeon CPU model today. (comment by Richard Henderson)
--- 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.54.0
PATCH v9 11/40 target/mips: add Octeon SAAD instruction
In reply to James HilliardSAAD 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.
---
Changes v6 -> v7:
- Use MO_64 for the doubleword atomic transaction; the signedness bits are irrelevant for a discarded fetch-add result. (suggested by Philippe Mathieu-Daudé)
Changes v2 -> v3:
- Split SAAD out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
Changes v3 -> v4:
- Note that SAAD shares the Octeon+ gated SAA translator path.
Changes v4 -> v5:
- Drop the Octeon+ gated wording/path and keep SAAD under the existing Octeon feature bucket.
--- 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.54.0
PATCH v9 12/40 target/mips: add Octeon ZCB and ZCBT instructions
In reply to James HilliardZCB 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.
---
Changes v8 -> v9:
- Use MO_ATOM_NONE for the 128-bit zero stores so TCG does not require unavailable 128-bit atomic stores on hosts that lack them.
Changes v7 -> v8:
- Fold the ZCBT wildcard decode into the ZCB patch so the series does not add a ZCB-only decode and rewrite it in the next patch.
Changes v6 -> v7:
- Use 128-bit zero stores with MO_128 instead of sixteen 64-bit stores. (suggested by Philippe Mathieu-Daudé)
- Fold ZCB and ZCBT into a single decodetree wildcard entry instead of using a duplicate entry with a selector comment. (suggested by Philippe Mathieu-Daudé)
Changes v2 -> v3:
- Split ZCB/ZCBT out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
--- 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 (); + +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, +mo_endian (ctx) |MO_128 |MO_ATOM_NONE ); + } + +return true; +}TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW );
Signature · 1 line
2.54.0
Re: [PATCH v9 12/40] target/mips: add Octeon ZCB and ZCBT instructions
Quoted 52 lines · James Hilliard
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.
Signed-off-by James Hilliard <[email protected]>---
Changes v8 -> v9:
- UseMO_ATOM_NONEfor the 128-bit zero stores so TCG does not require unavailable 128-bit atomic stores on hosts that lack them.Changes v7 -> v8:
- Fold the ZCBT wildcard decode into the ZCB patch so the series does not add a ZCB-only decode and rewrite it in the next patch.Changes v6 -> v7:
- Use 128-bit zero stores withMO_128instead of sixteen 64-bit stores. (suggested by Philippe Mathieu-Daudé)
- Fold ZCB and ZCBT into a single decodetree wildcard entry instead of using a duplicate entry with a selector comment. (suggested by Philippe Mathieu-Daudé)Changes v2 -> v3:
- Split ZCB/ZCBT out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)--- 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 @lxtarget/mips/tcg/octeon_translate.c +0
-0
target/mips/tcg/octeon_translate.c static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop) · line 185
Quoted 10 lines
target/mips/tcg/octeon_translate.c +7
-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;
Although $zero endianness is irrelevant :) but I prefer to keep it explicit for coding style.
I can squash upon applying if you agree or keep your patch as it.
Quoted 22 lines
target/mips/tcg/octeon_translate.c +18
-0+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, +mo_endian (ctx) |MO_128 |MO_ATOM_NONE ); + }> + + return true; +}TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW );
Re: [PATCH v9 12/40] target/mips: add Octeon ZCB and ZCBT instructions
Quoted 67 lines · Philippe Mathieu-Daudé
Quoted 52 lines · James Hilliard
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.
Signed-off-by James Hilliard <[email protected]>---
Changes v8 -> v9:
- UseMO_ATOM_NONEfor the 128-bit zero stores so TCG does not require unavailable 128-bit atomic stores on hosts that lack them.Changes v7 -> v8:
- Fold the ZCBT wildcard decode into the ZCB patch so the series does not add a ZCB-only decode and rewrite it in the next patch.Changes v6 -> v7:
- Use 128-bit zero stores withMO_128instead of sixteen 64-bit stores. (suggested by Philippe Mathieu-Daudé)
- Fold ZCB and ZCBT into a single decodetree wildcard entry instead of using a duplicate entry with a selector comment. (suggested by Philippe Mathieu-Daudé)Changes v2 -> v3:
- Split ZCB/ZCBT out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)--- 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 @lxtarget/mips/tcg/octeon_translate.c +0
-0target/mips/tcg/octeon_translate.c static bool trans_saa(DisasContext *ctx, arg_saa *a, MemOp mop) · line 185
Quoted 10 lines
target/mips/tcg/octeon_translate.c +7
-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;
Quoted 4 lines
Although $zero endianness is irrelevant :) but I prefer to keep it explicit for coding style.
I can squash upon applying if you agree or keep your patch as it.
Whichever you prefer is fine with me.
Quoted 26 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 22 lines
target/mips/tcg/octeon_translate.c +18
-0+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, +mo_endian (ctx) |MO_128 |MO_ATOM_NONE ); + }> + + return true; +}TRANS (LBX , trans_lx,MO_SB );TRANS (LBUX , trans_lx,MO_UB );TRANS (LHX , trans_lx,MO_SW );
PATCH v9 13/40 tcg: Introduce tcg_gen_addN_i64
In reply to James HilliardFrom: 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.
---
Changes v7 -> v8:
- New patch from Richard Henderson's v7.5 multiplier rework.
--- 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.54.0
Re: [PATCH v9 13/40] tcg: Introduce tcg_gen_addN_i64
Quoted 11 lines · James Hilliard
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.
Signed-off-by Richard Henderson <[email protected]>
Quoted 7 lines
---
Changes v7 -> v8:
- New patch from Richard Henderson's v7.5 multiplier rework.--- include/tcg/tcg-op-common.h | 1 + tcg/tcg-op.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
Richard, could we squash something like this?
-- >8 --
docs/devel/tcg-ops.rst +0 -0
@@ -672,6 +672,12 @@ Multiword arithmetic support | If mulu2/muls2 are not provided by the backend, the tcg-op
generator
can obtain the same results by emitting a pair of opcodes,
mul + muluh/mulsh.
+ * - addN *n*, *t0*, *t1*, *t2*
+
+ - | For each *n*, compute *t0* = *t1* + *t2* + *C*,
+ where *C* is the input carry bit provided by the host + architecture, and also compute the output carry bit. + Overlap between *t0* and *t1*/*t2* arrays is not allowed.
Memory Barrier support
----------------------
---
Quoted 66 lines
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@@ -2275,6 +2275,48 @@ void tcg_gen_addcio_i64(TCGv_i64 r, TCGv_i64 co, } } +void tcg_gen_addN_i64 (int n,TCGv_i64 *r,TCGv_i64 *a,TCGv_i64 *b) +{ +tcg_debug_assert (n >2 ); + +/* ??? Don't allow overlap for now. */ +for (int i =0 ; i < n -1 ; ++i) { +for (int j = i +1 ; j < n; ++j) { +tcg_debug_assert (r[i] != a[j]); +tcg_debug_assert (r[i] != b[j]); + } + } + +if (tcg_op_supported (INDEX_op_addci,TCG_TYPE_I64 ,0 )) { +tcg_gen_op3_i64 (INDEX_op_addco, r[0 ], a[0 ], b[0 ]); +for (int i =1 ; i < n -1 ; ++i) { +tcg_gen_op3_i64 (INDEX_op_addcio, r[i], a[i], b[i]); + } +tcg_gen_op3_i64 (INDEX_op_addci, r[n -1 ], a[n -1 ], b[n -1 ]); + }else { +TCGv_i64 t =tcg_temp_ebb_new_i64 (); +TCGv_i64 c =tcg_temp_ebb_new_i64 (); + +tcg_gen_add_i64 (t, a[0 ], b[0 ]); +tcg_gen_setcond_i64 (TCG_COND_LTU , c, t, a[0 ]); +tcg_gen_mov_i64 (r[0 ], t); + +for (int i =1 ; i < n -1 ; ++i) { +tcg_gen_add_i64 (t, a[i], c); +tcg_gen_setcond_i64 (TCG_COND_LTU , c, t, c); +tcg_gen_add_i64 (r[i], b[i], t); +tcg_gen_setcond_i64 (TCG_COND_LTU , t, r[i], t); +tcg_gen_or_i64 (c, c, t); + } + +tcg_gen_add_i64 (r[n -1 ], a[n -1 ], b[n -1 ]); +tcg_gen_add_i64 (r[n -1 ], r[n -1 ], c); + +tcg_temp_free_i64 (t); +tcg_temp_free_i64 (c); + } +} +void tcg_gen_sub2_i64 (TCGv_i64 rl,TCGv_i64 rh,TCGv_i64 al,TCGv_i64 ah,TCGv_i64 bl,TCGv_i64 bh) {
Re: [PATCH v9 13/40] tcg: Introduce tcg_gen_addN_i64
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 11 lines · James Hilliard
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.
Signed-off-by Richard Henderson <[email protected]>Quoted 8 lines
---
Changes v7 -> v8:
- New patch from Richard Henderson's v7.5 multiplier rework.
---
include/tcg/tcg-op-common.h| 1 +
tcg/tcg-op.c | 42 +++++++++++++++++++++++++++++++++++
+++++++2 files changed, 43 insertions(+)Richard, could we squash something like this?
-- >8 --
docs/devel/tcg-ops.rst +0
-0@@ -672,6 +672,12 @@ Multiword arithmetic support | If mulu2/muls2 are not provided by the backend, the tcg-opgenerator
can obtain the same results by emitting a pair of opcodes,
mul + muluh/mulsh.
Quoted 6 lines
+ * - addN *n*, *t0*, *t1*, *t2*
+
+ - | For each *n*, compute *t0* = *t1* + *t2* + *C*, + where *C* is the input carry bit provided by the host + architecture, and also compute the output carry bit. + Overlap between *t0* and *t1*/*t2* arrays is not allowed.
Better:
**Constraints**: *n* must be greater than 2 and overlap between *t0* and *t1*/*t2* arrays is not allowed.
Quoted 72 lines
Memory Barrier support
----------------------
---Quoted 66 lines
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@@ -2275,6 +2275,48 @@ void tcg_gen_addcio_i64(TCGv_i64 r, TCGv_i64 co, } } +void tcg_gen_addN_i64 (int n,TCGv_i64 *r,TCGv_i64 *a,TCGv_i64 *b) +{ + tcg_debug_assert(n > 2); + + /* ??? Don't allow overlap for now. */ + for (int i = 0; i < n - 1; ++i) { + for (int j = i + 1; j < n; ++j) { + tcg_debug_assert(r[i] != a[j]); + tcg_debug_assert(r[i] != b[j]); + } + } + + if (tcg_op_supported(INDEX_op_addci, TCG_TYPE_I64, 0)) { + tcg_gen_op3_i64(INDEX_op_addco, r[0], a[0], b[0]); + for (int i = 1; i < n - 1; ++i) { + tcg_gen_op3_i64(INDEX_op_addcio, r[i], a[i], b[i]); + } + tcg_gen_op3_i64(INDEX_op_addci, r[n - 1], a[n - 1], b[n - 1]); + } else { + TCGv_i64 t = tcg_temp_ebb_new_i64(); + TCGv_i64 c = tcg_temp_ebb_new_i64(); + + tcg_gen_add_i64(t, a[0], b[0]); + tcg_gen_setcond_i64(TCG_COND_LTU, c, t, a[0]); + tcg_gen_mov_i64(r[0], t); + + for (int i = 1; i < n - 1; ++i) { + tcg_gen_add_i64(t, a[i], c); + tcg_gen_setcond_i64(TCG_COND_LTU, c, t, c); + tcg_gen_add_i64(r[i], b[i], t); + tcg_gen_setcond_i64(TCG_COND_LTU, t, r[i], t); + tcg_gen_or_i64(c, c, t); + } + + tcg_gen_add_i64(r[n - 1], a[n - 1], b[n - 1]); + tcg_gen_add_i64(r[n - 1], r[n - 1], c); + + tcg_temp_free_i64(t); + tcg_temp_free_i64(c); + } +} + void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al, TCGv_i64 ah, TCGv_i64 bl, TCGv_i64 bh) {
Re: [PATCH v9 13/40] tcg: Introduce tcg_gen_addN_i64
In reply to Philippe Mathieu-DaudéQuoted 28 lines · Philippe Mathieu-Daudé
Quoted 11 lines · James Hilliard
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.
Signed-off-by Richard Henderson <[email protected]>Quoted 7 lines
---
Changes v7 -> v8:
- New patch from Richard Henderson's v7.5 multiplier rework.
---
include/tcg/tcg-op-common.h| 1 +
tcg/tcg-op.c | 42 ++++++++++++++++++++++++++++++++++++++++++2 files changed, 43 insertions(+)Richard, could we squash something like this?
-- >8 --
docs/devel/tcg-ops.rst +0
-0
docs/devel/tcg-ops.rst Multiword arithmetic support · line 680
Quoted 9 lines
docs/devel/tcg-ops.rst +6
-0@@ -672,6 +672,12 @@ Multiword arithmetic support | If mulu2/muls2 are not provided by the backend, the tcg-op generator can obtain the same results by emitting a pair of opcodes, mul + muluh/mulsh. + * - addN *n*, *t0*, *t1*, *t2* + + - | For each *n*, compute *t0* = *t1* + *t2* + *C*, + where *C* is the input carry bit provided by the host + architecture, and also compute the output carry bit. + Overlap between *t0* and *t1*/*t2* arrays is not allowed.
No, because there's no addN *opcode*. You're raising an old issue: there's no separate documentation for the tcg_gen_* interface. Also, the text is inaccurate.
r~
PATCH v9 14/40 tcg: Optimize INDEX_op_mul[us]2 for 0 and 1
In reply to James HilliardFrom: Richard Henderson <[email protected]>
Zero operands produce a zero high and low product. One operands produce a copy of the other operand and a zero or sign extension in the high half.
Fold those cases during TCG optimization so wide-multiply idioms used by target translators can collapse before code generation.
---
Changes v7 -> v8:
- New patch from Richard Henderson's v7.5 multiplier rework.
--- tcg/optimize.c | 92 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 32 deletions(-)
tcg/optimize.c +60 -32
@@ -2173,45 +2173,73 @@ static bool fold_multiply2(OptContext *ctx, TCGOp *op) {swap_commutative (op->args[0 ], &op->args[2 ], &op->args[3 ]); -if (arg_is_const (op->args[2 ]) &&arg_is_const (op->args[3 ])) { -uint64_t a =arg_const_val (op->args[2 ]); +if (arg_is_const (op->args[3 ])) {uint64_t b =arg_const_val (op->args[3 ]); -uint64_t h, l; -TCGArg rl, rh; +TCGArg rl = op->args[0 ]; +TCGArg rh = op->args[1 ];TCGOp *op2; -switch (op->opc) { -case INDEX_op_mulu2: -if (ctx->type ==TCG_TYPE_I32 ) { - l = (uint64_t )(uint32_t )a * (uint32_t )b; - h = (int32_t )(l >>32 ); - l = (int32_t )l; - }else { -mulu64 (&l, &h, a, b); - } -break ; -case INDEX_op_muls2: -if (ctx->type ==TCG_TYPE_I32 ) { - l = (int64_t )(int32_t )a * (int32_t )b; - h = l >>32 ; - l = (int32_t )l; - }else { -muls64 (&l, &h, a, b); +if (arg_is_const (op->args[2 ])) { +uint64_t a =arg_const_val (op->args[2 ]); +uint64_t h, l; + +switch (op->opc) { +case INDEX_op_mulu2: +if (ctx->type ==TCG_TYPE_I32 ) { + l = (uint64_t )(uint32_t )a * (uint32_t )b; + h = (int32_t )(l >>32 ); + l = (int32_t )l; + }else { +mulu64 (&l, &h, a, b); + } +break ; +case INDEX_op_muls2: +if (ctx->type ==TCG_TYPE_I32 ) { + l = (int64_t )(int32_t )a * (int32_t )b; + h = l >>32 ; + l = (int32_t )l; + }else { +muls64 (&l, &h, a, b); + } +break ; +default : +g_assert_not_reached (); } -break ; -default : -g_assert_not_reached (); - } - rl = op->args[0 ]; - rh = op->args[1 ]; +/* The proper opcode is supplied by tcg_opt_gen_mov. */ + op2 =opt_insert_before (ctx, op,0 ,2 ); +tcg_opt_gen_movi (ctx, op2, rl, l); +tcg_opt_gen_movi (ctx, op, rh, h); +return true; + } -/* The proper opcode is supplied by tcg_opt_gen_mov. */ - op2 =opt_insert_before (ctx, op,0 ,2 ); +if (b ==0 ) { + op2 =opt_insert_before (ctx, op,0 ,2 ); +tcg_opt_gen_movi (ctx, op2, rl,0 ); +tcg_opt_gen_movi (ctx, op, rh,0 ); +return true; + } +if (b ==1 ) { + op2 =opt_insert_before (ctx, op,0 ,2 ); +tcg_opt_gen_mov (ctx, op2, rl, op->args[2 ]); + +switch (op->opc) { +case INDEX_op_mulu2: +tcg_opt_gen_movi (ctx, op, rh,0 ); +break ; +case INDEX_op_muls2: + op->opc = INDEX_op_sar; + op->args[0 ] = rh; + op->args[1 ] = rl; + op->args[2 ] = +arg_new_constant (ctx,tcg_type_size (ctx->type) *8 -1 ); +break ; +default : +g_assert_not_reached (); + } -tcg_opt_gen_movi (ctx, op, rl, l); -tcg_opt_gen_movi (ctx, op2, rh, h); -return true; +return true; + } }return finish_folding (ctx, op); }
Signature · 1 line
2.54.0
Re: [PATCH v9 14/40] tcg: Optimize INDEX_op_mul[us]2 for 0 and 1
Quoted 119 lines · James Hilliard
From: Richard Henderson <[email protected]>
Zero operands produce a zero high and low product. One operands produce a copy of the other operand and a zero or sign extension in the high half.
Fold those cases during TCG optimization so wide-multiply idioms used by target translators can collapse before code generation.
Signed-off-by Richard Henderson <[email protected]>---
Changes v7 -> v8:
- New patch from Richard Henderson's v7.5 multiplier rework.--- tcg/optimize.c | 92 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 32 deletions(-)tcg/optimize.c +57
-29@@ -2173,45 +2173,73 @@ static bool fold_multiply2(OptContext *ctx, TCGOp *op) {swap_commutative (op->args[0 ], &op->args[2 ], &op->args[3 ]); -if (arg_is_const (op->args[2 ]) &&arg_is_const (op->args[3 ])) { -uint64_t a =arg_const_val (op->args[2 ]); +if (arg_is_const (op->args[3 ])) {uint64_t b =arg_const_val (op->args[3 ]); -uint64_t h, l; -TCGArg rl, rh; +TCGArg rl = op->args[0 ]; +TCGArg rh = op->args[1 ];TCGOp *op2; -switch (op->opc) { -case INDEX_op_mulu2: -if (ctx->type ==TCG_TYPE_I32 ) { - l = (uint64_t )(uint32_t )a * (uint32_t )b; - h = (int32_t )(l >>32 ); - l = (int32_t )l; - }else { -mulu64 (&l, &h, a, b); - } -break ; -case INDEX_op_muls2: -if (ctx->type ==TCG_TYPE_I32 ) { - l = (int64_t )(int32_t )a * (int32_t )b; - h = l >>32 ; - l = (int32_t )l; - }else { -muls64 (&l, &h, a, b); +if (arg_is_const (op->args[2 ])) { +uint64_t a =arg_const_val (op->args[2 ]); +uint64_t h, l; + +switch (op->opc) { +case INDEX_op_mulu2: +if (ctx->type ==TCG_TYPE_I32 ) { + l = (uint64_t )(uint32_t )a * (uint32_t )b; + h = (int32_t )(l >>32 ); + l = (int32_t )l; + }else { +mulu64 (&l, &h, a, b); + } +break ; +case INDEX_op_muls2: +if (ctx->type ==TCG_TYPE_I32 ) { + l = (int64_t )(int32_t )a * (int32_t )b; + h = l >>32 ; + l = (int32_t )l; + }else { +muls64 (&l, &h, a, b); + } +break ; +default : +g_assert_not_reached (); } -break ; -default : -g_assert_not_reached (); - } - rl = op->args[0 ]; - rh = op->args[1 ]; +/* The proper opcode is supplied by tcg_opt_gen_mov. */ + op2 =opt_insert_before (ctx, op,0 ,2 ); +tcg_opt_gen_movi (ctx, op2, rl, l); +tcg_opt_gen_movi (ctx, op, rh, h); +return true; + } -/* The proper opcode is supplied by tcg_opt_gen_mov. */ - op2 =opt_insert_before (ctx, op,0 ,2 ); +if (b ==0 ) { + op2 =opt_insert_before (ctx, op,0 ,2 ); +tcg_opt_gen_movi (ctx, op2, rl,0 ); +tcg_opt_gen_movi (ctx, op, rh,0 ); +return true; + } +if (b ==1 ) { + op2 =opt_insert_before (ctx, op,0 ,2 ); +tcg_opt_gen_mov (ctx, op2, rl, op->args[2 ]); + +switch (op->opc) { +case INDEX_op_mulu2: +tcg_opt_gen_movi (ctx, op, rh,0 ); +break ; +case INDEX_op_muls2: + op->opc = INDEX_op_sar; + op->args[0 ] = rh; + op->args[1 ] = rl; + op->args[2 ] = +arg_new_constant (ctx,tcg_type_size (ctx->type) *8 -1 ); +break ; +default : +g_assert_not_reached ();
tcg/optimize.c static bool fold_multiply2(OptContext *ctx, TCGOp *op) · line 2245
Quoted 10 lines
tcg/optimize.c +3
-3+ } -tcg_opt_gen_movi (ctx, op, rl, l); -tcg_opt_gen_movi (ctx, op2, rh, h); -return true; +return true; + } }return finish_folding (ctx, op); }
Removing the indentation changes, the content of this patch is:
-- >8 --
tcg/optimize.c +29 -3
@@ -2208,9 +2208,36 @@ static bool fold_multiply2(OptContext *ctx, TCGOp *op)/* The proper opcode is supplied by tcg_opt_gen_mov. */ op2 =opt_insert_before (ctx, op,0 ,2 ); -tcg_opt_gen_movi (ctx, op, rl, l); -tcg_opt_gen_movi (ctx, op2, rh, h); +tcg_opt_gen_movi (ctx, op2, rl, l); +tcg_opt_gen_movi (ctx, op, rh, h); +return true; + } + +if (b ==0 ) { + op2 =opt_insert_before (ctx, op,0 ,2 ); +tcg_opt_gen_movi (ctx, op2, rl,0 ); +tcg_opt_gen_movi (ctx, op, rh,0 ); +return true; + } +if (b ==1 ) { + op2 =opt_insert_before (ctx, op,0 ,2 ); +tcg_opt_gen_mov (ctx, op2, rl, op->args[2 ]); + +switch (op->opc) { +case INDEX_op_mulu2: +tcg_opt_gen_movi (ctx, op, rh,0 ); +break ; +case INDEX_op_muls2: + op->opc = INDEX_op_sar; + op->args[0 ] = rh; + op->args[1 ] = rl; + op->args[2 ] = +arg_new_constant (ctx,tcg_type_size (ctx->type) *8 -1 ); +break ; +default : +g_assert_not_reached (); + }return true; } } ---
I don't understand this change:
- tcg_opt_gen_movi(ctx, op, rl, l); - tcg_opt_gen_movi(ctx, op2, rh, h); + tcg_opt_gen_movi(ctx, op2, rl, l); + tcg_opt_gen_movi(ctx, op, rh, h);
PATCH v9 15/40 target/mips: add Octeon multiplier state
In reply to James HilliardAdd 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.
---
Changes v2 -> v3:
- Split the multiplier state out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
Changes v3 -> v4:
- Document and keep the Octeon3 MPL3-MPL5/P3-P5 high-lane state used by the two-source MTM/MTP forms.
Changes v7 -> v8:
- Incorporate Richard Henderson's v7.5 global TCG variable setup for inline multiplier translation.
--- target/mips/cpu.h | 12 ++++++++++++ target/mips/system/machine.c | 33 +++++++++++++++++++++++++++++++++ target/mips/tcg/translate.c | 18 ++++++++++++++++++ target/mips/tcg/translate.h | 2 ++ 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/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]);
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;
Signature · 1 line
2.54.0
PATCH v9 16/40 target/mips: add Octeon MTM instructions
In reply to James HilliardAdd 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.
---
Changes v2 -> v3:
- Split MTM0 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
Changes v3 -> v4:
- Keep the Octeon3 two-source rt high-lane operand and document that
legacy one-source MTM encodings use rt == $zero.
Changes v5 -> v6:
- Clarify the CN71XX-defined MPL1 zeroing after checking the register-state table and description.
Changes v7 -> v8:
- Combine MTM0/MTM1/MTM2 in the v7.5 inline TCG translator form from Richard Henderson.
--- 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.54.0
PATCH v9 17/40 target/mips: add Octeon MTP instructions
In reply to James HilliardAdd 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.
---
Changes v2 -> v3:
- Split MTP0/MTP1/MTP2 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
Changes v3 -> v4:
- Keep the Octeon3 two-source rt high-lane operand and document that
legacy one-source MTP encodings use rt == $zero.
Changes v5 -> v6:
- Zero P1 after checking the CN71XX register-state table and description.
Changes v7 -> v8:
- Combine MTP0/MTP1/MTP2 in the v7.5 inline TCG translator form from Richard Henderson.
--- 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.54.0
PATCH v9 18/40 target/mips: add Octeon VMULU instruction
In reply to James HilliardVMULU 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.
---
Changes v2 -> v3:
- Split VMULU out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
Changes v5 -> v6:
- Rename the translator helper callback typedef for clarity.
Changes v7 -> v8:
- Use Richard Henderson's v7.5 inline TCG translator with
tcg_gen_addN_i64. --- target/mips/tcg/octeon.decode | 2 ++ target/mips/tcg/octeon_translate.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 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; +}
Signature · 1 line
2.54.0
Re: [PATCH v9 18/40] target/mips: add Octeon VMULU instruction
Quoted 18 lines · James Hilliard
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.
Signed-off-by James Hilliard <[email protected]>Signed-off-by Richard Henderson <[email protected]>---
Changes v2 -> v3:
- Split VMULU out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)Changes v5 -> v6:
- Rename the translator helper callback typedef for clarity.
Quoted 7 lines
Changes v7 -> v8:
- Use Richard Henderson's v7.5 inline TCG translator withtcg_gen_addN_i64. --- target/mips/tcg/octeon.decode | 2 ++ target/mips/tcg/octeon_translate.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
PATCH v9 19/40 target/mips: add Octeon VMM0 instruction
In reply to James HilliardVMM0 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.
---
Changes v8 -> v9:
- Reuse octeon_zero_partial_product_state() for partial-product clearing.
Changes v2 -> v3:
- Split VMM0 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
Changes v3 -> v4:
- Document the Octeon3 chain update behavior.
Changes v5 -> v6:
- Zero MPL1 after checking the CN71XX VMM0 definition and add MPL1 smoke coverage.
Changes v7 -> v8:
- Use Richard Henderson's v7.5 inline TCG translator, which keeps only the architecturally defined MPL1 and partial-product clearing.
--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 16 ++++++++++++++++ 2 files changed, 17 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; +}
Signature · 1 line
2.54.0
Re: [PATCH v9 19/40] target/mips: add Octeon VMM0 instruction
Quoted 24 lines · James Hilliard
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.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by James Hilliard <[email protected]>Signed-off-by Richard Henderson <[email protected]>---
Changes v8 -> v9:
- Reuseocteon_zero_partial_product_state()for partial-product clearing.Changes v2 -> v3:
- Split VMM0 out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)Changes v3 -> v4:
- Document the Octeon3 chain update behavior.Changes v5 -> v6:
- Zero MPL1 after checking the CN71XX VMM0 definition and add MPL1 smoke coverage.
Quoted 7 lines
Changes v7 -> v8:
- Use Richard Henderson's v7.5 inline TCG translator, which keeps only the architecturally defined MPL1 and partial-product clearing.--- target/mips/tcg/octeon.decode | 1 + target/mips/tcg/octeon_translate.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
PATCH v9 20/40 target/mips: add Octeon V3MULU instruction
In reply to James HilliardV3MULU 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].
---
Changes v2 -> v3:
- Split V3MULU out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
Changes v3 -> v4:
- Keep the Octeon3 MPL3-MPL5/P3-P5 high lanes used by the two-source MTM/MTP forms and Cavium SDK/runtime code.
Changes v7 -> v8:
- Use Richard Henderson's v7.5 inline TCG translator with
tcg_gen_addN_i64. --- 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.54.0
PATCH v9 21/40 target/mips: add Octeon QMAC instructions
In reply to James HilliardQMAC.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.
---
Changes v5 -> v6:
- New patch.
Changes v7 -> v8:
- Use Richard Henderson's v7.5 inline TCG translator.
--- target/mips/tcg/octeon.decode | 4 +++ target/mips/tcg/octeon_translate.c | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 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 +60 -0
63 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v9 22/40 tests/tcg/mips: add Octeon instruction smoke test
In reply to James HilliardAdd a mips64/mips64el linux-user TCG smoke test for representative Octeon integer, comparison, population count, and multiplier instruction paths. Include hardware-backed regression coverage for VMM0 MPL1 zeroing and MTP0 P1 zeroing.
Run the test with -cpu Octeon68XX and share the source between the mips64 and mips64el target directories.
---
Changes v2 -> v3:
- Split the smoke test out of the combined Octeon arithmetic and memory instruction patch. (requested by Richard Henderson)
Changes v5 -> v6:
- Add VMM0/MPL1 and MTP0/P1 reset checks for the CN71XX-defined reset-state behavior.
--- MAINTAINERS | 2 + tests/tcg/mips/user/isa/octeon/octeon-insns.c | 204 ++++++++++++++++++++++++++ tests/tcg/mips64/Makefile.target | 20 +++ tests/tcg/mips64el/Makefile.target | 8 + 4 files changed, 234 insertions(+)
MAINTAINERS +2 -0
@@ -311,6 +311,8 @@ F: target/mips/ F: disas/*mips.c F: docs/system/cpu-models-mips.rst.inc F: tests/tcg/mips/ +F: tests/tcg/mips64/ +F: tests/tcg/mips64el/ OpenRISC TCG CPUs M: Stafford Horne <[email protected]>
tests/tcg/mips/user/isa/octeon/octeon-insns.c new file +204 -0
204 lines not on this page · raw message
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.54.0
PATCH v9 23/40 target/mips: add Octeon LA* atomic instructions
In reply to James HilliardImplement 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.
---
Changes v1 -> v2:
- Keep LA* atomics naturally aligned per Octeon L2 transaction semantics.
- Use explicit i64 TCG ops in the LA* translator paths. (suggested by Philippe Mathieu-Daudé)
Changes v2 -> v3:
- Drop redundant TARGET_LONG_BITS guards from doubleword atomic paths. (suggested by Richard Henderson)
- Group LA* translator wrappers by argument shape instead of adding one wrapper per instruction. (suggested by Richard Henderson)
Changes v3 -> v4:
- Use i64 atomic helpers for both word and doubleword paths and select word sign-extension through MO_SL. (suggested by Richard Henderson)
Changes v5 -> v6:
- Rename the shared translator helpers to distinguish fetch-add and exchange operations.
--- 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.54.0
PATCH v9 24/40 target/mips: add Octeon COP2 crypto state
In reply to James HilliardAdd the common state needed by Octeon's selector-driven COP2 crypto interfaces. This includes storage for the base hash, AES, CRC, GFM, 3DES, KASUMI, and SNOW3G engines, plus the shared selector-window mode used by overlapping hardware register banks.
Describe the shared HSH/SHA512, SHA3, SNOW3G, and ZUC selector window up front so later engine patches can add their own state and helper logic without rewriting common comments. Keep selector values out of the CPU state header; decodetree owns instruction decode and helper-local constants cover the few shared-window arithmetic cases.
Migrate the state in an Octeon-only subsection so non-Octeon CPU models do not grow migration data. Later patches wire helpers and explicit selector decode on top of this state.
---
Changes v8 -> v9:
- Remove the MIPSOcteonCop2Sel enum; selector values are decoded by decodetree or kept local to helper plumbing.
- Leave only COP2 state and migration data in this patch.
Changes v7 -> v8:
- Split COP2 crypto state and migration coverage out of the combined COP2 crypto core patch.
--- target/mips/cpu.h | 37 +++++++++++++++++++++++++++++++++++++ target/mips/system/machine.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+)
target/mips/cpu.h +37 -0
@@ -537,6 +537,41 @@ struct TCState { };struct MIPSITUState ; +typedef enum MIPSOcteonSharedMode { +OCTEON_SHARED_MODE_NONE =0 , +OCTEON_SHARED_MODE_SHA512 , +OCTEON_SHARED_MODE_SNOW3G , +}MIPSOcteonSharedMode ; + +typedef struct MIPSOcteonCryptoState { +uint64_t des3_key[3 ]; +uint64_t des3_iv; +uint64_t des3_result; +uint64_t hsh_iv[4 ]; +uint64_t hsh_dat[8 ]; +uint64_t hsh_ivw[8 ]; +uint64_t hsh_datw[16 ]; +uint64_t aes_iv[2 ]; +uint64_t aes_key[4 ]; +uint64_t aes_result[2 ]; +uint64_t aes_input[2 ]; +uint64_t gfm_mul[2 ]; +uint64_t gfm_resinp[2 ]; +uint64_t gfm_xor0; +uint64_t gfm_reflect_mul[2 ]; +uint64_t gfm_reflect_resinp[2 ]; +uint64_t gfm_reflect_xor0; +uint16_t gfm_poly; +uint8_t aes_keylen; +uint32_t shared_mode; +uint32_t crc_poly; +uint32_t crc_iv; +uint32_t crc_len; +uint32_t snow3g_fsm[3 ]; +uint32_t snow3g_lfsr[16 ]; +uint64_t snow3g_result; +}MIPSOcteonCryptoState ; + typedef struct CPUArchState { TCState active_tc; CPUMIPSFPUContext active_fpu;
@@ -558,6 +593,8 @@ typedef struct CPUArchState {#define MSAIR_ProcID 8#define MSAIR_Rev 0 +MIPSOcteonCryptoState octeon_crypto; +/* * CP0 Register 0 */
target/mips/system/machine.c +37 -0
@@ -279,6 +279,42 @@ static const VMStateDescription mips_vmstate_octeon_multiplier = { } }; +static const VMStateDescription mips_vmstate_octeon_crypto = { + .name ="cpu/octeon_crypto" , + .version_id =1 , + .minimum_version_id =1 , + .needed = mips_octeon_needed, + .fields = (const VMStateField []) { +VMSTATE_UINT64_ARRAY (env.octeon_crypto.des3_key,MIPSCPU ,3 ), +VMSTATE_UINT64 (env.octeon_crypto.des3_iv,MIPSCPU ), +VMSTATE_UINT64 (env.octeon_crypto.des3_result,MIPSCPU ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.hsh_iv,MIPSCPU ,4 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.hsh_dat,MIPSCPU ,8 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.hsh_ivw,MIPSCPU ,8 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.hsh_datw,MIPSCPU ,16 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_iv,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_key,MIPSCPU ,4 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_result,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_input,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.gfm_mul,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.gfm_resinp,MIPSCPU ,2 ), +VMSTATE_UINT64 (env.octeon_crypto.gfm_xor0,MIPSCPU ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.gfm_reflect_mul,MIPSCPU ,2 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.gfm_reflect_resinp,MIPSCPU ,2 ), +VMSTATE_UINT64 (env.octeon_crypto.gfm_reflect_xor0,MIPSCPU ), +VMSTATE_UINT16 (env.octeon_crypto.gfm_poly,MIPSCPU ), +VMSTATE_UINT8 (env.octeon_crypto.aes_keylen,MIPSCPU ), +VMSTATE_UINT32 (env.octeon_crypto.shared_mode,MIPSCPU ), +VMSTATE_UINT32 (env.octeon_crypto.crc_poly,MIPSCPU ), +VMSTATE_UINT32 (env.octeon_crypto.crc_iv,MIPSCPU ), +VMSTATE_UINT32 (env.octeon_crypto.crc_len,MIPSCPU ), +VMSTATE_UINT32_ARRAY (env.octeon_crypto.snow3g_fsm,MIPSCPU ,3 ), +VMSTATE_UINT32_ARRAY (env.octeon_crypto.snow3g_lfsr,MIPSCPU ,16 ), +VMSTATE_UINT64 (env.octeon_crypto.snow3g_result,MIPSCPU ), +VMSTATE_END_OF_LIST () + } +}; +const VMStateDescription vmstate_mips_cpu = { .name ="cpu" , .version_id =21 ,
@@ -396,6 +432,7 @@ const VMStateDescription vmstate_mips_cpu = { .subsections = (const VMStateDescription * const []) { &mips_vmstate_timer, &mips_vmstate_octeon_multiplier, + &mips_vmstate_octeon_crypto,NULL } };
Signature · 1 line
2.54.0
Re: [PATCH v9 24/40] target/mips: add Octeon COP2 crypto state
Quoted 18 lines · James Hilliard
target/mips/cpu.h +18
-0+typedef struct MIPSOcteonCryptoState { + uint64_t des3_key[3]; + uint64_t des3_iv; + uint64_t des3_result; + uint64_t hsh_iv[4]; + uint64_t hsh_dat[8]; + uint64_t hsh_ivw[8]; + uint64_t hsh_datw[16]; + uint64_t aes_iv[2]; + uint64_t aes_key[4]; + uint64_t aes_result[2]; + uint64_t aes_input[2]; + uint64_t gfm_mul[2]; + uint64_t gfm_resinp[2]; + uint64_t gfm_xor0; + uint64_t gfm_reflect_mul[2]; + uint64_t gfm_reflect_resinp[2]; + uint64_t gfm_reflect_xor0;
target/mips/cpu.h struct TCState { · line 573
Quoted 10 lines
target/mips/cpu.h +10
-0+uint16_t gfm_poly; +uint8_t aes_keylen; +uint32_t shared_mode; +uint32_t crc_poly; +uint32_t crc_iv; +uint32_t crc_len; +uint32_t snow3g_fsm[3 ]; +uint32_t snow3g_lfsr[16 ]; +uint64_t snow3g_result; +} MIPSOcteonCryptoState;
It might be easier if these were sorted to match Table 2-2.
Why do you use uint32_t crc_len for CRCLEN<3:0>?
There is no gfm_xor0 or gfm_reflect_xor0 in table 2-2.
I suspect your implementations of CVM_MT_GFM_XOR0 and CVM_MT_GFM_XOR0_REFLECT are wrong.
hsh_dat[8] is mis-sized? Compared to HASHDAT[15:0]<63:0>.
hsh_datw[8] is not a thing; As I read CVM_MF_HSH_DAT and CVM_MF_HSH_DATW, they are different ways of accessing the same data.
hsh_iv[4] is mis-sized; there is no hsh_ivw[]. Similar error wrt DAT?
aes_result/aes_input should be one AESRESINP. You should not invent non-architectural cpu state. Elsewhere you mention latch/result, but that would be an implementation detail of individual operations. That said, I don't see any use of aes_input / aes_result that actually overlap. You copy aes_input to a local variable in[], and write to aes_result from a local variable out[]. You've already implemented the latch.
Why shared_mode? I don't see anything like it in the docs. From later patches which add zuc_lfsr[] and snow3g_lfsr[], I think this is incorrect. The docs explicitly say that those modes overlap HASHDAT[]. You should simply re-use that data.
r~
PATCH v9 25/40 target/mips: add Octeon COP2 crypto helper plumbing
In reply to James HilliardAdd the Octeon COP2 crypto helper source file and build it with the MIPS TCG target. The initial file contains the shared selector-window helper constants and mode setter used by later COP2 engine patches.
Keep these selector constants local to the helper implementation. The instruction dispatch itself remains fully decoded by decodetree, and later operation selectors call per-operation helpers rather than a common selector-dispatch helper.
---
Changes v8 -> v9:
- Split helper plumbing out of the former monolithic COP2 helper patch.
- Keep shared-window selector arithmetic local to octeon_crypto.c.
--- target/mips/tcg/meson.build | 1 + target/mips/tcg/octeon_crypto.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
target/mips/tcg/meson.build +1 -0
@@ -18,6 +18,7 @@ mips_ss.add(files( 'lmmi_helper.c', 'msa_helper.c', 'msa_translate.c', + 'octeon_crypto.c', 'op_helper.c', 'rel6_translate.c', 'translate.c',
target/mips/tcg/octeon_crypto.c new file +37 -0
@@ -0,0 +1,37 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* MIPS Octeon crypto emulation helpers. +* +* Copyright (c) 2026 James Hilliard +*/ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "internal.h" +#include "exec/helper-proto.h" +#include "crypto/aes.h" +#include "crypto/clmul.h" +#include "crypto/sm4.h" +#include "qemu/bitops.h" +#include "qemu/host-utils.h" + +/* +* The shared HSH/SHA3/SNOW3G/ZUC register window needs selector-position +* arithmetic. Instruction dispatch itself is still fully decoded by +* decodetree and calls per-operation helpers. +*/ +#define OCTEON_HSH_DATW (N ) (0x0240u + (N)) +#define OCTEON_HSH_IVW (N ) (0x0250u + (N)) +#define OCTEON_SHA3_DAT24_SEL 0x0050u +#define OCTEON_SHA3_DAT15_MT_SEL 0x0051u +#define OCTEON_SHA3_DAT15_MF_SEL OCTEON_HSH_DATW(15) +#define OCTEON_SNOW3G_LFSR (N ) OCTEON_HSH_DATW(N) +#define OCTEON_SNOW3G_RESULT_SEL OCTEON_HSH_IVW(0) +#define OCTEON_SNOW3G_FSM (N ) OCTEON_HSH_IVW(1 + (N)) + +static inline void octeon_set_shared_mode (MIPSOcteonCryptoState *crypto, +MIPSOcteonSharedMode mode) +{ + crypto->shared_mode = mode; +}
Signature · 1 line
2.54.0
Re: [PATCH v9 25/40] target/mips: add Octeon COP2 crypto helper plumbing
target/mips/tcg/octeon_crypto.c line 31
Quoted 13 lines · James Hilliard
target/mips/tcg/octeon_crypto.c new file +13
-0+/* +* The shared HSH/SHA3/SNOW3G/ZUC register window needs selector-position +* arithmetic. Instruction dispatch itself is still fully decoded by +* decodetree and calls per-operation helpers. +*/ +#define OCTEON_HSH_DATW (N ) (0x0240u + (N)) +#define OCTEON_HSH_IVW (N ) (0x0250u + (N)) +#define OCTEON_SHA3_DAT24_SEL 0x0050u +#define OCTEON_SHA3_DAT15_MT_SEL 0x0051u +#define OCTEON_SHA3_DAT15_MF_SEL OCTEON_HSH_DATW(15) +#define OCTEON_SNOW3G_LFSR (N ) OCTEON_HSH_DATW(N) +#define OCTEON_SNOW3G_RESULT_SEL OCTEON_HSH_IVW(0) +#define OCTEON_SNOW3G_FSM (N ) OCTEON_HSH_IVW(1 + (N))
What are these for? The MF/MT offsets should be irrelevant now.
target/mips/tcg/octeon_crypto.c line 37
Quoted 7 lines
target/mips/tcg/octeon_crypto.c new file +6
-0+ +static inline void octeon_set_shared_mode (MIPSOcteonCryptoState *crypto, +MIPSOcteonSharedMode mode) +{ + crypto->shared_mode = mode; +}
Unused function. This patch won't compile with clang.
Also, as I mentioned against the previous patch, I think shared_mode is an error.
r~
PATCH v9 26/40 target/mips: add Octeon CRC COP2 helpers
In reply to James HilliardAdd helper support for the Octeon COP2 CRC register interface. This covers normal and reflected CRC state handling, byte/halfword/word/ doubleword/variable-width update selectors, and the reflected IV readback operation.
The register moves that can be represented as direct TCG loads/stores are left to the later explicit selector decode patch. This patch only adds the side-effecting CRC helper implementation.
---
Changes v8 -> v9:
- Split CRC selector operations into their own COP2 helper patch.
- Expose per-operation helpers instead of a generic selector helper.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 14 +++++ target/mips/tcg/octeon_crypto.c | 128 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+)
target/mips/helper.h +14 -0
@@ -25,6 +25,20 @@ DEF_HELPER_3(crc32, tl, tl, tl, i32) DEF_HELPER_3(crc32c, tl, tl, tl, i32)DEF_HELPER_FLAGS_4 (rotx,TCG_CALL_NO_RWG_SE , tl, tl, i32, i32, i32) +/* Octeon COP2 selector operation helpers. */ +DEF_HELPER_1(octeon_cp2_mf_crc_iv_reflect, i64, env) +DEF_HELPER_2(octeon_cp2_mt_crc_write_iv_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_byte, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_half, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_word, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_byte_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_half_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_word_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_dword, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_var, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_crc_write_dword_reflect, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_crc_write_var_reflect, void, env, i64) + /* microMIPS functions */ DEF_HELPER_4(lwm, void, env, tl, tl, i32)DEF_HELPER_4 (swm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +128 -0
131 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v9 26/40] target/mips: add Octeon CRC COP2 helpers
Quoted 3 lines · James Hilliard
crypto->shared_mode = mode;}
+static inlineuint32_tocteon_crc_reflect32_by_byte(uint32_t v)
Missing newline. There are several other instances in this file.
Otherwise,
Ideally, patch 37 would be split so that we see the decode and such that use these helpers. And so that patch 37 isn't 548 lines.
r~
PATCH v9 27/40 target/mips: add Octeon GFM COP2 helpers
In reply to James HilliardAdd helper support for the Octeon GFM carryless multiply selectors. This models the normal and reflected multiplication paths, including the XOR-and-multiply forms that update the result/input state used by Octeon crypto code.
Use QEMU's crypto/clmul helpers for the reflected 128-bit carryless multiply operation instead of carrying a target-local multiply loop.
---
Changes v8 -> v9:
- Split GFM selector operations into their own COP2 helper patch.
- Expose per-operation helpers instead of a generic selector helper.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 2 + target/mips/tcg/octeon_crypto.c | 98 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)
target/mips/helper.h +2 -0
@@ -38,6 +38,8 @@ DEF_HELPER_2(octeon_cp2_mt_crc_write_dword, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_var, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_dword_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_var_reflect, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_gfm_xormul1_reflect, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_gfm_xormul1, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +98 -0
108 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v9 27/40] target/mips: add Octeon GFM COP2 helpers
target/mips/tcg/octeon_crypto.c static void octeon_crc_update_reflect(MIPSOcteonCryptoState *crypto, · line 97
Quoted 7 lines · James Hilliard
target/mips/tcg/octeon_crypto.c +1
-0@@ -94,10 +94,108 @@ static void octeon_crc_update_reflect(MIPSOcteonCryptoState *crypto,octeon_crc_set_state_reflect (crypto, crc); } +static uint64_t octeon_gfm_reduce64 (Int128 product,uint8_t poly)
Missing newline.
Quoted 13 lines
target/mips/tcg/octeon_crypto.c +13
-0+static void octeon_gfm_mul64_uia2 (const uint64_t x[2 ],const uint64_t y[2 ], +uint8_t poly,uint64_t out[2 ]) +{ +uint64_t vx =revbit64 (x[1 ]); +uint64_t vy =revbit64 (y[0 ]); +Int128 product =clmul_64 (vx, vy); +uint64_t res =octeon_gfm_reduce64 (product,revbit32 (poly) >>24 ); + + out[0 ] =0 ; + out[1 ] =revbit64 (res); +} + +static void octeon_gfm_mul_reflect (MIPSOcteonCryptoState *crypto,uint64_t data)
target/mips/tcg/octeon_crypto.c static void octeon_crc_update_reflect(MIPSOcteonCryptoState *crypto, · line 138
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+{ +uint64_t in[2 ] = { + crypto->gfm_reflect_resinp[0 ] ^ crypto->gfm_reflect_xor0, + crypto->gfm_reflect_resinp[1 ] ^ data, + }; + +octeon_gfm_mul64_uia2 (in, crypto->gfm_reflect_mul, + crypto->gfm_poly, crypto->gfm_reflect_resinp); + crypto->gfm_reflect_xor0 =0 ; +}
This seems to be wrong. At least I don't see how it matches the pseudocode. Certainly helper_octeon_cp2_mt_gfm_xormul1_reflect should not just handle 64 bits like this.
Quoted 23 lines
target/mips/tcg/octeon_crypto.c +23
-0+static void octeon_gfm_mul (const uint64_t x[2 ],const uint64_t y[2 ], +uint16_t poly,uint64_t out[2 ]) +{ +uint64_t zh =0 , zl =0 ; +uint64_t vh = y[0 ], vl = y[1 ]; +uint64_t rh = (uint64_t )poly <<48 ; +int i; + +for (i =0 ; i <128 ; i++) { +bool bit; +bool lsb; + +if (i <64 ) { + bit = (x[0 ] >> (63 - i)) &1 ; + }else { + bit = (x[1 ] >> (127 - i)) &1 ; + } +if (bit) { + zh ^= vh; + zl ^= vl; + } + + lsb = vl &1 ;
target/mips/tcg/octeon_crypto.c static void octeon_crc_update_reflect(MIPSOcteonCryptoState *crypto, · line 171
Quoted 10 lines
target/mips/tcg/octeon_crypto.c +10
-0+ vl = (vh <<63 ) | (vl >>1 ); + vh >>=1 ; +if (lsb) { + vh ^= rh; + } + } + + out[0 ] = zh; + out[1 ] = zl; +}
Some comments would be good here, especially since this doesn't match the pseudocode.
There are lots of doubleword_bit_reflect in the pseudocode, which you appear to be avoiding by reversing the direction of the shift. You appear to be swapping the read and writeback of hi/lo to account for the individual and separate doubleword_bit_reflect wrt the 128-bit quantity.
Your treatment of the polynomial appears to be wrong. The pseudocode places 8 bits in POLY[0] and 8 bits in POLY[1], whereas you're placing 16 polynomial bits in POLY[0].
I think you're overthinking the function parameters. You might as well directly access env->crypto.gfm_*.
target/mips/tcg/octeon_crypto.c static void octeon_crc_update_reflect(MIPSOcteonCryptoState *crypto, · line 192
Quoted 11 lines
target/mips/tcg/octeon_crypto.c +11
-0+void helper_octeon_cp2_mt_gfm_xormul1 (CPUMIPSState *env,uint64_t value) +{ +MIPSOcteonCryptoState *crypto = &env->octeon_crypto; +uint64_t in[2 ] = { + crypto->gfm_resinp[0 ] ^ crypto->gfm_xor0, + crypto->gfm_resinp[1 ] ^ value, + }; + +if (crypto->gfm_poly <=0xff && crypto->gfm_mul[1 ] ==0 && in[0 ] ==0 ) { +octeon_gfm_mul64_uia2 (in, crypto->gfm_mul, + crypto->gfm_poly, crypto->gfm_resinp);
The uia2 path is definitely non-obvious.
I don't see how you can use clmul_64 and include the polynomial. If there were to be a clmul path, I would expect GFMPOLY == 0, so that V does not vary other than by shifting around the GFMMULT loop.
Either way, perhaps this is premature optimization.
r~
PATCH v9 28/40 target/mips: add Octeon SHA3 COP2 helpers
In reply to James HilliardAdd the Octeon SHA3 register-window state and helper operations. Keep the shared HSH/SHA3/SHA512 write path coherent, model the dedicated 25-lane Keccak state, and implement the Keccak-f[1600] permutation for the STARTOP selector.
The shared selector window still uses explicit selector-position arithmetic internally because multiple COP2 engines alias the same numeric window. Decode of the individual DMFC2/DMTC2 instructions remains in the later decodetree patch.
---
Changes v8 -> v9:
- Split SHA3 selector operations into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation SHA3 helpers.
- Use helper-local selector constants for shared-window position logic.
- Add matching helper.h declarations with the helper implementation.
Changes v1 -> v2:
- Use switch ranges and g_assert_not_reached() for SHA3 selector position decoding. (suggested by Philippe Mathieu-Daudé)
- Add selector dispatch updates in octeon_translate.c after moving COP2 decode out of translate.c. (suggested by Philippe Mathieu-Daudé)
Changes v5 -> v6:
- Rename SHA3 DAT15 selector aliases with MF/MT direction suffixes.
--- target/mips/cpu.h | 2 + target/mips/helper.h | 22 +++++ target/mips/system/machine.c | 1 + target/mips/tcg/octeon_crypto.c | 208 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+)
target/mips/cpu.h +2 -0
@@ -541,6 +541,7 @@ typedef enum MIPSOcteonSharedMode {OCTEON_SHARED_MODE_NONE =0 ,OCTEON_SHARED_MODE_SHA512 ,OCTEON_SHARED_MODE_SNOW3G , +OCTEON_SHARED_MODE_SHA3 , } MIPSOcteonSharedMode; typedef struct MIPSOcteonCryptoState {
@@ -551,6 +552,7 @@ typedef struct MIPSOcteonCryptoState {uint64_t hsh_dat[8 ];uint64_t hsh_ivw[8 ];uint64_t hsh_datw[16 ]; +uint64_t sha3_state[25 ];uint64_t aes_iv[2 ];uint64_t aes_key[4 ];uint64_t aes_result[2 ];
target/mips/helper.h +22 -0
@@ -27,6 +27,7 @@ DEF_HELPER_FLAGS_4(rotx, TCG_CALL_NO_RWG_SE, tl, tl, i32, i32, i32)/* Octeon COP2 selector operation helpers. */ DEF_HELPER_1(octeon_cp2_mf_crc_iv_reflect, i64, env) +DEF_HELPER_1(octeon_cp2_mf_sha3_dat24, i64, env) DEF_HELPER_2(octeon_cp2_mt_crc_write_iv_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_byte, void, env, i64)DEF_HELPER_2 (octeon_cp2_mt_crc_write_half, void, env, i64)
@@ -40,6 +41,27 @@ DEF_HELPER_2(octeon_cp2_mt_crc_write_dword_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_var_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_gfm_xormul1_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_gfm_xormul1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_dat24, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_dat15, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat2, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat3, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat4, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat5, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat6, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat7, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat8, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat9, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat10, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat11, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat12, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat13, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat14, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat15, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat16, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sha3_xordat17, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_sha3_startop, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/system/machine.c +1 -0
@@ -292,6 +292,7 @@ static const VMStateDescription mips_vmstate_octeon_crypto = {VMSTATE_UINT64_ARRAY (env.octeon_crypto.hsh_dat,MIPSCPU ,8 ),VMSTATE_UINT64_ARRAY (env.octeon_crypto.hsh_ivw,MIPSCPU ,8 ),VMSTATE_UINT64_ARRAY (env.octeon_crypto.hsh_datw,MIPSCPU ,16 ), +VMSTATE_UINT64_ARRAY (env.octeon_crypto.sha3_state,MIPSCPU ,25 ),VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_iv,MIPSCPU ,2 ),VMSTATE_UINT64_ARRAY (env.octeon_crypto.aes_key,MIPSCPU ,4 ), VMSTATE_UINT64_ARRAY(env.octeon_crypto.aes_result, MIPSCPU, 2),
target/mips/tcg/octeon_crypto.c +208 -0
224 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v9 29/40 target/mips: add Octeon ZUC COP2 helpers
In reply to James HilliardAdd the Octeon ZUC START and MORE helper operations and model the shared state window used by the hardware interface. This covers the keystream and MAC engine state, including the save-and-restore view that overlaps the HSH/SHA3 bank.
Shared-window writes also update the SHA512/SHA3 backing state so guests can switch between engines without stale register contents.
---
Changes v8 -> v9:
- Split ZUC selector operations into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation ZUC helpers.
- Use helper-local selector constants for shared-window position logic.
- Add matching helper.h declarations with the helper implementation.
Changes v1 -> v2:
- Add shared-window selector predicates and assert on unreachable ZUC selector switches. (suggested by Philippe Mathieu-Daudé)
- Preserve aliased HSH/SHA3/SHA512 backing state during ZUC shared-window writes.
- Add selector dispatch updates in octeon_translate.c after moving COP2 decode out of translate.c. (suggested by Philippe Mathieu-Daudé)
Changes v5 -> v6:
- Use the manual-aligned HSH_DATW field and shared HSH window helper names introduced by the COP2 crypto core patch.
--- target/mips/cpu.h | 5 + target/mips/helper.h | 2 + target/mips/system/machine.c | 4 + target/mips/tcg/octeon_crypto.c | 324 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 335 insertions(+)
target/mips/cpu.h +5 -0
@@ -541,6 +541,7 @@ typedef enum MIPSOcteonSharedMode {OCTEON_SHARED_MODE_NONE =0 ,OCTEON_SHARED_MODE_SHA512 ,OCTEON_SHARED_MODE_SNOW3G , +OCTEON_SHARED_MODE_ZUC ,OCTEON_SHARED_MODE_SHA3 , } MIPSOcteonSharedMode;
@@ -572,6 +573,10 @@ typedef struct MIPSOcteonCryptoState {uint32_t snow3g_fsm[3 ];uint32_t snow3g_lfsr[16 ];uint64_t snow3g_result; +uint32_t zuc_fsm[2 ]; +uint32_t zuc_lfsr[16 ]; +uint32_t zuc_window[3 ]; +uint32_t zuc_tresult; } MIPSOcteonCryptoState; typedef struct CPUArchState {
target/mips/helper.h +2 -0
@@ -62,6 +62,8 @@ DEF_HELPER_2(octeon_cp2_mt_sha3_xordat15, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_sha3_xordat16, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_sha3_xordat17, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_sha3_startop, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_zuc_start, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_zuc_more, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/system/machine.c +4 -0
@@ -312,6 +312,10 @@ static const VMStateDescription mips_vmstate_octeon_crypto = {VMSTATE_UINT32_ARRAY (env.octeon_crypto.snow3g_fsm,MIPSCPU ,3 ),VMSTATE_UINT32_ARRAY (env.octeon_crypto.snow3g_lfsr,MIPSCPU ,16 ),VMSTATE_UINT64 (env.octeon_crypto.snow3g_result,MIPSCPU ), +VMSTATE_UINT32_ARRAY (env.octeon_crypto.zuc_fsm,MIPSCPU ,2 ), +VMSTATE_UINT32_ARRAY (env.octeon_crypto.zuc_lfsr,MIPSCPU ,16 ), +VMSTATE_UINT32_ARRAY (env.octeon_crypto.zuc_window,MIPSCPU ,3 ), +VMSTATE_UINT32 (env.octeon_crypto.zuc_tresult,MIPSCPU ), VMSTATE_END_OF_LIST() } };
target/mips/tcg/octeon_crypto.c +324 -0
342 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v9 29/40] target/mips: add Octeon ZUC COP2 helpers
Quoted 13 lines · James Hilliard
target/mips/cpu.h +1
-0@@ -541,6 +541,7 @@ typedef enum MIPSOcteonSharedMode {OCTEON_SHARED_MODE_NONE =0 ,OCTEON_SHARED_MODE_SHA512 ,OCTEON_SHARED_MODE_SNOW3G , +OCTEON_SHARED_MODE_ZUC ,OCTEON_SHARED_MODE_SHA3 , } MIPSOcteonSharedMode;
target/mips/cpu.h typedef struct MIPSOcteonCryptoState { · line 580
Quoted 8 lines
target/mips/cpu.h +4
-0@@ -572,6 +573,10 @@ typedef struct MIPSOcteonCryptoState {uint32_t snow3g_fsm[3 ];uint32_t snow3g_lfsr[16 ];uint64_t snow3g_result; +uint32_t zuc_fsm[2 ]; +uint32_t zuc_lfsr[16 ]; +uint32_t zuc_window[3 ]; +uint32_t zuc_tresult; } MIPSOcteonCryptoState;
None of this is architectural state, and logically overlaps HASH{DAT,IV}.
r~
PATCH v9 30/40 target/mips: add Octeon SNOW3G COP2 helpers
In reply to James HilliardAdd helper support for the Octeon SNOW3G START and MORE selectors. This models the LFSR/FSM state, the hardware result window, and the shared HSH/SHA3/SNOW3G/ZUC register window used for state save and restore.
The helpers preserve the shared-window mode so DMFC2/DMTC2 accesses to the aliased window return the active engine view.
---
Changes v8 -> v9:
- Split SNOW3G selector operations into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation SNOW3G helpers.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 2 + target/mips/tcg/octeon_crypto.c | 233 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+)
target/mips/helper.h +2 -0
@@ -64,6 +64,8 @@ DEF_HELPER_2(octeon_cp2_mt_sha3_xordat17, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_sha3_startop, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_zuc_start, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_zuc_more, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_snow3g_start, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_snow3g_more, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +233 -0
245 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v9 31/40 target/mips: add Octeon AES COP2 helpers
In reply to James HilliardAdd helper support for the Octeon AES operation selectors. The direct register-transfer selectors are handled later by the explicit decode patch; this patch adds the ECB/CBC encrypt and decrypt operations that consume the AES input, key, IV, and key-length state.
The AESRESINP direct write path keeps a separate input latch and readback view. Later translator comments document that split where the direct TCG stores are emitted.
---
Changes v8 -> v9:
- Split AES operation selectors into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation AES helpers.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/cpu.h | 5 ++ target/mips/helper.h | 4 ++ target/mips/tcg/octeon_crypto.c | 141 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+)
target/mips/cpu.h +5 -0
@@ -556,6 +556,11 @@ typedef struct MIPSOcteonCryptoState {uint64_t sha3_state[25 ];uint64_t aes_iv[2 ];uint64_t aes_key[4 ]; +/* +* AESRESINP is one architectural selector bank. Keep a separate input +* latch so operation selectors can consume a pending block while DMFC2 +* reads expose the latest result/readback value. +*/ uint64_t aes_result[2 ];uint64_t aes_input[2 ];uint64_t gfm_mul[2 ];
target/mips/helper.h +4 -0
@@ -66,6 +66,10 @@ DEF_HELPER_2(octeon_cp2_mt_zuc_start, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_zuc_more, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_snow3g_start, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_snow3g_more, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_aes_enc_cbc1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_aes_enc1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_aes_dec_cbc1, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_aes_dec1, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +141 -0
153 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v9 31/40] target/mips: add Octeon AES COP2 helpers
Quoted 26 lines · James Hilliard
Add helper support for the Octeon AES operation selectors. The direct register-transfer selectors are handled later by the explicit decode patch; this patch adds the ECB/CBC encrypt and decrypt operations that consume the AES input, key, IV, and key-length state.
The AESRESINP direct write path keeps a separate input latch and readback view. Later translator comments document that split where the direct TCG stores are emitted.
Signed-off-by James Hilliard <[email protected]>---
Changes v8 -> v9:
- Split AES operation selectors into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation AES helpers.
- Add matchinghelper.hdeclarations with the helper implementation.--- target/mips/cpu.h | 5 ++ target/mips/helper.h | 4 ++ target/mips/tcg/octeon_crypto.c | 141 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+)target/mips/cpu.h +0
-0
target/mips/cpu.h typedef struct MIPSOcteonCryptoState { · line 565
Quoted 10 lines
target/mips/cpu.h +5
-0@@ -556,6 +556,11 @@ typedef struct MIPSOcteonCryptoState {uint64_t sha3_state[25 ];uint64_t aes_iv[2 ];uint64_t aes_key[4 ]; +/* +* AESRESINP is one architectural selector bank. Keep a separate input +* latch so operation selectors can consume a pending block while DMFC2 +* reads expose the latest result/readback value. +*/ uint64_t aes_result[2 ];uint64_t aes_input[2 ];
Specific example? Because this seems wrong to me.
target/mips/cpu.h static void octeon_snow3g_more(MIPSOcteonCryptoState *crypto) · line 766
Quoted 5 lines
target/mips/cpu.h +1
-0@@ -763,6 +763,116 @@ static void octeon_snow3g_more(MIPSOcteonCryptoState *crypto)octeon_set_shared_mode (crypto,OCTEON_SHARED_MODE_SNOW3G );octeon_snow3g_queue_result (crypto); } +static int octeon_aes_key_bits (const MIPSOcteonCryptoState *crypto)
Missing newline, multiple instances.
Otherwise the actual operations look fine.
r~
PATCH v9 32/40 target/mips: add Octeon SMS4 COP2 helpers
In reply to James HilliardAdd helper support for the Octeon SMS4 operation selectors. SMS4 reuses the AES RESINP, IV, and key banks, so the helpers share the existing AES state while implementing the SMS4 ECB/CBC encrypt and decrypt operations.
---
Changes v8 -> v9:
- Split SMS4 operation selectors into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation SMS4 helpers.
- Add matching helper.h declarations with the helper implementation.
Changes v1 -> v2:
- Add selector dispatch updates in octeon_translate.c after moving COP2 decode out of translate.c. (suggested by Philippe Mathieu-Daudé)
Changes v5 -> v6:
- Use RESINP wording for the SMS4 shared selector aliases.
--- target/mips/helper.h | 4 ++ target/mips/tcg/octeon_crypto.c | 121 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+)
target/mips/helper.h +4 -0
@@ -70,6 +70,10 @@ DEF_HELPER_2(octeon_cp2_mt_aes_enc_cbc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_aes_enc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_aes_dec_cbc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_aes_dec1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sms4_enc_cbc1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sms4_enc1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_sms4_dec_cbc1, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_sms4_dec1, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +121 -0
139 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v9 33/40 target/mips: add Octeon 3DES and KASUMI COP2 helpers
In reply to James HilliardAdd helper support for the Octeon 3DES and KASUMI operation selectors. The 3DES helpers implement ECB and CBC encrypt/decrypt over the shared 3DES key, IV, and result bank. KASUMI reuses the same register bank and adds its own encrypt selectors.
This keeps the operation selectors in helper code while leaving simple key, IV, and result register transfers to the later explicit selector decode patch.
---
Changes v8 -> v9:
- Split 3DES/KASUMI operation selectors into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation 3DES/KASUMI helpers.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 6 + target/mips/tcg/octeon_crypto.c | 456 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 462 insertions(+)
target/mips/helper.h +6 -0
@@ -74,6 +74,12 @@ DEF_HELPER_2(octeon_cp2_mt_sms4_enc_cbc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_sms4_enc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_sms4_dec_cbc1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_sms4_dec1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_des3_enc_cbc, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_kas_enc_cbc, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_des3_enc, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_kas_enc, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_des3_dec_cbc, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_des3_dec, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +456 -0
468 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v9 34/40 target/mips: add Octeon Camellia COP2 helpers
In reply to James HilliardAdd helper support for the Octeon Camellia ROUND, FL, and FLINV selectors. The engine reuses the AES RESINP bank, and guest-managed key schedules drive the Camellia F-function and FL layers through these COP2 operations.
Implement the Camellia F-function and FL layers directly from RFC 3713.
---
Changes v8 -> v9:
- Split Camellia operation selectors into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation Camellia helpers.
- Add matching helper.h declarations with the helper implementation.
Changes v1 -> v2:
- Drop the Octeon prefix from generic Camellia helper routines. (suggested by Philippe Mathieu-Daudé)
- Add selector dispatch updates in octeon_translate.c after moving COP2 decode out of translate.c. (suggested by Philippe Mathieu-Daudé)
Changes v5 -> v6:
- Use RESINP wording for the Camellia shared selector aliases.
--- target/mips/helper.h | 3 + target/mips/tcg/octeon_crypto.c | 124 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+)
target/mips/helper.h +3 -0
@@ -80,6 +80,9 @@ DEF_HELPER_2(octeon_cp2_mt_des3_enc, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_kas_enc, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_des3_dec_cbc, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_des3_dec, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_camellia_fl, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_camellia_flinv, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_camellia_round, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +124 -0
136 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v9 35/40 target/mips: add Octeon HSH COP2 helpers
In reply to James HilliardAdd helper support for the Octeon HSH hash selectors. This includes the base HSH data/IV windows, MD5, SHA1, SHA256, and SHA512 transform paths, and the shared HSH/SHA512 register-window readback and write operations.
The SHA512 path shares the wide HSH register bank with SHA3, SNOW3G, and ZUC. Keep the mode tracking centralized so later explicit DMFC2/DMTC2 selector decode can route aliased register accesses through these helpers when side effects or active-engine views are required.
---
Changes v8 -> v9:
- Split HSH/SHA helpers into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation HSH helpers.
- Keep shared-window readback and write helpers grouped with HSH.
- Add matching helper.h declarations with the helper implementation.
--- target/mips/helper.h | 53 ++++ target/mips/tcg/octeon_crypto.c | 570 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 623 insertions(+)
target/mips/helper.h +53 -0
@@ -28,6 +28,30 @@ DEF_HELPER_FLAGS_4(rotx, TCG_CALL_NO_RWG_SE, tl, tl, i32, i32, i32)/* Octeon COP2 selector operation helpers. */ DEF_HELPER_1(octeon_cp2_mf_crc_iv_reflect, i64, env) DEF_HELPER_1(octeon_cp2_mf_sha3_dat24, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw0, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw1, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw2, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw3, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw4, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw5, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw6, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw7, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw8, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw9, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw10, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw11, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw12, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw13, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw14, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_datw15, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_ivw0, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_ivw1, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_ivw2, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_ivw3, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_ivw4, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_ivw5, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_ivw6, i64, env) +DEF_HELPER_1(octeon_cp2_mf_hsh_ivw7, i64, env) DEF_HELPER_2(octeon_cp2_mt_crc_write_iv_reflect, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_crc_write_byte, void, env, i64)DEF_HELPER_2 (octeon_cp2_mt_crc_write_half, void, env, i64)
@@ -83,6 +107,35 @@ DEF_HELPER_2(octeon_cp2_mt_des3_dec, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_fl, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_flinv, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_camellia_round, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha_compat, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw2, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw3, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw4, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw5, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw6, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw7, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw8, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw9, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw10, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw11, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw12, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw13, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw14, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_datw15, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_ivw0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_ivw1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_ivw2, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_ivw3, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_ivw4, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_ivw5, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_ivw6, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_ivw7, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startmd5, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha256, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_hsh_startsha, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_hsh_startsha512, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
target/mips/tcg/octeon_crypto.c +570 -0
588 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v9 36/40 target/mips: add Octeon CHORD and LLM COP2 helpers
In reply to James HilliardAdd the Octeon CHORD hardware register access path and the LLM 36-bit and 64-bit read and write windows. Model both CHORD access forms, including the RDHWR $30 path and the legacy DMFC2 alias.
Implement sparse backing storage for the two LLM sets so user-mode code can save, restore, and probe the architectural state without allocating a full hardware-sized backing array.
---
Changes v8 -> v9:
- Split CHORD and LLM helpers into their own COP2 helper patch.
- Replace generic selector dispatch with per-operation LLM helpers.
- Add matching helper.h declarations with the helper implementation.
Changes v1 -> v2:
- Use neutral selector-slot wording for the LLM/CHORD alias comment.
- Add selector dispatch updates in octeon_translate.c after moving COP2 decode out of translate.c. (suggested by Philippe Mathieu-Daudé)
Changes v5 -> v6:
- Rename sparse LLM backing fields from llm_narrow/llm_wide to llm36/llm64 to match the 36-bit and 64-bit selector windows.
--- target/mips/cpu.c | 67 ++++++++++++++++++++++++++ target/mips/cpu.h | 5 ++ target/mips/helper.h | 9 ++++ target/mips/internal.h | 3 ++ target/mips/system/machine.c | 67 ++++++++++++++++++++++++++ target/mips/tcg/octeon_crypto.c | 103 ++++++++++++++++++++++++++++++++++++++++ target/mips/tcg/op_helper.c | 6 +++ target/mips/tcg/translate.c | 8 ++++ 8 files changed, 268 insertions(+)
target/mips/cpu.c +67 -0
@@ -27,6 +27,7 @@#include "internal.h" #include "kvm_mips.h" #include "qemu/module.h" +#include "qemu/qtree.h" #include "system/kvm.h" #include "system/qtest.h" #include "hw/core/qdev-properties.h"
@@ -183,6 +184,57 @@ static bool mips_cpu_has_work(CPUState *cs)#include "cpu-defs.c.inc" +static gint mips_octeon_u64_tree_compare (gconstpointer a,gconstpointer b, +gpointer user_data) +{ +uint64_t av = *(const uint64_t *)a; +uint64_t bv = *(const uint64_t *)b; + +return (av > bv) - (av < bv); +} + +QTree *mips_octeon_llm_tree_new (void ) +{ +return q_tree_new_full (mips_octeon_u64_tree_compare, +NULL , g_free, g_free); +} + +uint64_t mips_octeon_llm_load (QTree *tree,uint64_t addr) +{ +uint64_t key = addr; +uint64_t *value = tree ?q_tree_lookup (tree, &key) :NULL ; + +return value ? *value :0 ; +} + +void mips_octeon_llm_store (QTree **treep,uint64_t addr,uint64_t value) +{ +uint64_t *key; +uint64_t *stored; + +if (!*treep) { + *treep =mips_octeon_llm_tree_new (); + } + + key =g_new (uint64_t,1 ); + stored =g_new (uint64_t,1 ); + *key = addr; + *stored = value; +q_tree_replace (*treep, key, stored); +} + +static void mips_octeon_destroy_llm_state (MIPSOcteonCryptoState *crypto) +{ +if (crypto->llm36) { +q_tree_destroy (crypto->llm36); + crypto->llm36 =NULL ; + } +if (crypto->llm64) { +q_tree_destroy (crypto->llm64); + crypto->llm64 =NULL ; + } +} +static void mips_cpu_reset_hold (Object *obj,ResetType type) {CPUState *cs =CPU (obj);
@@ -194,6 +246,7 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type) mcc->parent_phases.hold (obj, type); } +mips_octeon_destroy_llm_state (&env->octeon_crypto);memset (env,0 , offsetof(CPUMIPSState , end_reset_fields));/* Reset registers to their default values */
@@ -248,6 +301,9 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type) env->active_fpu.fcr31 = env->cpu_model->CP1_fcr31; env->msair = env->cpu_model->MSAIR; env->insn_flags = env->cpu_model->insn_flags; +if (env->insn_flags &INSN_OCTEON ) { + env->octeon_crypto.chord =1 ; + }#if defined(CONFIG_USER_ONLY ) env->CP0_Status = (MIPS_HFLAG_UM << CP0St_KSU);
@@ -264,6 +320,9 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type)* hardware registers. */ env->CP0_HWREna |=0x0000000F ; +if (env->insn_flags &INSN_OCTEON ) { + env->CP0_HWREna |=0x40000000u ; + }if (env->CP0_Config1 & (1 <<CP0C1_FP )) { env->CP0_Status |= (1 << CP0St_CU1); }
@@ -422,6 +481,13 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type)#endif } +static void mips_cpu_finalize (Object *obj) +{ +MIPSCPU *cpu =MIPS_CPU (obj); + +mips_octeon_destroy_llm_state (&cpu->env.octeon_crypto); +} +static void mips_cpu_disas_set_info (const CPUState *cs,disassemble_info *info) {const MIPSCPU *cpu =MIPS_CPU (cs);
@@ -650,6 +716,7 @@ static const TypeInfo mips_cpu_type_info = { .instance_size = sizeof(MIPSCPU), .instance_align = __alignof(MIPSCPU), .instance_init = mips_cpu_initfn, + .instance_finalize = mips_cpu_finalize, .abstract = true, .class_size = sizeof(MIPSCPUClass), .class_init = mips_cpu_class_init,
target/mips/cpu.h +5 -0
@@ -11,6 +11,7 @@#include "fpu/softfloat-types.h" #include "hw/core/clock.h" #include "mips-defs.h" +#include "qemu/qtree.h" typedef struct CPUMIPSTLBContext CPUMIPSTLBContext ;
@@ -582,6 +583,10 @@ typedef struct MIPSOcteonCryptoState {uint32_t zuc_lfsr[16 ];uint32_t zuc_window[3 ];uint32_t zuc_tresult; +uint64_t llm_data[2 ]; +uint64_t chord; +QTree *llm36; +QTree *llm64; } MIPSOcteonCryptoState; typedef struct CPUArchState {
target/mips/helper.h +9 -0
@@ -136,6 +136,14 @@ DEF_HELPER_2(octeon_cp2_mt_hsh_startmd5, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_hsh_startsha256, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_hsh_startsha, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_hsh_startsha512, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_read_addr0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_write_addr0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_read64_addr0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_write64_addr0, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_read_addr1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_write_addr1, void, env, i64) +DEF_HELPER_2(octeon_cp2_mt_llm_read64_addr1, void, env, i64) +DEF_HELPER_2 (octeon_cp2_mt_llm_write64_addr1, void, env, i64) /* microMIPS functions */DEF_HELPER_4 (lwm, void, env, tl, tl, i32)
@@ -307,6 +315,7 @@ DEF_HELPER_1(rdhwr_cc, tl, env) DEF_HELPER_1(rdhwr_ccres, tl, env) DEF_HELPER_1(rdhwr_performance, tl, env) DEF_HELPER_1(rdhwr_xnp, tl, env) +DEF_HELPER_1(rdhwr_chord, tl, env) DEF_HELPER_2(pmon, void, env, int)DEF_HELPER_1 (wait, void, env)
target/mips/internal.h +3 -0
@@ -93,6 +93,9 @@ extern const int mips_defs_number;int mips_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int mips_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); +QTree *mips_octeon_llm_tree_new (void ); +uint64_t mips_octeon_llm_load (QTree *tree,uint64_t addr); +void mips_octeon_llm_store (QTree **treep,uint64_t addr,uint64_t value);#define USEG_LIMIT ((target_ulong)(int32_t)0x7FFFFFFFUL)#define KSEG0_BASE ((target_ulong)(int32_t)0x80000000UL)
target/mips/system/machine.c +67 -0
79 lines not on this page · raw message
target/mips/tcg/octeon_crypto.c +103 -0
268 lines not on this page · raw message
target/mips/tcg/op_helper.c +6 -0
@@ -255,6 +255,12 @@ target_ulong helper_rdhwr_xnp(CPUMIPSState *env)return (env->CP0_Config5 >>CP0C5_XNP ) &1 ; } +target_ulong helper_rdhwr_chord (CPUMIPSState *env) +{ +check_hwrena (env,30 ,GETPC ()); +return env->octeon_crypto.chord; +} +void helper_pmon (CPUMIPSState *env,int function) { function /=2 ;
target/mips/tcg/translate.c +8 -0
@@ -10925,6 +10925,14 @@ void gen_rdhwr(DisasContext *ctx, int rt, int rd, int sel) }break ;#endif +case 30 : +if (!(ctx->insn_flags &INSN_OCTEON )) { +gen_reserved_instruction (ctx); +break ; + } +gen_helper_rdhwr_chord (t0, tcg_env); +gen_store_gpr (t0, rt); +break ;default :/* Invalid */ MIPS_INVAL ("rdhwr" );gen_reserved_instruction (ctx);
Signature · 1 line
2.54.0
PATCH v9 37/40 target/mips: decode Octeon COP2 selectors explicitly
In reply to James HilliardDecode Octeon CP2 selector operations in octeon.decode instead of first accepting generic CP2 opcodes and re-decoding the selector inside a runtime helper.
Emit direct TCG loads and stores for simple COP2 register moves. Use signed 32-bit loads for 32-bit DMFC2 readback, matching MIPS register move semantics, and keep helper calls only for operation selectors and shared-window state that require side effects. Unknown Octeon CP2 selectors hit an explicit CP2_Undef decoder entry.
---
Changes v8 -> v9:
- Use signed direct loads for 32-bit DMFC2 register readback.
- Replace the generic selector helper calls with per-operation helper calls.
- Document the AESRESINP input latch and readback/result register split.
Changes v7 -> v8:
- Decode Octeon COP2 selectors explicitly in decodetree.
- Use direct TCG loads/stores for simple COP2 register transfers and preserve helper calls for operation selectors with side effects.
--- target/mips/helper.h | 1 + target/mips/tcg/octeon.decode | 205 ++++++++++++++++++++++ target/mips/tcg/octeon_translate.c | 342 +++++++++++++++++++++++++++++++++++++ 3 files changed, 548 insertions(+)
target/mips/helper.h +1 -0
@@ -145,6 +145,7 @@ DEF_HELPER_2(octeon_cp2_mt_llm_write_addr1, void, env, i64) DEF_HELPER_2(octeon_cp2_mt_llm_read64_addr1, void, env, i64)DEF_HELPER_2 (octeon_cp2_mt_llm_write64_addr1, void, env, i64) + /* microMIPS functions */ DEF_HELPER_4(lwm, void, env, tl, tl, i32)DEF_HELPER_4 (swm, void, env, tl, tl, i32)
target/mips/tcg/octeon.decode +205 -0
208 lines not on this page · raw message
target/mips/tcg/octeon_translate.c +342 -0
348 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v9 37/40] target/mips: decode Octeon COP2 selectors explicitly
target/mips/tcg/octeon_translate.c line 162
Quoted 2 lines · James Hilliard
target/mips/tcg/octeon_translate.c +2
-0+CP2_MF_I64 (CVM_MF_GFM_MUL_REFLECT0 , gfm_reflect_mul[0 ]); +CP2_MF_I64 (CVM_MF_GFM_MUL_REFLECT1 , gfm_reflect_mul[1 ]);
These perform rt = reflect(GFMMUL[i]), not read from separate storage.
target/mips/tcg/octeon_translate.c line 164
Quoted 2 lines
target/mips/tcg/octeon_translate.c +2
-0+CP2_MF_I64 (CVM_MF_GFM_RESINP_REFLECT0 , gfm_reflect_resinp[0 ]); +CP2_MF_I64 (CVM_MF_GFM_RESINP_REFLECT1 , gfm_reflect_resinp[1 ]);
Likewise.
Quoted 1 line
+CP2_MF_I64(CVM_MF_3DES_RESULT_MT,
des3_result);
Correct implementation, but it's named CVM_MF_KAS_RESULT.
Quoted 6 lines
target/mips/tcg/octeon_translate.c +6
-0+CP2_MF_HELPER (CVM_MF_HSH_DATW0 , hsh_datw0); +CP2_MF_HELPER (CVM_MF_HSH_DATW1 , hsh_datw1); +CP2_MF_HELPER (CVM_MF_HSH_DATW2 , hsh_datw2); +CP2_MF_HELPER (CVM_MF_HSH_DATW3 , hsh_datw3); +CP2_MF_HELPER (CVM_MF_HSH_DATW4 , hsh_datw4); +CP2_MF_HELPER (CVM_MF_HSH_DATW5 , hsh_datw5);
target/mips/tcg/octeon_translate.c line 210
Quoted 10 lines
target/mips/tcg/octeon_translate.c +10
-0+CP2_MF_HELPER (CVM_MF_HSH_DATW6 , hsh_datw6); +CP2_MF_HELPER (CVM_MF_HSH_DATW7 , hsh_datw7); +CP2_MF_HELPER (CVM_MF_HSH_DATW8 , hsh_datw8); +CP2_MF_HELPER (CVM_MF_HSH_DATW9 , hsh_datw9); +CP2_MF_HELPER (CVM_MF_HSH_DATW10 , hsh_datw10); +CP2_MF_HELPER (CVM_MF_HSH_DATW11 , hsh_datw11); +CP2_MF_HELPER (CVM_MF_HSH_DATW12 , hsh_datw12); +CP2_MF_HELPER (CVM_MF_HSH_DATW13 , hsh_datw13); +CP2_MF_HELPER (CVM_MF_HSH_DATW14 , hsh_datw14); +CP2_MF_HELPER (CVM_MF_HSH_DATW15 , hsh_datw15);
These should be straight 64-bit loads from HASHDAT[i].
CVM_MF_HSH_DATi should use something like
static bool trans_octeon_cp_mf_hsh_dat(DisasContext *ctx, arg_cp2 *a, int i)
{
TCGv_i64 t0 = tcg_temp_new_i64();
TCGv_i64 t1 = tcg_temp_new_i64();
tcg_gen_ld_i64(t0, tcg_env, OCTEON_CRYPTO_OFFSET(hash_dat[2 * i + 0]));
tcg_gen_ld_i64(t1, tcg_env, OCTEON_CRYPTO_OFFSET(hash_dat[2 * i + 1]));
tcg_gen_concat32_i64(t0, t0, t1);
gen_store_gpr(t0, a->rt);
return true;
}target/mips/tcg/octeon_translate.c line 226
Quoted 7 lines
target/mips/tcg/octeon_translate.c +7
-0+CP2_MT_I64 (CVM_MT_HSH_DAT0 , hsh_dat[0 ]); +CP2_MT_I64 (CVM_MT_HSH_DAT1 , hsh_dat[1 ]); +CP2_MT_I64 (CVM_MT_HSH_DAT2 , hsh_dat[2 ]); +CP2_MT_I64 (CVM_MT_HSH_DAT3 , hsh_dat[3 ]); +CP2_MT_I64 (CVM_MT_HSH_DAT4 , hsh_dat[4 ]); +CP2_MT_I64 (CVM_MT_HSH_DAT5 , hsh_dat[5 ]); +CP2_MT_I64 (CVM_MT_HSH_DAT6 , hsh_dat[6 ]);
Similarly
static bool trans_octeon_cp_mt_hsh_dat(DisasContext *ctx, arg_cp2 *a, int i)
{
TCGv_i64 t = tcg_temp_new_i64();
gen_load_gpr(t, a->rt);
tcg_gen_st32_i64(t, tcg_env, OCTEON_CRYPTO_OFFSET(hash_dat[2 * i + 1])
+ (HOST_WORDS_BIG_ENDIAN ? 4 : 0));
tcg_gen_shri_i64(t, t, 32);
tcg_gen_st32_i64(t, tcg_env, OCTEON_CRYPTO_OFFSET(hash_dat[2 * i + 0])
+ (HOST_WORDS_BIG_ENDIAN ? 4 : 0));
return true;
}target/mips/tcg/octeon_translate.c line 232
Quoted 2 lines
target/mips/tcg/octeon_translate.c +2
-0+CP2_MT_I64 (CVM_MT_GFM_MUL_REFLECT0 , gfm_reflect_mul[0 ]); +CP2_MT_I64 (CVM_MT_GFM_MUL_REFLECT1 , gfm_reflect_mul[1 ]);
These perform GFMMUL[i] = reflect(rt).
Quoted 1 line
+CP2_MT_I64(CVM_MT_GFM_XOR0_REFLECT,
gfm_reflect_xor0);
This performs GFMRESINP[0] ^= reflect(rt).
Quoted 1 line
+CP2_MT_U8(CVM_MT_AES_KEYLENGTH,
aes_keylen);
AESKEYLEN is 2 bits. You need to mask this write.
Quoted 1 line
+CP2_MT_U32(CVM_MT_CRC_WRITE_LEN,
crc_len);
CRCLEN is 4 bits. You need to mask this write.
Quoted 1 line
+CP2_MT_U32(CVM_MT_CRC_WRITE_POLYNOMIAL,
crc_poly);
The correct name appears to be CVM_MT_CRC_POLYNOMIAL
Quoted 1 line
+CP2_MT_U32(CVM_MT_CRC_WRITE_POLYNOMIAL_REFLECT,
crc_poly);
CVM_MT_CRC_POLYNOMIAL_REFLECT, and is missing the reflect.
CRCPOLY<31:0> = byte_bit_reflect(rt<31:0>)
target/mips/tcg/octeon_translate.c line 275
Quoted 11 lines
target/mips/tcg/octeon_translate.c +11
-0+CP2_MT_HELPER (CVM_MT_CRC_WRITE_IV_REFLECT , crc_write_iv_reflect); +CP2_MT_HELPER (CVM_MT_CRC_WRITE_BYTE , crc_write_byte); +CP2_MT_HELPER (CVM_MT_CRC_WRITE_HALF , crc_write_half); +CP2_MT_HELPER (CVM_MT_CRC_WRITE_WORD , crc_write_word); +CP2_MT_HELPER (CVM_MT_CRC_WRITE_BYTE_REFLECT , crc_write_byte_reflect); +CP2_MT_HELPER (CVM_MT_CRC_WRITE_HALF_REFLECT , crc_write_half_reflect); +CP2_MT_HELPER (CVM_MT_CRC_WRITE_WORD_REFLECT , crc_write_word_reflect); +CP2_MT_HELPER (CVM_MT_CRC_WRITE_DWORD , crc_write_dword); +CP2_MT_HELPER (CVM_MT_CRC_WRITE_VAR , crc_write_var); +CP2_MT_HELPER (CVM_MT_CRC_WRITE_DWORD_REFLECT , crc_write_dword_reflect); +CP2_MT_HELPER (CVM_MT_CRC_WRITE_VAR_REFLECT , crc_write_var_reflect);
Misnamed? s/_WRITE//.
Quoted 11 lines
target/mips/tcg/octeon_translate.c +11
-0+CP2_MT_HELPER (CVM_MT_SHA3_DAT24 , sha3_dat24); +CP2_MT_HELPER (CVM_MT_SHA3_DAT15 , sha3_dat15); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT0 , sha3_xordat0); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT1 , sha3_xordat1); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT2 , sha3_xordat2); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT3 , sha3_xordat3); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT4 , sha3_xordat4); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT5 , sha3_xordat5); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT6 , sha3_xordat6); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT7 , sha3_xordat7); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT8 , sha3_xordat8);
target/mips/tcg/octeon_translate.c line 298
Quoted 10 lines
target/mips/tcg/octeon_translate.c +10
-0+CP2_MT_HELPER (CVM_MT_SHA3_XORDAT9 , sha3_xordat9); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT10 , sha3_xordat10); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT11 , sha3_xordat11); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT12 , sha3_xordat12); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT13 , sha3_xordat13); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT14 , sha3_xordat14); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT15 , sha3_xordat15); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT16 , sha3_xordat16); +CP2_MT_HELPER (CVM_MT_SHA3_XORDAT17 , sha3_xordat17); +CP2_MT_HELPER (CVM_MT_SHA3_STARTOP , sha3_startop);
FWIW, SHA3 is missing from the document you shared.
Quoted 1 line
+CP2_MT_HELPER(CVM_MT_HSH_STARTSHA_COMPAT,
hsh_startsha_compat);
What's this? I don't see anything for 0x0057 in either the cn50xx or cn71xx docs.
Quoted 14 lines
target/mips/tcg/octeon_translate.c +14
-0+CP2_MT_HELPER (CVM_MT_HSH_DATW0 , hsh_datw0); +CP2_MT_HELPER (CVM_MT_HSH_DATW1 , hsh_datw1); +CP2_MT_HELPER (CVM_MT_HSH_DATW2 , hsh_datw2); +CP2_MT_HELPER (CVM_MT_HSH_DATW3 , hsh_datw3); +CP2_MT_HELPER (CVM_MT_HSH_DATW4 , hsh_datw4); +CP2_MT_HELPER (CVM_MT_HSH_DATW5 , hsh_datw5); +CP2_MT_HELPER (CVM_MT_HSH_DATW6 , hsh_datw6); +CP2_MT_HELPER (CVM_MT_HSH_DATW7 , hsh_datw7); +CP2_MT_HELPER (CVM_MT_HSH_DATW8 , hsh_datw8); +CP2_MT_HELPER (CVM_MT_HSH_DATW9 , hsh_datw9); +CP2_MT_HELPER (CVM_MT_HSH_DATW10 , hsh_datw10); +CP2_MT_HELPER (CVM_MT_HSH_DATW11 , hsh_datw11); +CP2_MT_HELPER (CVM_MT_HSH_DATW12 , hsh_datw12); +CP2_MT_HELPER (CVM_MT_HSH_DATW13 , hsh_datw13);
target/mips/tcg/octeon_translate.c line 344
Quoted 10 lines
target/mips/tcg/octeon_translate.c +10
-0+CP2_MT_HELPER (CVM_MT_HSH_DATW14 , hsh_datw14); +CP2_MT_HELPER (CVM_MT_HSH_DATW15 , hsh_datw15); +CP2_MT_HELPER (CVM_MT_HSH_IVW0 , hsh_ivw0); +CP2_MT_HELPER (CVM_MT_HSH_IVW1 , hsh_ivw1); +CP2_MT_HELPER (CVM_MT_HSH_IVW2 , hsh_ivw2); +CP2_MT_HELPER (CVM_MT_HSH_IVW3 , hsh_ivw3); +CP2_MT_HELPER (CVM_MT_HSH_IVW4 , hsh_ivw4); +CP2_MT_HELPER (CVM_MT_HSH_IVW5 , hsh_ivw5); +CP2_MT_HELPER (CVM_MT_HSH_IVW6 , hsh_ivw6); +CP2_MT_HELPER (CVM_MT_HSH_IVW7 , hsh_ivw7);
These should be straight 64-bit stores.
target/mips/tcg/octeon_translate.c line 356
Quoted 8 lines
target/mips/tcg/octeon_translate.c +8
-0+CP2_MT_HELPER (CVM_MT_LLM_READ_ADDR0 , llm_read_addr0); +CP2_MT_HELPER (CVM_MT_LLM_WRITE_ADDR0 , llm_write_addr0); +CP2_MT_HELPER (CVM_MT_LLM_READ64_ADDR0 , llm_read64_addr0); +CP2_MT_HELPER (CVM_MT_LLM_WRITE64_ADDR0 , llm_write64_addr0); +CP2_MT_HELPER (CVM_MT_LLM_READ_ADDR1 , llm_read_addr1); +CP2_MT_HELPER (CVM_MT_LLM_WRITE_ADDR1 , llm_write_addr1); +CP2_MT_HELPER (CVM_MT_LLM_READ64_ADDR1 , llm_read64_addr1); +CP2_MT_HELPER (CVM_MT_LLM_WRITE64_ADDR1 , llm_write64_addr1);
FWIW, Chord and LLM are missing from the document you shared.
r~
PATCH v9 38/40 target/mips: add Octeon CvmCount RDHWR support
In reply to James HilliardOcteon exposes CvmCount through RDHWR register 31. Add the Octeon-only decode path, enable the corresponding HWREna bit for linux-user, and use an unsigned mask when checking HWREna so bit 31 is handled safely.
For user-mode emulation, return host ticks as a monotonic counter source suitable for existing Octeon userspace code. In system mode, fall back to the existing CP0 Count value.
---
Changes v5 -> v6:
- New patch.
--- target/mips/cpu.c | 1 + target/mips/helper.h | 1 + target/mips/tcg/op_helper.c | 13 ++++++++++++- target/mips/tcg/translate.c | 11 +++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-)
target/mips/cpu.c +1 -0
@@ -322,6 +322,7 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type) env->CP0_HWREna |=0x0000000F ;if (env->insn_flags &INSN_OCTEON ) { env->CP0_HWREna |=0x40000000u ; + env->CP0_HWREna |=0x80000000u ; }if (env->CP0_Config1 & (1 <<CP0C1_FP )) { env->CP0_Status |= (1 << CP0St_CU1);
target/mips/helper.h +1 -0
@@ -317,6 +317,7 @@ DEF_HELPER_1(rdhwr_ccres, tl, env) DEF_HELPER_1(rdhwr_performance, tl, env) DEF_HELPER_1(rdhwr_xnp, tl, env) DEF_HELPER_1(rdhwr_chord, tl, env) +DEF_HELPER_1(rdhwr_cvmcount, tl, env) DEF_HELPER_2(pmon, void, env, int)DEF_HELPER_1 (wait, void, env)
target/mips/tcg/op_helper.c +12 -1
@@ -25,6 +25,7 @@#include "exec/memop.h" #include "fpu_helper.h" #include "qemu/crc32c.h" +#include "qemu/timer.h" #include <zlib.h> static inline target_ulong bitswap (target_ulong v)
@@ -209,7 +210,7 @@ target_ulong helper_yield(CPUMIPSState *env, target_ulong arg)static inline void check_hwrena (CPUMIPSState *env,int reg,uintptr_t pc) { -if ((env->hflags &MIPS_HFLAG_CP0 ) || (env->CP0_HWREna & (1 << reg))) { +if ((env->hflags &MIPS_HFLAG_CP0 ) || (env->CP0_HWREna & (1u << reg))) {return ; }do_raise_exception (env,EXCP_RI , pc);
@@ -261,6 +262,16 @@ target_ulong helper_rdhwr_chord(CPUMIPSState *env)return env->octeon_crypto.chord; } +target_ulong helper_rdhwr_cvmcount (CPUMIPSState *env) +{ +check_hwrena (env,31 ,GETPC ()); +#ifdef CONFIG_USER_ONLY +return cpu_get_host_ticks (); +#else +return (uint32_t )cpu_mips_get_count (env); +#endif +} +void helper_pmon (CPUMIPSState *env,int function) { function /=2 ;
target/mips/tcg/translate.c +11 -0
@@ -10933,6 +10933,17 @@ void gen_rdhwr(DisasContext *ctx, int rt, int rd, int sel)gen_helper_rdhwr_chord (t0, tcg_env);gen_store_gpr (t0, rt);break ; +case 31 : +if (!(ctx->insn_flags &INSN_OCTEON )) { +gen_reserved_instruction (ctx); +break ; + } +translator_io_start (&ctx->base); +gen_helper_rdhwr_cvmcount (t0, tcg_env); +gen_store_gpr (t0, rt); +gen_save_pc (ctx->base.pc_next +4 ); + ctx->base.is_jmp =DISAS_EXIT ; +break ;default :/* Invalid */ MIPS_INVAL ("rdhwr" );gen_reserved_instruction (ctx);
Signature · 1 line
2.54.0
PATCH v9 39/40 tests/tcg/mips: cover Octeon COP2, QMAC and CvmCount
In reply to James HilliardExtend the Octeon linux-user smoke test with AES key and key-length DMTC2/DMFC2 readback checks, QMAC/QMACS fixed-point accumulator checks, and an RDHWR $31 monotonicity check.
The COP2 readback cases exercise the explicit COP2 decodetree entries and direct TCG register-transfer paths introduced by the decode split. The QMAC and CvmCount cases keep the fixed-point accumulator and RDHWR paths covered by the same Octeon smoke binary.
---
Changes v8 -> v9:
- Combine the v8 COP2 selector readback and QMAC/CvmCount test patches.
- Fix the commit message to refer to RDHWR $31.
Changes v7 -> v8:
- Split AES COP2 selector readback coverage out of the COP2 crypto core patch.
Changes v5 -> v6:
- Add QMAC/QMACS and CvmCount smoke coverage.
--- tests/tcg/mips/user/isa/octeon/octeon-insns.c | 128 ++++++++++++++++++++++++++ 1 file changed, 128 insertions(+)
tests/tcg/mips/user/isa/octeon/octeon-insns.c +128 -0
@@ -129,6 +129,59 @@ static uint64_t octeon_vmm0(uint64_t mpl0, uint64_t p0,return rd; } +static uint64_t octeon_qmac_lo (uint64_t rs,uint64_t rt,uint64_t lo) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[rs]\n\t" +"move $9, %[rt]\n\t" +"mtlo %[lo]\n\t" +"mthi $0\n\t" +".word 0x710904d2\n\t" /* qmac.03 $8, $9 */ +"mflo %[rd]\n\t" + : [rd]"=r" (rd) + : [rs]"r" (rs), [rt]"r" (rt), [lo]"r" (lo) + :"$8" ,"$9" ); + +return rd; +} + +static uint64_t octeon_qmacs_state (uint64_t rs,uint64_t rt,uint64_t lo) +{ +uint64_t hi, rd; + + asmvolatile ( +"move $8, %[rs]\n\t" +"move $9, %[rt]\n\t" +"mtlo %[lo]\n\t" +"mthi $0\n\t" +".word 0x71090012\n\t" /* qmacs.00 $8, $9 */ +"mfhi %[hi]\n\t" +"mflo %[rd]\n\t" + : [hi]"=r" (hi), [rd]"=r" (rd) + : [rs]"r" (rs), [rt]"r" (rt), [lo]"r" (lo) + :"$8" ,"$9" ); + +return ((hi &1 ) <<32 ) | (rd &0xffffffff ); +} + +static uint64_t octeon_rdhwr31_non_decreasing (void ) +{ +uint64_t first, second; + + asmvolatile ( +".word 0x7c08f83b\n\t" /* rdhwr $8, $31 */ +".word 0x7c09f83b\n\t" /* rdhwr $9, $31 */ +"move %[first], $8\n\t" +"move %[second], $9\n\t" + : [first]"=r" (first), [second]"=r" (second) + : + :"$8" ,"$9" ); + +return second >= first; +} +static uint64_t octeon_vmm0_zeroes_mpl1 (void ) {uint64_t rd;
@@ -186,6 +239,70 @@ static uint64_t octeon_mtp0_zeroes_p1(void)return rd; } +static uint64_t octeon_cop2_key0_readback (uint64_t value) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[value]\n\t" +".word 0x48a80104\n\t" /* dmtc2 $8, AES_KEY0 selector */ +".word 0x482a0104\n\t" /* dmfc2 $10, AES_KEY0 selector */ +"move %[rd], $10\n\t" + : [rd]"=r" (rd) + : [value]"r" (value) + :"$8" ,"$10" ); + +return rd; +} + +static uint64_t octeon_cop2_key2_readback (uint64_t value) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[value]\n\t" +".word 0x48a80106\n\t" /* dmtc2 $8, AES_KEY2 selector */ +".word 0x482a0106\n\t" /* dmfc2 $10, AES_KEY2 selector */ +"move %[rd], $10\n\t" + : [rd]"=r" (rd) + : [value]"r" (value) + :"$8" ,"$10" ); + +return rd; +} + +static uint64_t octeon_cop2_key3_readback (uint64_t value) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[value]\n\t" +".word 0x48a80107\n\t" /* dmtc2 $8, AES_KEY3 selector */ +".word 0x482a0107\n\t" /* dmfc2 $10, AES_KEY3 selector */ +"move %[rd], $10\n\t" + : [rd]"=r" (rd) + : [value]"r" (value) + :"$8" ,"$10" ); + +return rd; +} + +static uint64_t octeon_cop2_keylength_readback (uint64_t value) +{ +uint64_t rd; + + asmvolatile ( +"move $8, %[value]\n\t" +".word 0x48a80110\n\t" /* dmtc2 $8, AES_KEYLENGTH selector */ +".word 0x482a0110\n\t" /* dmfc2 $10, AES_KEYLENGTH selector */ +"move %[rd], $10\n\t" + : [rd]"=r" (rd) + : [value]"r" (value) + :"$8" ,"$10" ); + +return rd; +} +int main (void ) {assert (octeon_baddu (0x123 ,0x0f0 ) ==0x13 );
@@ -195,10 +312,21 @@ int main(void)assert (octeon_seq (0xabc ,0xdef ) ==0 );assert (octeon_sne (0xabc ,0xabc ) ==0 );assert (octeon_sne (0xabc ,0xdef ) ==1 ); +assert (octeon_qmac_lo (0x0003000000000000ULL ,2 ,1 ) ==13 ); +assert (octeon_qmacs_state (1 ,1 ,0x7ffffffe ) ==0x17fffffffULL ); +assert (octeon_qmacs_state (0x8000 ,0x8000 ,0 ) ==0x17fffffffULL ); +assert (octeon_rdhwr31_non_decreasing ());assert (octeon_vmulu (5 ,7 ,11 ) ==46 );assert (octeon_vmm0 (5 ,13 ,7 ,11 ) ==59 );assert (octeon_vmm0_zeroes_mpl1 () ==0 );assert (octeon_mtp0_zeroes_p1 () ==0 ); +assert (octeon_cop2_key0_readback (0x1122334455667788ULL ) == +0x1122334455667788ULL ); +assert (octeon_cop2_key2_readback (0x8877665544332211ULL ) == +0x8877665544332211ULL ); +assert (octeon_cop2_key3_readback (0x0102030405060708ULL ) == +0x0102030405060708ULL ); +assert (octeon_cop2_keylength_readback (0xa5 ) ==0xa5 );return 0 ; }
Signature · 1 line
2.54.0
PATCH v9 40/40 target/mips: expose Octeon68XX floating-point support
In reply to James HilliardOcteon68XX 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.
---
Changes v1 -> v2:
- Move this CPU-model correction into a separate final patch. (suggested by Philippe Mathieu-Daudé)
--- 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.54.0
Re: [PATCH v9 40/40] target/mips: expose Octeon68XX floating-point support
Quoted 7 lines · James Hilliard
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.
Quoted 8 lines
Signed-off-by James Hilliard <[email protected]>---
Changes v1 -> v2:
- Move this CPU-model correction into a separate final patch. (suggested by Philippe Mathieu-Daudé)--- target/mips/cpu-defs.c.inc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)