From patchwork Fri Feb 23 11:12:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 86264 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 782A83858018 for ; Fri, 23 Feb 2024 11:12:41 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 248873858425 for ; Fri, 23 Feb 2024 11:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 248873858425 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 248873858425 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::631 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708686727; cv=none; b=q0kfJeriAHEUjHtLQfihn2GSaNidICcJxW1rWOi+/6v6MGhZg6qEr6AewldVM3drB7uzuqP1Y3WVS9qKxExF/axLPPz9onRH00jiVfwvRTzuoVDg527By6PMZWxvvzJyOLHC+0ELNpuHzv7k6dom2gJIEpG9M355AHBQ5EkFoS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708686727; c=relaxed/simple; bh=RfLM3bVBl1uMnEMWOuSSPVDYq/W6Yg32/VG1EZlCZOo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=vUbiGCQpimA/JwA72SOwISOnHUmjhPDQxsbKHhyD0tZ7BaT+t8921f7mhacLWVQw9DMJ8PCSGcpxM7SxpoPeOmHNqfc5fkQEhlhMgwa6HcAkV49PHN0fdAUC2VpD2TrX1g3KKdZXD6TPsjWI+QGK7Fk47MqzCtTLZmoXE/Zx+Cw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a3e891b5e4eso79802566b.0 for ; Fri, 23 Feb 2024 03:12:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1708686724; x=1709291524; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=zSXmVsbMIwtV+zq4PXTv1Zs8QXSeMcMGVj/s3Dv9Gfc=; b=QtqYVK/SJWAICX4kbZWLmQMPl7/uoIqcXNavI66usr8JZP6DD4mlgLlKFdZGzZGuEg d1c1othbT7+OD2X/dAocmPeZpPrqqTL29jNac/Df/NbNTD3REQVa1+FXxULmVn4YTD0J YP82YLavpdPzw5JdowijgzOM4b6dRx6Tk3nZRhgpGKxCtpUd2oxT2YEok4HVXvxiKlbk mTINAshMJdAnQ4Djohxp4EMnf4sVrmlsZ+M0ZumL1nh90EA+neBdobRC00GdraysOBx/ P8PyC7wcP3K7FUQqdhpnGoA2RbKaFJANo7XG7CoXYij3WYwpbUi9cPlrHNGAGN4ZdT0g elIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708686724; x=1709291524; h=content-transfer-encoding:in-reply-to:autocrypt:references:cc:to :from:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zSXmVsbMIwtV+zq4PXTv1Zs8QXSeMcMGVj/s3Dv9Gfc=; b=oDh+LvgwNYgUAR4d38OOrS3Crd/nozjcveSL6G41uzBfy94kyzMw+VxpOYSihYMXlG pkME6Bha0Py/SE8tq2ep/zHItlp2dWtjOTfDiHRGYXrt+8ZwqXOEpz8vN73LIwL0CdFw aTCy7+VTfciSgYKU9XaIjrFjxJXUCPfBZzY2IJfxxe3Dge3QrsEPppuInTaz40yMd+xl NGoIa8FPInu8zmhQXpyFqtMdJatpmRu79heoQickgaCHJLHV/W75ZIVpFhDPpkingGJ8 Px+kTAsfiWncAaJf08OShB1haMU/L0mKjE2nqIo99B3THBfB0yaYmUqEbNP9MGl3a3la pWIg== X-Gm-Message-State: AOJu0YyZKMqCrCtRZ+Erx13f1aVXzcv9o87wEdqBTGV6iNweTKNo0/0O EB5l1KcD7GHUJvpj9YUXtLSEFHyYYoZF9Cb/+epWeQmxJzYlbdN/5fnmeqpocEx24Yo9q8JhfSY = X-Google-Smtp-Source: AGHT+IGXrgXOc6mcy4oLYvE/UHvN1tl0Vpj4k66rBMzVltVLNj+jZok8rApZuN0+sbnIFfe0HSsaFQ== X-Received: by 2002:a17:906:f847:b0:a3e:bc98:7243 with SMTP id ks7-20020a170906f84700b00a3ebc987243mr1077363ejb.71.1708686723820; Fri, 23 Feb 2024 03:12:03 -0800 (PST) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id ps2-20020a170906bf4200b00a3f20a8d2f6sm2836017ejb.112.2024.02.23.03.12.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 23 Feb 2024 03:12:03 -0800 (PST) Message-ID: Date: Fri, 23 Feb 2024 12:12:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 2/4] x86/APX: correct .insn opcode space determination when REX2 is needed Content-Language: en-US From: Jan Beulich To: Binutils Cc: "H.J. Lu" , Lili Cui References: Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 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MlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: X-Spam-Status: No, score=-3025.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org In this case spaces 0f38 and 0f3a may not be put in place. To achieve the intended effect, operand parsing (but not operand processing) needs pulling ahead, so we know whether eGRP-s are in use. --- v2: Add --divide for new testcase. --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -12849,13 +12849,43 @@ s_insn (int dummy ATTRIBUTE_UNUSED) } } + /* Parse operands, if any, before evaluating encoding space. */ + if (*line == ',') + { + i.memshift = -1; + + ptr = parse_operands (line + 1, &i386_mnemonics[MN__insn]); + this_operand = -1; + if (!ptr) + goto bad; + line = ptr; + + if (!i.operands) + { + as_bad (_("expecting operand after ','; got nothing")); + goto done; + } + + if (i.mem_operands > 1) + { + as_bad (_("too many memory references for `%s'"), + &i386_mnemonics[MN__insn]); + goto done; + } + + /* No need to distinguish encoding_evex and encoding_evex512. */ + if (i.encoding == encoding_evex512) + i.encoding = encoding_evex; + } + /* Trim off encoding space. */ if (j > 1 && !i.insn_opcode_space && (val >> ((j - 1) * 8)) == 0x0f) { uint8_t byte = val >> ((--j - 1) * 8); i.insn_opcode_space = SPACE_0F; - switch (byte & -(j > 1)) + switch (byte & -(j > 1 && !i.rex2_encoding + && (i.encoding != encoding_egpr || evex))) { case 0x38: i.insn_opcode_space = SPACE_0F38; @@ -12878,42 +12908,17 @@ s_insn (int dummy ATTRIBUTE_UNUSED) if (j > 2) { as_bad (_("opcode residual (%#"PRIx64") too wide"), (uint64_t) val); - goto bad; + goto done; } i.opcode_length = j; /* Handle operands, if any. */ - if (*line == ',') + if (i.operands) { i386_operand_type combined; expressionS *disp_exp = NULL; bool changed; - i.memshift = -1; - - ptr = parse_operands (line + 1, &i386_mnemonics[MN__insn]); - this_operand = -1; - if (!ptr) - goto bad; - line = ptr; - - if (!i.operands) - { - as_bad (_("expecting operand after ','; got nothing")); - goto done; - } - - if (i.mem_operands > 1) - { - as_bad (_("too many memory references for `%s'"), - &i386_mnemonics[MN__insn]); - goto done; - } - - /* No need to distinguish encoding_evex and encoding_evex512. */ - if (i.encoding == encoding_evex512) - i.encoding = encoding_evex; - if (i.encoding == encoding_egpr) { if (vex || xop) --- /dev/null +++ b/gas/testsuite/gas/i386/insn-rex2.l @@ -0,0 +1,38 @@ +[ ]*[0-9]+[ ]+\.text +[ ]*[0-9]+[ ]+insn_rex2: +[ ]*[0-9]+ .... D58001C0[ ]+\.insn \{rex2\} 0x0f01/0, %eax +[ ]*[0-9]+ .... D58038C0[ ]+\.insn \{rex2\} 0x0f38/0, %eax +[ ]*[0-9]+ .... D5803801[ ]+\.insn \{rex2\} 0x0f3801/0, %eax +[ ]*[0-9]+ +C0 +[ ]*[0-9]+ .... D5803901[ ]+\.insn \{rex2\} 0x0f3901/0, %eax +[ ]*[0-9]+ +C0 +[ ]*[0-9]+ .... D5803A01[ ]+\.insn \{rex2\} 0x0f3a01/0, \$0xCC, %eax +[ ]*[0-9]+ +C0CC +[ ]*[0-9]+[ ]+ +[ ]*[0-9]+ .... D58801C0[ ]+\.insn \{rex2\} 0x0f01/0, %rax +[ ]*[0-9]+ .... D58838C0[ ]+\.insn \{rex2\} 0x0f38/0, %rax +[ ]*[0-9]+ .... D5883801[ ]+\.insn \{rex2\} 0x0f3801/0, %rax +[ ]*[0-9]+ +C0 +[ ]*[0-9]+ .... D5883901[ ]+\.insn \{rex2\} 0x0f3901/0, %rax +[ ]*[0-9]+ +C0 +[ ]*[0-9]+ .... D5883A01[ ]+\.insn \{rex2\} 0x0f3a01/0, \$0xCC, %rax +[ ]*[0-9]+ +C0CC +[ ]*[0-9]+[ ]+ +[ ]*[0-9]+ .... D58901C0[ ]+\.insn \{rex2\} 0x0f01/0, %r8 +[ ]*[0-9]+ .... D58938C0[ ]+\.insn \{rex2\} 0x0f38/0, %r8 +[ ]*[0-9]+ .... D5893801[ ]+\.insn \{rex2\} 0x0f3801/0, %r8 +[ ]*[0-9]+ +C0 +[ ]*[0-9]+ .... D5893901[ ]+\.insn \{rex2\} 0x0f3901/0, %r8 +[ ]*[0-9]+ +C0 +[ ]*[0-9]+ .... D5893A01[ ]+\.insn \{rex2\} 0x0f3a01/0, \$0xCC, %r8 +[ ]*[0-9]+ +C0CC +[ ]*[0-9]+[ ]+ +[ ]*[0-9]+ .... D59801C0[ ]+\.insn 0x0f01/0, %r16 +[ ]*[0-9]+ .... D59838C0[ ]+\.insn 0x0f38/0, %r16 +[ ]*[0-9]+ .... D5983801[ ]+\.insn 0x0f3801/0, %r16 +[ ]*[0-9]+ +C0 +[ ]*[0-9]+ .... D5983901[ ]+\.insn 0x0f3901/0, %r16 +[ ]*[0-9]+ +C0 +[ ]*[0-9]+ .... D5983A01[ ]+\.insn 0x0f3a01/0, \$0xCC, %r16 +[ ]*[0-9]+[ ]+C0CC +#pass --- /dev/null +++ b/gas/testsuite/gas/i386/insn-rex2.s @@ -0,0 +1,25 @@ + .text +insn_rex2: + .insn {rex2} 0x0f01/0, %eax + .insn {rex2} 0x0f38/0, %eax + .insn {rex2} 0x0f3801/0, %eax + .insn {rex2} 0x0f3901/0, %eax + .insn {rex2} 0x0f3a01/0, $0xCC, %eax + + .insn {rex2} 0x0f01/0, %rax + .insn {rex2} 0x0f38/0, %rax + .insn {rex2} 0x0f3801/0, %rax + .insn {rex2} 0x0f3901/0, %rax + .insn {rex2} 0x0f3a01/0, $0xCC, %rax + + .insn {rex2} 0x0f01/0, %r8 + .insn {rex2} 0x0f38/0, %r8 + .insn {rex2} 0x0f3801/0, %r8 + .insn {rex2} 0x0f3901/0, %r8 + .insn {rex2} 0x0f3a01/0, $0xCC, %r8 + + .insn 0x0f01/0, %r16 + .insn 0x0f38/0, %r16 + .insn 0x0f3801/0, %r16 + .insn 0x0f3901/0, %r16 + .insn 0x0f3a01/0, $0xCC, %r16 --- a/gas/testsuite/gas/i386/x86-64.exp +++ b/gas/testsuite/gas/i386/x86-64.exp @@ -126,6 +126,7 @@ run_dump_test "x86-64-sysenter-mixed" run_dump_test "x86-64-sysenter-amd" run_list_test "x86-64-sysenter-amd" "-mamd64" run_dump_test "insn-64" +run_list_test "insn-rex2" "-aln --divide" run_dump_test "noreg64" run_list_test "noreg64" run_dump_test "noreg64-data16"