From nobody Thu Nov 6 10:37:33 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540489832865916.6233146338036; Thu, 25 Oct 2018 10:50:32 -0700 (PDT) Received: from localhost ([::1]:56154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjlw-0000q2-FQ for importer@patchew.org; Thu, 25 Oct 2018 13:50:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjKp-0006hw-BO for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:22:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFjJl-0008PR-C8 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:11 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:33175) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFjJl-0008Oz-4B for qemu-devel@nongnu.org; Thu, 25 Oct 2018 13:21:09 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 77DCA21D40; Thu, 25 Oct 2018 13:21:08 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 25 Oct 2018 13:21:08 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id F04A3E4A48; Thu, 25 Oct 2018 13:21:07 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= mesmtp; bh=fYsZGRW0YHhXGv8pP27rHxV616A9uwdwPf1z17lY9Wc=; b=exkgU yxF8U6VJ+kjn+nm2ToVwu37W+bmSx0oCMWhTjtJHfY7xFahXxpEs0vHcxr5B/Zyi Io/lD4rv4YI4BHbS2qvWXahsT3gjglVIpC3tVs2iAAoykkkV+z4qIy6Ha5LmVKZD EXr5CJ/CloeOOpMQcQuEOJ+RxPQpVuA89XZPps= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=fYsZGRW0YHhXGv8pP27rHxV616A9u wdwPf1z17lY9Wc=; b=BWFpXVKgmiU7PxhbejjXT5C7kJo0oPx/QGBePYDg9gwgK cDAzCzEdI6hoXKYv56GqrdbA1hcuGZXXDA4nKiRhe7tNMjTLNFxcw/Aa5/sTY3lH h6+fkx8aHV1MBvcgPDQFNfyF1QIiqJlA+mnDc7fa+10TxOLTSWKJgCp47RI7j/2G YXGfc/Y/pCNrxidygQSCMnFtXOmR8IXM7BbL7dMQO2l8aE4GR0QCcNONAH1lx0gh YEtXE/qKd504nrk/IzEY0NF2rORx70UZEGUiCDeuAnDml+JjC9Q4rY2kwMlRWEec yLwrrM4vFDRogSfA85Qh2bpglCjZ09vLla0fR84FQ== X-ME-Sender: X-ME-Proxy: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 13:20:15 -0400 Message-Id: <20181025172057.20414-7-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025172057.20414-1-cota@braap.org> References: <20181025172057.20414-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [RFC 06/48] tcg: use QHT for helper_table 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: Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Pavel Dovgalyuk , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This will allow us to add TCG helpers at run-time. While at it, rename tcg_find_helper to tcg_helper_find for consistency with the added tcg_helper_foo functions. Signed-off-by: Emilio G. Cota Reviewed-by: Alex Benn=C3=A9e --- tcg/tcg.c | 59 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index e85133ef05..65da3c5dbf 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -33,6 +33,7 @@ #include "qemu/error-report.h" #include "qemu/cutils.h" #include "qemu/host-utils.h" +#include "qemu/xxhash.h" #include "qemu/timer.h" =20 /* Note: the long term plan is to reduce the dependencies on the QEMU @@ -879,13 +880,46 @@ typedef struct TCGHelperInfo { static const TCGHelperInfo all_helpers[] =3D { #include "exec/helper-tcg.h" }; -static GHashTable *helper_table; +static struct qht helper_table; +static bool helper_table_inited; =20 static int indirect_reg_alloc_order[ARRAY_SIZE(tcg_target_reg_alloc_order)= ]; static void process_op_defs(TCGContext *s); static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type, TCGReg reg, const char *name); =20 +static inline uint32_t tcg_helper_func_hash(const void *func) +{ + return qemu_xxhash2((uint64_t)func); +} + +static bool tcg_helper_cmp(const void *ap, const void *bp) +{ + const TCGHelperInfo *a =3D ap; + const TCGHelperInfo *b =3D bp; + + return a->func =3D=3D b->func && + a->flags =3D=3D b->flags && + a->sizemask =3D=3D b->sizemask && + !strcmp(a->name, b->name); +} + +static bool tcg_helper_lookup_cmp(const void *obj, const void *func) +{ + const TCGHelperInfo *info =3D obj; + + return info->func =3D=3D func; +} + +static void tcg_helper_insert(const TCGHelperInfo *info) +{ + uint32_t hash =3D tcg_helper_func_hash(info->func); + bool inserted; + + inserted =3D qht_insert(&helper_table, (void *)info, hash, NULL); + g_assert(inserted); +} + void tcg_context_init(TCGContext *s) { int op, total_args, n, i; @@ -919,13 +953,13 @@ void tcg_context_init(TCGContext *s) } =20 /* Register helpers. */ - /* Use g_direct_hash/equal for direct pointer comparisons on func. */ - helper_table =3D g_hash_table_new(NULL, NULL); + qht_init(&helper_table, tcg_helper_cmp, ARRAY_SIZE(all_helpers), + QHT_MODE_AUTO_RESIZE); =20 for (i =3D 0; i < ARRAY_SIZE(all_helpers); ++i) { - g_hash_table_insert(helper_table, (gpointer)all_helpers[i].func, - (gpointer)&all_helpers[i]); + tcg_helper_insert(&all_helpers[i]); } + helper_table_inited =3D true; =20 tcg_target_init(s); process_op_defs(s); @@ -1620,9 +1654,10 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nar= gs, TCGTemp **args) int i, real_args, nb_rets, pi; unsigned sizemask, flags; TCGHelperInfo *info; + uint32_t hash =3D tcg_helper_func_hash(func); TCGOp *op; =20 - info =3D g_hash_table_lookup(helper_table, (gpointer)func); + info =3D qht_lookup_custom(&helper_table, func, hash, tcg_helper_looku= p_cmp); flags =3D info->flags; sizemask =3D info->sizemask; =20 @@ -1825,11 +1860,15 @@ static char *tcg_get_arg_str(TCGContext *s, char *b= uf, } =20 /* Find helper name. */ -static inline const char *tcg_find_helper(TCGContext *s, uintptr_t val) +static inline const char *tcg_helper_find(TCGContext *s, uintptr_t val) { const char *ret =3D NULL; - if (helper_table) { - TCGHelperInfo *info =3D g_hash_table_lookup(helper_table, (gpointe= r)val); + if (helper_table_inited) { + uint32_t hash =3D tcg_helper_func_hash((void *)val); + TCGHelperInfo *info; + + info =3D qht_lookup_custom(&helper_table, (void *)val, hash, + tcg_helper_lookup_cmp); if (info) { ret =3D info->name; } @@ -1919,7 +1958,7 @@ void tcg_dump_ops(TCGContext *s) =20 /* function name, flags, out args */ col +=3D qemu_log(" %s %s,$0x%" TCG_PRIlx ",$%d", def->name, - tcg_find_helper(s, op->args[nb_oargs + nb_iarg= s]), + tcg_helper_find(s, op->args[nb_oargs + nb_iarg= s]), op->args[nb_oargs + nb_iargs + 1], nb_oargs); for (i =3D 0; i < nb_oargs; i++) { col +=3D qemu_log(",%s", tcg_get_arg_str(s, buf, sizeof(bu= f), --=20 2.17.1