From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2051.outbound.protection.outlook.com [40.107.21.51]) by sourceware.org (Postfix) with ESMTPS id 2BCB33858281 for ; Fri, 17 Nov 2023 09:47:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2BCB33858281 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2BCB33858281 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.21.51 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700214476; cv=pass; b=vspn7+9k3BtGP8pq42PPNNAwbWH/2QMSIwrTpCws6vJeYmb3qWvq4+6tTYnOx5Lukjd75i3xfugPg2nDh1HYuPJuv4NyRfHxssI7BWpus5KlVbF86I9XqQSgdWWMerRLA7b0fM7WdOXhKJG9sfQwHu9bCTtdx5+rKxBMPXcYJvY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700214476; c=relaxed/simple; bh=d6vgfiGmgrZdX7O0t+aUpwy35gDwJ+AJP0D6ucYnSMw=; h=DKIM-Signature:Message-ID:Date:Subject:To:From:MIME-Version; b=Yfa8bp88fmcNtjcpCwapTkNUIeMuBLJn8BP0vnAlvfav/BlitLZSuDO5dz/JH/3y7TObgWBlkVlyyjvqqAUs4tddp7HedAx7QgA0QmvgyA5SU0MwjPEscQ/ejWAT+5i4BJYofafpb07aOrdsVujT+fTu3DwXGSTUp70a0yFWmes= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Khd84OyJW40CbBbg368BAMekGkP930Kl09IaatBFJt7W3iN3KMKH5Voaw+SMUPNBXRugTspvMdazgnwyWhZAlLUwXhT2k3Sab8sF9KiADjbXo0aLqYdKx0HRYfKMCjGbTjQsWicTsrqiJEnreaFDv0RJDRFDwuWNXMgewqywibGdFlck9KZ6dg9sBGNB/ncrK37ITGUSnoTnD3RaUz+1PE/5sLPkM5NGOy2rJ9V0+wZakLPbhNA7o0EgEEKBjAvStZtpSKClOSbZOAb4pcekTYtOUb75zBh98KL5mBRmgZeHEMmz8VD8yAog4QUvj3J0ppqqaESCy2lH+CNJr8kXFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tVqeW4U+l+ykIj6kuHRkT6xm+bK1fi62xi2rmEAlTrg=; b=BgnLxiuUvxs73lD7Iicok4pHWakxISelNfhGXnRRZ8z1Om4+x0cGJJnEDPoUkXCDEGcuBRRJTYuJAkMBaxAJqTC6IO6qtb/9CRGuybBU3PgKXHQBiEdfcL68qXBSdytm1e0ad/diP/2ljcdHxgcJ3d+V2hvPHY7kg45PQ2D1a2rtJaIdsjIbvXMZM0keANWS876xeXTbh9eOlJlR4CyD1Oo1n3OGxi4Jb0w5QhlyRXcH9q+RvGNkJRe9ETocImMnlSKPGtOjtAcqs/1ElF5Sz2bTHiT3nd4ShOtS7EqPJ2M+YrckJJXPg1LZP2HSahyk9k7XAks7uRNd+GgkDODApw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tVqeW4U+l+ykIj6kuHRkT6xm+bK1fi62xi2rmEAlTrg=; b=hjNqMKuB8H7cD3MY7NcdgtNMglOF0vrPxMKMyZAr4ue2l++tAcJRimKpGOechcVPa4gtFwoF2UE2RIA9d2u/44JVKPJr+Vz0/UzWF21ueCUbl9i7NlYJQ2B61fnjC2xDbeE6wrv0qap7su3hGRSQwftccWkRzXDp42E4JtyuLArBh37qSJKemMrPYzg14r0cfLKDCQGga7InxVOXtWYsD1B1bUZcCZgRzrB57BBHBP5or3ZGGVqModAx8FCXT1E465lGK7dY1fepTKCFW6UvMbTgNQaYBaFk6Q8Gaqo3xB5Qv8I1UBS+8dRO7LXrgPsGc0/v1k/OOBvK+fvEQQTXHw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) by AS1PR04MB9698.eurprd04.prod.outlook.com (2603:10a6:20b:481::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.11; Fri, 17 Nov 2023 09:47:51 +0000 Received: from DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44]) by DU2PR04MB8790.eurprd04.prod.outlook.com ([fe80::eb8e:fa24:44c1:5d44%3]) with mapi id 15.20.7025.010; Fri, 17 Nov 2023 09:47:51 +0000 Message-ID: <018bb6c6-9f01-4723-bf32-1944758d695c@suse.com> Date: Fri, 17 Nov 2023 10:47:48 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH][v3] Support APX NDD optimized encoding. Content-Language: en-US To: "Hu, Lin1" Cc: "Lu, Hongjiu" , "binutils@sourceware.org" References: <8ed3b7a2-8cba-6428-1c01-5b6c28ca4a89@suse.com> <20231115025925.2891038-1-lin1.hu@intel.com> <4c7a8e8c-de67-4d40-9cba-8fc04de1e309@suse.com> From: Jan Beulich Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUz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pC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR4P281CA0369.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f8::9) To DU2PR04MB8790.eurprd04.prod.outlook.com (2603:10a6:10:2e1::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8790:EE_|AS1PR04MB9698:EE_ X-MS-Office365-Filtering-Correlation-Id: 00dfdc43-685e-4583-329b-08dbe752436b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XNCGqBQSvImIe66ZTFNt2CdVsFsQ3sSWBQ+Qy0JQFGal2OeMvMTgwDyjL+5fm6qwVLNsNiZGl94luLEBrdxj92sUoVJ0ttzCVJetqtmV1bdKeHc5e8HJHxVnSHPf+OMcwKDtehwjcJBd9QlanXy9t5u4+aLPlKJrQAGRq9d+NT76xSXDKhIbdpkZYUxgXWlgONrNJw8i/53Up4RAOnJn0K9He08vuLU8C951k2bSC1Q5hdPILeubbCnPNsBlnMxPofNBsjnNq/au+MFYt2O/fKeUNP24vNsU9QHmrih56McufJRah3XXJkKo8Wj1SIf3Glb+E6thCaNtdX+wOQmuDlQtmtVvV6kkaCGqUAM8YuD1H1hKt5mHdlykV3b+BZuqY/shcDUMUbrLodbhwqbxUA7Q0ZAjkCEc4UMK7UYccUMT1A7JTBnju9ROy2Jm3K9OhaeaF1XeDqkWxmZbKW5+mXbQj734gmlcOcY8UQ4S3eLS/J6x90Kcq02EhfFhcHgCM3NI/0RUEIjHqZAjl3Uasz4sbwpr9gdxmtnKEGI+awdScayHDXrnFvQsXOWtraKMfdE4YT6ouTWNc56vh+rWPh30We+PIqykkVfW46SHV7YITt8Vli54AMOoJfs+T5JdDKOu/1jUsxIo0AI6JSt4zw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8790.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(396003)(39860400002)(366004)(346002)(136003)(230922051799003)(186009)(1800799009)(64100799003)(451199024)(2616005)(86362001)(66899024)(5660300002)(8936002)(8676002)(4326008)(31696002)(83380400001)(41300700001)(26005)(2906002)(6512007)(66476007)(66556008)(66946007)(54906003)(6916009)(316002)(31686004)(6506007)(53546011)(6486002)(38100700002)(478600001)(36756003)(6666004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eHdOdXlxMStONGxpYTgzQ2d3bkEvc3kzNkZGUTFKNnpSR3lKUFowaDF5VEZZ?= =?utf-8?B?OVF1MlRhSnFwQzExL3I1MjVsUjBDUWRDWkhvZDVqU0xaNkc5Y3F2VHh4SEpJ?= =?utf-8?B?UFgrZVYyUDdKb29keXE0cXZoMHJ4U09Jc1dhTUgxdGdqajAzN1lWRUZqU1h2?= =?utf-8?B?VHBYZUE3YTJDa0sycWN5c0JCRGE4S09OU2V6V3g1cWIvamFXQkQyck04Q3RF?= =?utf-8?B?K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lNcE1sQ2Mr?= =?utf-8?B?Sjh0d3lSMVRPaWRBdk1HUWlka0NCcVQwZitpOW00YmlVdHcvengwbEEzb1o2?= =?utf-8?Q?wm6vupBrO8vkaiQEDQenXB2ew?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00dfdc43-685e-4583-329b-08dbe752436b X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8790.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2023 09:47:51.0277 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VjnLcUsYS2wWpLqL4Cm4DynrC0+B47kku9nWHt4PWeo3objX+On+Gomaq76AvjIZ5gRgToUiHP0RCMww8N9wGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR04MB9698 X-Spam-Status: No, score=-3026.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 17.11.2023 08:24, Hu, Lin1 wrote: >> -----Original Message----- >> From: Jan Beulich >> Sent: Wednesday, November 15, 2023 5:35 PM >> >> On 15.11.2023 03:59, Hu, Lin1 wrote: >>> --- a/gas/config/tc-i386.c >>> +++ b/gas/config/tc-i386.c >>> @@ -7208,6 +7208,43 @@ check_EgprOperands (const insn_template *t) >>> return 0; >>> } >>> >>> +/* Optimize APX NDD insns to legacy insns. */ static bool >>> +convert_NDD_to_REX2 (const insn_template *t) { >>> + if (t->opcode_modifier.vexvvvv == VexVVVV_DST >>> + && t->opcode_space == SPACE_EVEXMAP4 >>> + && !i.has_nf >>> + && i.reg_operands >= 2) >>> + { >>> + unsigned int readonly_var = ~0; >>> + unsigned int dest = i.operands - 1; >>> + unsigned int src1 = i.operands - 2; >>> + unsigned int src2 = (i.operands > 3) ? i.operands - 3 : 0; >>> + >>> + if (i.types[src1].bitfield.class == Reg >>> + && i.op[src1].regs == i.op[dest].regs) >>> + readonly_var = src2; >>> + /* adcx, adox and imul can't support to swap the source operands. */ >>> + else if (i.types[src2].bitfield.class == Reg >>> + && i.op[src2].regs == i.op[dest].regs >>> + && optimize > 1 >>> + && t->opcode_modifier.commutative) >> >> Comment and code still aren't in line: "support to swap the source >> operands" >> really is the D attribute in the opcode table, whereas >> t->opcode_modifier.commutative is related to the C attribute (and all >> t->three >> insns named really are commutative). It looks to me that the code is correct, >> so it would then be the comment that may need updating. But it may also >> be better to additionally check .d here (making the code robust against C >> being added to the truly commutative yet not eligible to be optimized insns). >> In which case the comment might say "adcx, adox, and imul, while >> commutative, don't support to swap the source operands". >> > > I think we don't need to worry about it for now, because we've constrained the function with vexvvvvvvdest, and these instructions must be NDD instructions. And adcx, adox and imul don't have D attribute. Right, and I thought to leverage this. IOW ... > If I add check .d here, I will need to exclude them. ... I don't think I understand this. > Based on our previous discussion, I modified tc-i386.c as follows > > +/* Check if the instruction use the REX registers. */ > +static bool > +check_RexOperands (const insn_template *t) I don't think I can spot a use of the parameter in the function. > +{ > + for (unsigned int op = 0; op < i.operands; op++) > + { > + if (i.types[op].bitfield.class != Reg > + /* Special case for (%dx) while doing input/output op */ > + || i.input_output_operand) Once again: Is this needed? Respective insns shouldn't even make it here. Plus if they did, ... > + continue; > + > + if (i.op[op].regs->reg_flags & (RegRex | RegRex64)) > + return true; ... the loop would continue for (%dx) kind operands anyway. > + } > + > + if ((i.index_reg && (i.index_reg->reg_flags & (RegRex | RegRex64))) > + || (i.base_reg && (i.base_reg->reg_flags & (RegRex | RegRex64)))) > + return true; > + > + /* Check pseudo prefix {rex} are valid. */ > + if (i.rex_encoding) > + return true; > + return false; Just "return i.rex_encoding;"? > +} > + > +/* Optimize APX NDD insns to legacy insns. */ > +static unsigned int > +convert_NDD_to_legacy (const insn_template *t) > +{ > + unsigned int readonly_var = ~0; One issue I continue to have is the name of this variable. Good names help understanding what code is doing. And in 3-operand NDD insns there are uniformly 2 operands which are only read. > + if (t->opcode_modifier.vexvvvv == VexVVVV_DST > + && t->opcode_space == SPACE_EVEXMAP4 > + && !i.has_nf > + && i.reg_operands >= 2) > + { > + unsigned int dest = i.operands - 1; > + unsigned int src1 = i.operands - 2; > + unsigned int src2 = (i.operands > 3) ? i.operands - 3 : 0; > + > + if (i.types[src1].bitfield.class == Reg > + && i.op[src1].regs == i.op[dest].regs) > + readonly_var = src2; > + /* adcx, adox, and imul, while commutative, don't support to swap > + the source operands. */ > + else if (i.types[src2].bitfield.class == Reg > + && i.op[src2].regs == i.op[dest].regs > + && optimize > 1 > + && t->opcode_modifier.commutative) > + readonly_var = src1; > + } > + return readonly_var; > +} You're no longer converting anything in this function, which - I'm sorry to say that - once again makes its name unsuitable. > @@ -7728,6 +7782,55 @@ match_template (char mnem_suffix) > i.memshift = memshift; > } > > + /* If we can optimize a NDD insn to legacy insn, like > + add %r16, %r8, %r8 -> add %r16, %r8, > + add %r8, %r16, %r8 -> add %r16, %r8, then rematch template. > + Note that the semantics have not been changed. */ > + if (optimize > + && !i.no_optimize > + && i.vec_encoding != vex_encoding_evex > + && t + 1 < current_templates->end > + && !t[1].opcode_modifier.evex > + && t[1].opcode_space <= SPACE_0F38) In all of these checks what I'm missing is a check that we're actually dealing with an NDD template. > + { > + unsigned int readonly_var = convert_NDD_to_legacy (t); > + size_match = true; > + > + if (readonly_var != (unsigned int) ~0) > + { > + for (j = 0; j < i.operands - 2; j++) > + { > + check_register = j; > + if (t->opcode_modifier.d) > + check_register ^= 1; > + overlap0 = operand_type_and (i.types[check_register], > + t[1].operand_types[check_register]); > + if (!operand_type_match (overlap0, i.types[check_register])) > + size_match = false; > + } I'm afraid that without a comment I don't understand what this is about. > + if (size_match > + && (t[1].opcode_space <= SPACE_0F > + || (!check_EgprOperands (t + 1) // These conditions are exclude adcx/adox with inappropriate registers. > + && !check_RexOperands (t + 1) > + && !i.op[i.operands - 1].regs->reg_type.bitfield.qword))) Saying "inappropriate" in such a comment doesn't really help, as it's then still unclear what is "appropriate". But the comment will need re-formatting anyway. > + { > + unsigned int src1 = i.operands - 2; Looks like this variable is no longer used? > + unsigned int src2 = (i.operands > 3) ? i.operands - 3 : 0; > + > + if (readonly_var != src2) > + swap_2_operands (readonly_var, src2); > + > + --i.operands; > + --i.reg_operands; > + > + specific_error = progress (internal_error); > + continue; > + } > + > + } > + } > + > /* We've found a match; break out of loop. */ > break; > > What's your opinion? I need some further clarification first, as per above. I also don't think I can properly identify (yet) which parts of the code are solely related to the ADCX/ADOX special case. The more code that's special for these, the more I'd be inclined to ask that dealing with them be a separate patch, for us to judge whether effort and effect are in reasonable balance. Jan