From patchwork Tue Dec 13 21:25:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 633524 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3342644pvb; Tue, 13 Dec 2022 13:27:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf6wEsXti4TJrxBvE0sD7heg1vE5Ch6tojsVRisGgkdHuaxaFe9pzb2aRxPqNiNTehUvQgaj X-Received: by 2002:a05:622a:5913:b0:3a8:12fc:42f1 with SMTP id ga19-20020a05622a591300b003a812fc42f1mr20013858qtb.25.1670966845715; Tue, 13 Dec 2022 13:27:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670966845; cv=none; d=google.com; s=arc-20160816; b=mjnQ56jB13yDTcVCaSmm4ECQFX/vB7JkBJ7scWT/txnWCVmnGAndgI9TEzIrb0ks7w m1Q69eAz43ME9Gf/KuuAZ2pjU7EcYA71GUjpQDx6UGEHBrgnkwaUxppbk/GDeGTf0Mlj cYzvjQOV8dzIM1jtPGZ8C/eIK2sdd5IQat5psHnYAQpJd6ls7hpAbGZk/7IPOMXYxDKB 8btxKCGze48PdK7hPdqg0yova+2l0ksXg4v23gwzriJdk18fpjEShufrIoEvg2irXq/Y Lk2+UzqsszMgvszHvnx/J6gJ9OMnJKrPvEE+PkJvOVn4JOhiDkL6kwqL2U4U2WArKQ1/ 1AvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7o/uTcMX+wfPe8sHfpNtvUDYBEo1al5HudozA0YE4Gk=; b=x+qa41Qr8adO7Rp2fhpnWonVrguLtB4lnM/n6r998zST1zhuxMGz4V+jp4TlAHVBHC 3+xaLpXCv+0BwYRKgpOu8qU+kj2mjia59PdnfaJQCHENDJVE5F056XHisO2lQuRmN/fu 1VUUySIR1XeanJhfP2b8LNE86Q9wOZ15qggk5N5w6yeDooHveW+MhlKKegIQCyqqyTmO dzvlc2jzROl2cXnUlmmw9G61ZTvWM1fPCHPJyLyydabPvfDDQyH5IvCvQINuz+pehKoo cqwaiZM9Ml9exkE4KesHp9U4qYbyKpBV/e6FiKUB2PzppfEcsh2+vpMH/1cV8G44cjhQ nOuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xKI1dESW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ay15-20020a05622a228f00b003a515efad4fsi593977qtb.591.2022.12.13.13.27.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Dec 2022 13:27:25 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xKI1dESW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5Cmz-0000ik-3N; Tue, 13 Dec 2022 16:26:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5Cmx-0000hD-1D for qemu-devel@nongnu.org; Tue, 13 Dec 2022 16:26:11 -0500 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p5Cmv-0003D0-DP for qemu-devel@nongnu.org; Tue, 13 Dec 2022 16:26:10 -0500 Received: by mail-oi1-x236.google.com with SMTP id l127so1028567oia.8 for ; Tue, 13 Dec 2022 13:26:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7o/uTcMX+wfPe8sHfpNtvUDYBEo1al5HudozA0YE4Gk=; b=xKI1dESWd2pYyhQUd6WIcEc11vhstWeuqvoC4ADEoizfZaQp4fhZtQIGU5C7EW9lxC W0XtoyVsl99lAUdqMLcskX6a4yh65clr4GnEOya7ry+8gRMgGykNB/j2L9g9l0aovrZF Pbt0vY3vFmPb607r84Wed3xlB2xXcL4P3jM9mHIpIoKhqnHw8P40oYsZ2xjgVrH0cLfW Sh0215CnMGcqGI7sZZJxTFVmID7JwpUGqx1VCROGW6CBDcpNA+Fwam9/el7mAD71KUaN Y/VRRG9KtRYpPdY+19+XPyejEfCItYYA+4a/VjnzpYqdqdAydroGVdL5FJNxmiT7fBqa reSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7o/uTcMX+wfPe8sHfpNtvUDYBEo1al5HudozA0YE4Gk=; b=7WO1wBp/aaSIDYf/Mh05GsiudbssRaIX8++2fwgjNQDvY7TBglkmEMvl4/Fm/QqrAI 0KJXsRRi824NkXNWDrCYHPR8AIbh9y96Vrsbimx5FvRu9bwIbst4/7UzeO1yp6fhmy3m VotP0/L6bMIVddcgfy5MjWX4DUFjZIGVoy3yRjjOleS3ZP45TORN1cXMbGx62hiwZHR/ 9Ugm0933n+Ty3i/KRAClr+QxUeXHbe0FaYYqeRekQQUCTR8mENsP5k5PzrJcERqDq5r1 CcWtv1S64fi/+xyaLZf/vsLpapHsmUqNQe2urDhZ5o8/5yfeRGP4eKtGgTIerJgQrfpO OA3g== X-Gm-Message-State: ANoB5pmdU3pVPBtR+xgnWRI7BcTynxJ3rzGvapZvlGnI9DLvK9UUnT2F Ax6UuOV6mQEwkNa+D5KhoWKqYZGLMSGXsqemT8c= X-Received: by 2002:a05:6808:2085:b0:35e:915c:f0b4 with SMTP id s5-20020a056808208500b0035e915cf0b4mr5552667oiw.16.1670966768708; Tue, 13 Dec 2022 13:26:08 -0800 (PST) Received: from stoup.. ([2806:102e:18:2efc:c63:85ed:4256:8ad0]) by smtp.gmail.com with ESMTPSA id a7-20020a056808098700b0035c073aa0d8sm5006831oic.18.2022.12.13.13.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 13:26:08 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v4 24/27] tcg: Factor init_ffi_layouts() out of tcg_context_init() Date: Tue, 13 Dec 2022 15:25:38 -0600 Message-Id: <20221213212541.1820840-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221213212541.1820840-1-richard.henderson@linaro.org> References: <20221213212541.1820840-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::236; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x236.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Message-Id: <20221111074101.2069454-27-richard.henderson@linaro.org> [PMD: Split from bigger patch] Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20221122180804.938-3-philmd@linaro.org> --- tcg/tcg.c | 83 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 46cce228a0..3c3bb2d422 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -573,7 +573,49 @@ static ffi_type *typecode_to_ffi(int argmask) } g_assert_not_reached(); } -#endif + +static void init_ffi_layouts(void) +{ + /* g_direct_hash/equal for direct comparisons on uint32_t. */ + ffi_table = g_hash_table_new(NULL, NULL); + for (int i = 0; i < ARRAY_SIZE(all_helpers); ++i) { + uint32_t typemask = all_helpers[i].typemask; + gpointer hash = (gpointer)(uintptr_t)typemask; + struct { + ffi_cif cif; + ffi_type *args[]; + } *ca; + ffi_status status; + int nargs; + + if (g_hash_table_lookup(ffi_table, hash)) { + continue; + } + + /* Ignoring the return type, find the last non-zero field. */ + nargs = 32 - clz32(typemask >> 3); + nargs = DIV_ROUND_UP(nargs, 3); + + ca = g_malloc0(sizeof(*ca) + nargs * sizeof(ffi_type *)); + ca->cif.rtype = typecode_to_ffi(typemask & 7); + ca->cif.nargs = nargs; + + if (nargs != 0) { + ca->cif.arg_types = ca->args; + for (int j = 0; j < nargs; ++j) { + int typecode = extract32(typemask, (j + 1) * 3, 3); + ca->args[j] = typecode_to_ffi(typecode); + } + } + + status = ffi_prep_cif(&ca->cif, FFI_DEFAULT_ABI, nargs, + ca->cif.rtype, ca->cif.arg_types); + assert(status == FFI_OK); + + g_hash_table_insert(ffi_table, hash, (gpointer)&ca->cif); + } +} +#endif /* CONFIG_TCG_INTERPRETER */ typedef struct TCGCumulativeArgs { int arg_idx; /* tcg_gen_callN args[] */ @@ -768,44 +810,7 @@ static void tcg_context_init(unsigned max_cpus) } #ifdef CONFIG_TCG_INTERPRETER - /* g_direct_hash/equal for direct comparisons on uint32_t. */ - ffi_table = g_hash_table_new(NULL, NULL); - for (i = 0; i < ARRAY_SIZE(all_helpers); ++i) { - struct { - ffi_cif cif; - ffi_type *args[]; - } *ca; - uint32_t typemask = all_helpers[i].typemask; - gpointer hash = (gpointer)(uintptr_t)typemask; - ffi_status status; - int nargs; - - if (g_hash_table_lookup(ffi_table, hash)) { - continue; - } - - /* Ignoring the return type, find the last non-zero field. */ - nargs = 32 - clz32(typemask >> 3); - nargs = DIV_ROUND_UP(nargs, 3); - - ca = g_malloc0(sizeof(*ca) + nargs * sizeof(ffi_type *)); - ca->cif.rtype = typecode_to_ffi(typemask & 7); - ca->cif.nargs = nargs; - - if (nargs != 0) { - ca->cif.arg_types = ca->args; - for (int j = 0; j < nargs; ++j) { - int typecode = extract32(typemask, (j + 1) * 3, 3); - ca->args[j] = typecode_to_ffi(typecode); - } - } - - status = ffi_prep_cif(&ca->cif, FFI_DEFAULT_ABI, nargs, - ca->cif.rtype, ca->cif.arg_types); - assert(status == FFI_OK); - - g_hash_table_insert(ffi_table, hash, (gpointer)&ca->cif); - } + init_ffi_layouts(); #endif tcg_target_init(s);