From patchwork Thu Feb 14 22:59:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10814007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 704851399 for ; Thu, 14 Feb 2019 23:22:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F3EF2F3C1 for ; Thu, 14 Feb 2019 23:22:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5380A2F3C7; Thu, 14 Feb 2019 23:22:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,FROM_LOCAL_NOVOWEL,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E29B02F3C1 for ; Thu, 14 Feb 2019 23:22:19 +0000 (UTC) Received: from localhost ([127.0.0.1]:56610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guQKh-0003zg-05 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Feb 2019 18:22:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guQ8v-00034j-7s for qemu-devel@nongnu.org; Thu, 14 Feb 2019 18:10:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1guQ05-00054W-8Y for qemu-devel@nongnu.org; Thu, 14 Feb 2019 18:01:02 -0500 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]:33729) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1guQ03-0004us-D2 for qemu-devel@nongnu.org; Thu, 14 Feb 2019 18:00:59 -0500 Received: by mail-lj1-x241.google.com with SMTP id f24-v6so6762953ljk.0 for ; Thu, 14 Feb 2019 15:00:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=e943WlHW5z8ipEKUYhBhoIuaS8/+dToXV2CJYGVYCqY=; b=sXeXa09P9v7/NZx6VLQ9ErLH46hIJBc0Gtg9HYHao/9JYoFC+3JnvBsFVFQvleGeAR MI9HaKV4Zf/CVtsFVXuruVUBEho6OkHLpDZQPfdXraYcIJ7GycoSu7Vj2cF4mB4NP7G4 E46LQdBjU88e52hYuvVeD0zCR6osT6OBclz608o9Rmop/zpndPKg+sFFECoauAgarhhL lGTX/4bvRoXLmCf6l+jY0gEOUGfpgEE6FH+Fo81ETKelABArJ5lzdo2cm0VwiEx2pcsf yhvAHUyyDOZVyriILNeBqAMZMRniOuzyyCrXwU6q6/jBDs7ZyO9UozCX22OYQW18PU6J adSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=e943WlHW5z8ipEKUYhBhoIuaS8/+dToXV2CJYGVYCqY=; b=qASTrf8nnm+OR09327nSiK2usTmA/gSpwfabxD/CPx7XEylYeqdbY18bFUP1WWHBfs Wdp4QdWLKqTbd1+/HtmrLvtbtY0pxek5IxaUoFVK6PFm7zwin2Bo7Uzst7hd/dIax6Wk YDG/BbqvVO4aWszcXkfRvg2sGyaBrUADAl0kCWWZ5/hwotNcsvLUB/9sLZgVm1I0HRI9 zK/hmuiP3Xr7owWjrIo2o0ar6rmeG6clzWckJ0OGzawRV4O9vem113FCRqZKe0JS3//F qhsbaa2qKH2kXNiY4QAgMKjmtbzlbiTkYrizDm/KW+5770x2doG8mTCrGb7pck7mF3YH MwlA== X-Gm-Message-State: AHQUAuaWKhWeUgsYK3tpNdY9y+bsmznasV/UkkWE8qu2yAALkoP/zj3D N9gtQo4shS3RKZ32fu5jWL37T7VhPsk= X-Google-Smtp-Source: AHgI3IYfNG7dsGidnZNRcPRbp4MsJlCuUeq+DKj1AK/b7YYuJFIueNGt9GwrwE8k6DyKpuDQr2MjVA== X-Received: by 2002:a2e:9a8b:: with SMTP id p11mr3824753lji.66.1550185244048; Thu, 14 Feb 2019 15:00:44 -0800 (PST) Received: from octofox.cadence.com (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id h123sm172384lfh.26.2019.02.14.15.00.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 15:00:43 -0800 (PST) From: Max Filippov To: qemu-devel@nongnu.org Date: Thu, 14 Feb 2019 14:59:49 -0800 Message-Id: <20190214230000.24894-3-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190214230000.24894-1-jcmvbkbc@gmail.com> References: <20190214230000.24894-1-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::241 Subject: [Qemu-devel] [PATCH 02/13] target/xtensa: don't require opcode table sorting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Filippov , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Requirement for alphabetical opcode sorting in opcode tables is awkward and does not allow sharing implementation between multiple opcodes. Use hash tables to find opcodes by name. Move implementation from the translate.c to the helper.c to its only user and remove declaration from the cpu.h Signed-off-by: Max Filippov --- target/xtensa/cpu.h | 2 -- target/xtensa/helper.c | 42 ++++++++++++++++++++++++++++++++++++++++++ target/xtensa/translate.c | 14 -------------- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index 47d80a59e2f5..2765665ceca6 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -587,8 +587,6 @@ static inline void xtensa_select_static_vectors(CPUXtensaState *env, env->static_vectors = n; } void xtensa_runstall(CPUXtensaState *env, bool runstall); -XtensaOpcodeOps *xtensa_find_opcode_ops(const XtensaOpcodeTranslators *t, - const char *opcode); #define XTENSA_OPTION_BIT(opt) (((uint64_t)1) << (opt)) #define XTENSA_OPTION_ALL (~(uint64_t)0) diff --git a/target/xtensa/helper.c b/target/xtensa/helper.c index 321ca4295521..57709fc20caf 100644 --- a/target/xtensa/helper.c +++ b/target/xtensa/helper.c @@ -30,10 +30,52 @@ #include "exec/exec-all.h" #include "exec/gdbstub.h" #include "exec/helper-proto.h" +#include "qemu/error-report.h" #include "qemu/host-utils.h" static struct XtensaConfigList *xtensa_cores; +static void add_translator_to_hash(GHashTable *translator, + const char *name, + const XtensaOpcodeOps *opcode) +{ + if (!g_hash_table_insert(translator, (void *)name, (void *)opcode)) { + error_report("Multiple definitions of '%s' opcode in a single table", + name); + } +} + +static GHashTable *hash_opcode_translators(const XtensaOpcodeTranslators *t) +{ + unsigned i, j; + GHashTable *translator = g_hash_table_new(g_str_hash, g_str_equal); + + for (i = 0; i < t->num_opcodes; ++i) { + add_translator_to_hash(translator, + (void *)t->opcode[i].name, + (void *)(t->opcode + i)); + } + return translator; +} + +static XtensaOpcodeOps * +xtensa_find_opcode_ops(const XtensaOpcodeTranslators *t, + const char *name) +{ + static GHashTable *translators; + GHashTable *translator; + + if (translators == NULL) { + translators = g_hash_table_new(g_direct_hash, g_direct_equal); + } + translator = g_hash_table_lookup(translators, t); + if (translator == NULL) { + translator = hash_opcode_translators(t); + g_hash_table_insert(translators, (void *)t, translator); + } + return g_hash_table_lookup(translator, name); +} + static void init_libisa(XtensaConfig *config) { unsigned i, j; diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 62283cd1ccc8..26342aaa1f82 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -1274,20 +1274,6 @@ void restore_state_to_opc(CPUXtensaState *env, TranslationBlock *tb, env->pc = data[0]; } -static int compare_opcode_ops(const void *a, const void *b) -{ - return strcmp((const char *)a, - ((const XtensaOpcodeOps *)b)->name); -} - -XtensaOpcodeOps * -xtensa_find_opcode_ops(const XtensaOpcodeTranslators *t, - const char *name) -{ - return bsearch(name, t->opcode, t->num_opcodes, - sizeof(XtensaOpcodeOps), compare_opcode_ops); -} - static void translate_abs(DisasContext *dc, const uint32_t arg[], const uint32_t par[]) {