From patchwork Fri Jan 13 11:11:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 43174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp208739wrt; Fri, 13 Jan 2023 03:12:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXt8ySHo2J+bcXkbnINeT6QSgqG8JCAC1PtoM5GFuP7Qa5tVxg7Aq8lCkWfdBwSaZYS8/gLR X-Received: by 2002:a17:906:6881:b0:84d:4d6c:a462 with SMTP id n1-20020a170906688100b0084d4d6ca462mr14259579ejr.25.1673608335021; Fri, 13 Jan 2023 03:12:15 -0800 (PST) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hp26-20020a1709073e1a00b0086b9409d5e8si411611ejc.360.2023.01.13.03.12.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 03:12:15 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=yOfAlXNn; arc=fail (signature failed); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CEED9385B535 for ; Fri, 13 Jan 2023 11:12:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEED9385B535 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673608333; bh=xTrDIJgn251L10nRVJVOuiKM9eIZ4y6p1iugYfL/5yQ=; h=Date:Subject:To:Cc:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=yOfAlXNn0L7iQmBBiKPm+uE7oQW3SU9KsRpfCw+ajTcEq6g7rDOWRzj+hRZiw3F6u tbwGtHkPxcorzqdiWMy0mVK/1M5Q1z3N2LqwSm6NZM4jvQAoa07IEmuYHOw5doCKnc K2wHa1NwvClE4QxMk/toTN4KwS3VE/NQ69Ygfx0U= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2063.outbound.protection.outlook.com [40.107.22.63]) by sourceware.org (Postfix) with ESMTPS id 3B4D93854830 for ; Fri, 13 Jan 2023 11:11:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B4D93854830 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kj2+4uIgyOPPxw2qfyEJmFbZVdhsBKql6dKIvQOH2gq0RS45/ZOrS19trIaKKL2oCizgThsM0OWzOCJujiy8Xqyjk+XKw8G1XGoAV7b7Gl05iV0dNN0DNlfy5B7TC79215mNMEQd21xp+/umkqipqwVe4W+c/bP926A8bw/3pY6yDC1NNK6J+3FmkAu1cABMKPdiyslLBxyrFnHfVEM8QETW41N1dNK7ghsog0647BmYpz69JUQwXy40bYisn51ah0q3hBroYfyfN8JKrA94ELn5KWwAGYCMYiZ3eh+9dOVpjKI8jyh60+GARDvKdPnjrsuzQu+cmS2MAFUOb3beJQ== 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=xTrDIJgn251L10nRVJVOuiKM9eIZ4y6p1iugYfL/5yQ=; b=edIWPJhZ1MUBt1S9wFOooX3eeOy2NymBZsGCXedWbJQreNrR9Wv+eRrMEgbVTp5JeTqiN0t+WHCu8BE5H0pp0FFPoBSntvuSh2bJlMTPtQrzs9BJDLVI6cwdXnO/39VcWXDt9O4ItoBFwYLQ2F6F6/UH1RAk2rXuHXDfVpbqmlGkLgZq5+Ndt4AMJD8dEu1c2qQ8/3mny+IMP1UxEDcb0XGDkDiY7dRKCDjycY1Dn3i89GRvn+OGc8eaKpG+BuPd2qhSytZHOrhP9Sd00S0nLMGI1ETR6XD/wHK7dxePVkuOfHaSnVSdgC0MHeLgQ+FjvadwtItdvcS9F1cdH903xA== 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 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by AS8PR04MB8401.eurprd04.prod.outlook.com (2603:10a6:20b:3f3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13; Fri, 13 Jan 2023 11:11:39 +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; Fri, 13 Jan 2023 11:11:39 +0000 Message-ID: <1d538fdf-536a-37b0-556b-b4ca86b0a090@suse.com> Date: Fri, 13 Jan 2023 12:11:37 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: [PATCH 8/8] x86: split i386-gen's opcode hash entry struct Content-Language: en-US To: Binutils Cc: "H.J. Lu" References: In-Reply-To: X-ClientProxiedBy: FR0P281CA0145.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:96::18) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|AS8PR04MB8401:EE_ X-MS-Office365-Filtering-Correlation-Id: bcd8b7ac-1456-42b9-30d9-08daf556f165 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w7WwOYcnbXvLQWfOLA8mUq/4vsEvhwHTkuPTx3BGs+2nT1Tc4PoOhF1wyqhp1KqWRvExat+iy4fkVirAT+r/VsERHnOb+QG7DoyHYjjpqJRqDjuOMb0NThCdoIJKBGNXQUNGgKnfdks6DeHHZYFmqd77JOn/6C8Sq9NLtT7P7gsgmvccjNafyz5LRqKxo6vsQTP6WEXtuBIui7TxrtdaVZWCr6G56vIkKf+TpBL4j7wlUnBa+ZGadsoJ2xhP15ORLX0E8BSmyDMDfGR54SVRNTg3+1V8CcpNcStjBZwFlPlO5d2pMP788ACHoDgD4oPnmL85GYSKf/3Ca3oYrTqh2WenHEq0bT9wsdRw/xuUbHxERfXrr+PQRQ167n/0qUFi3yROfZcTOG8tGVM+yfEdZ4tGi9rUcqXBfTuV4dMVcIJJkMOjzv16oVSnjjAGVlVLZV123X2tZ8fQloov/wgtVjSLSCIx6isydPtWDEjH+UzkeCrYLgVRX7FxDRha8odQH/WtWSMJTixTnv8obX+Z3abyGPJQmb1mm9dRwUpBXEAoli1iJsZL0yWLptqFcMMwUnueC/j3xmBuC0Rmf2oeNVenEBbveZaJVx4Cul7pR78iPeyTmIbkc6pExsqaA1kL27WnGHIIDdRKnK+zDdg7l57yCcnDrUDurdVsMDhXIvJKGMukzPjOyHRJyCCgwuNbuJ3hy3DKxq8V+DTvT4lw/etXxQrtuklk+rnGEnE4rMQ= 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)(136003)(39860400002)(346002)(366004)(396003)(376002)(451199015)(6486002)(86362001)(36756003)(478600001)(31696002)(6506007)(2616005)(26005)(38100700002)(6512007)(186003)(316002)(66946007)(66476007)(66556008)(8676002)(31686004)(6916009)(4326008)(5660300002)(2906002)(8936002)(41300700001)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?z5R4yiql2NOFmPwFEYRo9fMAHCD0?= =?utf-8?q?0UHMawJsqaHw6y9PvmQYTRUrjuXBoqNK9hWOoa5/4FjCS+EjvBaFX2dtTbqBOgQpI?= =?utf-8?q?sEt7RKQy2GOqN14KTzuzBgC13qEQa3f4f/m3cgJwBe1XIJzGomnSlCoaxFImCMEG7?= =?utf-8?q?dInu+1yfRoh+iyS1wBBN1iv6OFR02pUICkET20h2aPeBxlPzOQdpwHPw25lxGbVEu?= =?utf-8?q?8Juk6FA4pa5T59EXsFbp57xAPVrrV3u/pqWYkXyL9syqDqUe1cc3HDGqKcO9zur7j?= =?utf-8?q?xdXcPJoyh6ryESLTxUMqs/J80491PBVuWgGMnKcfEsgOXbYWEG4Y/QqWCbbNgdDcO?= =?utf-8?q?7AghPkZYXa6YOVXhKmcD15w5cFIcMyupIif1Iil7bxFwnWHoir7cTp39akBhOe0tu?= =?utf-8?q?h5Y+xYIbZDIe0EqejL8oS7YBdjLm9WPU0BvDq300XS4auLD5eM9Jodgcdef2WbWHb?= =?utf-8?q?PfOflGhXJWyMO22Q01vamwFs2sqWBntjCpMS4BqL5lkGF09/sXti4VS3K10p+qlxG?= =?utf-8?q?E5zmEv6sA/LQY40/uAgz02C5ZQBG+ThJyq6LB/VFUx70nVrXfn4KIX7BMuApkz6Vn?= =?utf-8?q?al2K4jsbB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GQ7vIpthMONCiTHfvYtN4Gv0YvIWOQ178VAd00BpqIJ0?= =?utf-8?q?eWb74BnwfYBx?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: bcd8b7ac-1456-42b9-30d9-08daf556f165 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2023 11:11:39.3529 (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: n0OB9rMCEr3g4ql7/S4XAX0jAiqpSHsP+vDwSCzoI2j2FAgEZxVnrLlkP2fBstL29mwqfc/orE5ta1pphGn03A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8401 X-Spam-Status: No, score=-3028.7 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 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.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jan Beulich via Binutils From: Jan Beulich Reply-To: Jan Beulich Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754905533345622747?= X-GMAIL-MSGID: =?utf-8?q?1754905533345622747?= All glibc malloc() implementations I've checked have a smallest allocation size worth of 3 pointers, with an increment worth of 2 pointers. Hence mnemonics with multiple templates can be stored more efficiently when maintaining the shared "name" field only in the actual hash entry. (To express the shared nature, also convert "name" to by pointer-to-const.) While doing the conversation also pull out common code from the involved if/else construct in expand_templates(). --- a/opcodes/i386-gen.c +++ b/opcodes/i386-gen.c @@ -1293,10 +1293,13 @@ output_i386_opcode (FILE *table, const c struct opcode_hash_entry { - struct opcode_hash_entry *next; - char *name; - char *opcode; - int lineno; + const char *name; + struct opcode_entry + { + struct opcode_entry *next; + char *opcode; + int lineno; + } entry; }; /* Calculate the hash value of an opcode hash entry P. */ @@ -1432,7 +1435,8 @@ expand_templates (char *name, const char { static unsigned int idx, opcode_array_size; struct opcode_hash_entry **opcode_array = *opcode_array_p; - struct opcode_hash_entry **hash_slot, **entry; + struct opcode_hash_entry **hash_slot; + struct opcode_entry *entry; char *ptr1 = strchr(name, '<'), *ptr2; if (ptr1 == NULL) @@ -1458,26 +1462,25 @@ expand_templates (char *name, const char opcode_array[idx] = (struct opcode_hash_entry *) xmalloc (sizeof (struct opcode_hash_entry)); - opcode_array[idx]->next = NULL; opcode_array[idx]->name = xstrdup (name); - opcode_array[idx]->opcode = xstrdup (str); - opcode_array[idx]->lineno = lineno; *hash_slot = opcode_array[idx]; + entry = &opcode_array[idx]->entry; idx++; } else { /* Append it to the existing one. */ - entry = hash_slot; - while ((*entry) != NULL) - entry = &(*entry)->next; - *entry = (struct opcode_hash_entry *) - xmalloc (sizeof (struct opcode_hash_entry)); - (*entry)->next = NULL; - (*entry)->name = (*hash_slot)->name; - (*entry)->opcode = xstrdup (str); - (*entry)->lineno = lineno; + struct opcode_entry **entryp = &(*hash_slot)->entry.next; + + while (*entryp != NULL) + entryp = &(*entryp)->next; + entry = (struct opcode_entry *)xmalloc (sizeof (struct opcode_entry)); + *entryp = entry; } + + entry->next = NULL; + entry->opcode = xstrdup (str); + entry->lineno = lineno; } else if ((ptr2 = strchr(ptr1 + 1, '>')) == NULL) fail ("%s: %d: missing '>'\n", filename, lineno); @@ -1599,7 +1602,7 @@ process_i386_opcodes (FILE *table) char buf[2048]; unsigned int i, j, nr, offs; size_t l; - char *str, *p, *last, *name; + char *str, *p, *last; htab_t opcode_hash_table; struct opcode_hash_entry **opcode_array = NULL; int lineno = 0, marker = 0; @@ -1619,6 +1622,8 @@ process_i386_opcodes (FILE *table) /* Put everything on opcode array. */ while (!feof (fp)) { + char *name; + if (fgets (buf, sizeof (buf), fp) == NULL) break; @@ -1700,11 +1705,11 @@ process_i386_opcodes (FILE *table) /* Process opcode array. */ for (j = 0; j < i; j++) { - struct opcode_hash_entry *next; + const char *name = opcode_array[j]->name; + struct opcode_entry *next; - for (next = opcode_array[j]; next; next = next->next) + for (next = &opcode_array[j]->entry; next; next = next->next) { - name = next->name; str = next->opcode; lineno = next->lineno; last = str + strlen (str); @@ -1723,7 +1728,7 @@ process_i386_opcodes (FILE *table) for (nr = j = 0; j < i; j++) { - struct opcode_hash_entry *next = opcode_array[j]; + struct opcode_entry *next = &opcode_array[j]->entry; do { @@ -1753,10 +1758,10 @@ process_i386_opcodes (FILE *table) str = NULL; for (l = strlen (opcode_array[offs = j = 0]->name); j < i; j++) { + const char *name = opcode_array[j]->name; const char *next = NULL; size_t l1 = j + 1 < i ? strlen(next = opcode_array[j + 1]->name) : 0; - name = opcode_array[j]->name; if (str == NULL) str = mkident (name); if (l < l1 && !strcmp(name, next + l1 - l))