From nobody Sun Feb 8 10:34:38 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1608109978; cv=none; d=zohomail.com; s=zohoarc; b=Wesa6JOdP8DpyQxl3/YCwM8L1Vbi+F61ertGlhb3P9SqIxstt7LYRMZuDYcNqn+vFB5ND6zf7sysEQO/nTjvudN+Zk7sE1swx+tPS+HLckOE3Y9O3DeNVpcBV2wgnWjJ/QLejvhkpPTQgtUtfyI0pQMMz3KUDDr6V3DQG+yQEzs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608109978; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=UoktslZxUvRLpe5e2Q74so+Hlan9Ao0g+ynl4a54ohQ=; b=TbV7AfkS15jMjpWx0lcGyuiOhVTcHONJti6syn6ui4N74KkRv7Na16AfS22/iiiR39vhle6G47IbxWvopoiediG6cpOZVavYu9hXwYgv7JPbZ84TNkVtpx19NmIkxB7CHkMaPlQfI2qFyI+v/8ehTFI4jGFsMwr718pOF5V1yHE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608109978663933.5404613757081; Wed, 16 Dec 2020 01:12:58 -0800 (PST) Received: from localhost ([::1]:46620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpSrh-0006Ge-BU for importer@patchew.org; Wed, 16 Dec 2020 04:12:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSpn-0004kh-4m; Wed, 16 Dec 2020 04:10:59 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43132) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSpk-0007H4-KR; Wed, 16 Dec 2020 04:10:58 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0BG92RHh028487; Wed, 16 Dec 2020 04:10:44 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 35fdvg2p4b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:10:43 -0500 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0BG94SgM035159; Wed, 16 Dec 2020 04:10:43 -0500 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 35fdvg2p3u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:10:43 -0500 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0BG989Il031094; Wed, 16 Dec 2020 09:10:41 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma04wdc.us.ibm.com with ESMTP id 35cng96d3e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 09:10:41 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0BG9Aebd21823808 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Dec 2020 09:10:41 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D4F127805F; Wed, 16 Dec 2020 09:10:40 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2C9637805E; Wed, 16 Dec 2020 09:10:34 +0000 (GMT) Received: from pub.ltc.br.ibm.com (unknown [9.85.141.22]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 16 Dec 2020 09:10:33 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=UoktslZxUvRLpe5e2Q74so+Hlan9Ao0g+ynl4a54ohQ=; b=f3coDdUkX51mtGlsl8BZJhRwVZo203k2dKd63l++P14iFDEARZKLZ/AbM9fMJSMGVA0C mNKZC1dwQvrGyo/jj/GouMqmepWsnvf6v60KlkjNvB1qe6ZtV2aWEJG+kxbGMwPfzzAe cAeQ79T+kv2NAzzfTKBAwzKhMP7QSGytSG7kbF+EzBHm4bTHbw6ShN82Iwp+z50ixWot TPrM13CcjA9QeNl8cYv7cQwwR8TZkpCLUK0aA1mnwGh0WG9DanVCKKx6M+Y3TGx4DkpL r1oOdh5JCbensWsDqBuY59lG4nPWKml1yoBO1IasXfRdMj8w9JHVsjKzZdS33cJiH3Nc AA== From: Gustavo Romero To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 1/7] target/ppc: Add infrastructure for prefixed instructions Date: Wed, 16 Dec 2020 06:07:58 -0300 Message-Id: <20201216090804.58640-2-gromero@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216090804.58640-1-gromero@linux.ibm.com> References: <20201216090804.58640-1-gromero@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-16_02:2020-12-15, 2020-12-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012160055 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=gromero@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, gromero@linux.ibm.com, gustavo.romero@protonmail.com, Michael Roth , mroth@lamentation.net, clg@kaod.org, david@gibson.dropbear.id.au, alex.bennee@linaro.org, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth Some prefixed instructions (Type 0 and 1, e.g. 8-byte Load/Store or 8LS), have a completely seperate namespace for their primary opcodes. Other prefixed instructions (Type 2 and 3, e.g. Modified Load/Store or MLS) actually re-use existing opcodes to provide a modified variant. We could handle these by extending the existing opcode handlers to check for the prefix and handle accordingly, but in some cases it is cleaner to define seperate handlers for these in their own table entry, and avoids the need to add error-handling to existing handlers for cases where they are called for a prefixed Type 2/3 instruction but don't implement the handling for them. In the future we can re-work things to support both approaches if cases arise where that seems warranted. Then we have the normal non-prefixed instructions. To handle all 3 of these cases we extend the table size 3x, with normal instructions indexed directly by their primary opcodes, Type 0/1 indexed by primary opcode + PPC_CPU_PREFIXED_OPCODE_OFFSET, and Type 2/3 indexed by primary opcode + PPC_CPU_PREFIXED_MODIFIED_OPCODE_OFFSET. Various exception/SRR handling changes related to prefixed instructions are yet to be implemented. For instance, no alignment interrupt is generated if a prefixed instruction crosses the 64-byte boundary; no SRR bit related to prefixed instructions is set on any interrupt, like for FP unavailable interrupt, data storage interrupt, etc. For details, please see PowerISA v3.1, particularly the following sections: 1.6 Instruction Formats, p. 11 1.6.3 Instruction Prefix Formats, p. 22 3.3.2 Fixed-Point Load Instructions, p. 51 4.6.2 Floating-Point Load Instructions, p. 149 Chapter 7 Interrupts, p. 1247 Signed-off-by: Michael Roth [ gromero: - comments clean up and updates - additional comments in the commit log ] Signed-off-by: Gustavo Romero --- target/ppc/cpu.h | 30 +++++- target/ppc/internal.h | 14 +++ target/ppc/translate.c | 170 +++++++++++++++++++++++++++++++- target/ppc/translate_init.c.inc | 11 ++- 4 files changed, 218 insertions(+), 7 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index e8aa185d4f..1e40a923bd 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -979,8 +979,34 @@ struct ppc_radix_page_info { #define PPC_TLB_EPID_LOAD 8 #define PPC_TLB_EPID_STORE 9 =20 -#define PPC_CPU_OPCODES_LEN 0x40 -#define PPC_CPU_INDIRECT_OPCODES_LEN 0x20 +/* + * The primary op-code field extracted from the instruction (PO) is used a= s the + * index in the top-level QEMU opcode table. That table is then further us= ed to + * find the proper handler, or a pointer to another table (OPC1, OPC2 etc)= . For + * the normal opcodes (PO field of normal insns) the 64 first entries are = used. + * + * Prefixed instructions can be divided into two major groups of instructi= ons: + * the first group is formed by type 0 and 1, and the second group is by t= ype 2 + * and 3. Opcodes (PO) related to prefixed type 0/1 can have the same opco= des + * as the normal instructions but don't have any semantics related to them= . But + * since it's an primary opcode anyway it was decided to simply extend the + * top-level table that handles the primary opcodes for the normal instruc= tions. + * On the other handle, prefixed instructions type 2/3 work like modifiers= for + * existing normal instructions. In that case it would be possible to reus= e the + * handlers for the normal instructions, but that would require changing t= he + * normal instruction handler in a way it would have to check, for instanc= e, on + * which ISA it has to take care of prefixes insns, and that is already do= ne by + * GEN_HANDLER_* helpers when registering a new instruction, where there i= s a + * a field to inform on which ISA the instruction exists. Hence, it was de= cided + * to add another 64 entries for specific handler for the prefixed instruc= tions + * of type 2/3. Thus the size of top-level PO lookup table is 3*64 =3D 192= , hence + * representing three namespaces for decoding PO: for normal insns, for ty= pe 0/1 + * and for type 2/3. + */ +#define PPC_CPU_OPCODES_LEN 0xc0 /* 64 + 64 + 64 =3D 1= 92 */ +#define PPC_CPU_INDIRECT_OPCODES_LEN 0x20 +#define PPC_CPU_PREFIXED_OPCODE_OFFSET 0x40 /* Prefixed type 0/1 = */ +#define PPC_CPU_PREFIXED_MODIFIED_OPCODE_OFFSET 0x80 /* Prefixed type 2/3 = */ =20 struct CPUPPCState { /* Most commonly used resources during translated code execution first= */ diff --git a/target/ppc/internal.h b/target/ppc/internal.h index 15d655b356..d03d691a44 100644 --- a/target/ppc/internal.h +++ b/target/ppc/internal.h @@ -129,6 +129,7 @@ EXTRACT_SHELPER(SIMM5, 16, 5); EXTRACT_HELPER(UIMM5, 16, 5); /* 4 bits unsigned immediate value */ EXTRACT_HELPER(UIMM4, 16, 4); + /* Bit count */ EXTRACT_HELPER(NB, 11, 5); /* Shift count */ @@ -146,6 +147,19 @@ EXTRACT_HELPER(TO, 21, 5); =20 EXTRACT_HELPER(CRM, 12, 8); =20 +/* + * Instruction prefix fields + * + * as per PowerISA 3.1 1.6.3 + */ + +/* prefixed instruction type */ +EXTRACT_HELPER(PREFIX_TYPE, 24, 2); +/* 1-bit sub-type */ +EXTRACT_HELPER(PREFIX_ST1, 23, 1); +/* 4-bit sub-type */ +EXTRACT_HELPER(PREFIX_ST4, 20, 4); + #ifndef CONFIG_USER_ONLY EXTRACT_HELPER(SR, 16, 4); #endif diff --git a/target/ppc/translate.c b/target/ppc/translate.c index fedb9b2271..eab6561094 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -180,6 +180,8 @@ struct DisasContext { uint32_t flags; uint64_t insns_flags; uint64_t insns_flags2; + uint32_t prefix; + uint32_t prefix_subtype; }; =20 /* Return true iff byteswap is needed in a scalar memop */ @@ -376,6 +378,12 @@ GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NO= NE) #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) = \ GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2) =20 +#define GEN_HANDLER_E_PREFIXED(name, opc1, opc2, opc3, inval, type, type2)= \ +GEN_OPCODE_PREFIXED(name, opc1, opc2, opc3, inval, type, type2, false) + +#define GEN_HANDLER_E_PREFIXED_M(name, opc1, opc2, opc3, inval, type, type= 2) \ +GEN_OPCODE_PREFIXED(name, opc1, opc2, opc3, inval, type, type2, true) + #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) = \ GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE) =20 @@ -395,6 +403,8 @@ typedef struct opcode_t { #endif opc_handler_t handler; const char *oname; + bool prefixed; + bool modified; } opcode_t; =20 /* Helpers for priv. check */ @@ -449,6 +459,23 @@ typedef struct opcode_t { }, = \ .oname =3D stringify(name), = \ } +#define GEN_OPCODE_PREFIXED(name, op1, op2, op3, invl, _typ, _typ2, _modif= ied)\ +{ = \ + .opc1 =3D op1, = \ + .opc2 =3D op2, = \ + .opc3 =3D op3, = \ + .opc4 =3D 0xff, = \ + .handler =3D { = \ + .inval1 =3D invl, = \ + .type =3D _typ, = \ + .type2 =3D _typ2, = \ + .handler =3D &gen_##name, = \ + .oname =3D stringify(name), = \ + }, = \ + .oname =3D stringify(name), = \ + .prefixed =3D true, = \ + .modified =3D _modified, = \ +} #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) = \ { = \ .opc1 =3D op1, = \ @@ -525,6 +552,22 @@ typedef struct opcode_t { }, = \ .oname =3D stringify(name), = \ } +#define GEN_OPCODE_PREFIXED(name, op1, op2, op3, invl, _typ, _typ2, _modif= ied)\ +{ = \ + .opc1 =3D op1, = \ + .opc2 =3D op2, = \ + .opc3 =3D op3, = \ + .opc4 =3D 0xff, = \ + .handler =3D { = \ + .inval1 =3D invl, = \ + .type =3D _typ, = \ + .type2 =3D _typ2, = \ + .handler =3D &gen_##name, = \ + }, = \ + .oname =3D stringify(name), = \ + .prefixed =3D true, = \ + .modified =3D _modified, = \ +} #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) = \ { = \ .opc1 =3D op1, = \ @@ -7991,6 +8034,101 @@ static bool ppc_tr_breakpoint_check(DisasContextBas= e *dcbase, CPUState *cs, return true; } =20 + + +/* + * Prefixed instruction sub-types + * + * as per PowerISA 3.1 1.6.3 + */ +enum { + /* prefixed instruction but subtype doesn't match any of below ones */ + PREFIX_ST_INVALID =3D -1, + /* non-prefixed instruction (normal instruction) */ + PREFIX_ST_NONE =3D 0, + /* Type 0b00 prefixed insn sub-types */ + PREFIX_ST_8LS, /* 8-byte load/store */ + PREFIX_ST_8MLS, /* 8-byte masked load/store */ + /* Type 0b01 prefixed insn sub-types */ + PREFIX_ST_8RR, /* 8-byte reg-to-reg */ + PREFIX_ST_8MRR, /* 8-byte masked reg-to-reg */ + /* Type 0b10 prefixed insn sub-types */ + PREFIX_ST_MLS, /* modified load/store */ + PREFIX_ST_MMLS, /* modified masked load/store */ + /* Type 0b11 prefixed insn sub-types */ + PREFIX_ST_MRR, /* modified reg-to-reg */ + PREFIX_ST_MMRR, /* modified mask reg-to-reg */ + PREFIX_ST_MMIRR, /* modified masked immediate reg-to-reg */ +}; + +static int32_t parse_prefix_subtype(uint32_t prefix) +{ + int32_t prefix_subtype =3D PREFIX_ST_INVALID; + + /* primary opcode 1 is reserved for instruction prefixes */ + if (opc1(prefix) !=3D 1) { + return PREFIX_ST_NONE; + } + + switch (PREFIX_TYPE(prefix)) { + case 0: + if (PREFIX_ST1(prefix) =3D=3D 0) { + prefix_subtype =3D PREFIX_ST_8LS; + } else if (PREFIX_ST1(prefix) =3D=3D 1) { + prefix_subtype =3D PREFIX_ST_8MLS; + } + break; + case 1: + if (PREFIX_ST4(prefix) =3D=3D 0) { + prefix_subtype =3D PREFIX_ST_8RR; + } else if (PREFIX_ST4(prefix) =3D=3D 8) { + prefix_subtype =3D PREFIX_ST_8MRR; + } + break; + case 2: + if (PREFIX_ST1(prefix) =3D=3D 0) { + prefix_subtype =3D PREFIX_ST_MLS; + } else if (PREFIX_ST1(prefix) =3D=3D 1) { + prefix_subtype =3D PREFIX_ST_MMLS; + } + break; + case 3: + if (PREFIX_ST4(prefix) =3D=3D 0) { + prefix_subtype =3D PREFIX_ST_MRR; + } else if (PREFIX_ST4(prefix) =3D=3D 8) { + prefix_subtype =3D PREFIX_ST_MMRR; + } else if (PREFIX_ST4(prefix) =3D=3D 9) { + prefix_subtype =3D PREFIX_ST_MMIRR; + } + break; + } + + return prefix_subtype; +} + +static uint32_t opc1_idx(DisasContext *ctx) +{ + uint32_t table_offset =3D 0; + + switch (ctx->prefix_subtype) { + case PREFIX_ST_8LS: + case PREFIX_ST_8MLS: + case PREFIX_ST_8RR: + case PREFIX_ST_8MRR: + table_offset =3D PPC_CPU_PREFIXED_OPCODE_OFFSET; + break; + case PREFIX_ST_MLS: + case PREFIX_ST_MMLS: + case PREFIX_ST_MRR: + case PREFIX_ST_MMRR: + case PREFIX_ST_MMIRR: + table_offset =3D PPC_CPU_PREFIXED_MODIFIED_OPCODE_OFFSET; + break; + } + + return table_offset + opc1(ctx->opcode); +} + static void ppc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) { DisasContext *ctx =3D container_of(dcbase, DisasContext, base); @@ -8004,14 +8142,40 @@ static void ppc_tr_translate_insn(DisasContextBase = *dcbase, CPUState *cs) =20 ctx->opcode =3D translator_ldl_swap(env, ctx->base.pc_next, need_byteswap(ctx)); + /* check for prefix */ + ctx->prefix_subtype =3D parse_prefix_subtype(ctx->opcode); + if (ctx->prefix_subtype =3D=3D PREFIX_ST_INVALID) { + qemu_log_mask(LOG_GUEST_ERROR, "invalid/unsupported prefix: " + "%08x " TARGET_FMT_lx "\n", + ctx->prefix, ctx->base.pc_next); + } else if (ctx->prefix_subtype !=3D PREFIX_ST_NONE) { + /* + * this is the 4-byte prefix of an instruction, read the + * next 4 and advance the PC + * + * TODO: we can optimize this to do a single load since we + * read in target_long anyways already + * + * double-check endianess cases. + * + * engineering note about endianess changing based on rfid + * or interrupt. does this need to be accounted for here? + */ + ctx->prefix =3D ctx->opcode; + ctx->base.pc_next +=3D 4; + ctx->opcode =3D translator_ldl_swap(env, ctx->base.pc_next, + need_byteswap(ctx)); + } else { + ctx->prefix =3D 0; + } =20 - LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n", + LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) prefix %08x (%s= )\n", ctx->opcode, opc1(ctx->opcode), opc2(ctx->opcode), - opc3(ctx->opcode), opc4(ctx->opcode), + opc3(ctx->opcode), opc4(ctx->opcode), ctx->prefix, ctx->le_mode ? "little" : "big"); ctx->base.pc_next +=3D 4; table =3D cpu->opcodes; - handler =3D table[opc1(ctx->opcode)]; + handler =3D table[opc1_idx(ctx)]; if (is_indirect_opcode(handler)) { table =3D ind_table(handler); handler =3D table[opc2(ctx->opcode)]; diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.= inc index bb66526280..0ea8c2c5c1 100644 --- a/target/ppc/translate_init.c.inc +++ b/target/ppc/translate_init.c.inc @@ -9563,8 +9563,13 @@ static int insert_in_table(opc_handler_t **table, un= signed char idx, } =20 static int register_direct_insn(opc_handler_t **ppc_opcodes, - unsigned char idx, opc_handler_t *handler) + unsigned char idx, opc_handler_t *handler, + bool prefixed, bool modified) { + if (prefixed) { + idx =3D modified ? idx + PPC_CPU_PREFIXED_MODIFIED_OPCODE_OFFSET + : idx + PPC_CPU_PREFIXED_OPCODE_OFFSET; + } if (insert_in_table(ppc_opcodes, idx, handler) < 0) { printf("*** ERROR: opcode %02x already assigned in main " "opcode table\n", idx); @@ -9688,7 +9693,8 @@ static int register_insn(opc_handler_t **ppc_opcodes,= opcode_t *insn) } } } else { - if (register_direct_insn(ppc_opcodes, insn->opc1, &insn->handler) = < 0) { + if (register_direct_insn(ppc_opcodes, insn->opc1, &insn->handler, + insn->prefixed, insn->modified) < 0) { return -1; } } @@ -9766,6 +9772,7 @@ static void dump_ppc_insns(CPUPPCState *env) for (opc1 =3D 0x00; opc1 < PPC_CPU_OPCODES_LEN; opc1++) { table =3D env->opcodes; handler =3D table[opc1]; + /* TODO: need to update opcode dump to account for prefixed space = */ if (is_indirect_opcode(handler)) { /* opc2 is 5 bits long */ for (opc2 =3D 0; opc2 < PPC_CPU_INDIRECT_OPCODES_LEN; opc2++) { --=20 2.17.1 From nobody Sun Feb 8 10:34:38 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1608110145; cv=none; d=zohomail.com; s=zohoarc; b=ORY8C6On90ro2OgDJjJNY6BGxnu+6V6mUEYtF+gzndpjjA2bAJLKlOBGYaa9N+OddcSMR5aubwZIvhE1Pz2dF+DszyiKadCIKaPPdLa11SZ49qYuQetlZNjR2Ih5ILKkcXEysDiXBFxWn8aTQ2edMbbyed30l3pnBwPSwGrIrLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608110145; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=jJ94XpvYxTeTpvrDI/SHSRje2SCi79KqVQGCQF520DI=; b=fZVJd3T/pLP/pMFsMCKVqaH1gvoVPyJddT1OU/fkfrjuZ6WHmzFYkpy0wVre2TMv02qrea9NfGhLSkkF+hrTPvHjMDVjX1RAZ1IxIQl/Chw+DYrWCKu5xzvX2KvQd+C4A2PGmPw0YXOPVNxYcO56ZihjhRPgmRixjA069WA5eH8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608110145819211.55516088470654; Wed, 16 Dec 2020 01:15:45 -0800 (PST) Received: from localhost ([::1]:53036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpSuO-0000RC-B1 for importer@patchew.org; Wed, 16 Dec 2020 04:15:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSq0-000519-TX; Wed, 16 Dec 2020 04:11:14 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45378 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSpr-0007J9-UK; Wed, 16 Dec 2020 04:11:12 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0BG92FUu069408; Wed, 16 Dec 2020 04:10:51 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 35fdveamr3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:10:50 -0500 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0BG94P9u079717; Wed, 16 Dec 2020 04:10:50 -0500 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0b-001b2d01.pphosted.com with ESMTP id 35fdveamqp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:10:50 -0500 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0BG96qjH019004; Wed, 16 Dec 2020 09:10:49 GMT Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by ppma02dal.us.ibm.com with ESMTP id 35d5260904-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 09:10:49 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0BG9Am2A19464538 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Dec 2020 09:10:48 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 788D97805C; Wed, 16 Dec 2020 09:10:48 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2B967805E; Wed, 16 Dec 2020 09:10:41 +0000 (GMT) Received: from pub.ltc.br.ibm.com (unknown [9.85.141.22]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 16 Dec 2020 09:10:41 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=jJ94XpvYxTeTpvrDI/SHSRje2SCi79KqVQGCQF520DI=; b=EbOh0dROSXzvgE0IPGXstw5W6/YDI8t9mci6kJxSw50PmJGTFuFwC8V55fb7qmplYxn6 nlmkMEpFjpOH71kTzgJQ899qiLH1KgUnUKLCF/DmhGOuzzpMtU60coXzLBcoYRGGQPp0 qKGPTkXmRUqZjwHB7cnqPq9FjPlLv0Rr6BuZZ0BZya5bb+BBhi/ZeoIHibbWJDlCb7KV SN5LRcldPMYgThGAlIdmP4cWG/apN6FrApN1f06VYjmRw7zBT0z2HEneHrDDGWB0UkVE 22SiP3rMJ1w4PNj0nZa7Olw1JNiKuF3IlMeM9lcicCKbV0iMzS9Ot/4E30YMZR23v//S EQ== From: Gustavo Romero To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 2/7] target/ppc: Add support for prefixed load/store instructions Date: Wed, 16 Dec 2020 06:07:59 -0300 Message-Id: <20201216090804.58640-3-gromero@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216090804.58640-1-gromero@linux.ibm.com> References: <20201216090804.58640-1-gromero@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-16_02:2020-12-15, 2020-12-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 mlxscore=0 mlxlogscore=989 clxscore=1015 spamscore=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 bulkscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012160055 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=gromero@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, gromero@linux.ibm.com, gustavo.romero@protonmail.com, Michael Roth , mroth@lamentation.net, clg@kaod.org, david@gibson.dropbear.id.au, alex.bennee@linaro.org, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth This commit adds support for the following prefixed load and store instructions for GPRs: plbz, plh{a,z}, plw{a,z}, pld, plq pstb, psth, pstw, pstd, pstq paddi Signed-off-by: Michael Roth [ gromero: - fix for gen_addr_imm34_index() - fix build when target !=3D TARGET_PPC64 - removed redundant PREFIX_R bit helper - changes in commit log ] Signed-off-by: Gustavo Romero --- target/ppc/internal.h | 6 + target/ppc/translate.c | 264 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 270 insertions(+) diff --git a/target/ppc/internal.h b/target/ppc/internal.h index d03d691a44..f67bd30730 100644 --- a/target/ppc/internal.h +++ b/target/ppc/internal.h @@ -159,6 +159,12 @@ EXTRACT_HELPER(PREFIX_TYPE, 24, 2); EXTRACT_HELPER(PREFIX_ST1, 23, 1); /* 4-bit sub-type */ EXTRACT_HELPER(PREFIX_ST4, 20, 4); +/* 18 bits signed immediate value */ +EXTRACT_SHELPER(SIMM18, 0, 18); +/* 18 bits unsigned immediate value */ +EXTRACT_HELPER(UIMM18, 0, 18); +/* R bit controls if CIA should be added when computing the EA */ +EXTRACT_HELPER(R, 20, 1); =20 #ifndef CONFIG_USER_ONLY EXTRACT_HELPER(SR, 16, 4); diff --git a/target/ppc/translate.c b/target/ppc/translate.c index eab6561094..0bca3a02e4 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -2495,6 +2495,37 @@ static inline void gen_addr_add(DisasContext *ctx, T= CGv ret, TCGv arg1, } } =20 +/* returns true if exception was generated */ +static inline int gen_addr_imm34_index(DisasContext *ctx, TCGv EA) +{ + uint64_t offset; + + /* ISA says that if R=3D1 then RA must be 0, otherwise the form is inv= alid */ + if (R(ctx->prefix) =3D=3D 1) { + if (unlikely(rA(ctx->opcode) !=3D 0)) { + gen_exception(ctx, POWERPC_EXCP_INVAL_INVAL); + return true; + } + /* + * To find out the address of a prefixed instruction + * it's necessary to rewind 8 bytes because they are + * twice the size of non-prefixed instructions. + */ + tcg_gen_movi_tl(EA, ctx->base.pc_next - 8); + } else { + gen_addr_register(ctx, EA); + } + + offset =3D (uint64_t)UIMM18(ctx->prefix) << 16; + offset |=3D UIMM(ctx->opcode); + /* sign-extend 34 bit offset to 64-bits... */ + if (extract64(offset, 33, 1) =3D=3D 1) { + offset |=3D -1UL << 34; + } + tcg_gen_addi_tl(EA, EA, offset); + return false; +} + static inline void gen_align_no_le(DisasContext *ctx) { gen_exception_err(ctx, POWERPC_EXCP_ALIGN, @@ -2714,6 +2745,35 @@ static void gen_ld(DisasContext *ctx) tcg_temp_free(EA); } =20 +static void gen_pld(DisasContext *ctx) +{ + TCGv EA; + + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_ld64_i64(ctx, cpu_gpr[rD(ctx->opcode)], EA); +out: + tcg_temp_free(EA); +} + +/* paddi */ +static void gen_paddi(DisasContext *ctx) +{ + TCGv EA; + + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_ld64_i64(ctx, cpu_gpr[rD(ctx->opcode)], EA); + +out: + tcg_temp_free(EA); +} + /* lq */ static void gen_lq(DisasContext *ctx) { @@ -2776,6 +2836,195 @@ static void gen_lq(DisasContext *ctx) } tcg_temp_free(EA); } + +static void gen_plq(DisasContext *ctx) +{ + int ra, rd; + TCGv EA, rd0, rd1; + + ra =3D rA(ctx->opcode); + rd =3D rD(ctx->opcode); + if (unlikely((rd & 1) || rd =3D=3D ra)) { + gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); + return; + } + + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + + rd0 =3D cpu_gpr[rd]; + rd1 =3D cpu_gpr[rd + 1]; + + if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { + /* Restart with exclusive lock. */ + gen_helper_exit_atomic(cpu_env); + ctx->base.is_jmp =3D DISAS_NORETURN; + } else { + tcg_gen_qemu_ld_i64(rd0, EA, ctx->mem_idx, + ctx->le_mode ? MO_LEQ : MO_BEQ); + gen_addr_add(ctx, EA, EA, 8); + tcg_gen_qemu_ld_i64(rd1, EA, ctx->mem_idx, + ctx->le_mode ? MO_LEQ : MO_BEQ); + } +out: + tcg_temp_free(EA); +} + +static void gen_plbz(DisasContext *ctx) +{ + TCGv EA; + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_ld8u(ctx, cpu_gpr[rD(ctx->opcode)], EA); +out: + tcg_temp_free(EA); +} + +static void gen_plhz(DisasContext *ctx) +{ + TCGv EA; + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], EA); +out: + tcg_temp_free(EA); +} + +static void gen_plha(DisasContext *ctx) +{ + TCGv EA; + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], EA); +out: + tcg_temp_free(EA); +} + +static void gen_plwz(DisasContext *ctx) +{ + TCGv EA; + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], EA); +out: + tcg_temp_free(EA); +} + +static void gen_plwa(DisasContext *ctx) +{ + TCGv EA; + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA); +out: + tcg_temp_free(EA); +} + +static void gen_pstb(DisasContext *ctx) +{ + TCGv EA; + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_st8(ctx, cpu_gpr[rS(ctx->opcode)], EA); +out: + tcg_temp_free(EA); +} + +static void gen_psth(DisasContext *ctx) +{ + TCGv EA; + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], EA); +out: + tcg_temp_free(EA); +} + +static void gen_pstw(DisasContext *ctx) +{ + TCGv EA; + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], EA); +out: + tcg_temp_free(EA); +} + +static void gen_pstd(DisasContext *ctx) { + TCGv EA; + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + gen_qemu_st64_i64(ctx, cpu_gpr[rS(ctx->opcode)], EA); +out: + tcg_temp_free(EA); +} + +static void gen_pstq(DisasContext *ctx) { + int ra, rs; + TCGv EA, rs0, rs1; + + ra =3D rA(ctx->opcode); + rs =3D rD(ctx->opcode); + if (unlikely((rs & 1) || rs =3D=3D ra)) { + gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); + return; + } + + gen_set_access_type(ctx, ACCESS_INT); + EA =3D tcg_temp_new(); + if (gen_addr_imm34_index(ctx, EA)) { + goto out; + } + + rs0 =3D cpu_gpr[rs]; + rs1 =3D cpu_gpr[rs + 1]; + + if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { + /* Restart with exclusive lock. */ + gen_helper_exit_atomic(cpu_env); + ctx->base.is_jmp =3D DISAS_NORETURN; + } else { + tcg_gen_qemu_st_i64(rs0, EA, ctx->mem_idx, + ctx->le_mode ? MO_LEQ : MO_BEQ); + gen_addr_add(ctx, EA, EA, 8); + tcg_gen_qemu_st_i64(rs1, EA, ctx->mem_idx, + ctx->le_mode ? MO_LEQ : MO_BEQ); + } +out: + tcg_temp_free(EA); +} + + #endif =20 /*** Integer store = ***/ @@ -7067,6 +7316,9 @@ GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC= _NONE, PPC2_ISA205), GEN_HANDLER_E(cmprb, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE, PPC2_ISA300), GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL), GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), +#if defined(TARGET_PPC64) +GEN_HANDLER_E_PREFIXED_M(paddi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC= 2_ISA310), +#endif GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), @@ -7128,6 +7380,18 @@ GEN_HANDLER2_E(extswsli1, "extswsli", 0x1F, 0x1B, 0x= 1B, 0x00000000, GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B), GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX), GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B), +GEN_HANDLER_E_PREFIXED_M(plbz, 0x22, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2= _ISA310), +GEN_HANDLER_E_PREFIXED_M(plhz, 0x28, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2= _ISA310), +GEN_HANDLER_E_PREFIXED_M(plha, 0x2a, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2= _ISA310), +GEN_HANDLER_E_PREFIXED_M(plwz, 0x20, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2= _ISA310), +GEN_HANDLER_E_PREFIXED(plwa, 0x29, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2_I= SA310), +GEN_HANDLER_E_PREFIXED(pld, 0x39, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2_IS= A310), +GEN_HANDLER_E_PREFIXED(plq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2_IS= A310), +GEN_HANDLER_E_PREFIXED_M(pstb, 0x26, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2= _ISA310), +GEN_HANDLER_E_PREFIXED_M(psth, 0x2c, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2= _ISA310), +GEN_HANDLER_E_PREFIXED_M(pstw, 0x24, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2= _ISA310), +GEN_HANDLER_E_PREFIXED(pstd, 0x3d, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2_I= SA310), +GEN_HANDLER_E_PREFIXED(pstq, 0x3c, 0xFF, 0xFF, 0x00000000, PPC_64B, PPC2_I= SA310), #endif /* handles lfdp, lxsd, lxssp */ GEN_HANDLER_E(dform39, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA205= ), --=20 2.17.1 From nobody Sun Feb 8 10:34:38 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1608110143; cv=none; d=zohomail.com; s=zohoarc; b=eTpWYQeEWy0PIE7CB2JpO4/xq56kTXN+Qb7N2EMRyanvfPIp5Af00t4rvUgadK/0jPbxrSyt8+MkWQHyfPu8MlfIoidPK7lIgVIaKEnpEKe38sCGrX0DQoXtLnMhnXC97OnskLb2eqEtz+0V/bAj3dmrTwwXa+eih5ABC7agIus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608110143; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=w2m/yIIcGqQfTts/iNsLwFx+e0jO2r4JyyuHgTvWSGI=; b=D16LYmTHCJZoXC791LcWDHAtnjClgcmp5xkSONwxVi9Jfmo0iP1cVUYKWjGBKYsntJnN7E7fE597IS2HJUgJfd4c7yIDMqyzn/Pz5ynz/QCXjdbCqS4LAee/nfOjY/VRwsH3+fb191S4KEESpzZvRvkja3FqHTnY/SSFtOyfD+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608110142927398.59632147423247; Wed, 16 Dec 2020 01:15:42 -0800 (PST) Received: from localhost ([::1]:52744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpSuK-0000IU-9O for importer@patchew.org; Wed, 16 Dec 2020 04:15:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSq2-00051C-7T; Wed, 16 Dec 2020 04:11:14 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:11896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSpx-0007JU-KT; Wed, 16 Dec 2020 04:11:13 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0BG92d18139041; Wed, 16 Dec 2020 04:11:01 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 35feshs31v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:11:01 -0500 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0BG93qGN142946; Wed, 16 Dec 2020 04:11:00 -0500 Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com with ESMTP id 35feshs31c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:11:00 -0500 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0BG96qn5019061; Wed, 16 Dec 2020 09:10:59 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma02dal.us.ibm.com with ESMTP id 35d5260919-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 09:10:59 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0BG9AwSa15860212 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Dec 2020 09:10:58 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 090CB7805C; Wed, 16 Dec 2020 09:10:58 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8284978060; Wed, 16 Dec 2020 09:10:49 +0000 (GMT) Received: from pub.ltc.br.ibm.com (unknown [9.85.141.22]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 16 Dec 2020 09:10:48 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=w2m/yIIcGqQfTts/iNsLwFx+e0jO2r4JyyuHgTvWSGI=; b=GrCnW3K6DVtS3hru3g57CjHWqAHGMro0lbapy3zeg1R0B9yDr+qjewXgXFuY91Fyhm7D /NJ/N2/sL7aiex4xC7fzkfBotJJc4eIIb3VpQH3Un0782e5GpLTt7EQhlOeiW0LNGUad X3RSImkdoxZ95dqogrRBCzU8fm9hMHtW/mPbR/yflTgEHjjFzkG0sOTZOlh3yV4R6kKG iNSrpEXoSFuyhLn3MxdjIOIcfRJsM/rDQPMHppVgvkevArFo9bYlCU4q1QlwSufra1NC Bvon9iAjVFM4UkabpLYwlAt6EKjNq01UyXqdKQHuT2ie9zMFkFbeOuj6bFalldSZhExh 9g== From: Gustavo Romero To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 3/7] tests/tcg: Add tests for prefixed load/store instructions Date: Wed, 16 Dec 2020 06:08:00 -0300 Message-Id: <20201216090804.58640-4-gromero@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216090804.58640-1-gromero@linux.ibm.com> References: <20201216090804.58640-1-gromero@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-16_02:2020-12-15, 2020-12-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 mlxscore=0 bulkscore=0 phishscore=0 malwarescore=0 adultscore=0 impostorscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012160055 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=gromero@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, gromero@linux.ibm.com, gustavo.romero@protonmail.com, Michael Roth , mroth@lamentation.net, clg@kaod.org, david@gibson.dropbear.id.au, alex.bennee@linaro.org, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth This commit adds various tests to exercise the implementation of prefixed load/store instructions on POWER10. Signed-off-by: Michael Roth [ gromero - fix to avoid alignment interrupt, don't cross 64-byte boundary - fix displacement for pl{bz,hz,ha,wz,wa,d} to skip branch insn. - tweaks in debug output - commit log ] Signed-off-by: Gustavo Romero --- tests/tcg/ppc64 | 1 + tests/tcg/ppc64le/Makefile.target | 16 + .../test-prefixed-load-store.c | 945 ++++++++++++++++++ 3 files changed, 962 insertions(+) create mode 120000 tests/tcg/ppc64 create mode 100644 tests/tcg/ppc64le/Makefile.target create mode 100644 tests/tcg/ppc64le/instruction-tests/test-prefixed-load-= store.c diff --git a/tests/tcg/ppc64 b/tests/tcg/ppc64 new file mode 120000 index 0000000000..e25d62b735 --- /dev/null +++ b/tests/tcg/ppc64 @@ -0,0 +1 @@ +ppc64le/ \ No newline at end of file diff --git a/tests/tcg/ppc64le/Makefile.target b/tests/tcg/ppc64le/Makefile= .target new file mode 100644 index 0000000000..aabc046eb5 --- /dev/null +++ b/tests/tcg/ppc64le/Makefile.target @@ -0,0 +1,16 @@ +# -*- Mode: makefile -*- +# +# PPC - included from tests/tcg/Makefile +# + +EXTRA_RUNS+=3Drun-test-mmap + +VPATH +=3D $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/instruction-tests +QEMU_OPTS +=3D -cpu power10 + +PPC_TESTS =3D test-prefixed-load-store + +TESTS +=3D $(PPC_TESTS) + +test-prefixed-load-store: test-prefixed-load-store.c + gcc $< -o test-prefixed-load-store diff --git a/tests/tcg/ppc64le/instruction-tests/test-prefixed-load-store.c= b/tests/tcg/ppc64le/instruction-tests/test-prefixed-load-store.c new file mode 100644 index 0000000000..f5948ada85 --- /dev/null +++ b/tests/tcg/ppc64le/instruction-tests/test-prefixed-load-store.c @@ -0,0 +1,945 @@ +#include +#include +#include +#include +#include +#include +#include + +bool debug =3D false; + +#define dprintf(...) \ + do { \ + if (debug =3D=3D true) { \ + fprintf(stderr, "%s: ", __func__); \ + fprintf(stderr, __VA_ARGS__); \ + } \ + } while (0); + +bool le; + +#define PSTB(_RS, _RA, _d0, _d1, _R) \ + ".align 6;" \ + ".long 1 << 26 | 2 << 24 | (" #_R ") << 20 | (" #_d0 ");" \ + ".long 38 << 26 | (" #_RS ") << 21 | (" #_RA ") << 16 | (" #_d1 ");" +#define PSTH(_RS, _RA, _d0, _d1, _R) \ + ".align 6;" \ + ".long 1 << 26 | 2 << 24 | (" #_R ") << 20 | (" #_d0 ");" \ + ".long 44 << 26 | (" #_RS ") << 21 | (" #_RA ") << 16 | (" #_d1 ");" +#define PSTW(_RS, _RA, _d0, _d1, _R) \ + ".align 6;" \ + ".long 1 << 26 | 2 << 24 | (" #_R ") << 20 | (" #_d0 ");" \ + ".long 36 << 26 | (" #_RS ") << 21 | (" #_RA ") << 16 | (" #_d1 ");" +#define PSTD(_RS, _RA, _d0, _d1, _R) \ + ".align 6;" \ + ".long 1 << 26 | (" #_R ") << 20 | (" #_d0 ");" \ + ".long 61 << 26 | (" #_RS ") << 21 | (" #_RA ") << 16 | (" #_d1 ");" + +#define PST_CALL(op, src, dest_ptr, offset_upper18, offset_lower16, r) \ + do { \ + asm( \ + op(%1, %0, offset_upper18, offset_lower16, r) \ + : "+r" (dest_ptr) \ + : "r" (src)); \ + } while (0); + +void check_pst(uint64_t src, uint64_t dest, uint64_t dest_orig, int width)= { + uint64_t dest_orig_mask; + uint64_t src_mask =3D (width =3D=3D 8) ? -1UL : (1UL << (8*width)) - 1; + + if (le) { + dest_orig_mask =3D -1UL << (8*width); + assert(dest =3D=3D ((dest_orig & dest_orig_mask) | ((src & src_mas= k)))); + } else { + dest_orig_mask =3D (-1UL << (8*width)) >> (8*width); + assert(dest =3D=3D ((dest_orig & dest_orig_mask) | ((src & src_mas= k) << (8*(8-width))))); + } +} + +void test_pst_offset(int width) { + uint64_t dest_orig =3D 0x2726252423222120; + uint64_t src =3D 0x1716151413111110; + uint64_t dest =3D dest_orig; + void *dest_ptr, *dest_ptr_offset; + + dest_ptr =3D &dest; + + switch (width) { + case 1: + dest_ptr_offset =3D dest_ptr - 1; + PST_CALL(PSTB, src, dest_ptr_offset, 0, 1, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr - 0xFFFF; + PST_CALL(PSTB, src, dest_ptr_offset, 0, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr + 1; + PST_CALL(PSTB, src, dest_ptr_offset, 0x3FFFF, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr - 0x1FFFFFFFF; + PST_CALL(PSTB, src, dest_ptr_offset, 0x1FFFF, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + break; + case 2: + dest_ptr_offset =3D dest_ptr - 1; + PST_CALL(PSTH, src, dest_ptr_offset, 0, 1, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr - 0xFFFF; + PST_CALL(PSTH, src, dest_ptr_offset, 0, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr + 1; + PST_CALL(PSTH, src, dest_ptr_offset, 0x3FFFF, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr - 0x1FFFFFFFF; + PST_CALL(PSTH, src, dest_ptr_offset, 0x1FFFF, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + break; + case 4: + dest_ptr_offset =3D dest_ptr - 1; + PST_CALL(PSTW, src, dest_ptr_offset, 0, 1, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr - 0xFFFF; + PST_CALL(PSTW, src, dest_ptr_offset, 0, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr + 1; + PST_CALL(PSTW, src, dest_ptr_offset, 0x3FFFF, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr - 0x1FFFFFFFF; + PST_CALL(PSTW, src, dest_ptr_offset, 0x1FFFF, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + break; + case 8: + dest_ptr_offset =3D dest_ptr - 1; + PST_CALL(PSTD, src, dest_ptr_offset, 0, 1, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr - 0xFFFF; + PST_CALL(PSTD, src, dest_ptr_offset, 0, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr + 1; + PST_CALL(PSTD, src, dest_ptr_offset, 0x3FFFF, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + dest_ptr_offset =3D dest_ptr - 0x1FFFFFFFF; + PST_CALL(PSTD, src, dest_ptr_offset, 0x1FFFF, 0xFFFF, 0); + check_pst(src, dest, dest_orig, width); + break; + default: + assert(false); + } +} + +void test_pst(int width) { + uint64_t dest_orig =3D 0x2726252423222120; + uint64_t src =3D 0x1716151413111110; + uint64_t dest, dest_copy; + void *dest_ptr =3D &dest; + void *dest_copy_ptr =3D &dest_copy; + + /* sanity check against non-prefixed ops */ + dest_copy =3D dest_orig; + switch (width) { + case 1: + asm( + "stb %1, 0(%0)" + : "+r" (dest_copy_ptr) + : "r" (src)); + break; + case 2: + asm( + "sth %1, 0(%0)" + : "+r" (dest_copy_ptr) + : "r" (src)); + break; + case 4: + asm( + "stw %1, 0(%0)" + : "+r" (dest_copy_ptr) + : "r" (src)); + break; + case 8: + asm( + "std %1, 0(%0)" + : "+r" (dest_copy_ptr) + : "r" (src)); + break; + default: + assert(false); + } + + dest =3D dest_orig; + switch (width) { + case 1: + PST_CALL(PSTB, src, dest_ptr, 0, 0, 0); + break; + case 2: + PST_CALL(PSTH, src, dest_ptr, 0, 0, 0); + break; + case 4: + PST_CALL(PSTW, src, dest_ptr, 0, 0, 0); + break; + case 8: + PST_CALL(PSTD, src, dest_ptr, 0, 0, 0); + break; + default: + assert(false); + } + + assert(dest =3D=3D dest_copy); + check_pst(src, dest, dest_orig, width); +} + +void test_pstb(void) { + test_pst(1); + test_pst_offset(1); +} + +void test_psth(void) { + test_pst(2); + test_pst_offset(2); +} + +void test_pstw(void) { + test_pst(4); + test_pst_offset(4); +} + +void test_pstd(void) { + test_pst(8); + test_pst_offset(8); +} + +#define PLBZ(_RT, _RA, _d0, _d1, _R) \ + ".align 6;" \ + ".long 1<<26 | 2<<24 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 34<<26 | (" #_RT ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" +#define PLHZ(_RT, _RA, _d0, _d1, _R) \ + ".align 6;" \ + ".long 1<<26 | 2<<24 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 40<<26 | (" #_RT ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" +#define PLHA(_RT, _RA, _d0, _d1, _R) \ + ".align 6;" \ + ".long 1<<26 | 2<<24 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 42<<26 | (" #_RT ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" +#define PLWZ(_RT, _RA, _d0, _d1, _R) \ + ".align 6;" \ + ".long 1<<26 | 2<<24 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 32<<26 | (" #_RT ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" +#define PLWA(_RT, _RA, _d0, _d1, _R) \ + ".align 6;" \ + ".long 1<<26 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 41<<26 | (" #_RT ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" +#define PLD(_RT, _RA, _d0, _d1, _R) \ + ".align 6;" \ + ".long 1<<26 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 57<<26 | (" #_RT ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" + +#define PL_CALL(op, src, src_ptr, dest, offset_upper18, offset_lower16, r)= \ + do { = \ + asm( = \ + op(%0, %2, offset_upper18, offset_lower16, r) = \ + : "+r" (dest) = \ + : "r" (src), "r" (src_ptr)); = \ + } while (0); + +void check_pl_z(uint64_t src, uint64_t dest, int width) { + uint64_t src_mask; + + if (le) { + src_mask =3D (width =3D=3D 8) ? -1UL : (1UL << (8*width)) - 1; + assert(dest =3D=3D (src & src_mask)); + } else { + src_mask =3D (width =3D=3D 8) ? -1UL : -1UL << (8*(8-width)); + assert(dest =3D=3D (src & src_mask) >> (8*(8-width))); + } +} + +void check_pl_a(uint64_t src, uint64_t dest, int width) { + uint64_t src_mask, sign_mask; + + /* TODO: docs suggest testing high-order bit of src byte/halfword/etc,= but + * QEMU seems to use high-order bit of src double in every case? + * + * but for le, it's based on the former? afa qemu goes??? + */ + if (le) { + sign_mask =3D (src & (1UL << (width*8-1))) ? -1UL << (8*width) : 0; + } else { + sign_mask =3D (src & (1UL << 63)) ? -1UL << (8*width) : 0; + } + + if (le) { + src_mask =3D (width =3D=3D 8) ? -1UL : (1UL << (8*width)) - 1; + assert(dest =3D=3D ((src & src_mask) | sign_mask)); + } else { + src_mask =3D (width =3D=3D 8) ? -1UL : -1UL << (8*(8-width)); + assert(dest =3D=3D (((src & src_mask) >> (8*(8-width))) | sign_mas= k)); + } +} + +void test_pl_a(int width, uint64_t src, uint64_t dest_orig) { + uint64_t dest =3D 0, dest_copy; + void *src_ptr =3D &src; + void *src_ptr_offset; + + /* sanity check against non-prefixed ops */ + dest_copy =3D dest_orig; + + switch (width) { + case 2: + asm( + "lha %0, 0(%2)" + : "+r" (dest_copy) + : "r" (src), "r" (src_ptr)); + break; + case 4: + asm( + "lwa %0, 0(%2)" + : "+r" (dest_copy) + : "r" (src), "r" (src_ptr)); + break; + case 8: + asm( + "ld %0, 0(%2)" + : "+r" (dest_copy) + : "r" (src), "r" (src_ptr)); + break; + default: + assert(false); + } + + switch (width) { + case 2: + dest =3D dest_orig; + src_ptr_offset =3D src_ptr; + PL_CALL(PLHA, src, src_ptr_offset, dest, 0, 0, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 1; + PL_CALL(PLHA, src, src_ptr_offset, dest, 0, 1, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0xFFFF; + PL_CALL(PLHA, src, src_ptr_offset, dest, 0, 0xFFFF, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr + 1; + PL_CALL(PLHA, src, src_ptr_offset, dest, 0x3FFFF, 0xFFFF, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0x1FFFFFFFF; + PL_CALL(PLHA, src, src_ptr_offset, dest, 0x1FFFF, 0xFFFF, 0); + check_pl_a(src, dest, width); + break; + case 4: + dest =3D dest_orig; + src_ptr_offset =3D src_ptr; + PL_CALL(PLWA, src, src_ptr_offset, dest, 0, 0, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 1; + PL_CALL(PLWA, src, src_ptr_offset, dest, 0, 1, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0xFFFF; + PL_CALL(PLWA, src, src_ptr_offset, dest, 0, 0xFFFF, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr + 1; + PL_CALL(PLWA, src, src_ptr_offset, dest, 0x3FFFF, 0xFFFF, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0x1FFFFFFFF; + PL_CALL(PLWA, src, src_ptr_offset, dest, 0x1FFFF, 0xFFFF, 0); + check_pl_a(src, dest, width); + break; + case 8: + dest =3D dest_orig; + src_ptr_offset =3D src_ptr; + PL_CALL(PLD, src, src_ptr_offset, dest, 0, 0, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 1; + PL_CALL(PLD, src, src_ptr_offset, dest, 0, 1, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0xFFFF; + PL_CALL(PLD, src, src_ptr_offset, dest, 0, 0xFFFF, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr + 1; + PL_CALL(PLD, src, src_ptr_offset, dest, 0x3FFFF, 0xFFFF, 0); + check_pl_a(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0x1FFFFFFFF; + PL_CALL(PLD, src, src_ptr_offset, dest, 0x1FFFF, 0xFFFF, 0); + check_pl_a(src, dest, width); + break; + default: + assert(false); + } + + assert(dest =3D=3D dest_copy); +} + +void test_pl_z(int width, uint64_t src, uint64_t dest_orig) { + uint64_t dest =3D 0, dest_copy; + void *src_ptr =3D &src; + void *src_ptr_offset; + + /* sanity check against non-prefixed ops */ + dest_copy =3D dest_orig; + + switch (width) { + case 1: + asm( + "lbz %0, 0(%2)" + : "+r" (dest_copy) + : "r" (src), "r" (src_ptr)); + break; + case 2: + asm( + "lhz %0, 0(%2)" + : "+r" (dest_copy) + : "r" (src), "r" (src_ptr)); + break; + case 4: + asm( + "lwz %0, 0(%2)" + : "+r" (dest_copy) + : "r" (src), "r" (src_ptr)); + break; + case 8: + asm( + "ld %0, 0(%2)" + : "+r" (dest_copy) + : "r" (src), "r" (src_ptr)); + break; + default: + assert(false); + } + + dest =3D dest_orig; + switch (width) { + case 1: + dest =3D dest_orig; + src_ptr_offset =3D src_ptr; + PL_CALL(PLBZ, src, src_ptr_offset, dest, 0, 0, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 1; + PL_CALL(PLBZ, src, src_ptr_offset, dest, 0, 1, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0xFFFF; + PL_CALL(PLBZ, src, src_ptr_offset, dest, 0, 0xFFFF, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr + 1; + PL_CALL(PLBZ, src, src_ptr_offset, dest, 0x3FFFF, 0xFFFF, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0x1FFFFFFFF; + PL_CALL(PLBZ, src, src_ptr_offset, dest, 0x1FFFF, 0xFFFF, 0); + check_pl_z(src, dest, width); + break; + case 2: + dest =3D dest_orig; + src_ptr_offset =3D src_ptr; + PL_CALL(PLHZ, src, src_ptr_offset, dest, 0, 0, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 1; + PL_CALL(PLHZ, src, src_ptr_offset, dest, 0, 1, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0xFFFF; + PL_CALL(PLHZ, src, src_ptr_offset, dest, 0, 0xFFFF, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr + 1; + PL_CALL(PLHZ, src, src_ptr_offset, dest, 0x3FFFF, 0xFFFF, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0x1FFFFFFFF; + PL_CALL(PLHZ, src, src_ptr_offset, dest, 0x1FFFF, 0xFFFF, 0); + check_pl_z(src, dest, width); + break; + case 4: + dest =3D dest_orig; + src_ptr_offset =3D src_ptr; + PL_CALL(PLWZ, src, src_ptr_offset, dest, 0, 0, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 1; + PL_CALL(PLWZ, src, src_ptr_offset, dest, 0, 1, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0xFFFF; + PL_CALL(PLWZ, src, src_ptr_offset, dest, 0, 0xFFFF, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr + 1; + PL_CALL(PLWZ, src, src_ptr_offset, dest, 0x3FFFF, 0xFFFF, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0x1FFFFFFFF; + PL_CALL(PLWZ, src, src_ptr_offset, dest, 0x1FFFF, 0xFFFF, 0); + check_pl_z(src, dest, width); + break; + case 8: + dest =3D dest_orig; + src_ptr_offset =3D src_ptr; + PL_CALL(PLD, src, src_ptr_offset, dest, 0, 0, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 1; + PL_CALL(PLD, src, src_ptr_offset, dest, 0, 1, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0xFFFF; + PL_CALL(PLD, src, src_ptr_offset, dest, 0, 0xFFFF, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr + 1; + PL_CALL(PLD, src, src_ptr_offset, dest, 0x3FFFF, 0xFFFF, 0); + check_pl_z(src, dest, width); + dest =3D dest_orig; + src_ptr_offset =3D src_ptr - 0x1FFFFFFFF; + PL_CALL(PLD, src, src_ptr_offset, dest, 0x1FFFF, 0xFFFF, 0); + check_pl_z(src, dest, width); + break; + default: + assert(false); + } + + assert(dest =3D=3D dest_copy); +} + +void test_plbz(void) { + test_pl_z(1, 0x8716151413111110, 0x0726252423222120); + test_pl_z(1, 0x1716151413111110, 0x0726252423222120); + test_pl_z(1, 0x1716151413111180, 0x0726252423222120); +} + +void test_plhz(void) { + test_pl_z(2, 0x8716151483111110, 0x0726252423222120); + test_pl_z(1, 0x1716151413111110, 0x0726252423222120); + test_pl_z(1, 0x1716151413118110, 0x0726252423222120); +} + +void test_plha(void) { + test_pl_a(2, 0x8716151483111110, 0x0726252423222120); + test_pl_a(2, 0x1716151413111110, 0x0726252423222120); + test_pl_a(2, 0x1716151413118110, 0x0726252423222120); +} + +void test_plwz(void) { + test_pl_z(4, 0x8716151483111110, 0x0726252423222120); + test_pl_z(4, 0x1716151413111110, 0x0726252423222120); + test_pl_z(4, 0x1716151483111110, 0x0726252423222120); +} + +void test_plwa(void) { + test_pl_a(4, 0x8716151483111110, 0x0726252423222120); + test_pl_a(4, 0x1716151413111110, 0x0726252423222120); + test_pl_a(4, 0x1716151483111110, 0x0726252423222120); +} + +void test_pld(void) { + test_pl_a(8, 0x8716151483111110, 0x0726252423222120); + test_pl_a(8, 0x1716151413111110, 0x0726252423222120); +} + +#define QUADWORD_HI 0x0f0e0d0c0b0a0908 +#define QUADWORD_LO 0x0706050403020100 + +#define PSTQ(_RS, _RA, _d0, _d1, _R) \ + ".long 1<<26 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 60<<26 | (" #_RS ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" + +void test_pstq(void) { + register uint64_t rs0 asm("r22"); + register uint64_t rs1 asm("r23"); + uint64_t storage[2] =3D { 0 }; + void *src_ptr =3D storage; + + if (le) { + /* + * MEM(EA, 16) <- RSp+1||RSp + * where RQ[15..0] =3D RSp+1||RSp =3D rs1[7..0] || rs0[7..0] + */ + rs0 =3D QUADWORD_LO; + rs1 =3D QUADWORD_HI; + } else { + /* + * MEM(EA, 16) <- RSp||RSp+1 + * where RQ[0..15] =3D RSp||RSp+1 =3D rs0[0..7] || rs1[0..7] + */ + rs0 =3D QUADWORD_HI; + rs1 =3D QUADWORD_LO; + } + + asm( + PSTQ(22, %0, 0, 0, 0) + : "+r" (src_ptr) + : "r" (rs0), "r" (rs1)); + + if (le) { + assert(storage[0] =3D=3D QUADWORD_LO); + assert(storage[1] =3D=3D QUADWORD_HI); + } else { + assert(storage[0] =3D=3D QUADWORD_HI); + assert(storage[1] =3D=3D QUADWORD_LO); + } + + /* sanity check against stq */ + asm( + "stq 22, 0(%0)" + : "+r" (src_ptr) + : "r" (rs0), "r" (rs1)); + + if (le) { + assert(storage[0] =3D=3D QUADWORD_HI); + assert(storage[1] =3D=3D QUADWORD_LO); + } else { + assert(storage[0] =3D=3D QUADWORD_HI); + assert(storage[1] =3D=3D QUADWORD_LO); + } +} + +#define PLQ(_RT, _RA, _d0, _d1, _R) \ + ".long 1<<26 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 56<<26 | (" #_RT ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" + +void test_plq(void) { + register uint64_t rdest0 asm("r20") =3D 7; + register uint64_t rdest1 asm("r21") =3D 8; + uint64_t dest0a =3D 7; + uint64_t dest0b =3D 7; + uint64_t dest1a =3D 7; + uint64_t dest1b =3D 7; + uint8_t src[16]; + void *src_ptr =3D &src; + int i; + + for (i =3D 0; i < 16; i++) { + src[i] =3D i; + } + + /* + * PLQ: + * + * loads to RTp+1||RTp for little-endian + * RTp||RTp+1 for big-endian + * + * so we'd expect: + * + * value: 0x0f0e..08 || 0706..00 + * + * little-endian: + * + * uint64_t storage[2] =3D { 0x0706050403020100, + * 0x0f0e0d0c0b0a0908 }; + * plq 20,0(storage): + * r21[0..7] || r20[0..7] + * 0x0001020304050607 0x08090a0b0c0d0e0f + * + * big-endian: + * + * uint64_t storage[2] =3D { 0x0f0e0d0c0b0a0908, + * 0x0706050403020100 }; + * + * plq 20,0(storage): + * r20[0..7] || r21[0..7] + * 0x0f0e0d0c0b0a0908 0x0706050403020100 + * + * Note: According to spec, for GPRs at least, GPR byte ordering is al= ways + * big-endian with regard to loads/stores. Hence the need to "reverse = load" + * in the case of loading little-endian value into a register, as oppo= sed to + * simply assuming both the storage and the register would both use + * host-endian. + * + * But, this is just as far as the documentation goes, which is always + * left-to-right/big-endian byte ordering. The actual hardware register + * stores byte 0 in a little-endian to value to byte 0 in the register= , so + * registers are loaded host-endian even though the documentation sort= of + * suggests otherwise in some cases. + */ + asm( + PLQ(20, %2, 0, 0, 0) + : "=3Dr" (rdest0), "=3Dr" (rdest1) + : "r" (src_ptr)); + + dest0a =3D rdest0; + dest1a =3D rdest1; + + /* loads to dest0||dest1 for both endians */ + asm( + "lq 20, 0(%2)" + : "=3Dr" (rdest0), "=3Dr" (rdest1) + : "r" (src_ptr)); + + dest0b =3D rdest0; + dest1b =3D rdest1; + + if (le) { + assert(dest0a =3D=3D ((uint64_t*)src)[0]); + assert(dest1a =3D=3D ((uint64_t*)src)[1]); + assert(dest0a =3D=3D dest1b); + assert(dest1a =3D=3D dest0b); + } else { + assert(dest0a =3D=3D ((uint64_t*)src)[0]); + assert(dest1a =3D=3D ((uint64_t*)src)[1]); + assert(dest0a =3D=3D dest0b); + assert(dest1a =3D=3D dest1b); + } + + /* TODO: PC-relative and negative offsets just like all the others */ +} + +void test_plq2(void) { + register uint64_t rdest0 asm("r20") =3D 7; + register uint64_t rdest1 asm("r21") =3D 8; + register uint64_t rdest0b asm("r22") =3D 7; + register uint64_t rdest1b asm("r23") =3D 8; + uint64_t storage[2]; + void *src_ptr =3D storage; + + if (le) { + storage[0] =3D QUADWORD_LO; + storage[1] =3D QUADWORD_HI; + } else { + storage[0] =3D QUADWORD_HI; + storage[1] =3D QUADWORD_LO; + } + + /* + * PLQ: + * + * loads to RTp+1||RTp for little-endian + * RTp||RTp+1 for big-endian + * + * loads into register using host-endian encoding + * calls it "reverse-order" for little-endian, but + * the byte-ordering is switched based on endianess + * so we still copy mem[0] to reg[0], etc., in all + * cases. i.e. storage endian encoding is maintained + * in the register encoding after load, even though + * documentation might still call it reverse and + * reference left-to-right byte ordering in some + * cases even for little-endian + * + * so we'd expect: + * + * value: 0x0f0e..08 || 0706..00 + * + * little-endian: + * + * uint64_t storage[2] =3D { 0x0706050403020100, + * 0x0f0e0d0c0b0a0908 }; + * plq 20,0(storage): + * RTquad[15..0] =3D r21[7..0] || r20[7..0] + * r21[7..0] || r20[7..0] + * 0x0f0e0d0c0b0a0908 0x0706050403020100 + * + * big-endian: + * + * uint64_t storage[2] =3D { 0x0f0e0d0c0b0a0908, + * 0x0706050403020100 }; + * + * plq 20,0(storage): + * RTquad[0..15] =3D r20[0..7] || r21[0..7] + * r20[0..7] || r21[0..7] + * 0x0f0e0d0c0b0a0908 0x0706050403020100 + **/ + asm( + PLQ(20, %2, 0, 0, 0) + : "=3Dr" (rdest0), "=3Dr" (rdest1) + : "r" (src_ptr)); + + if (le) { + assert(rdest0 =3D=3D QUADWORD_LO); + assert(rdest1 =3D=3D QUADWORD_HI); + } else { + assert(rdest0 =3D=3D QUADWORD_HI); + assert(rdest1 =3D=3D QUADWORD_LO); + } + + /* sanity check against lq */ + asm( + "lq 22, 0(%2)" + : "=3Dr" (rdest0b), "=3Dr" (rdest1b) + : "r" (src_ptr)); + + if (le) { + assert(rdest0 =3D=3D rdest1b); + assert(rdest1 =3D=3D rdest0b); + } else { + assert(rdest0 =3D=3D rdest0b); + assert(rdest1 =3D=3D rdest1b); + } +} + +void test_plbz_cia(void) { + uint64_t dest =3D 0; + + asm( + PLBZ(%0, 0, 0, 8 /* skip plbz */ + 4 /* skip b */, 1) + "b 1f\n" + ".byte 0x1a\n" + ".byte 0x1b\n" + ".byte 0x1c\n" + ".byte 0x1d\n" + "1: nop\n" + : "+r" (dest)); + + assert(dest =3D=3D 0x1a); +} + +void test_plhz_cia(void) { + uint64_t dest =3D 0; + + asm( + PLHZ(%0, 0, 0, 8 /* skip plhz */ + 4 /* skip b */, 1) + "b 1f\n" + ".byte 0x1a\n" + ".byte 0x1b\n" + ".byte 0x1c\n" + ".byte 0x1d\n" + "1: nop\n" + : "+r" (dest)); + + if (le) { + assert(dest =3D=3D 0x1b1a); + } else { + assert(dest =3D=3D 0x1a1b); + } +} + +void test_plha_cia(void) { + uint64_t dest =3D 0; + + asm( + PLHA(%0, 0, 0, 8 /* skip plha */ + 4 /* skip b */, 1) + "b 1f\n" + ".byte 0x8a\n" + ".byte 0x8b\n" + ".byte 0x1c\n" + ".byte 0x1d\n" + ".byte 0x2a\n" + ".byte 0x2b\n" + ".byte 0x2c\n" + ".byte 0x2d\n" + "1: nop\n" + : "+r" (dest)); + + if (le) { + assert(dest =3D=3D 0xFFFFFFFFFFFF8b8a); + } else { + assert(dest =3D=3D 0xFFFFFFFFFFFF8a8b); + } +} + +void test_plwz_cia(void) { + uint64_t dest =3D 0; + + asm( + PLWZ(%0, 0, 0, 8 /* skip plwz */ + 4 /* skip b */, 1) + "b 1f\n" + ".byte 0x1a\n" + ".byte 0x1b\n" + ".byte 0x1c\n" + ".byte 0x1d\n" + "1: nop\n" + : "+r" (dest)); + + if (le) { + assert(dest =3D=3D 0x1d1c1b1a); + } else { + assert(dest =3D=3D 0x1a1b1c1d); + } +} + +void test_plwa_cia(void) { + uint64_t dest =3D 0; + + asm( + PLWA(%0, 0, 0, 8 /* skip plwa */ + 4 /* skip b */, 1) + "b 1f\n" + ".byte 0x8a\n" + ".byte 0x1b\n" + ".byte 0x1c\n" + ".byte 0x8d\n" + ".byte 0x2a\n" + ".byte 0x2b\n" + ".byte 0x2c\n" + ".byte 0x2d\n" + "1: nop\n" + : "+r" (dest)); + + if (le) { + assert(dest =3D=3D 0xFFFFFFFF8d1c1b8a); + } else { + assert(dest =3D=3D 0xFFFFFFFF8a1b1c8d); + } +} + +void test_pld_cia(void) { + uint64_t dest =3D 0; + + asm( + PLD(%0, 0, 0, 8 /* skip pld */ + 4 /* skip b */, 1) + "b 1f\n" + ".byte 0x1a\n" + ".byte 0x1b\n" + ".byte 0x1c\n" + ".byte 0x1d\n" + ".byte 0x2a\n" + ".byte 0x2b\n" + ".byte 0x2c\n" + ".byte 0x2d\n" + "1: nop\n" + : "+r" (dest)); + + if (le) { + assert(dest =3D=3D 0x2d2c2b2a1d1c1b1a); + } else { + assert(dest =3D=3D 0x1a1b1c1d2a2b2c2d); + } +} + +#define do_test(testname) \ + if (debug) \ + fprintf(stderr, "-> running test: " #testname "\n"); \ + test_##testname(); \ + +int main(int argc, char **argv) +{ + le =3D (htole16(1) =3D=3D 1); + + if (argc > 1 && !strcmp(argv[1], "-d")) { + debug =3D true; + } + + do_test(pstb); + do_test(psth); + do_test(pstw); + do_test(pstd); + do_test(plbz); + do_test(plhz); + do_test(plha); + do_test(psth); + do_test(pld); + + do_test(pstq); + do_test(plq); + do_test(plq2); + + do_test(plbz_cia); + do_test(plhz_cia); + do_test(plha_cia); + do_test(plwz_cia); + do_test(plwa_cia); + do_test(pld_cia); + + dprintf("All tests passed\n"); + return 0; +} --=20 2.17.1 From nobody Sun Feb 8 10:34:38 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1608110294; cv=none; d=zohomail.com; s=zohoarc; b=SWiThBOJVkqRZi9PmOkpTH6ZD1f3mxBD4fltlb4SKm3WadmwhoPpQHCZzwuftrnzpOxKqHR5ozUWfNhE+9hHUa/f8fTxdtRvIP+dVXr4VxlRQATguMM+DQ/z0yOatZW6gVEWbpv7KOMQJD95KtNRde5j2SdcK1oyI0BV2N9rl1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608110294; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=CoA67O50IW9BVuVBZwocpCeADYdBCFfpfHhsgm8nkvk=; b=F8PMHGDUuXXZe6CxXDe/6fG14/9074K4bN3EPaZNg4+EY5w43IQcFKi7uFc6N+BDghnGPMTzFPR+Yxqga/hqkKlzXqM5+GHJv4EVwYcmApOtPjM0BogDIOZb1fQEIVk+GfXdZ/FOenJCWw0fZmIPFvDYi8WlEuQw8e6J1p2icn0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608110294319339.13779073652165; Wed, 16 Dec 2020 01:18:14 -0800 (PST) Received: from localhost ([::1]:32828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpSwm-0003me-LW for importer@patchew.org; Wed, 16 Dec 2020 04:18:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSqD-0005CB-D2; Wed, 16 Dec 2020 04:11:25 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:13584 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSqB-0007NY-3U; Wed, 16 Dec 2020 04:11:25 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0BG93vHR140842; Wed, 16 Dec 2020 04:11:12 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 35fe53j54g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:11:12 -0500 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0BG95Ob9148599; Wed, 16 Dec 2020 04:11:12 -0500 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0b-001b2d01.pphosted.com with ESMTP id 35fe53j541-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:11:11 -0500 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0BG8uuGZ006090; Wed, 16 Dec 2020 09:11:11 GMT Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by ppma01wdc.us.ibm.com with ESMTP id 35cng8unx2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 09:11:09 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0BG9B5di23986658 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Dec 2020 09:11:05 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9CA7778067; Wed, 16 Dec 2020 09:11:05 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0625E7805C; Wed, 16 Dec 2020 09:10:59 +0000 (GMT) Received: from pub.ltc.br.ibm.com (unknown [9.85.141.22]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 16 Dec 2020 09:10:58 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=CoA67O50IW9BVuVBZwocpCeADYdBCFfpfHhsgm8nkvk=; b=CUJLbu34Y6qFCaubiPseFekVQZlp17HItycG/R1HiXn4Ny1lHx2vfely9ia5Z+DQjvZg +pTRVdmHWhSvYOIMgpLLdtusKcGo0+YO77hiw6hQ40kRVf6MUqxVMb0I2iu7G6V6sN+j 5/hPOpLlqf7vKcI6BvhRG/Rd2gdoXiHzsQbdeMaLintSRN2H5unlK4FPcf4bJis//u28 Xt83blP+s2AOb6O5vyiViN1V2DzFglpy/XBGvL9am6Gq9kXlX/V2kI//j6cqaNwxIPa6 VMGUS3cmpDDWva3BszIAIAsLQBh7pgrU4tnVh4kRYIzDnu0NWAuMsBLIU4bcN57pflqe HA== From: Gustavo Romero To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 4/7] target/ppc: Add support for paired vector load/store instructions Date: Wed, 16 Dec 2020 06:08:01 -0300 Message-Id: <20201216090804.58640-5-gromero@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216090804.58640-1-gromero@linux.ibm.com> References: <20201216090804.58640-1-gromero@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-16_02:2020-12-15, 2020-12-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 bulkscore=0 phishscore=0 priorityscore=1501 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012160058 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.158.5; envelope-from=gromero@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, gromero@linux.ibm.com, gustavo.romero@protonmail.com, Michael Roth , mroth@lamentation.net, clg@kaod.org, david@gibson.dropbear.id.au, alex.bennee@linaro.org, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth This adds support for the following load/store instructions for paired vector registers: lxvp, plxvp, lxvpx stxvp, pstxvp, stxvpx Signed-off-by: Michael Roth [ gromero: - fix in helper_load_paired_vec(), for LE - fix in helper_store_paired_vec(), for LE - fix build when target !=3D PPC64 ] Sgined-off-by: Gustavo Romero --- target/ppc/helper.h | 3 ++ target/ppc/internal.h | 7 +++ target/ppc/mem_helper.c | 61 ++++++++++++++++++++++++++ target/ppc/translate.c | 8 ++++ target/ppc/translate/vsx-impl.c.inc | 66 +++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+) diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 6a4dccf70c..e8ecd2e878 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -279,6 +279,9 @@ DEF_HELPER_4(lxvl, void, env, tl, vsr, tl) DEF_HELPER_4(lxvll, void, env, tl, vsr, tl) DEF_HELPER_4(stxvl, void, env, tl, vsr, tl) DEF_HELPER_4(stxvll, void, env, tl, vsr, tl) +/* lxvp/stxvp, plxvp/pstxvp, lxvpx/stxvpx */ +DEF_HELPER_4(store_paired_vec, void, env, tl, vsr, vsr) +DEF_HELPER_4(load_paired_vec, void, env, tl, vsr, vsr) #endif DEF_HELPER_4(vsumsws, void, env, avr, avr, avr) DEF_HELPER_4(vsum2sws, void, env, avr, avr, avr) diff --git a/target/ppc/internal.h b/target/ppc/internal.h index f67bd30730..27a5311e3a 100644 --- a/target/ppc/internal.h +++ b/target/ppc/internal.h @@ -80,6 +80,12 @@ static inline int16_t name(uint32_t opcode) = \ (((opcode >> (shift_op_d2)) & ((1 << (d2_bits)) - 1)) << (shift_d2= )); \ } =20 +#define EXTRACT_HELPER_SPLIT_SHIFTED(name, shift1, nb1, shift2, nb2, shift= 3) \ +static inline uint32_t name(uint32_t opcode) = \ +{ = \ + return extract32(opcode, shift1, nb1) << (nb2 + shift3) | = \ + extract32(opcode, shift2, nb2) << shift3; = \ +} =20 /* Opcode part 1 */ EXTRACT_HELPER(opc1, 26, 6); @@ -226,6 +232,7 @@ EXTRACT_HELPER(SP, 19, 2); EXTRACT_HELPER(IMM8, 11, 8); EXTRACT_HELPER(DCMX, 16, 7); EXTRACT_HELPER_SPLIT_3(DCMX_XV, 5, 16, 0, 1, 2, 5, 1, 6, 6); +EXTRACT_HELPER_SPLIT_SHIFTED(xTp, 21, 1, 22, 4, 1); =20 void helper_compute_fprf_float16(CPUPPCState *env, float16 arg); void helper_compute_fprf_float32(CPUPPCState *env, float32 arg); diff --git a/target/ppc/mem_helper.c b/target/ppc/mem_helper.c index 98f589552b..8d35a19c68 100644 --- a/target/ppc/mem_helper.c +++ b/target/ppc/mem_helper.c @@ -532,6 +532,67 @@ STVE(stvewx, cpu_stl_data_ra, bswap32, u32) #undef I #undef LVE =20 +#ifdef TARGET_PPC64 +void helper_load_paired_vec(CPUPPCState *env, target_ulong addr, + ppc_vsr_t *xt0, ppc_vsr_t *xt1) +{ + ppc_vsr_t t0, t1; + int i; + + t0.s128 =3D int128_zero(); + t1.s128 =3D int128_zero(); + + if (msr_le) { + for (i =3D 0; i < 16; i++) { + t1.VsrB(15 - i) =3D cpu_ldub_data_ra(env, addr, GETPC()); + addr =3D addr_add(env, addr, 1); + } + for (i =3D 0; i < 16; i++) { + t0.VsrB(15 - i) =3D cpu_ldub_data_ra(env, addr, GETPC()); + addr =3D addr_add(env, addr, 1); + } + } else { // TODO: check if it's correct for BE. + for (i =3D 0; i < 16; i++) { + t0.VsrB(i) =3D cpu_ldub_data_ra(env, addr, GETPC()); + addr =3D addr_add(env, addr, 1); + } + for (i =3D 0; i < 16; i++) { + t1.VsrB(i) =3D cpu_ldub_data_ra(env, addr, GETPC()); + addr =3D addr_add(env, addr, 1); + } + } + + *xt0 =3D t0; + *xt1 =3D t1; +} + +void helper_store_paired_vec(CPUPPCState *env, target_ulong addr, + ppc_vsr_t *xt0, ppc_vsr_t *xt1) +{ + int i; + + if (msr_le) { + for (i =3D 0; i < 16; i++) { + cpu_stb_data_ra(env, addr, xt1->VsrB(15 - i), GETPC()); + addr =3D addr_add(env, addr, 1); + } + for (i =3D 0; i < 16; i++) { + cpu_stb_data_ra(env, addr, xt0->VsrB(15 - i), GETPC()); + addr =3D addr_add(env, addr, 1); + } + } else { // TODO: check if it's correct for BE. + for (i =3D 0; i < 16; i++) { + cpu_stb_data_ra(env, addr, xt0->VsrB(i), GETPC()); + addr =3D addr_add(env, addr, 1); + } + for (i =3D 0; i < 16; i++) { + cpu_stb_data_ra(env, addr, xt1->VsrB(i), GETPC()); + addr =3D addr_add(env, addr, 1); + } + } +} +#endif /* TARGET_PPC64 */ + #ifdef TARGET_PPC64 #define GET_NB(rb) ((rb >> 56) & 0xFF) =20 diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 0bca3a02e4..25a3c1198b 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7397,6 +7397,14 @@ GEN_HANDLER_E_PREFIXED(pstq, 0x3c, 0xFF, 0xFF, 0x000= 00000, PPC_64B, PPC2_ISA310) GEN_HANDLER_E(dform39, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA205= ), /* handles stfdp, lxv, stxsd, stxssp, stxv */ GEN_HANDLER_E(dform3D, 0x3D, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA205= ), +#if defined(TARGET_PPC64) +GEN_HANDLER_E_PREFIXED(plxvp, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC2= _ISA310), +GEN_HANDLER_E_PREFIXED(pstxvp, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC= 2_ISA310), +/* handles lxvp, stxvp */ +GEN_HANDLER_E(dqform6, 0x6, 0x0, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA310), +GEN_HANDLER_E(lxvpx, 0x1F, 0xD, 0xA, 0x00000000, PPC_NONE, PPC2_ISA310), +GEN_HANDLER_E(stxvpx, 0x1F, 0xD, 0xE, 0x00000000, PPC_NONE, PPC2_ISA310), +#endif GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING), diff --git a/target/ppc/translate/vsx-impl.c.inc b/target/ppc/translate/vsx= -impl.c.inc index b518de46db..6640b7ae05 100644 --- a/target/ppc/translate/vsx-impl.c.inc +++ b/target/ppc/translate/vsx-impl.c.inc @@ -376,6 +376,72 @@ VSX_VECTOR_LOAD_STORE_LENGTH(stxvl) VSX_VECTOR_LOAD_STORE_LENGTH(stxvll) #endif =20 +#ifdef TARGET_PPC64 + +static void gen_dqform6(DisasContext *ctx) +{ + TCGv EA; + TCGv_ptr xt0, xt1; + + EA =3D tcg_temp_new(); + xt0 =3D gen_vsr_ptr(xTp(ctx->opcode)); + xt1 =3D gen_vsr_ptr(xTp(ctx->opcode) + 1); + gen_set_access_type(ctx, ACCESS_INT); + gen_addr_imm_index(ctx, EA, 0x0F); + + if (extract32(ctx->opcode, 0, 4) =3D=3D 1) { + /* stxvp */ + gen_helper_store_paired_vec(cpu_env, EA, xt0, xt1); + } else { + /* lxvp */ + gen_helper_load_paired_vec(cpu_env, EA, xt0, xt1); + } + + tcg_temp_free(EA); + tcg_temp_free_ptr(xt0); + tcg_temp_free_ptr(xt1); +} + +#define VSX_VECTOR_LOAD_STORE_PAIRED(name, dform, op) \ +static void gen_##name(DisasContext *ctx) \ +{ \ + TCGv EA; \ + TCGv_ptr xt0, xt1; \ + \ + if (unlikely(!ctx->altivec_enabled)) { \ + gen_exception(ctx, POWERPC_EXCP_VPU); \ + return; \ + } \ + \ + EA =3D tcg_temp_new(); \ + xt0 =3D gen_vsr_ptr(xTp(ctx->opcode)); \ + xt1 =3D gen_vsr_ptr(xTp(ctx->opcode) + 1); \ + gen_set_access_type(ctx, ACCESS_INT); \ + \ + if (dform) { \ + /* pstxvp, plxvp, 8LS, D-form */ \ + if (gen_addr_imm34_index(ctx, EA)) { \ + goto out; \ + } \ + } else { \ + /* lxvpx, stxvpx, X-form */ \ + gen_addr_reg_index(ctx, EA); \ + } \ + \ + gen_helper_##op##_paired_vec(cpu_env, EA, xt0, xt1); \ +out: \ + tcg_temp_free(EA); \ + tcg_temp_free_ptr(xt0); \ + tcg_temp_free_ptr(xt1); \ +} + +VSX_VECTOR_LOAD_STORE_PAIRED(plxvp, 1, load) +VSX_VECTOR_LOAD_STORE_PAIRED(pstxvp, 1, store) +VSX_VECTOR_LOAD_STORE_PAIRED(lxvpx, 0, load) +VSX_VECTOR_LOAD_STORE_PAIRED(stxvpx, 0, store) + +#endif + #define VSX_LOAD_SCALAR_DS(name, operation) \ static void gen_##name(DisasContext *ctx) \ { \ --=20 2.17.1 From nobody Sun Feb 8 10:34:38 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1608110410; cv=none; d=zohomail.com; s=zohoarc; b=XdwSZkajONxuPQhdy7dTq2fVtv3Z1xuKe9DFOMygDKwp+Qb3xJKAFeJT1bQhFZ65jQlzuJCjClsXgCdGCB95GfiJA2p5R/Ha4GiqmhD5hQUOsR10SyChz/gQ5OyQ+0Z6cVeZsR57Me5zdBbMHrB7HF6UVJjkg+2wPkJXnBHEfZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608110410; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Hm55d5/wfI1U3mi6Feh8IE2m5ufrxX+zsZ7TMRfBoSE=; b=ZN7PxmIPcuihtHZbMOV4aaCgP3biyrzNQA+KKk9IcMrvxrXrQcEODHi58Xs0ANdhADs+jtITqnS+wwhhIc5OECex8QkN5cdagY6MVM1I8H/pv9GcLNsbimOAN13FyeFbygNJjPARWuzlUDssDv0FLq2pRxT4IzXk8iUqN3SbIic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160811041075699.54900061700505; Wed, 16 Dec 2020 01:20:10 -0800 (PST) Received: from localhost ([::1]:36954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpSyf-0005U5-LC for importer@patchew.org; Wed, 16 Dec 2020 04:20:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSqM-0005L2-ML; Wed, 16 Dec 2020 04:11:39 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:28596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSqH-0007Q3-Ms; Wed, 16 Dec 2020 04:11:33 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0BG92S3J028544; Wed, 16 Dec 2020 04:11:17 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 35fdvg2pmk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:11:16 -0500 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0BG967id046797; Wed, 16 Dec 2020 04:11:16 -0500 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 35fdvg2pkx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:11:16 -0500 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0BG97McI011648; Wed, 16 Dec 2020 09:11:14 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma04dal.us.ibm.com with ESMTP id 35cng9e0ct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 09:11:14 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0BG9BDPo5898502 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Dec 2020 09:11:13 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 550C378067; Wed, 16 Dec 2020 09:11:13 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BBDB078066; Wed, 16 Dec 2020 09:11:06 +0000 (GMT) Received: from pub.ltc.br.ibm.com (unknown [9.85.141.22]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 16 Dec 2020 09:11:06 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=Hm55d5/wfI1U3mi6Feh8IE2m5ufrxX+zsZ7TMRfBoSE=; b=SJI2g4UhmpHnuvOzbwmjiBRfuERKvUc5PauFNGS8NXxo1h3MYVTiylJwkbQ0kkm4KUTr p8ebKVTeC8D6sLufrNhC2m86A7Q8vSKxV9XMT6nQdc9wsyWgomLkHAD9OYfBUfqN55Mc TbrlYc1KS/z6Vzc7tEQb6Wox794kuLiicVSmjAawqIFwGhlW1mPiZ5lGepUeJLKKChbh R7oJcH9husv/rPQ1bfUbdcO6z1irhMP/pusJwDBLooCfPKMkwzbhQPp0JfpsFCT8W+XY X7pwXFWiU8jF4B4xKdOkQQmrrU8262qeqQmuP+VPOlEAtfEkah+29QZ2Yy9r5Ui1IP+f AQ== From: Gustavo Romero To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 5/7] tests/tcg: Add tests for paired vector load/store instructions Date: Wed, 16 Dec 2020 06:08:02 -0300 Message-Id: <20201216090804.58640-6-gromero@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216090804.58640-1-gromero@linux.ibm.com> References: <20201216090804.58640-1-gromero@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-16_02:2020-12-15, 2020-12-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012160055 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=gromero@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, gromero@linux.ibm.com, gustavo.romero@protonmail.com, Michael Roth , mroth@lamentation.net, clg@kaod.org, david@gibson.dropbear.id.au, alex.bennee@linaro.org, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth Signed-off-by: Michael Roth [ gromero: - aligned prefixed insns., avoiding cross 64-byte boundary - fix to skip branch insn. just after PLXVP - fix various buffer offsets used in comparisons, for LE only - tweaks in debug output ] Signed-off-by: Gustavo Romero --- tests/tcg/ppc64le/Makefile.target | 9 + .../test-paired-load-store-vsx.c | 567 ++++++++++++++++++ 2 files changed, 576 insertions(+) create mode 100644 tests/tcg/ppc64le/instruction-tests/test-paired-load-st= ore-vsx.c diff --git a/tests/tcg/ppc64le/Makefile.target b/tests/tcg/ppc64le/Makefile= .target index aabc046eb5..aaa43a83a7 100644 --- a/tests/tcg/ppc64le/Makefile.target +++ b/tests/tcg/ppc64le/Makefile.target @@ -11,6 +11,15 @@ QEMU_OPTS +=3D -cpu power10 PPC_TESTS =3D test-prefixed-load-store =20 TESTS +=3D $(PPC_TESTS) +PPC_VSX_TESTS =3D test-paired-load-store-vsx + +VSX_CFLAGS =3D -maltivec -mvsx +$(PPC_VSX_TESTS): CFLAGS+=3D$(VSX_CFLAGS) + +PPC_TESTS +=3D $(PPC_VSX_TESTS) =20 test-prefixed-load-store: test-prefixed-load-store.c gcc $< -o test-prefixed-load-store + +test-paired-load-store-vsx: test-paired-load-store-vsx.c + gcc $< -o test-paired-load-store-vsx diff --git a/tests/tcg/ppc64le/instruction-tests/test-paired-load-store-vsx= .c b/tests/tcg/ppc64le/instruction-tests/test-paired-load-store-vsx.c new file mode 100644 index 0000000000..61c25d9f41 --- /dev/null +++ b/tests/tcg/ppc64le/instruction-tests/test-paired-load-store-vsx.c @@ -0,0 +1,567 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +bool debug =3D false; + +#define dprintf(...) \ + do { \ + if (debug =3D=3D true) { \ + fprintf(stderr, "%s: ", __func__); \ + fprintf(stderr, __VA_ARGS__); \ + } \ + } while (0); + +bool le; + +#define PLXVP(_Tp, _RA, _d0, _d1, _R, _TX) \ + ".align 6;" \ + ".long 1 << 26 | (" #_R ") << 20 | (" #_d0 ");" \ + ".long 58 << 26 | (" #_Tp ") << 22 | (" #_TX ") << 21 | (" #_RA ") << = 16 | (" #_d1 ");" + +void test_plxvp_cia(void) { + register vector unsigned char v0 asm("vs8") =3D { 0 }; + register vector unsigned char v1 asm("vs9") =3D { 0 }; + int i; + + /* load defined bytes below into vs8,vs9 using CIA with relative offse= t */ + asm( + PLXVP(4, 0, 0, 8 /* skip plxvp */ + 4 /* skip b */, 1, 0) + "b 1f;" + ".byte 0;" + ".byte 1;" + ".byte 2;" + ".byte 3;" + ".byte 4;" + ".byte 5;" + ".byte 6;" + ".byte 7;" + ".byte 8;" + ".byte 9;" + ".byte 10;" + ".byte 11;" + ".byte 12;" + ".byte 13;" + ".byte 14;" + ".byte 15;" + ".byte 16;" + ".byte 17;" + ".byte 18;" + ".byte 19;" + ".byte 20;" + ".byte 21;" + ".byte 22;" + ".byte 23;" + ".byte 24;" + ".byte 25;" + ".byte 26;" + ".byte 27;" + ".byte 28;" + ".byte 29;" + ".byte 30;" + ".byte 31;" + "1: nop;" + : "+wa" (v0), "+wa" (v1)); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D 16 + i); + else + assert(v0[i] =3D=3D (31 - i)); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D i); + else + assert(v1[i] =3D=3D 15 - i); // FIXME + } +} + +void test_plxvp(void) { + register vector unsigned char v0 asm("vs6") =3D { 0 }; + register vector unsigned char v1 asm("vs7") =3D { 0 }; + uint8_t buf[64] __attribute__((aligned(16))); + uint8_t *buf_ptr =3D (uint8_t *)&buf; + int i; + + for (i =3D 0; i < 64; i++) { + buf[i] =3D i; + } + + /* load buf[0:31] into vs6,vs7 using EA with no offset */ + asm(PLXVP(3, %2, 0, 0, 0, 0) + : "+wa" (v0), "+wa" (v1) + : "r" (buf_ptr)); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[16 + i]); + else + assert(v0[i] =3D=3D buf[i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[i]); + else + assert(v1[i] =3D=3D buf[16 + i]); // FIXME + } + + /* load buf[32:63] into vs6,vs7 using EA with d1 offset */ + buf_ptr =3D buf_ptr + 32 - 0x1000; + asm(PLXVP(3, %2, 0, 0x1000, 0, 0) + : "+wa" (v0), "+wa" (v1) + : "r" (buf_ptr)); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[32 + 16 + i]); + else + assert(v0[i] =3D=3D buf[32 + i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[32 + i]); + else + assert(v1[i] =3D=3D buf[48 + i]); // FIXME + } + + /* load buf[0:31] into vs6,vs7 using EA with d0||d1 offset */ + buf_ptr =3D buf; + buf_ptr =3D buf_ptr - ((0x1000 << 16) | 0x1000); + asm(PLXVP(3, %2, 0x1000, 0x1000, 0, 0) + : "+wa" (v0), "+wa" (v1) + : "r" (buf_ptr)); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[16 + i]); + else + assert(v0[i] =3D=3D buf[i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[i]); + else + assert(v1[i] =3D=3D buf[16 + i]); // FIXME + } + + /* TODO: test signed offset */ + /* TODO: PC-relative addresses */ + /* load buf[32:63] into vs6,vs7 using EA with negative d0||d1 offset */ + buf_ptr =3D buf; + buf_ptr =3D buf_ptr + 32 + 0x1000; + asm(PLXVP(3, %2, 0x3ffff, 0xf000, 0, 0) + : "+wa" (v0), "+wa" (v1) + : "r" (buf_ptr)); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[32 + 16 + i]); + else + assert(v0[i] =3D=3D buf[32 + i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[32 + i]); + else + assert(v1[i] =3D=3D buf[48 + i]); // FIXME + } +} + +#define PSTXVP(_Sp, _RA, _d0, _d1, _R, _SX) \ + ".align 6;" \ + ".long 1 << 26 | (" #_R ") << 20 | (" #_d0 ");" \ + ".long 62 << 26 | (" #_Sp ") << 22 | (" #_SX ") << 21 | (" #_RA ") << = 16 | (" #_d1 ");" + +void test_pstxvp(void) { + register vector unsigned char v0 asm("vs6") =3D { +// FIXME: reorder values for readability + 0, 1, 2, 3, + 4, 5, 6, 7, + 8, 9, 10, 11, + 12, 13, 14, 15 + }; + register vector unsigned char v1 asm("vs7") =3D { +// FIXME: reorder values for readability + 16, 17, 18, 19, + 20, 21, 22, 23, + 24, 25, 26, 27, + 28, 29, 30, 31 + }; + uint8_t buf[64] __attribute__((aligned(16))); + uint8_t *buf_ptr =3D (uint8_t *)&buf; + int i; + + for (i =3D 0; i < 64; i++) { + buf[i] =3D 0; + } + + /* store vs6,vs7 into buf[0:31] using EA with no offset */ + asm(PSTXVP(3, %0, 0, 0, 0, 0) + : "+r" (buf_ptr) + : "wa" (v0), "wa" (v1)); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[16 + i]); + else + assert(v0[i] =3D=3D buf[i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[i]); + else + assert(v1[i] =3D=3D buf[16 + i]); // FIXME + } + + /* store vs6,vs7 into buf[32:63] using EA with d1 offset */ + buf_ptr =3D buf_ptr + 32 - 0x1000; + asm(PSTXVP(3, %0, 0, 0x1000, 0, 0) + : "+r" (buf_ptr) + : "wa" (v0), "wa" (v1)); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[32 + 16 + i]); + else + assert(v0[i] =3D=3D buf[32 + i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[32 + i]); + else + assert(v1[i] =3D=3D buf[48 + i]); // FIXME + } + + /* store buf[0:31] into vs6,vs7 using EA with d0||d1 offset */ + buf_ptr =3D buf; + buf_ptr =3D buf_ptr - ((0x1000 << 16) | 0x1000); + asm(PSTXVP(3, %0, 0x1000, 0x1000, 0, 0) + : "+r" (buf_ptr) + : "wa" (v0), "wa" (v1)); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[16 + i]); + else + assert(v0[i] =3D=3D buf[i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[i]); + else + assert(v1[i] =3D=3D buf[16 + i]); // FIXME + } + + /* TODO: test signed offset */ + /* TODO: PC-relative addresses */ +} + +/* TODO: we force 2 instead of 1 in opc2 currently to hack around + * QEMU impl, need a single handler to deal with the 1 in bit 31 + */ +#define STXVP(_Sp, _RA, _DQ, _SX) \ + ".align 6;" \ + ".long 6 << 26 | (" #_Sp ") << 22 | (" #_SX ") << 21 | (" #_RA ") << 1= 6 | (" #_DQ ") << 4 | 1;" + +void test_stxvp(void) { + register vector unsigned char v0 asm("vs4") =3D { + 0, 1, 2, 3, + 4, 5, 6, 7, + 8, 9, 10, 11, + 12, 13, 14, 15 + }; + register vector unsigned char v1 asm("vs5") =3D { + 16, 17, 18, 19, + 20, 21, 22, 23, + 24, 25, 26, 27, + 28, 29, 30, 31 + }; + uint8_t buf[64] __attribute__((aligned(16))); + uint8_t *buf_ptr =3D (uint8_t *)&buf; + int i; + + for (i =3D 0; i < 64; i++) { + buf[i] =3D 7; + } + + /* store v0,v1 into buf[0:31] using EA with no offset */ + asm(STXVP(2, %0, 0, 0) + : "+r" (buf_ptr) + : "wa" (v0), "wa" (v1) + ); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(buf[i] =3D=3D v1[i]); + else + assert(buf[i] =3D=3D v0[i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(buf[16 + i] =3D=3D v0[i]); + else + assert(buf[16 + i] =3D=3D v1[i]); // FIXME + } + + /* store v0,v1 into buf[32:63] using EA with offset 0x40 */ + buf_ptr =3D buf_ptr + 32 - 0x40; + asm(STXVP(2, %0, 4, 0) + : "+r" (buf_ptr) + : "wa" (v0), "wa" (v1) + ); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(buf[32 + i] =3D=3D v1[i]); + else + assert(buf[32 + i] =3D=3D v0[i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(buf[32 + 16 + i] =3D=3D v0[i]); + else + assert(buf[48 + i] =3D=3D v1[i]); // FIXME + } + + /* TODO: test signed offset */ + /* TODO: PC-relative addresses */ +} + +#define LXVP(_Tp, _RA, _DQ, _TX) \ + ".long 6 << 26 | (" #_Tp ") << 22 | (" #_TX ") << 21 | (" #_RA ") << 1= 6 | (" #_DQ ") << 4;" + +void test_lxvp(void) { + register vector unsigned char v0 asm("vs4") =3D { 0 }; + register vector unsigned char v1 asm("vs5") =3D { 0 }; + uint8_t buf[64] __attribute__((aligned(16))); + uint8_t *buf_ptr =3D (uint8_t *)&buf; + int i; + + for (i =3D 0; i < 64; i++) { + buf[i] =3D i; + } + + /* load buf[0:31] into v0,v1 using EA with no offset */ + asm(LXVP(2, %2, 0, 0) + : "=3Dwa" (v0), "=3Dwa" (v1) + : "r" (buf_ptr) + ); + + for (i =3D 0; i < 16; i++) { + if (le) { + assert(v0[i] =3D=3D buf[16 + i]); + + } else + assert(v0[i] =3D=3D buf[i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[i]); + else + assert(v1[i] =3D=3D buf[16+i]); // FIXME + } + + /* load buf[32:63] into v0,v1 using EA with 0x40 offset */ + buf_ptr =3D buf_ptr + 32 - 0x40; + asm(LXVP(2, %2, 4, 0) + : "=3Dwa" (v0), "=3Dwa" (v1) + : "r" (buf_ptr) + ); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[32+16+i]); + else + assert(v0[i] =3D=3D buf[32+i]); // FIXME + + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[32+i]); + else + assert(v1[i] =3D=3D buf[48+i]); // FIXME + } + + /* TODO: signed offsets */ + /* TODO: PC-relative addresses */ +} + +#define LXVPX(_Tp, _RA, _RB, _TX) \ + ".long 31 << 26 | (" #_Tp ") << 22 | (" #_TX ") << 21 | (" #_RA ") << = 16 | (" #_RB ") << 11 | 333 << 1;" + +void test_lxvpx(void) { + register vector unsigned char v0 asm("vs8") =3D { 0 }; + register vector unsigned char v1 asm("vs9") =3D { 0 }; + uint8_t buf[64] __attribute__((aligned(16))); + uint8_t *buf_ptr =3D (uint8_t *)&buf; + uint32_t offset; + int i; + + for (i =3D 0; i < 64; i++) { + buf[i] =3D i; + } + + /* load buf[0:31] into v0,v1 using EA with no offset */ + offset =3D 0; + asm(LXVPX(4, %2, %3, 0) + : "=3Dwa" (v0), "=3Dwa" (v1) + : "r" (buf_ptr), "r" (offset) + ); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[16 + i]); + else + assert(v0[i] =3D=3D buf[i]); // FIXME + + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[i]); + else + assert(v1[i] =3D=3D buf[16+i]); // FIXME + } + + /* load buf[32:63] into v0,v1 using EA with 0x40 offset */ + offset =3D 0x40; + buf_ptr =3D buf_ptr + 32 - offset; + asm(LXVPX(4, %2, %3, 0) + : "=3Dwa" (v0), "=3Dwa" (v1) + : "r" (buf_ptr), "r" (offset) + ); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[32 + 16 + i]); + else + assert(v0[i] =3D=3D buf[32+i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[32 + i]); + else + assert(v1[i] =3D=3D buf[48+i]); // FIXME + } + + /* TODO: signed offsets */ + /* TODO: PC-relative addresses */ +} + +#define STXVPX(_Sp, _RA, _RB, _SX) \ + ".long 31 << 26 | (" #_Sp ") << 22 | (" #_SX ") << 21 | (" #_RA ") << = 16 | (" #_RB ") << 11 | 461 << 1;" + +void test_stxvpx(void) { + register vector unsigned char v0 asm("vs10") =3D { +// FIXME: reorder for readability + 0, 1, 2, 3, + 4, 5, 6, 7, + 8, 9, 10, 11, + 12, 13, 14, 15 + }; + register vector unsigned char v1 asm("vs11") =3D { +// FIXME: ditto + 16, 17, 18, 19, + 20, 21, 22, 23, + 24, 25, 26, 27, + 28, 29, 30, 31 + }; + uint8_t buf[64] __attribute__((aligned(16))); + uint8_t *buf_ptr =3D (uint8_t *)&buf; + uint32_t offset; + int i; + + for (i =3D 0; i < 64; i++) { + buf[i] =3D 7; + } + + /* store v0,v1 into buf[0:31] using EA with no offset */ + offset =3D 0; + asm(STXVPX(5, %0, %1, 0) + : "+r" (buf_ptr) + : "r" (offset), "wa" (v0), "wa" (v1) + ); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(buf[i] =3D=3D v1[i]); + else + assert(buf[i] =3D=3D v0[i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[16 + i]); + else + assert(buf[16 + i] =3D=3D v1[i]); // FIXME + } + + /* store v0,v1 into buf[32:63] using EA with offset 0x40 */ + offset =3D 0x40; + buf_ptr =3D buf_ptr + 32 - offset; + asm(STXVPX(5, %0, %1, 0) + : "+r" (buf_ptr) + : "r" (offset), "wa" (v0), "wa" (v1) + ); + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v0[i] =3D=3D buf[32 + 16 + i]); + else + assert(buf[48 + i] =3D=3D v1[i]); // FIXME + } + + for (i =3D 0; i < 16; i++) { + if (le) + assert(v1[i] =3D=3D buf[32 + i]); + else + assert(buf[32 + i] =3D=3D v0[i]); // FIXME + } + + /* TODO: test signed offset */ + /* TODO: PC-relative addresses */ +} + +#define do_test(testname) \ + if (debug) \ + fprintf(stderr, "-> running test: " #testname "\n"); \ + test_##testname(); \ + +int main(int argc, char **argv) +{ + le =3D (htole16(1) =3D=3D 1); + + if (argc > 1 && !strcmp(argv[1], "-d")) { + debug =3D true; + } + + do_test(lxvp); + do_test(stxvp); + do_test(plxvp); + do_test(plxvp_cia); + do_test(pstxvp); + do_test(lxvpx); + do_test(stxvpx); + + dprintf("All tests passed\n"); + return 0; +} --=20 2.17.1 From nobody Sun Feb 8 10:34:38 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1608110523; cv=none; d=zohomail.com; s=zohoarc; b=LnnQuiAoss587NlrmUzGb6Z6Nm9NYOnV9CMyOG1oZ7jm6PkKRIUW0AK5C+ZhccktNIZtcHCJ7YWfWqwoqv+/holwWX0Zp4RJqKFeYN9gks3TDIjQx+8b7mjN3VOtGu8f+XF6e/hMIlVXjwL8BwJo/8s2IkH6lUj3CHqMwrsk+y8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608110523; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=oj9eaO3I877bdEB502k3p/9XtE2KcXY8aiPkw3cYas4=; b=KypCinJ9mC6MKwV19opurWta8FJWNgVXW6wA4QPN/YxWuEZmUOXb89BSQ6z+0OwFrrqi/4k2sBGVCC/uuMrNJw0EwY6qhWjpiIJXl+38FszGQK0FWeZG2i3ha0ifKeJwNVct3mSU0pKuUmXqw+RnBEw+FwBnOYLj7Z6bykviQ3I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608110523369972.8113232388514; Wed, 16 Dec 2020 01:22:03 -0800 (PST) Received: from localhost ([::1]:39126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpT0U-0006Tc-AD for importer@patchew.org; Wed, 16 Dec 2020 04:22:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSqU-0005MK-0v; Wed, 16 Dec 2020 04:11:43 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:59456) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSqJ-0007QH-C5; Wed, 16 Dec 2020 04:11:41 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0BG92SAf028557; Wed, 16 Dec 2020 04:11:23 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 35fdvg2pre-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:11:23 -0500 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0BG92hkc029411; Wed, 16 Dec 2020 04:11:22 -0500 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 35fdvg2pqm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:11:22 -0500 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0BG96pSE026017; Wed, 16 Dec 2020 09:11:22 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma03dal.us.ibm.com with ESMTP id 35cng9p2e9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 09:11:21 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0BG9BK8m23396622 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Dec 2020 09:11:20 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9B1737805F; Wed, 16 Dec 2020 09:11:20 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 54F4B7805C; Wed, 16 Dec 2020 09:11:14 +0000 (GMT) Received: from pub.ltc.br.ibm.com (unknown [9.85.141.22]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 16 Dec 2020 09:11:13 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=oj9eaO3I877bdEB502k3p/9XtE2KcXY8aiPkw3cYas4=; b=I/LfIjyzFlqFvFlSh42/BIyFUckIl3Nty8NvBR8/V+C9muhPd6YwF+bMuC6yyOl84Aat sL4K6kq5AVm710tGDvM5cRZHrc8qfWAMxLUNQBgMT421RW1XUCrLzxcftU+G1dH+Of3d gPpyPvtJcGRvjc54Kt0USzuFhJrnHobDZ7PPE3rvWC1HxyUxVsDYnW+8tHpQk4IsuynQ bJVyfuGRsqFt1IukpXDP1i2JdYGU32dLwULCWXRVdDArRMZ+X6nEvMzoCQ4atWXJkwpW jvyi//q0C3ax5f8UW0yOy96O4FrKGaauoJWlemziZloUA46KLVCtNEfVOAzZMKQRzoMq /w== From: Gustavo Romero To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 6/7] target/ppc: Add support for prefixed load/store FP instructions Date: Wed, 16 Dec 2020 06:08:03 -0300 Message-Id: <20201216090804.58640-7-gromero@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216090804.58640-1-gromero@linux.ibm.com> References: <20201216090804.58640-1-gromero@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-16_02:2020-12-15, 2020-12-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012160055 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=gromero@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, gromero@linux.ibm.com, gustavo.romero@protonmail.com, Michael Roth , mroth@lamentation.net, clg@kaod.org, david@gibson.dropbear.id.au, alex.bennee@linaro.org, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth This commit adds support for the following load/store instructions for FP registers: plf, plfd pstfs, pstfd Signed-off-by: Michael Roth Signed-off-by: Gustavo Romero --- target/ppc/translate/fp-impl.c.inc | 48 ++++++++++++++++++++++++++++++ target/ppc/translate/fp-ops.c.inc | 6 ++++ 2 files changed, 54 insertions(+) diff --git a/target/ppc/translate/fp-impl.c.inc b/target/ppc/translate/fp-i= mpl.c.inc index 9f7868ee28..1eec98de0f 100644 --- a/target/ppc/translate/fp-impl.c.inc +++ b/target/ppc/translate/fp-impl.c.inc @@ -874,6 +874,28 @@ static void glue(gen_, name)(DisasContext *ctx) = \ tcg_temp_free_i64(t0); = \ } =20 +#define GEN_PLDF(name, ldop, opc, type) = \ +static void glue(gen_, p##name)(DisasContext *ctx) = \ +{ = \ + TCGv EA; = \ + TCGv_i64 t0; = \ + if (unlikely(!ctx->fpu_enabled)) { = \ + gen_exception(ctx, POWERPC_EXCP_FPU); = \ + return; = \ + } = \ + gen_set_access_type(ctx, ACCESS_FLOAT); = \ + EA =3D tcg_temp_new(); = \ + t0 =3D tcg_temp_new_i64(); = \ + if (gen_addr_imm34_index(ctx, EA)) { = \ + goto out; = \ + } = \ + gen_qemu_##ldop(ctx, t0, EA); = \ + set_fpr(rD(ctx->opcode), t0); = \ +out: = \ + tcg_temp_free(EA); = \ + tcg_temp_free_i64(t0); = \ +} + #define GEN_LDUF(name, ldop, opc, type) = \ static void glue(gen_, name##u)(DisasContext *ctx) = \ { = \ @@ -943,6 +965,7 @@ static void glue(gen_, name##x)(DisasContext *ctx) = \ =20 #define GEN_LDFS(name, ldop, op, type) = \ GEN_LDF(name, ldop, op | 0x20, type); = \ +GEN_PLDF(name, ldop, op | 0x20, type); = \ GEN_LDUF(name, ldop, op | 0x21, type); = \ GEN_LDUXF(name, ldop, op | 0x01, type); = \ GEN_LDXF(name, ldop, 0x17, op | 0x00, type) @@ -1109,6 +1132,28 @@ static void glue(gen_, name)(DisasContext *ctx) = \ tcg_temp_free_i64(t0); = \ } =20 +#define GEN_PSTF(name, stop, opc, type) = \ +static void glue(gen_, p##name)(DisasContext *ctx) = \ +{ = \ + TCGv EA; = \ + TCGv_i64 t0; = \ + if (unlikely(!ctx->fpu_enabled)) { = \ + gen_exception(ctx, POWERPC_EXCP_FPU); = \ + return; = \ + } = \ + gen_set_access_type(ctx, ACCESS_FLOAT); = \ + EA =3D tcg_temp_new(); = \ + t0 =3D tcg_temp_new_i64(); = \ + if (gen_addr_imm34_index(ctx, EA)) { = \ + goto out; = \ + } = \ + get_fpr(t0, rS(ctx->opcode)); = \ + gen_qemu_##stop(ctx, t0, EA); = \ +out: = \ + tcg_temp_free(EA); = \ + tcg_temp_free_i64(t0); = \ +} + #define GEN_STUF(name, stop, opc, type) = \ static void glue(gen_, name##u)(DisasContext *ctx) = \ { = \ @@ -1178,6 +1223,7 @@ static void glue(gen_, name##x)(DisasContext *ctx) = \ =20 #define GEN_STFS(name, stop, op, type) = \ GEN_STF(name, stop, op | 0x20, type); = \ +GEN_PSTF(name, stop, op | 0x20, type); = \ GEN_STUF(name, stop, op | 0x21, type); = \ GEN_STUXF(name, stop, op | 0x01, type); = \ GEN_STXF(name, stop, 0x17, op | 0x00, type) @@ -1483,12 +1529,14 @@ static void gen_stfqx(DisasContext *ctx) #undef GEN_FLOAT_BS =20 #undef GEN_LDF +#undef GEN_PLDF #undef GEN_LDUF #undef GEN_LDUXF #undef GEN_LDXF #undef GEN_LDFS =20 #undef GEN_STF +#undef GEN_PSTF #undef GEN_STUF #undef GEN_STUXF #undef GEN_STXF diff --git a/target/ppc/translate/fp-ops.c.inc b/target/ppc/translate/fp-op= s.c.inc index 88fab65628..fed0db8f65 100644 --- a/target/ppc/translate/fp-ops.c.inc +++ b/target/ppc/translate/fp-ops.c.inc @@ -52,6 +52,8 @@ GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT), =20 #define GEN_LDF(name, ldop, opc, type) = \ GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), +#define GEN_PLDF(name, ldop, opc, type) = \ +GEN_HANDLER_E_PREFIXED_M(p##name, opc, 0xFF, 0xFF, 0x0, PPC_64B, PPC2_ISA3= 10), #define GEN_LDUF(name, ldop, opc, type) = \ GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), #define GEN_LDUXF(name, ldop, opc, type) = \ @@ -60,6 +62,7 @@ GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), #define GEN_LDFS(name, ldop, op, type) = \ GEN_LDF(name, ldop, op | 0x20, type) = \ +GEN_PLDF(name, ldop, op | 0x20, type) = \ GEN_LDUF(name, ldop, op | 0x21, type) = \ GEN_LDUXF(name, ldop, op | 0x01, type) = \ GEN_LDXF(name, ldop, 0x17, op | 0x00, type) @@ -73,6 +76,8 @@ GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NO= NE, PPC2_ISA205), =20 #define GEN_STF(name, stop, opc, type) = \ GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), +#define GEN_PSTF(name, ldop, opc, type) = \ +GEN_HANDLER_E_PREFIXED_M(p##name, opc, 0xFF, 0xFF, 0x0, PPC_64B, PPC2_ISA3= 10), #define GEN_STUF(name, stop, opc, type) = \ GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), #define GEN_STUXF(name, stop, opc, type) = \ @@ -81,6 +86,7 @@ GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), #define GEN_STFS(name, stop, op, type) = \ GEN_STF(name, stop, op | 0x20, type) = \ +GEN_PSTF(name, stop, op | 0x20, type) = \ GEN_STUF(name, stop, op | 0x21, type) = \ GEN_STUXF(name, stop, op | 0x01, type) = \ GEN_STXF(name, stop, 0x17, op | 0x00, type) --=20 2.17.1 From nobody Sun Feb 8 10:34:38 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1608110221; cv=none; d=zohomail.com; s=zohoarc; b=mqT1siQVa/oEdqFFmvqqeGHJwonyEIu/+dMdkFOXu8aEc1uQTKTw+4jgHuYhHDBrhzEWNSVu5RjvWlGq9c/kAeHVOXH+H+eGZg07Mefau4QxYhjL5Jgzxb7jPi2ATaxYY6X9KGCzTjoDxk87mNmu8gxseX5kBZ09/mFAqhYR50w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608110221; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=uDGgCz42jUY4Fg7+euXEuO4bnMXILPjKnV5gzZ/IKmU=; b=m0otn0CImsRqgu/8aHk3DE/jPFYMmoETg9yFcipnqfmN3ozIL27qW6bFUoNBvmt6UzgGmAoZlz23mE9Xah3yeSBUjNzt4lQs3BQBOAIwypakEwe0M/MGpJGaOyeyB5yQQu6HzkHsMEvr6km7Ylv0J32ERmAKeRj8cxkwpkaZ4w4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608110221646685.7505203419965; Wed, 16 Dec 2020 01:17:01 -0800 (PST) Received: from localhost ([::1]:56064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpSvc-0001mN-Fr for importer@patchew.org; Wed, 16 Dec 2020 04:17:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSqY-0005OT-Jy; Wed, 16 Dec 2020 04:11:46 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:11044) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSqQ-0007TJ-O6; Wed, 16 Dec 2020 04:11:46 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0BG92jFW139587; Wed, 16 Dec 2020 04:11:31 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 35feshs3fm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:11:30 -0500 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0BG93ZGP142052; Wed, 16 Dec 2020 04:11:30 -0500 Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 35feshs3fa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 04:11:30 -0500 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0BG97Ig6011618; Wed, 16 Dec 2020 09:11:29 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma04dal.us.ibm.com with ESMTP id 35cng9e0f7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 09:11:29 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0BG9BSB125166226 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Dec 2020 09:11:28 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EEDA67805C; Wed, 16 Dec 2020 09:11:27 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A67127805E; Wed, 16 Dec 2020 09:11:21 +0000 (GMT) Received: from pub.ltc.br.ibm.com (unknown [9.85.141.22]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 16 Dec 2020 09:11:21 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=uDGgCz42jUY4Fg7+euXEuO4bnMXILPjKnV5gzZ/IKmU=; b=VaT/+/BeKSuNEkovQNd4/ZHMPVEJSFjNmXoG5UfFA/k9Isz2LK+IwLaikjNLyKQodzq+ 9uGbgadL5KTRrby1iRFgyuDERkazLa2n3DE2AdszAUt0c+lrtaRNk0+6GAtrk7oPQsSZ keKi+4WWboxTTHvxrLnhzCe3Ftj6WmkmUjr3xZkATmI0IF2KaE04iY8Vx8vUyDhboFIb HIBgWYRyP659ao+/uPQ471496n1DG1jXAocGvBTHlFMF4lh44YeZGvAo5eLPd/HJftUO Jz+dDwM6Zwc713v3vZ60OlGCU5m+nTHlLcpbVEsrBA+T6bDXQtTS7MSGZaPeItRvMHVr Ow== From: Gustavo Romero To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 7/7] tests/tcg: Add tests for prefixed load/store FP instructions Date: Wed, 16 Dec 2020 06:08:04 -0300 Message-Id: <20201216090804.58640-8-gromero@linux.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216090804.58640-1-gromero@linux.ibm.com> References: <20201216090804.58640-1-gromero@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-16_02:2020-12-15, 2020-12-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 mlxscore=0 bulkscore=0 phishscore=0 malwarescore=0 adultscore=0 impostorscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012160055 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=148.163.156.1; envelope-from=gromero@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, gromero@linux.ibm.com, gustavo.romero@protonmail.com, Michael Roth , mroth@lamentation.net, clg@kaod.org, david@gibson.dropbear.id.au, alex.bennee@linaro.org, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michael Roth Signed-off-by: Michael Roth [ gromero: - tweaks in debug output ] Signed-off-by: Gustavo Romero --- tests/tcg/ppc64le/Makefile.target | 4 + .../test-prefixed-load-store-fp.c | 270 ++++++++++++++++++ 2 files changed, 274 insertions(+) create mode 100644 tests/tcg/ppc64le/instruction-tests/test-prefixed-load-= store-fp.c diff --git a/tests/tcg/ppc64le/Makefile.target b/tests/tcg/ppc64le/Makefile= .target index aaa43a83a7..c6eac40b74 100644 --- a/tests/tcg/ppc64le/Makefile.target +++ b/tests/tcg/ppc64le/Makefile.target @@ -9,6 +9,7 @@ VPATH +=3D $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/instruction= -tests QEMU_OPTS +=3D -cpu power10 =20 PPC_TESTS =3D test-prefixed-load-store +PPC_TESTS +=3D test-prefixed-load-store-fp =20 TESTS +=3D $(PPC_TESTS) PPC_VSX_TESTS =3D test-paired-load-store-vsx @@ -23,3 +24,6 @@ test-prefixed-load-store: test-prefixed-load-store.c =20 test-paired-load-store-vsx: test-paired-load-store-vsx.c gcc $< -o test-paired-load-store-vsx + +test-prefixed-load-store-fp: test-prefixed-load-store-fp.c + gcc $< -o test-prefixed-load-store-fp diff --git a/tests/tcg/ppc64le/instruction-tests/test-prefixed-load-store-f= p.c b/tests/tcg/ppc64le/instruction-tests/test-prefixed-load-store-fp.c new file mode 100644 index 0000000000..baf8c3febf --- /dev/null +++ b/tests/tcg/ppc64le/instruction-tests/test-prefixed-load-store-fp.c @@ -0,0 +1,270 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +bool debug =3D false; + +#define dprintf(...) \ + do { \ + if (debug =3D=3D true) { \ + fprintf(stderr, "%s: ", __func__); \ + fprintf(stderr, __VA_ARGS__); \ + } \ + } while (0); + +bool le; + +#define PLFS(_FRT, _RA, _d0, _d1, _R) \ + ".long 1<<26 | 2<<24 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 48<<26 | (" #_FRT ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" +#define PSTFS(_FRS, _RA, _d0, _d1, _R) \ + ".long 1<<26 | 2<<24 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 52<<26 | (" #_FRS ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" +#define PLFD(_FRT, _RA, _d0, _d1, _R) \ + ".long 1<<26 | 2<<24 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 50<<26 | (" #_FRT ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" +#define PSTFD(_FRS, _RA, _d0, _d1, _R) \ + ".long 1<<26 | 2<<24 | (" #_R ")<<20 | (" #_d0 ")\n" \ + ".long 54<<26 | (" #_FRS ")<<21 | (" #_RA ")<<16 | (" #_d1 ")\n" + +void test_plfs(void) { + float dest =3D 0; + float dest_copy =3D 0; + float src =3D FLT_MAX; + void *src_ptr =3D &src; + + /* sanity check against lfs */ + asm( + "lfs %0, 0(%2)" + : "+f" (dest_copy) + : "f" (src), "r" (src_ptr)); + + asm( + PLFS(%0, %2, 0, 0, 0) + : "+f" (dest) + : "f" (src), "r" (src_ptr)); + + assert(dest =3D=3D src); + assert(dest_copy =3D=3D dest); +} + +void test_pstfs(void) { + float dest =3D 0; + float dest_copy =3D 0; + float src =3D FLT_MAX; + void *dest_ptr =3D &dest; + void *dest_copy_ptr =3D &dest_copy; + + /* sanity check against stfs */ + asm( + "stfs %1, 0(%0)" + : "+r" (dest_copy_ptr) + : "f" (src)); + + asm( + PSTFS(%1, %0, 0, 0, 0) + : "+r" (dest_ptr) + : "f" (src)); + + assert(dest =3D=3D src); + assert(dest_copy =3D=3D dest); +} + +void test_plfd(void) { + double dest =3D 0; + double dest_copy =3D 0; + double src =3D DBL_MAX; + void *src_ptr =3D &src; + + /* sanity check against lfd */ + asm( + "lfd %0, 0(%2)" + : "+d" (dest_copy) + : "d" (src), "r" (src_ptr)); + + asm( + PLFD(%0, %2, 0, 0, 0) + : "+d" (dest) + : "d" (src), "r" (src_ptr)); + + assert(dest =3D=3D src); + assert(dest_copy =3D=3D dest); +} + +void test_pstfd(void) { + double dest =3D 0; + double dest_copy =3D 0; + double src =3D DBL_MAX; + void *dest_ptr =3D &dest; + void *dest_copy_ptr =3D &dest_copy; + + /* sanity check against stfs */ + asm( + "stfd %1, 0(%0)" + : "+r" (dest_copy_ptr) + : "f" (src)); + + asm( + PSTFD(%1, %0, 0, 0, 0) + : "+r" (dest_ptr) + : "f" (src)); + + assert(dest =3D=3D src); + assert(dest_copy =3D=3D dest); +} + +void test_plfs_offset(void) { + float dest; + float src =3D FLT_MAX; + void *src_ptr =3D &src; + void *src_ptr_offset; + + src_ptr_offset =3D src_ptr - 1; + dest =3D 0; + asm( + PLFS(%0, %2, 0, 0x1, 0) + : "=3Df" (dest) + : "f" (src), "r" (src_ptr_offset)); + assert(dest =3D=3D src); + + src_ptr_offset =3D src_ptr - 0x1FFFFFFFF; + dest =3D 0; + asm( + PLFS(%0, %2, 0x1FFFF, 0xFFFF, 0) + : "=3Df" (dest) + : "f" (src), "r" (src_ptr_offset)); + assert(dest =3D=3D src); + + src_ptr_offset =3D src_ptr + 1; + dest =3D 0; + asm( + PLFS(%0, %2, 0x3FFFF, 0xFFFF, 0) + : "=3Df" (dest) + : "f" (src), "r" (src_ptr_offset)); + assert(dest =3D=3D src); +} + +void test_pstfs_offset(void) { + float dest; + float src =3D FLT_MAX; + void *dest_ptr =3D &dest; + void *dest_ptr_offset; + + dest_ptr_offset =3D dest_ptr - 1; + dest =3D 0; + asm( + PSTFS(%1, %0, 0x0, 0x1, 0) + : "+r" (dest_ptr_offset) + : "f" (src)); + assert(dest =3D=3D src); + + dest_ptr_offset =3D dest_ptr - 0x1FFFFFFFF; + dest =3D 0; + asm( + PSTFS(%1, %0, 0x1FFFF, 0xFFFF, 0) + : "+r" (dest_ptr_offset) + : "f" (src)); + assert(dest =3D=3D src); + + dest_ptr_offset =3D dest_ptr + 1; + dest =3D 0; + asm( + PSTFS(%1, %0, 0x3FFFF, 0xFFFF, 0) + : "+r" (dest_ptr_offset) + : "f" (src)); + assert(dest =3D=3D src); +} + +void test_plfd_offset(void) { + double dest; + double src =3D DBL_MAX; + void *src_ptr =3D &src; + void *src_ptr_offset; + + src_ptr_offset =3D src_ptr - 1; + dest =3D 0; + asm( + PLFD(%0, %2, 0, 0x1, 0) + : "+f" (dest) + : "f" (src), "r" (src_ptr_offset)); + assert(dest =3D=3D src); + + src_ptr_offset =3D src_ptr - 0x1FFFFFFFF; + dest =3D 0; + asm( + PLFD(%0, %2, 0x1FFFF, 0xFFFF, 0) + : "+f" (dest) + : "f" (src), "r" (src_ptr_offset)); + assert(dest =3D=3D src); + + src_ptr_offset =3D src_ptr + 1; + dest =3D 0; + asm( + PLFD(%0, %2, 0x3FFFF, 0xFFFF, 0) + : "+f" (dest) + : "f" (src), "r" (src_ptr_offset)); + assert(dest =3D=3D src); +} + +void test_pstfd_offset(void) { + double dest; + double src =3D DBL_MAX; + void *dest_ptr =3D &dest; + void *dest_ptr_offset; + + dest_ptr_offset =3D dest_ptr - 1; + dest =3D 0; + asm( + PSTFD(%1, %0, 0x0, 0x1, 0) + : "+r" (dest_ptr_offset) + : "f" (src)); + assert(dest =3D=3D src); + + dest_ptr_offset =3D dest_ptr - 0x1FFFFFFFF; + dest =3D 0; + asm( + PSTFD(%1, %0, 0x1FFFF, 0xFFFF, 0) + : "+r" (dest_ptr_offset) + : "f" (src)); + assert(dest =3D=3D src); + + dest_ptr_offset =3D dest_ptr + 1; + dest =3D 0; + asm( + PSTFD(%1, %0, 0x3FFFF, 0xFFFF, 0) + : "+r" (dest_ptr_offset) + : "f" (src)); + assert(dest =3D=3D src); +} + +#define do_test(testname) \ + if (debug) \ + fprintf(stderr, "-> running test: " #testname "\n"); \ + test_##testname(); \ + +int main(int argc, char **argv) +{ + le =3D (htole16(1) =3D=3D 1); + + if (argc > 1 && !strcmp(argv[1], "-d")) { + debug =3D true; + } + + do_test(plfs); + do_test(pstfs); + do_test(plfd); + do_test(pstfd); + + do_test(plfs_offset); + do_test(pstfs_offset); + do_test(plfd_offset); + do_test(pstfd_offset); + + dprintf("All tests passed\n"); + return 0; +} --=20 2.17.1