Enable DMF for Power ISA 3.2
cover Enable DMF for Power ISA 3.2
This series aims to implement the dense math facility introduced in RFC 02653: Dense Math Facility for Power ISA 3.2.
The RFC is available in the OpenPOWER website here :
https://files.openpowerfoundation.org/s/Fyp9TWZf8oYTd7D
Chinmay Rath (8):
target/ppc: Add flag for Power ISA 3.2 target/ppc: Enable Dense Math Facility for ISA 3.2 target/ppc: Implement DMR getter/setter and some DMF insns. target/ppc: Add FSSIR spr for ISA 3.2
target/ppc: Implement DMMR and DMXOR instructions. target/ppc: Implement DMF accumulator instructions target/ppc: Add function to point to dmr regs in tcg_env target/ppc: Add DMF Outer-Product accumulate to ACC insns
target/ppc/cpu.h | 23 ++- target/ppc/fpu_helper.c | 5 + target/ppc/helper_regs.c | 4 + target/ppc/insn32.decode | 201 +++++++++++++++++----- target/ppc/insn64.decode | 244 +++++++++++++++++++------- target/ppc/int_helper.c | 5 + target/ppc/translate.c | 13 ++ target/ppc/translate/dmf-impl.c.inc | 255 ++++++++++++++++++++++++++++ 8 files changed, 644 insertions(+), 106 deletions(-) create mode 100644 target/ppc/translate/dmf-impl.c.inc
Signature · 1 line
2.55.0
RFC PATCH 1/8 target/ppc: Add flag for Power ISA 3.2
Adding flag for Power ISA 3.2.
--- target/ppc/cpu.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
target/ppc/cpu.h +3 -1
@@ -2597,6 +2597,8 @@ enum {PPC2_PPE42X =0x0000000000100000ULL ,/* PPE42XM instructions */ PPC2_PPE42XM =0x0000000000200000ULL , +/* Power ISA 3.2 */ +PPC2_ISA320 =0x0000000000400000ULL , #define PPC_TCG_INSNS2 (PPC2_BOOKE206 | PPC2_VSX | PPC2_PRCNTL | PPC2_DBRX | \ PPC2_ISA205 | PPC2_ISA207 | PPC2_PERM_ISA206 | \
@@ -2605,7 +2607,7 @@ enum {PPC2_FP_CVT_S64 |PPC2_TM |PPC2_PM_ISA206 | \PPC2_ISA300 |PPC2_ISA310 |PPC2_MEM_LWSYNC | \PPC2_BCDA_ISA206 |PPC2_PPE42 |PPC2_PPE42X | \ - PPC2_PPE42XM) + PPC2_PPE42XM | PPC2_ISA320) };/*****************************************************************************/
Signature · 1 line
2.55.0
RFC PATCH 2/8 target/ppc: Enable Dense Math Facility for ISA 3.2
In reply to Chinmay RathThis patch implements the dense math registers (DMR) that are introduced in RFC 02653 for ISA 3.2 as part of the dense math facility (DMF). Also adds a new hflag for the same.
DMR which are 1024 bits long are implemented as an array of 'rows' which are 128 bits each. DMF instructions manipulate DMRs in the granularity of these rows.
--- target/ppc/cpu.h | 13 +++++++++++++ target/ppc/helper_regs.c | 4 ++++ target/ppc/translate.c | 2 ++ 3 files changed, 19 insertions(+)
target/ppc/cpu.h +13 -0
@@ -355,6 +355,11 @@ typedef union _ppc_vsr_t {typedef ppc_vsr_t ppc_avr_t ;typedef ppc_vsr_t ppc_fprp_t ;typedef ppc_vsr_t ppc_acc_t ; +typedef ppc_vsr_t ppc_dmr_row_t ; + +typedef struct ppc_dmr_t { +ppc_dmr_row_t row[8 ]; +}ppc_dmr_t ;#if !defined(CONFIG_USER_ONLY )/* Software TLB cache */
@@ -449,6 +454,7 @@ typedef enum {#define MSR_SEM5 PPC_BIT_NR(38)/* SIB Error Mask Bit 5 (PPE42) */ #define MSR_SEM6 PPC_BIT_NR(39)/* SIB Error Mask Bit 6 (PPE42) */ #define MSR_VSX PPC_BIT_NR(40)/* Vector Scalar Extension (>= 2.06)x hflags */ +#define MSR_DM PPC_BIT_NR(39)/* Dense Math Facility (>= 3.2) x hflags */ #define MSR_IS0 PPC_BIT_NR(40)/* Instance Specific Bit 0 (PPE42) */ #define MSR_S PPC_BIT_NR(41)/* Secure state */ #define MSR_SIBRC0 PPC_BIT_NR(41)/* Last SIB return code Bit 0 (PPE42) */
@@ -743,6 +749,7 @@ FIELD(MSR, SIBRCA, MSR_SIBRCA7, 8)#define FSCR_IC_EBB 7#define FSCR_IC_TAR 8#define FSCR_IC_SCV 12 +#define FSCR_IC_DM 14/* Exception state register bits definition */ #define ESR_PIL PPC_BIT(36)/* Illegal Instruction */
@@ -844,6 +851,8 @@ enum {POWERPC_FLAG_BHRB =0x01000000 ,/* Use PPE42-specific behavior */ POWERPC_FLAG_PPE42 =0x02000000 , +/* Has DMF */ + POWERPC_FLAG_DM = 0x04000000, };/*
@@ -873,6 +882,7 @@ enum {HFLAGS_INSN_CNT =19 ,/* PMU instruction count enabled */ HFLAGS_BHRB_ENABLE =20 ,/* Summary flag for enabling BHRB */ HFLAGS_VSX =23 ,/* MSR_VSX if cpu has VSX */ +HFLAGS_DM =24 ,/* MSR_DM */ HFLAGS_VR =25 ,/* MSR_VR if cpu has VRE */ HFLAGS_IMMU_IDX = 26, /* 26..28 -- the composite immu_idx */
@@ -1364,6 +1374,9 @@ struct CPUArchState {float_status fp_status;/* Floating point execution context */ target_ulong fpscr;/* Floating point status and control register */ +/* DMF registers */ + ppc_dmr_t dmr[8] QEMU_ALIGNED(16); +/* Internal devices resources */ ppc_tb_t *tb_env;/* Time base and decrementer */ ppc_dcr_t *dcr_env;/* Device control registers */
target/ppc/helper_regs.c +4 -0
@@ -189,6 +189,10 @@ static uint32_t hreg_compute_hflags_value(CPUPPCState *env)/* PPE42 has a single address space and no problem state */ msr =0 ; } +if (ppc_flags &POWERPC_FLAG_DM ) { +QEMU_BUILD_BUG_ON (MSR_DM !=HFLAGS_DM ); + msr_mask |=1 <<MSR_DM ; + }#ifndef CONFIG_USER_ONLY if (!env->has_hv_mode || (msr & (1ull <<MSR_HV ))) {
target/ppc/translate.c +2 -0
@@ -187,6 +187,7 @@ struct DisasContext {bool fpu_enabled;bool altivec_enabled;bool vsx_enabled; +bool dm_enabled;bool spe_enabled;bool tm_enabled;bool gtse;
@@ -5023,6 +5024,7 @@ static void ppc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->spe_enabled = (hflags >>HFLAGS_SPE ) &1 ; ctx->altivec_enabled = (hflags >>HFLAGS_VR ) &1 ; ctx->vsx_enabled = (hflags >>HFLAGS_VSX ) &1 ; + ctx->dm_enabled = (hflags >>HFLAGS_DM ) &1 ; ctx->tm_enabled = (hflags >>HFLAGS_TM ) &1 ; ctx->gtse = (hflags >>HFLAGS_GTSE ) &1 ; ctx->hr = (hflags >>HFLAGS_HR ) &1 ;
Signature · 1 line
2.55.0
RFC PATCH 3/8 target/ppc: Implement DMR getter/setter and some DMF insns.
In reply to Chinmay RathFrom RFC 02653 for Power ISA 3.2 :
Implement the getter and setter for DMRs with row level granularity.
Implement the following DMF instructions :
DMSETDMRZ : X-form
DMXX{EXTF,INST}DMR256 : XX2-form
DMXX{EXTF,INST}DMR512 : XX3-form--- target/ppc/cpu.h | 5 ++ target/ppc/insn32.decode | 18 +++++++ target/ppc/translate.c | 11 ++++ target/ppc/translate/dmf-impl.c.inc | 80 +++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 target/ppc/translate/dmf-impl.c.inc
target/ppc/cpu.h +5 -0
@@ -3055,6 +3055,11 @@ static inline ppc_avr_t *cpu_avr_ptr(CPUPPCState *env, int i)return (ppc_avr_t *)((uintptr_t )env +avr_full_offset (i)); } +static inline int dmr_row_offset (int reg,int row) +{ + return offsetof(CPUPPCState, dmr[reg].row[row]); +} +static inline bool ppc_has_spr (PowerPCCPU *cpu,int spr) {/* We can test whether the SPR is defined by checking for a valid name */
target/ppc/insn32.decode +18 -0
@@ -274,12 +274,20 @@ &MMIRR_XX3 xa xb xt pmsk xmsk ymsk %xx_at 23:3 %xx_xa_pair 2:1 17:4 !function=times_2 +%xx_xb_pair 1:1 12:4 !function=times_2 @XX3_at ...... ... .. ..... ..... ........ ... &MMIRR_XX3 xt=%xx_at xb=%xx_xb \ pmsk=255 xmsk=15 ymsk=15 &XX3_dm xt xa xb dm @XX3_dm ...... ..... ..... ..... . dm:2 ..... ... &XX3_dm xt=%xx_xt xa=%xx_xa xb=%xx_xb +&XX3_abp_as_p xap xbp as p +@XX3_abp_as_p ...... as:3 .. .... p:1 .... . ........ ... &XX3_abp_as_p xap=%xx_xa_pair xbp=%xx_xb_pair + +%p0p1 16:1 11:1 +&XX2_bp_as_p xbp as p +@XX2_bp_as_p ...... as:3 ...... . .... . ......... .. &XX2_bp_as_p xbp=%xx_xb_pair p=%p0p1 + &XX4 xt xa xb xc @XX4 ...... ..... ..... ..... ..... .. .... &XX4 xt=%xx_xt xa=%xx_xa xb=%xx_xb xc=%xx_xc
@@ -1534,6 +1542,16 @@ VMODUD 000100 ..... ..... ..... 11011001011 @VX VMODSQ 000100 ..... ..... ..... 11100001011 @VX VMODUQ 000100 ..... ..... ..... 11000001011 @VX +## DMF Instructions + +DMSETDMRZ 011111 ... -- 00010 ----- 0010110001 - @X_a + +DMXXEXTFDMR512 111100 ... -- .... . .... - 11100010 ..- @XX3_abp_as_p +DMXXINSTDMR512 111100 ... -- .... . .... - 11101010 ..- @XX3_abp_as_p + +DMXXEXTFDMR256 111100 ... ------ . .... . 111100100 .- @XX2_bp_as_p +DMXXINSTDMR256 111100 ... ------ . .... . 111100101 .- @XX2_bp_as_p + ## SLB Management Instructions SLBIE 011111 ----- ----- ..... 0110110010 - @X_rb
target/ppc/translate.c +11 -0
@@ -3992,6 +3992,15 @@ static int64_t dw_compose_ea(DisasContext *ctx, int x) } \ } while (0) +#define REQUIRE_DM (CTX ) \ + do { \ + if (unlikely(!(CTX)->dm_enabled)) { \ + gen_exception_err((CTX), POWERPC_EXCP_FU, \ + FSCR_IC_DM); \ + return true; \ + } \ + } while (0) +#define REQUIRE_FPU (ctx) \ do { \ if (unlikely(!(ctx)->fpu_enabled)) { \
@@ -4384,6 +4393,8 @@ static bool trans_ICBIEP(DisasContext *ctx, arg_X_ea *a)#include "translate/vsx-impl.c.inc" +#include "translate/dmf-impl.c.inc" +#include "translate/dfp-impl.c.inc" #include "translate/spe-impl.c.inc"
target/ppc/translate/dmf-impl.c.inc new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.55.0
I know that Saif has done some work on DMF recently so adding him to the CC list as well.
Regards,
Glenn
Quoted 26 lines · Chinmay Rath
This series aims to implement the dense math facility introduced in RFC 02653: Dense Math Facility for Power ISA 3.2.
The RFC is available in the OpenPOWER website here :
https://files.openpowerfoundation.org/s/Fyp9TWZf8oYTd7DChinmay Rath (8):
target/ppc: Add flag for Power ISA 3.2 target/ppc: Enable Dense Math Facility for ISA 3.2 target/ppc: Implement DMR getter/setter and some DMF insns. target/ppc: Add FSSIR spr for ISA 3.2
target/ppc: Implement DMMR and DMXOR instructions. target/ppc: Implement DMF accumulator instructions target/ppc: Add function to point to dmr regs intcg_envtarget/ppc: Add DMF Outer-Product accumulate to ACC insnstarget/ppc/cpu.h | 23 ++- target/ppc/fpu_helper.c | 5 + target/ppc/helper_regs.c | 4 + target/ppc/insn32.decode | 201 +++++++++++++++++----- target/ppc/insn64.decode | 244 +++++++++++++++++++------- target/ppc/int_helper.c | 5 + target/ppc/translate.c | 13 ++ target/ppc/translate/dmf-impl.c.inc | 255 ++++++++++++++++++++++++++++ 8 files changed, 644 insertions(+), 106 deletions(-) create mode 100644 target/ppc/translate/dmf-impl.c.inc
RFC PATCH 4/8 target/ppc: Add FSSIR spr for ISA 3.2
In reply to Chinmay RathRFC 02653 for Power ISA 3.2 adds FSSIR spr to indicate if DMF has any unsaved state. Defining this SPR.
--- target/ppc/cpu.h | 1 + 1 file changed, 1 insertion(+)
target/ppc/cpu.h +1 -0
@@ -2179,6 +2179,7 @@ void ppc_compat_add_property(Object *obj, const char *name,#define SPR_UDEXCR (0x32C)#define SPR_TAR (0x32F)#define SPR_ASDR (0x330) +#define SPR_FSSIR (0x33B)#define SPR_DEXCR (0x33C)#define SPR_IC (0x350)#define SPR_VTB (0x351)
Signature · 1 line
2.55.0
RFC PATCH 5/8 target/ppc: Implement DMMR and DMXOR instructions.
In reply to Chinmay RathThis patch implements DMMR and DMXOR instructions, that are part of the Dense Math Facility in RFC 02653, Power ISA 3.2
--- target/ppc/insn32.decode | 6 ++++++ target/ppc/translate/dmf-impl.c.inc | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
target/ppc/insn32.decode +6 -0
@@ -231,6 +231,9 @@ &X_a ra @X_a ...... ra:3 .. ..... ..... .......... . &X_a +&X_ab ra rb +@X_ab ...... ra:3 .. ..... rb:3 .. ........... &X_ab + &X_tl rt l @X_tl ...... rt:5 ... l:2 ..... .......... . &X_tl
@@ -1552,6 +1555,9 @@ DMXXINSTDMR512 111100 ... -- .... . .... - 11101010 ..- @XX3_abp_as_p DMXXEXTFDMR256 111100 ... ------ . .... . 111100100 .- @XX2_bp_as_p DMXXINSTDMR256 111100 ... ------ . .... . 111100101 .- @XX2_bp_as_p +DMMR 011111 ... -- 00110 ... -- 0010110001 - @X_ab +DMXOR 011111 ... -- 00111 ... -- 0010110001 - @X_ab + ## SLB Management Instructions SLBIE 011111 ----- ----- ..... 0110110010 - @X_rb
target/ppc/translate/dmf-impl.c.inc +27 -0
@@ -78,3 +78,30 @@ TRANS_FLAGS2(ISA320, DMXXEXTFDMR512, do_ext_inst_512, true) TRANS_FLAGS2(ISA320, DMXXINSTDMR512, do_ext_inst_512, false) TRANS_FLAGS2(ISA320, DMXXEXTFDMR256, do_ext_inst_256, true) TRANS_FLAGS2(ISA320, DMXXINSTDMR256, do_ext_inst_256, false) + +static bool trans_DMMR(DisasContext *ctx, arg_DMMR *a) +{ + REQUIRE_INSNS_FLAGS2(ctx, ISA320); + REQUIRE_DM(ctx); + + TCGv_i128 temp; + temp = tcg_temp_new_i128(); + for (int row = 0; row < 8; row++) { + get_dmr_row(temp, a->rb, row); + set_dmr_row(a->ra, row, temp); + } + return true; +} + +static bool trans_DMXOR(DisasContext *ctx, arg_DMXOR *a) +{ + REQUIRE_INSNS_FLAGS2(ctx, ISA320); + REQUIRE_DM(ctx); + + for (int row = 0; row < 8; row++) { + tcg_gen_gvec_xor(MO_64, dmr_row_offset(a->ra, row), + dmr_row_offset(a->ra, row), dmr_row_offset(a->rb, row), + 16, 16); + } + return true; +}
Signature · 1 line
2.55.0
RFC PATCH 6/8 target/ppc: Implement DMF accumulator instructions
In reply to Chinmay RathThis patch implements the following instructions that are part of the Dense Math Facility in RFC 02653 Power ISA 3.2 :
DMXX{MF, MT}ACC and DMSETACCZ
These instructions have the exact same opcodes as the older equivalent vector instructions. This is handled using overlapping pattern groups.
--- target/ppc/insn32.decode | 20 +++++++---- target/ppc/translate/dmf-impl.c.inc | 55 +++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 6 deletions(-)
target/ppc/insn32.decode +14 -6
@@ -1429,12 +1429,6 @@ XVTLSBB 111100 ... -- 00010 ..... 111011011 . - @XX2_bf_xb @XL_s ......-------------- s:1 .......... - &XL_s RFEBB 010011-------------- . 0010010010 - @XL_s -## Accumulator Instructions - -XXMFACC 011111 ... -- 00000 ----- 0010110001 - @X_a -XXMTACC 011111 ... -- 00001 ----- 0010110001 - @X_a -XXSETACCZ 011111 ... -- 00011 ----- 0010110001 - @X_a - ## VSX Vector Logical instructions XXLAND 111100 ..... ..... ..... 10000010 ... @XX3
@@ -1547,6 +1541,20 @@ VMODUQ 000100 ..... ..... ..... 11000001011 @VX ## DMF Instructions +## DMF accumulator instructions overlap with the existing accumulator ones. +{ + DMXXMFACC 011111 ... -- 00000 ----- 0010110001 - @X_a + XXMFACC 011111 ... -- 00000 ----- 0010110001 - @X_a +} +{ + DMXXMTACC 011111 ... -- 00001 ----- 0010110001 - @X_a + XXMTACC 011111 ... -- 00001 ----- 0010110001 - @X_a +} +{ + DMSETACCZ 011111 ... -- 00011 ----- 0010110001 - @X_a + XXSETACCZ 011111 ... -- 00011 ----- 0010110001 - @X_a +} + DMSETDMRZ 011111 ... -- 00010 ----- 0010110001 - @X_a DMXXEXTFDMR512 111100 ... -- .... . .... - 11100010 ..- @XX3_abp_as_p
target/ppc/translate/dmf-impl.c.inc +55 -0
58 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC PATCH 7/8 target/ppc: Add function to point to dmr regs in tcg_env
In reply to Chinmay RathTo access registers within tcg_env, in a helper function, a pointer to the required register is traditionally passed to the helper function. Adding one such function for future usage.
--- target/ppc/translate/dmf-impl.c.inc | 7 +++++++ 1 file changed, 7 insertions(+)
target/ppc/translate/dmf-impl.c.inc +7 -0
@@ -10,6 +10,13 @@ static inline void get_dmr_row(TCGv_i128 dst, int reg, int row) tcg_gen_ld_i128(dst, tcg_env, dmr_row_offset(reg, row)); } +static inline TCGv_ptr gen_dmr_ptr(int reg) +{ + TCGv_ptr r = tcg_temp_new_ptr(); + tcg_gen_addi_ptr(r, tcg_env, offsetof(CPUPPCState, dmr[reg])); + return r; +} + static bool trans_DMSETDMRZ(DisasContext *ctx, arg_DMSETDMRZ *a) { TCGv_i128 zero;
Signature · 1 line
2.55.0
RFC PATCH 8/8 target/ppc: Add DMF Outer-Product accumulate to ACC insns
In reply to Chinmay RathPowerPC ISA 3.2 DMF RFC02653 moves the exisiting VSX Outer-Product instructions to the DMF. Add those instructions.
The instructions have new names now, though their opcode remains exactly the same. This is handled using overlapping pattern group in the decodetree specification. Since the operations remain logically the same, reusing the same helpers. Results now accumulate to the accumulators in the DMRs.
--- target/ppc/fpu_helper.c | 5 + target/ppc/insn32.decode | 157 ++++++++++++++---- target/ppc/insn64.decode | 244 ++++++++++++++++++++-------- target/ppc/int_helper.c | 5 + target/ppc/translate/dmf-impl.c.inc | 86 ++++++++++ 5 files changed, 398 insertions(+), 99 deletions(-)
target/ppc/fpu_helper.c +5 -0
@@ -3386,6 +3386,11 @@ static float64 extract_bf16(bfloat16 in, float_status *fp_status)return bfloat16_to_float64 (in, fp_status); } +/* +* ISA 3.2 onwards accumulators are assigned in DMRs instead of VSRs. +* However both ppc_acc_t and ppc_dmr_row_t are essentially ppc_vsr_t, +* hence the below helpers work for either. +*/ static void vsxger16 (CPUPPCState *env,ppc_vsr_t *a,ppc_vsr_t *b,ppc_acc_t *at,uint32_t mask,bool acc,bool neg_mul,bool neg_acc,extract_f16 extract)
target/ppc/insn32.decode +122 -35
163 lines not on this page · raw message
target/ppc/insn64.decode +180 -64
250 lines not on this page · raw message
target/ppc/int_helper.c +5 -0
@@ -782,6 +782,11 @@ static int64_t ger_rank2(uint32_t a, uint32_t b, uint32_t mask)return psum; } +/* +* ISA 3.2 onwards accumulators are assigned in DMRs instead of VSRs. +* However both ppc_acc_t and ppc_dmr_row_t are essentially ppc_vsr_t, +* hence this helpers works for either. +*/ static void xviger (CPUPPCState *env,ppc_vsr_t *a,ppc_vsr_t *b,ppc_acc_t *at,uint32_t mask,bool sat,bool acc,do_ger ger) {
target/ppc/translate/dmf-impl.c.inc +86 -0
89 lines not on this page · raw message
Signature · 1 line
2.55.0