From patchwork Fri Oct 18 13:38:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 99188 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 AABE2385842A for ; Fri, 18 Oct 2024 13:39:00 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 1823D3858C3A for ; Fri, 18 Oct 2024 13:38:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1823D3858C3A 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 1823D3858C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729258702; cv=none; b=CfKqfcUcr2r4jto1mkHGou/oLEby1HA7TSW+KNeOesXthOiQvO3qL3NeAJZ8dNCIDj3g1FEyOyhK8laRtXAmv95Pn//RjtXqrC1vNUQQ4d5J8mvrnEhCsyDDOInZZLiJokA8XU7RHSBznzfQ7Zozhyi0pqy1DdvpnqB6JfWWGl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729258702; c=relaxed/simple; bh=bEw1vsUjOa81ZfkAKev9X50K0se98S1DkxXdmSMeo50=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=hsnj1FBvwgmbDO6MNgRxilBxTTFBrokOuX1+40ArwEDClxzAKeg6YpdBizP39HoUoPVKxOwQNBk6H9VD/huJfitOe0KpylHRnr34EQeHyzUufOZzM0evwyYhJrfTeREke+Xs/6iH0weK5XuwgxTF4bpDjd5w+uJ4yADG0ADHgm4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-43163667f0eso4751155e9.0 for ; Fri, 18 Oct 2024 06:38:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1729258699; x=1729863499; darn=sourceware.org; h=content-transfer-encoding:autocrypt:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=yFC178O/S7O0F5r4HVnWa4FUUNlmg/ojnT+zOIsE4w4=; b=Uwt+txEPNAPtLZk85iKgIqPNJdsXQ6VOCLPzXgdMJm8RwQbnjvuVaIueUQ88ujQDOy oHj4UndeGDVAXt4KLTjq26M0oz3/01pwYxlvrK98J1q3wuQ++FXcbR+fxlQBU/cWIVn2 ELTSZsRTU9gydMC+kAdFPv1jn96WKRs8Y9G0J6peapjFM2OOGEA3NAcDKX+MgOK5EJks rf2bl0r4owOkHsEWQUSqS15EKnSjVIDMAfB4NUP7BfnOpcg9SxbIi1cjsVQ/YlcrZ1BF GwEnXVgBx+0uYLsG3cMyOi5FyIn1MzzZHYpPDCj7l0KXcOnTmJi/fOOmTdy9oANWELge blMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729258699; x=1729863499; h=content-transfer-encoding:autocrypt:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yFC178O/S7O0F5r4HVnWa4FUUNlmg/ojnT+zOIsE4w4=; b=D7xm/UbNm1+dO4UMiPTV8f6S8YiO5kJSpDwKmQfpxTEEyVftm30qCSJjxScbHr9BLi ifsGdZdGbbjVGUeSXPxNkScKxPYHzMszObuUZjZEvqO2NSXDZlRua044ro4mi5HyVW9h 410+M2rnmfwDY1fTEKgP95KrGBW6HcE6hHglYFZSiBP83l7hrJSEdZ/oQVGpXnC3NoZ8 oV+HPJV6/skE+Le/koHQRAuID7xX46mYiNpTyX3Pw9QNGjdEBF6qLt91qlEFDCRMc2qR jUJqloL5OwD9+4iltlI9mMm5NGQi+qVgd80GT4huFCoQXpOkAdEWLQR031CEDrPvp/IN CltA== X-Gm-Message-State: AOJu0YwRVL0tnl97Yew0g2jTDcz+L5nRcVeiqUOAuDp/TxYH0BmBufm7 pHDnOXz1Pq6EX6MMdfVdiggCohhbm9iF0BbDw9P65C+YU0h1Z4iV/Gl2Oxqlq0WmZ+IbCxFxfUg = X-Google-Smtp-Source: AGHT+IEG1fSomRuUgmppDz5i+75O9F8tDcQ/0SZCH2UWdmNKb4lTSte2cOh+mD/UIO573mUPLJejyw== X-Received: by 2002:a05:600c:1d27:b0:431:5847:f63f with SMTP id 5b1f17b1804b1-4316164ac7amr18404015e9.13.1729258698636; Fri, 18 Oct 2024 06:38:18 -0700 (PDT) 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 5b1f17b1804b1-431606d5910sm27643885e9.43.2024.10.18.06.38.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Oct 2024 06:38:18 -0700 (PDT) Message-ID: <56c55dba-6b9a-414a-93ac-6ec6592ce3be@suse.com> Date: Fri, 18 Oct 2024 15:38:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Binutils Cc: "H.J. Lu" From: Jan Beulich Subject: [PATCH] x86: add a helper to copy insn operand info Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGW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wIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL X-Spam-Status: No, score=-3023.1 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 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 We're doing such in fairly many places, and yet more are likely to appear; centralize the logic, much like we already have swap_2_operands(). While there also correct mis-indentation in adjacent code in process_operands(). --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -172,6 +172,7 @@ static int i386_intel_parse_name (const static const reg_entry *parse_register (const char *, char **); static const char *parse_insn (const char *, char *, enum parse_mode); static char *parse_operands (char *, const char *); +static void copy_operand (unsigned int, unsigned int); static void swap_operands (void); static void swap_2_operands (unsigned int, unsigned int); static enum i386_flag_code i386_addressing_mode (void); @@ -5149,17 +5150,11 @@ optimize_encoding (void) i.tm.base_opcode = 0x00; i.tm.extension_opcode = None; if (i.operands >= 2) - { - i.tm.operand_types[0] = i.tm.operand_types[1]; - i.op[0].regs = i.op[1].regs; - i.types[0] = i.types[1]; - } + copy_operand (0, 1); else { /* Legacy form with omitted shift count operand. */ - i.tm.operand_types[1] = i.tm.operand_types[0]; - i.op[1].regs = i.op[0].regs; - i.types[1] = i.types[0]; + copy_operand (1, 0); i.operands = 2; } i.reg_operands++; @@ -5445,10 +5440,7 @@ optimize_encoding (void) i.reg_operands = 3; i.tm.operands = 3; - i.op[2].regs = i.op[0].regs; - i.types[2] = i.types[0]; - i.flags[2] = i.flags[0]; - i.tm.operand_types[2] = i.tm.operand_types[0]; + copy_operand (2, 0); i.tm.opcode_modifier.sse2avx = 0; } @@ -5492,9 +5484,7 @@ optimize_encoding (void) i.tm.extension_opcode = None; if (i.tm.opcode_modifier.vexvvvv) i.tm.opcode_modifier.vexvvvv = VexVVVV_SRC1; - i.tm.operand_types[0] = i.tm.operand_types[1]; - i.op[0].regs = i.op[1].regs; - i.types[0] = i.types[1]; + copy_operand (0, 1); i.reg_operands++; i.imm_operands = 0; } @@ -5518,11 +5508,7 @@ optimize_encoding (void) ++i.reg_operands; ++i.tm.operands; - i.op[2].regs = i.op[0].regs; - i.types[2] = i.types[0]; - i.flags[2] = i.flags[0]; - i.tm.operand_types[2] = i.tm.operand_types[0]; - + copy_operand (2, 0); swap_2_operands (1, 2); } else if (i.tm.base_opcode == 0x16 @@ -5550,16 +5536,8 @@ optimize_encoding (void) = i.tm.opcode_modifier.sse2avx ? VEXW0 : VEXWIG; } - i.op[0].regs = i.op[1].regs; - i.types[0] = i.types[1]; - i.flags[0] = i.flags[1]; - i.tm.operand_types[0] = i.tm.operand_types[1]; - - i.op[1].regs = i.op[2].regs; - i.types[1] = i.types[2]; - i.flags[1] = i.flags[2]; - i.reloc[1] = i.reloc[2]; - i.tm.operand_types[1] = i.tm.operand_types[2]; + copy_operand (0, 1); + copy_operand (1, 2); i.operands = 2; i.imm_operands = 0; @@ -5586,16 +5564,8 @@ optimize_encoding (void) i.tm.opcode_modifier.opcodeprefix = PREFIX_0XF3; } - i.op[0].regs = i.op[1].regs; - i.types[0] = i.types[1]; - i.flags[0] = i.flags[1]; - i.tm.operand_types[0] = i.tm.operand_types[1]; - - i.op[1].regs = i.op[2].regs; - i.types[1] = i.types[2]; - i.flags[1] = i.flags[2]; - i.reloc[1] = i.reloc[2]; - i.tm.operand_types[1] = i.tm.operand_types[2]; + copy_operand (0, 1); + copy_operand (1, 2); i.operands = 2; i.imm_operands = 0; @@ -5660,16 +5630,8 @@ optimize_encoding (void) if (i.tm.opcode_modifier.vex) i.tm.opcode_modifier.vexw = VEXWIG; - i.op[0].regs = i.op[1].regs; - i.types[0] = i.types[1]; - i.flags[0] = i.flags[1]; - i.tm.operand_types[0] = i.tm.operand_types[1]; - - i.op[1].regs = i.op[2].regs; - i.types[1] = i.types[2]; - i.flags[1] = i.flags[2]; - i.reloc[1] = i.reloc[2]; - i.tm.operand_types[1] = i.tm.operand_types[2]; + copy_operand (0, 1); + copy_operand (1, 2); i.operands = 2; i.imm_operands = 0; @@ -5699,20 +5661,9 @@ optimize_encoding (void) --i.operands; - i.op[i.operands - 1].regs = i.op[i.operands].regs; - i.types[i.operands - 1] = i.types[i.operands]; - i.flags[i.operands - 1] = i.flags[i.operands]; - i.tm.operand_types[i.operands - 1] = i.tm.operand_types[i.operands]; - - i.op[1].regs = i.op[i.operands - 1].regs; - i.types[1] = i.types[i.operands - 1]; - i.flags[1] = i.flags[i.operands - 1]; - i.tm.operand_types[1] = i.tm.operand_types[i.operands - 1]; - - i.op[0].regs = i.op[1].regs; - i.types[0] = i.types[1]; - i.flags[0] = i.flags[1]; - i.tm.operand_types[0] = i.tm.operand_types[1]; + copy_operand (i.operands - 1, i.operands); + copy_operand (1, i.operands - 1); + copy_operand (0, 1); /* Switch from EVEX to VEX encoding if possible. Sadly we can't (always) tell use of the {evex} pseudo-prefix (which otherwise @@ -5742,30 +5693,15 @@ optimize_encoding (void) i.tm.opcode_modifier.opcodeprefix = PREFIX_0XF3; if (i.op[0].imms->X_add_number == 0) - { - i.op[0].regs = i.op[1].regs; - --i.operands; - } + --i.operands; else { - i.op[0].disps = i.op[1].disps; - i.reloc[0] = i.reloc[1]; i.operands = 2; i.tm.opcode_modifier.vexvvvv = 0; } - i.types[0] = i.types[1]; - i.flags[0] = i.flags[1]; - i.tm.operand_types[0] = i.tm.operand_types[1]; - - i.op[1].regs = i.op[2].regs; - i.types[1] = i.types[2]; - i.flags[1] = i.flags[2]; - i.tm.operand_types[1] = i.tm.operand_types[2]; - - i.op[2].regs = i.op[3].regs; - i.types[2] = i.types[3]; - i.flags[2] = i.flags[3]; - i.tm.operand_types[2] = i.tm.operand_types[3]; + copy_operand (0, 1); + copy_operand (1, 2); + copy_operand (2, 3); } i.imm_operands = 0; @@ -5858,16 +5794,8 @@ optimize_nf_encoding (void) = (i.op[0].imms->X_add_number == 1) != (i.tm.extension_opcode == 0); i.tm.opcode_modifier.w = 1; - i.types[0] = i.types[1]; - i.types[1] = i.types[2]; - i.tm.operand_types[0] = i.tm.operand_types[1]; - i.tm.operand_types[1] = i.tm.operand_types[2]; - i.op[0] = i.op[1]; - i.op[1] = i.op[2]; - i.flags[0] = i.flags[1]; - i.flags[1] = i.flags[2]; - i.reloc[0] = i.reloc[1]; - i.reloc[1] = NO_RELOC; + copy_operand (0, 1); + copy_operand (1, 2); i.imm_operands = 0; --i.operands; @@ -5956,9 +5884,7 @@ optimize_nf_encoding (void) i.tm.opcode_modifier.vexvvvv = VexVVVV_DST; i.operands = 3; i.reg_operands = 2; - i.op[2].regs = i.op[1].regs; - i.tm.operand_types[2] = i.tm.operand_types[1]; - i.types[2] = i.types[1]; + copy_operand (2, 1); } } @@ -6150,9 +6076,7 @@ optimize_nf_encoding (void) i.op[0].disps = NULL; i.flags[0] = Operand_Mem; - i.tm.operand_types[1] = i.tm.operand_types[i.operands - 1]; - i.op[1].regs = i.op[i.operands - 1].regs; - i.types[1] = i.types[i.operands - 1]; + copy_operand (1, i.operands - 1); i.operands = 2; i.mem_operands = i.reg_operands = 1; @@ -6213,10 +6137,8 @@ optimize_nf_encoding (void) */ if (i.operands == 2) { - i.tm.operand_types[2] = i.tm.operand_types[1]; + copy_operand (2, 1); i.tm.operand_types[2].bitfield.baseindex = 0; - i.op[2].regs = i.op[1].regs; - i.types[2] = i.types[1]; i.reg_operands = 2; i.operands = 3; } @@ -8116,6 +8038,19 @@ parse_operands (char *l, const char *mne } static void +copy_operand (unsigned int to, unsigned int from) +{ + i.types[to] = i.types[from]; + i.tm.operand_types[to] = i.tm.operand_types[from]; + i.flags[to] = i.flags[from]; + i.op[to] = i.op[from]; + i.reloc[to] = i.reloc[from]; + i.imm_bits[to] = i.imm_bits[from]; + /* Note: i.mask and i.broadcast aren't handled here, as what (if + anything) to do there depends on context. */ +} + +static void swap_2_operands (unsigned int xchg1, unsigned int xchg2) { union i386_op temp_op; @@ -10689,11 +10624,8 @@ process_operands (void) number 0. */ if (i.tm.mnem_off == MN_tilezero) { - i.op[1].regs = i.op[0].regs; + copy_operand (1, 0); i.op[0].regs -= i.op[0].regs->reg_num; - i.types[1] = i.types[0]; - i.tm.operand_types[1] = i.tm.operand_types[0]; - i.flags[1] = i.flags[0]; i.operands++; i.reg_operands++; i.tm.operands++; @@ -10731,12 +10663,7 @@ process_operands (void) /* Add the implicit xmm0 for instructions with VEX prefix and 3 sources. */ for (j = i.operands; j > 0; j--) - { - i.op[j] = i.op[j - 1]; - i.types[j] = i.types[j - 1]; - i.tm.operand_types[j] = i.tm.operand_types[j - 1]; - i.flags[j] = i.flags[j - 1]; - } + copy_operand (j, j - 1); i.op[0].regs = (const reg_entry *) str_hash_find (reg_hash, "xmm0"); i.types[0] = regxmm; @@ -10748,10 +10675,6 @@ process_operands (void) dupl++; dest++; - i.op[dupl] = i.op[dest]; - i.types[dupl] = i.types[dest]; - i.tm.operand_types[dupl] = i.tm.operand_types[dest]; - i.flags[dupl] = i.flags[dest]; } else { @@ -10759,15 +10682,12 @@ process_operands (void) i.operands++; i.reg_operands++; i.tm.operands++; - - i.op[dupl] = i.op[dest]; - i.types[dupl] = i.types[dest]; - i.tm.operand_types[dupl] = i.tm.operand_types[dest]; - i.flags[dupl] = i.flags[dest]; } - if (i.tm.opcode_modifier.immext) - process_immext (); + copy_operand (dupl, dest); + + if (i.tm.opcode_modifier.immext) + process_immext (); } else if (i.tm.operand_types[0].bitfield.instance == Accum && i.tm.opcode_modifier.modrm) @@ -10775,16 +10695,7 @@ process_operands (void) unsigned int j; for (j = 1; j < i.operands; j++) - { - i.op[j - 1] = i.op[j]; - i.types[j - 1] = i.types[j]; - - /* We need to adjust fields in i.tm since they are used by - build_modrm_byte. */ - i.tm.operand_types [j - 1] = i.tm.operand_types [j]; - - i.flags[j - 1] = i.flags[j]; - } + copy_operand (j - 1, j); /* No adjustment to i.reg_operands: This was already done at the top of the function. */