From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2050.outbound.protection.outlook.com [40.107.21.50]) by sourceware.org (Postfix) with ESMTPS id 9CB293858D28 for ; Tue, 17 Jan 2023 16:16:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9CB293858D28 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-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KY744YoGr6N6OAUHZKGIAtHcgUHqaQJpRMq5avUwCkIWQbdx9rAiQu1iJchBuA2hrkaj/ZUekZXNwcwpBb+SlK6rYtBptUBeOMFlgymldMEmxgGf9NRx4ezoIOvhuR6IoW5HerDAZNDozpB+odeD57uQA21BxEWZ/rx+xzPc8vlOApkPOtJ/bigRMU+joEa16a3eNilkeuPNDdjl3xRdeg1Fw1gvvIfbWHRd4NBWEoU937jvuTuhuCTVkhux0GPdgSa/lfUdNDxEAodhkrUttAY4XNLy8HEIs887/kUd60Mg2PiEagoMilcDEgulWZ5qYYZz6gg3R0fLuNhlNJCpaA== 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=Eh2r8dS3NGE5dzxUu9EdA1tMTMGXEfklVpJyuEF/JkE=; b=kCCNLVf+ZsXAfylv9vfBEmlRLs9/wBgs0i8VTXRK80VLDf8naHqZvJBqP7nzsFCc6F92lOX5hMdqMlb4RuPEvgs7DUEN2P+wd5gzTUowRIS2GK60UwZEr0+ZN4VHg4pzA0fONe3DqzYx86REwsdltMKeSFpo3sMRszM4fSGEn8Q67O2oQ/4E+0Bbsd5910ZXsNwrbAp12tnyJI7u7F28PbF9PJ3rSwenAR13DEkoHJ7hr7M0J6nkkMP675zH7HSi2rBUntwsjokw3A0yum9QK7XsFd3xC9dvrw0MHhZ55x0npWEqSg+fQoajN4OL2TY8PUKcGgv6tsnVwIqCLbd+5Q== 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=Eh2r8dS3NGE5dzxUu9EdA1tMTMGXEfklVpJyuEF/JkE=; b=Rou/PFrRmFUJBA10JlTG1pR0D54Cyah8t6L7BUfHFX+tjS/4xFQ+jsViHqR87GQ/zRdJ2vtubBu8M8q2OBxlKcMaCKZYmNtgGZ7LVXESLVUnh0pi34EBEW0ucbo4dCKKiyOvii8AuXyMd74CPZiSfwF8hvFwPm5ySarUuq82nOpPX52I7YBlXwr+D1vsoylB4rmefcfasr+QuWoUmJH6WARgcvKcA4KDpMpD/a2uOYatpOjq5vEAh07J8xXDoCmBk5rmsdf7zyt7VDBzx1Ok+C3O0/jN88askKZstpe2RgKbw2g6Te0XaLwEeqDxjPZOYFnY7MX8EpqiHmRkxNvwNA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AM9PR04MB7571.eurprd04.prod.outlook.com (2603:10a6:20b:2dd::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.23; Tue, 17 Jan 2023 16:16:56 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::2991:58a4:e308:4389%7]) with mapi id 15.20.6002.012; Tue, 17 Jan 2023 16:16:56 +0000 Message-ID: <8ed80af6-b36b-46d4-de64-530331bd4e4d@suse.com> Date: Tue, 17 Jan 2023 17:16:53 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [RFC] x86: proposal for a new .insn directive Content-Language: en-US To: "H.J. Lu" Cc: Binutils References: <7166b647-c3a3-6103-c4d2-7c59a1520518@suse.com> From: Jan Beulich In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR0P281CA0092.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a9::13) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AM9PR04MB7571:EE_ X-MS-Office365-Filtering-Correlation-Id: d9f6a055-8e6e-4e0d-085c-08daf8a6406d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZfCLq3JjzLj83Hzfyoj0tt8J8nsE0/PcMSjnAKeyGNJEnVeg/kYEkBXRZA6AmmdLkzfViXU7zY4jTZmyiGT7//Lz/lnIji+Gp8cfg0S/81fpthmCfB5Nl2YNRMAIKTQxWmwfGop8sl5wKTr0spVTUCNIv72t25om/FdTxnTWLyPIi/H6WbbZP5nfPMnUNHX0nxkTlK81D/U+39UeqrTaEX/xTIJ0WBtOfSFr/v+yOsHRIty6w0gNaiE2U2JEGDrrb6SPjO/YWGbvYkXHwypJBhFpJKasMXGJN/XK3yDaQ5HUrijlFL5PSmfiWDhoUBG+CMqkrafl28uHEZl9Ixzv1X2bY64NvVU6noky8e73VEhzQvNAdnEDSIj7ZdSDGXNpDLJaR0Ina4i/wCEhufTqh0cGZvQvLsJ/2U5JV5sNwuNmH1se2yXF+ExkLmOk5d9Y5EjtOi972iG8MIpZp2zpoz3ymdnTiHMP8jG6mR6FfPl5x8zAmOWEwuiBZo7OCTzt8dYfkVqNV874+wjFy+NCxq1y/GLfsMp9NL18LfYLB5xkP/W4QO8LycIzSOEhNZ87hwO/NAo/e8NO/edvkORQJCXflDNji4GiYo53JE60OoiIVmrRy3ziinbSza97Wl4GQUyeSBSP7yGKnHTuS1G/XNzSapKhOj6EwJbPYWVRId0B9WLVJdZn8qbqtT0kzEsw74TyNoUloftHk77CNQyVfG4k1BbEF99exQAi7rfpD+re99oLnhEUCdQZlSGqMW2e6VjImyHC7uc6CiVz69Mu/g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(376002)(346002)(39860400002)(136003)(396003)(366004)(451199015)(83380400001)(38100700002)(5660300002)(6916009)(86362001)(2906002)(4326008)(31696002)(8936002)(66556008)(66946007)(8676002)(66476007)(478600001)(6506007)(186003)(53546011)(26005)(2616005)(6512007)(6666004)(6486002)(316002)(41300700001)(31686004)(66899015)(36756003)(142923001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bXlZanFWWlhwaGlDeC85b3o2RDFXU3F1WTdSZXVoZmNiTDBvaldYaWtlZkZO?= =?utf-8?B?WGhjSFQyVENHSGp0MGRqcG8vR21Scks3Ry8vS1FpdkZGMU1JMlNwdmZROG5t?= =?utf-8?B?Umc5TnNWSTZiNE1vMVpEZ0k1STZ4clJaNVM2N0cvREFrYTJBRHNHeHQ1clEz?= =?utf-8?B?VmhZRlcvN3BnOUlwTmNpTUpzcGpOcGFpdEdWd09KWDRkcW5VYXA5NHk3NG5W?= =?utf-8?B?Uk0vMVE5TV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R1NP?= =?utf-8?B?RUV1VnJ0eXcra2ZHQWJrZmRlcUNrM2NDSy9FWWNJbis3aU1UMjluVzlhNDh4?= =?utf-8?Q?qg6159MHz0wkQfsTg+yecFjTA?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: d9f6a055-8e6e-4e0d-085c-08daf8a6406d X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2023 16:16:55.7524 (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: sgsj13GLvyZY0BDYo+JwErtYvY2re4D5u/I0vtcV9z3Pr+Nw4NkDzBx7Y4tl8VzlW3UKXhYUUb/laGQz+tKnbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB7571 X-Spam-Status: No, score=-3028.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP 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.01.2023 16:56, H.J. Lu wrote: > On Fri, Jan 13, 2023 at 3:58 AM Jan Beulich wrote: >> >> All, >> >> certain other architectures (Arm, RISC-V) have such, and x86 would imo >> benefit from such even more: It is notoriously difficult to encode new >> insns with operands which a certain version of gas doesn't support yet. >> This is in particular related to the building of the ModR/M and SIB >> bytes as well the VEX/XOP/EVEX prefixes. >> >> I would appreciate feedback on the proposal (in form of an assembly >> source file, providing examples at the same time). Besides pointing >> out issues / oversights, thoughts on the various TBDs would be helpful. >> >> Thanks, Jan >> >> .text >> insn: >> >> # .insn [] [] [+r|/] [,[,...]] >> >> # Legacy encoding prefixes altering encoding space (0x0f, 0x0f38, 0x0f3a) >> # have to be specified as high byte(s) of . This also extends >> # to certain FPU opcodes or sub-spaces like that of major opcode 0x0f01. >> >> # Legacy encoding prefixes altering meaning (0x66, 0xF2, 0xF3) may be >> # specified as high byte of (perhaps already including an >> # encoding space prefix). Other prefixes should be spelled out as usual >> # ahead of or, for segment overrides, with the memory >> # operand. >> >> # Operand order may not match that of the instruction actually being >> # expressed: While for a memory operand (of which there can be only one) it >> # is clear how to encode it in the resulting ModR/M byte, register operands >> # are encoded strictly in the order >> # - ModR/M.rm, ModR/M.reg for 2-operand insns, >> # - ModR/M.rm, {E,}VEX.vvvv, ModR/M.reg for 3-operand insns, and >> # - Imm{4,5}, ModR/M.rm, {E,}VEX.vvvv, ModR/M.reg for 4-operand insns, >> # obviously with the ModR/M.rm slot skipped when there is a memory operand, >> # and obviously with the ModR/M.reg slot skipped when there is an extension >> # opcode. (For Intel syntax of course all in the opposite order.) >> >> # Immediate operands (including immediate-like displacements, i.e. when not >> # part of ModR/M addressing) should be specified by separate .byte / .word / >> # .long / .quad (or alike) directives. >> # TBD: How to deal with this for RIP-relative addressing? >> # TBD: How to deal with this for 4-operand insns? >> >> # When register operand size varies for an actual insn (like e.g. for MOVZX or >> # VPMOVZX*), registers nevertheless need spelling out in a uniform manner, such >> # that any of them could be used to derive operand size attributes (e.g. >> # operand size prefix, REX.W, VEX.W, or VEX.L) as well as the EVEX Disp8 >> # scaling factor. >> # TBD: Could also go from largest operand size, albeit that may end up confusing >> # in AT&T mode, where memory operands don't have size, yet the memory >> # operand may have larger size than the register one(s) (and would hence be >> # the one which the attribute - see below - needs deriving from). >> >> # For VEX / XOP / EVEX is arranged like this: >> # {VEX,XOP,EVEX}[.][.][.][.] >> # where >> # - can be LIG, 128, 256, or (EVEX only) 512 as well as L0/L1 for >> # VEX / XOP and L0-L3 for EVEX, >> # - can be NP, 66, F3, or F2, >> # - can be >> # - 0f, 0f38, 0f3a, or M0...M31 for VEX, >> # - 08...3f (hex) for XOP, >> # - 0f, 0f38, 0f3a, or M0...M15 for EVEX, >> # - can be WIG, W0, or W1. >> # Omitted means "infer from operand size" if there is at least one >> # sized operand, or LIG otherwise. >> # Omitted means NP. >> # Omitted implies encoding is taken from . >> # Omitted means "infer from GPR operand size" if there is at least >> # one GPR operand, or WIG otherwise. >> >> # TBD: Is operand order being dependent on AT&T vs Intel syntax okay? >> >> .insn 0x90 # nop >> .insn 0xf390 # pause >> .insn rep 0x90 # pause >> .insn 0xd9c9 # fxch >> .insn 0xf30f01d9 # vmgexit >> >> .insn 0x89, %ecx, %eax # mov %ecx, %eax >> .insn 0x89, %ax, %cx # mov %ax, %cx >> >> .insn 0x8b, (%eax), %ecx # mov (%eax), %ecx >> >> .insn 0x0fc8+r, %edx # bswap %edx >> >> .insn lock 0x80/0, %fs:(%eax); .byte 1 # lock addb $1, %fs:(%eax) >> >> 1: >> .insn 0xe2; .byte 1b-.-1 # loop 1b >> .insn 0xc7f8; .long 1b-.-4 # xbegin 1b >> >> .insn 0x0fb6, %ax, %cx # movzx %al, %cx >> .insn 0x0fb7, %eax, %ecx # movzx %ax, %ecx >> >> .insn VEX.66.0F 0x58, %xmm0, %xmm1, %xmm2 # vaddpd %xmm0, %xmm1, %xmm2 >> .insn VEX.66 0x0f58, %ymm0, %ymm1, %ymm2 # vaddpd %ymm0, %ymm1, %ymm2 >> .insn VEX.LIG.F3.0F 0x58, %xmm0, %xmm1, %xmm2 # vaddss %xmm0, %xmm1, %xmm2 >> >> .insn VEX.66.0F3A.W0 0x68, %xmm0, %xmm1, (%edx), %xmm3 # vfmaddps %xmm0, %xmm1, (%edx), %xmm3 >> .insn VEX.66.0F3A.W1 0x68, %xmm0, %xmm1, (%edx), %xmm3 # vfmaddps %xmm0, %xmm1, %xmm3, (%edx) >> .insn VEX.66.0F3A.W1 0x68, %xmm0, %xmm1, %xmm2, (%ebx) # vfmaddps %xmm0, %xmm1, %xmm2, (%ebx) >> >> .insn VEX.66.0F3A.W0 0x48, $0, %xmm0, %xmm1, (%edx), %xmm3 # vpermil2ps $0, %xmm0, %xmm1, (%edx), %xmm3 >> .insn VEX.66.0F3A.W1 0x48, $1, %xmm0, %xmm1, (%edx), %xmm3 # vpermil2ps $1, %xmm0, %xmm1, %xmm3, (%edx) >> .insn VEX.66.0F3A.W1 0x48, $2, %xmm0, %xmm1, %xmm2, (%ebx) # vpermil2ps $2, %xmm0, %xmm1, %xmm2, (%ebx) >> >> .insn VEX.L0.0F.W0 0x93, %eax, %k0 # kmovw %eax, %k0 >> >> .insn VEX.256.0F.WIG 0x77 # vzeroall >> >> .insn EVEX.NP.0F.W0 0x58, {rn-sae}, %zmm0, %zmm1, %zmm2 # vaddps {rn-sae}, %zmm0, %zmm1, %zmm2 >> .insn EVEX.66.0F.W1 0x58, 8(%eax){1to8}, %zmm1, %zmm2{%k2}{z} # vaddpd 8(%eax){1to8}, %zmm0, %zmm1{%k2}{z} >> >> # TBD: How to specify the Disp8 scaling factor here? (In Intel syntax we can simply >> # use memory operand size.) >> .insn EVEX.66.0F38.W0 0x88, 4(%eax), %ymm1 # vexpandps 4(%eax), %ymm1 > > I think it is a nice feature. But it will be very difficult to > support all complex > x86 encoding schemes which change over time. Of course, and especially also if yet new schemes would appear. We can only possibly encode what we're aware of; but even that may help with unknown (or further extended) schemes, compared to today's need of resorting to .byte. > We can start with the regular encoding schemes first. Well, at the very least immediates need dealing with in some sensible way. So at least those two TBDs will need addressing up front (or maybe while I'm starting with some initial work here, which I may have time for in about two weeks). Jan