From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id A77823858D37 for ; Mon, 21 Feb 2022 15:14:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A77823858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pf1-x430.google.com with SMTP id i21so9118602pfd.13 for ; Mon, 21 Feb 2022 07:14:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=W+4Uil3FHlY3ZIsqqZVoq1MOxka180B7M7JxhueNJmM=; b=bztVEf30bn0kRXm0MwfKU0ybnnptWhGakjRTP6i7f9KLOZ6GYD0pbbz0duCDgRTGiq khAHT1icQQCD3mxx3LJ3H//LI1e0dcJyeBza4DwxIn2y3w/0q5e+QjsGLVkRmUdLw9St xjjY1wNXnDk8DPYZ5HVChrx4oEczCP8v20XmdQWXK6aiaW3rYHB+QSO/lrTgLbLmH99A iDbgq4hVVlDQGRX4kyerx1sH8HGkGFI5FDct1ZmHSEs7Eco+cTDyvJjJRkBQJRYyX/EA KXagd+MzzIhgPgDTj3nKF8KsloXSTBWm7cQoIkI2D8VY3hiuwSnzqGal4EpVuNGFgYJg SZNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=W+4Uil3FHlY3ZIsqqZVoq1MOxka180B7M7JxhueNJmM=; b=fkx+rEwYJia+BeC/pLVbCM9m1U9ZVv3hiVJlhjDPoDnIVD8vVHgjt2vngehdDKJgx8 Dxal2xtpNDwjU57VJV9Wq209WRIuwmko3RqLVUt/MyzjonB3+AxtwYIdkVTMGW0c8hFD lElr/lX2mfb7hr6/BrJlYs+5HuwsFijuAGPExASkhc+j3E4W01A5gtIAOpHfQtbJ37GW TgCOtuZnGKhPLDRXj+JaMuA4otcq6PvvmaC99SquEkgA3nphtCtITNnuskmv/6w9f+yk drIIAmA4Cnjrwilzg7rvO7lcXKdziN0Um8WxP10Z/5YKoNYFi4H5/IzDERqWZzNiFQj0 UHKw== X-Gm-Message-State: AOAM532jmKwdJHoQqDl3xaAcR8cxWiZmTL3DkxV+4JTtHbALkxzcYWI2 pp7hxq6i4RStcHF31FEWdRmK5hy3fMzqjA== X-Google-Smtp-Source: ABdhPJw8VDB+2P4V3KIo9v5PuVY8OxO58gCOZoY7h5DgE81vo5T7G6HDsU3Jk0wdrR+OYRDsSIWMag== X-Received: by 2002:a63:8a43:0:b0:364:a57:2b76 with SMTP id y64-20020a638a43000000b003640a572b76mr16911773pgd.143.1645456476499; Mon, 21 Feb 2022 07:14:36 -0800 (PST) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id t15sm18596857pgc.49.2022.02.21.07.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 07:14:36 -0800 (PST) From: Kito Cheng To: binutils@sourceware.org, kito.cheng@gmail.com, jim.wilson.gcc@gmail.com, research_trasio@irq.a4lg.com, jbeulich@suse.com, philipp.tomsich@vrull.eu, palmer@dabbelt.com, nelson.chu@sifive.com, cmuellner@ventanamicro.com, jiawei@iscas.ac.cn Cc: Kito Cheng Subject: [PATCH v2] RISC-V: Maintain a string to hold the canonical order Date: Mon, 21 Feb 2022 23:14:31 +0800 Message-Id: <20220221151431.22634-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Mon, 21 Feb 2022 15:14:39 -0000 Using dummy entry in riscv_supported_std_ext cause confusing and wrongly support `b` and `k` extensions. bfd/ * elfxx-riscv.c (riscv_supported_std_ext): Drop unsupported extensions. (riscv_ext_canonical_order): New. (riscv_init_ext_order): Use riscv_ext_canonical_order rather than riscv_supported_std_ext to compute canonical order. V2 Changes: - Use `*ext` rather than `*ext != NULL` for checking is reach end of string. --- bfd/elfxx-riscv.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c index 9f52bb545ac..27d06d2fa3d 100644 --- a/bfd/elfxx-riscv.c +++ b/bfd/elfxx-riscv.c @@ -1163,17 +1163,10 @@ static struct riscv_supported_ext riscv_supported_std_ext[] = {"q", ISA_SPEC_CLASS_20191213, 2, 2, 0 }, {"q", ISA_SPEC_CLASS_20190608, 2, 2, 0 }, {"q", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, - {"l", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, {"c", ISA_SPEC_CLASS_20191213, 2, 0, 0 }, {"c", ISA_SPEC_CLASS_20190608, 2, 0, 0 }, {"c", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, - {"b", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, - {"k", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, - {"j", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, - {"t", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, - {"p", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, {"v", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, - {"n", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, {NULL, 0, 0, 0, 0} }; @@ -1341,6 +1334,9 @@ riscv_recognized_prefixed_ext (const char *ext) return false; } +/* Canonical order for single letter extensions. */ +static const char riscv_ext_canonical_order[] = "eigmafdqlcbjktpvn"; + /* Array is used to compare the orders of standard extensions quickly. */ static int riscv_ext_order[26] = {0}; @@ -1356,16 +1352,8 @@ riscv_init_ext_order (void) /* The orders of all standard extensions are positive. */ int order = 1; - int i = 0; - while (riscv_supported_std_ext[i].name != NULL) - { - const char *ext = riscv_supported_std_ext[i].name; - riscv_ext_order[(*ext - 'a')] = order++; - i++; - while (riscv_supported_std_ext[i].name - && strcmp (ext, riscv_supported_std_ext[i].name) == 0) - i++; - } + for (const char *ext = &riscv_ext_canonical_order[0]; *ext; ++ext) + riscv_ext_order[(*ext - 'a')] = order++; /* Some of the prefixed keyword are not single letter, so we set their prefixed orders in the riscv_compare_subsets directly, -- 2.34.0