From patchwork Fri Mar 15 11:04:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10854541 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E50314DE for ; Fri, 15 Mar 2019 11:06:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 343DF2A94B for ; Fri, 15 Mar 2019 11:06:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 285A82A94D; Fri, 15 Mar 2019 11:06:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 817762A94B for ; Fri, 15 Mar 2019 11:06:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h4kdL-0001HH-HE; Fri, 15 Mar 2019 11:04:15 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h4kdK-0001H5-CN for xen-devel@lists.xenproject.org; Fri, 15 Mar 2019 11:04:14 +0000 X-Inumbo-ID: 108dcb02-4712-11e9-bc90-bc764e045a96 Received: from prv1-mh.provo.novell.com (unknown [137.65.248.33]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 108dcb02-4712-11e9-bc90-bc764e045a96; Fri, 15 Mar 2019 11:04:12 +0000 (UTC) Received: from INET-PRV1-MTA by prv1-mh.provo.novell.com with Novell_GroupWise; Fri, 15 Mar 2019 05:04:12 -0600 Message-Id: <5C8B86A9020000780021F2BB@prv1-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 18.1.0 Date: Fri, 15 Mar 2019 05:04:09 -0600 From: "Jan Beulich" To: "xen-devel" References: <5B6BF83602000078001DC548@prv1-mh.provo.novell.com> <5C8B7EC0020000780021F10B@prv1-mh.provo.novell.com> In-Reply-To: <5C8B7EC0020000780021F10B@prv1-mh.provo.novell.com> Mime-Version: 1.0 Content-Disposition: inline Subject: [Xen-devel] [PATCH v8 41/50] x86emul: support AVX512_4FMAPS insns X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: George Dunlap , Andrew Cooper , Wei Liu , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jan Beulich --- v8: Correct vcpu_has_*() insertion point. v7: Re-base. v6: New. --- a/tools/tests/x86_emulator/evex-disp8.c +++ b/tools/tests/x86_emulator/evex-disp8.c @@ -538,6 +538,13 @@ static const struct test avx512pf_512[] INSNX(scatterpf1q, 66, 0f38, c7, 6, vl, sd, el), }; +static const struct test avx512_4fmaps_512[] = { + INSN(4fmaddps, f2, 0f38, 9a, el_4, d, vl), + INSN(4fmaddss, f2, 0f38, 9b, el_4, d, vl), + INSN(4fnmaddps, f2, 0f38, aa, el_4, d, vl), + INSN(4fnmaddss, f2, 0f38, ab, el_4, d, vl), +}; + static const struct test avx512_bitalg_all[] = { INSN(popcnt, 66, 0f38, 54, vl, bw, vl), INSN(pshufbitqmb, 66, 0f38, 8f, vl, b, vl), @@ -941,6 +948,7 @@ void evex_disp8_test(void *instr, struct RUN(avx512er, 512); #define cpu_has_avx512pf cpu_has_avx512f RUN(avx512pf, 512); + RUN(avx512_4fmaps, 512); RUN(avx512_bitalg, all); RUN(avx512_ifma, all); RUN(avx512_vbmi, all); --- a/tools/tests/x86_emulator/test_x86_emulator.c +++ b/tools/tests/x86_emulator/test_x86_emulator.c @@ -4274,6 +4274,81 @@ int main(int argc, char **argv) } #endif + printf("%-40s", "Testing v4fmaddps 32(%ecx),%zmm4,%zmm4{%k5}..."); + if ( stack_exec && cpu_has_avx512_4fmaps ) + { + decl_insn(v4fmaddps); + static const struct { + float f[16]; + } in = {{ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 + }}, out = {{ + 1 + 1 * 9 + 2 * 10 + 3 * 11 + 4 * 12, + 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16 + 16 * 9 + 17 * 10 + 18 * 11 + 19 * 12 + }}; + + asm volatile ( "vmovups %1, %%zmm4\n\t" + "vbroadcastss %%xmm4, %%zmm7\n\t" + "vaddps %%zmm4, %%zmm7, %%zmm5\n\t" + "vaddps %%zmm5, %%zmm7, %%zmm6\n\t" + "vaddps %%zmm6, %%zmm7, %%zmm7\n\t" + "kmovw %2, %%k5\n" + put_insn(v4fmaddps, + "v4fmaddps 32(%0), %%zmm4, %%zmm4%{%%k5%}") + :: "c" (NULL), "m" (in), "rmk" (0x8001) ); + + set_insn(v4fmaddps); + regs.ecx = (unsigned long)∈ + rc = x86_emulate(&ctxt, &emulops); + if ( rc != X86EMUL_OKAY || !check_eip(v4fmaddps) ) + goto fail; + + asm ( "vcmpeqps %1, %%zmm4, %%k0\n\t" + "kmovw %%k0, %0" : "=g" (rc) : "m" (out) ); + if ( rc != 0xffff ) + goto fail; + printf("okay\n"); + } + else + printf("skipped\n"); + + printf("%-40s", "Testing v4fnmaddss 16(%edx),%zmm4,%zmm4{%k3}..."); + if ( stack_exec && cpu_has_avx512_4fmaps ) + { + decl_insn(v4fnmaddss); + static const struct { + float f[16]; + } in = {{ + 1, 2, 3, 4, 5, 6, 7, 8 + }}, out = {{ + 1 - 1 * 5 - 2 * 6 - 3 * 7 - 4 * 8, 2, 3, 4 + }}; + + asm volatile ( "vmovups %1, %%xmm4\n\t" + "vaddss %%xmm4, %%xmm4, %%xmm5\n\t" + "vaddss %%xmm5, %%xmm4, %%xmm6\n\t" + "vaddss %%xmm6, %%xmm4, %%xmm7\n\t" + "kmovw %2, %%k3\n" + put_insn(v4fnmaddss, + "v4fnmaddss 16(%0), %%xmm4, %%xmm4%{%%k3%}") + :: "d" (NULL), "m" (in), "rmk" (1) ); + + set_insn(v4fnmaddss); + regs.edx = (unsigned long)∈ + rc = x86_emulate(&ctxt, &emulops); + if ( rc != X86EMUL_OKAY || !check_eip(v4fnmaddss) ) + goto fail; + + asm ( "vcmpeqps %1, %%zmm4, %%k0\n\t" + "kmovw %%k0, %0" : "=g" (rc) : "m" (out) ); + if ( rc != 0xffff ) + goto fail; + printf("okay\n"); + } + else + printf("skipped\n"); + #undef decl_insn #undef put_insn #undef set_insn --- a/tools/tests/x86_emulator/x86-emulate.h +++ b/tools/tests/x86_emulator/x86-emulate.h @@ -146,6 +146,7 @@ static inline bool xcr0_mask(uint64_t ma #define cpu_has_avx512_vbmi2 (cp.feat.avx512_vbmi2 && xcr0_mask(0xe6)) #define cpu_has_avx512_bitalg (cp.feat.avx512_bitalg && xcr0_mask(0xe6)) #define cpu_has_avx512_vpopcntdq (cp.feat.avx512_vpopcntdq && xcr0_mask(0xe6)) +#define cpu_has_avx512_4fmaps (cp.feat.avx512_4fmaps && xcr0_mask(0xe6)) #define cpu_has_xgetbv1 (cpu_has_xsave && cp.xstate.xgetbv1) --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -1924,6 +1924,7 @@ static bool vcpu_has( #define vcpu_has_avx512_bitalg() vcpu_has( 7, ECX, 12, ctxt, ops) #define vcpu_has_avx512_vpopcntdq() vcpu_has( 7, ECX, 14, ctxt, ops) #define vcpu_has_rdpid() vcpu_has( 7, ECX, 22, ctxt, ops) +#define vcpu_has_avx512_4fmaps() vcpu_has( 7, EDX, 3, ctxt, ops) #define vcpu_has_clzero() vcpu_has(0x80000008, EBX, 0, ctxt, ops) #define vcpu_must_have(feat) \ @@ -3205,6 +3206,18 @@ x86_decode( state); state->simd_size = simd_other; } + + switch ( b ) + { + /* v4f{,n}madd{p,s}s need special casing */ + case 0x9a: case 0x9b: case 0xaa: case 0xab: + if ( evex.pfx == vex_f2 ) + { + disp8scale = 4; + state->simd_size = simd_128; + } + break; + } } break; @@ -9388,6 +9401,24 @@ x86_emulate( avx512_vlen_check(true); goto simd_zmm; + case X86EMUL_OPC_EVEX_F2(0x0f38, 0x9a): /* v4fmaddps m128,zmm+3,zmm{k} */ + case X86EMUL_OPC_EVEX_F2(0x0f38, 0xaa): /* v4fnmaddps m128,zmm+3,zmm{k} */ + host_and_vcpu_must_have(avx512_4fmaps); + generate_exception_if((ea.type != OP_MEM || evex.w || evex.brs || + evex.lr != 2), + EXC_UD); + op_mask = op_mask & 0xffff ? 0xf : 0; + goto simd_zmm; + + case X86EMUL_OPC_EVEX_F2(0x0f38, 0x9b): /* v4fmaddss m128,xmm+3,xmm{k} */ + case X86EMUL_OPC_EVEX_F2(0x0f38, 0xab): /* v4fnmaddss m128,xmm+3,xmm{k} */ + host_and_vcpu_must_have(avx512_4fmaps); + generate_exception_if((ea.type != OP_MEM || evex.w || evex.brs || + evex.lr == 3), + EXC_UD); + op_mask = op_mask & 1 ? 0xf : 0; + goto simd_zmm; + case X86EMUL_OPC_EVEX_66(0x0f38, 0xa0): /* vpscatterd{d,q} [xyz]mm,mem{k} */ case X86EMUL_OPC_EVEX_66(0x0f38, 0xa1): /* vpscatterq{d,q} [xyz]mm,mem{k} */ case X86EMUL_OPC_EVEX_66(0x0f38, 0xa2): /* vscatterdp{s,d} [xyz]mm,mem{k} */ --- a/xen/include/asm-x86/cpufeature.h +++ b/xen/include/asm-x86/cpufeature.h @@ -116,6 +116,9 @@ #define cpu_has_avx512_vpopcntdq boot_cpu_has(X86_FEATURE_AVX512_VPOPCNTDQ) #define cpu_has_rdpid boot_cpu_has(X86_FEATURE_RDPID) +/* CPUID level 0x00000007:0.edx */ +#define cpu_has_avx512_4fmaps boot_cpu_has(X86_FEATURE_AVX512_4FMAPS) + /* CPUID level 0x80000007.edx */ #define cpu_has_itsc boot_cpu_has(X86_FEATURE_ITSC)