From patchwork Tue Nov 22 18:08:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 627513 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2633059pvb; Tue, 22 Nov 2022 10:09:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Tj2WChTf0EHvfr2O02wnC7t/0r9idYqjRzpXxJ7qZGHEiFgZnPFnmILBlgpLrcjgV0wiI X-Received: by 2002:a05:620a:cd6:b0:6f7:65f6:aa2f with SMTP id b22-20020a05620a0cd600b006f765f6aa2fmr21961978qkj.222.1669140569850; Tue, 22 Nov 2022 10:09:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669140569; cv=none; d=google.com; s=arc-20160816; b=LIzGyUC5LHo6W7j4jaCDnqcHhV4o00+vqg4fwddf3AmRTKihfpHJixinWTstKf0XXP +kQ9AkkVs9DA2mXMtNpFHGRUrpgyq3+D0XnGXWvOu/7lT5FYS1oniLi9h8WpECBWvjo4 XyApyE0AhZnUCB7cPU0QEriXXHuzp/8xKH4BYiBUu3jvbaR9/b1QHIOQucCz4gQ3SZFe ScPxm85eDCUbZfanfzoZZz/M+70hGwYYMv16NSkwOk6isFv9L7YonmuJNyHxViGqfAKN fvj01pIFbZ740R6lGAHQ4jxazWgG0aERTzXZmNoQy2l9RIZiLtXV/6GVDtiGudGKkG8i vXLw== 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=dxHXsv2E4iYr9vm2mCwNgEjbUPevhHxvL9iTZPxK6ik=; b=SvV3n/UTMOjtjba112i7LGHi0sGpIZnAhQv4Vzrr7Hyq4swTTuDgCTcvBaDhW93vNj kBI5PbGgjjbiPagkxCD8fRxpbP+H2PMVuHwbp7Da+vERxQBJ91FxgFuOBMBWqG2lehjx GnOam2ZEQuy0Juz4CKtKA526Bh4/KoZPugp13Exa9asVvsB9xfzvL8UCOfhWjre/HG+R MdvjQD/kqg/6jPlMaXxYkfnGu/cGAMi402CkAA6zK1pUiLSt14nCTJhmCv3Kn2PVlMsx wAywfzyZ4llVxMbxK65png5g0ki4+LGrfVVa+FScA79QvmxcWZttpB7WgbErTXHYV8st T4IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J36gG8+l; 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 128-20020a370686000000b006fa0634928asi7840041qkg.462.2022.11.22.10.09.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Nov 2022 10:09:29 -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=J36gG8+l; 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 1oxXh4-0001Rb-Ev; Tue, 22 Nov 2022 13:08:26 -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 1oxXgy-0001N3-4I for qemu-devel@nongnu.org; Tue, 22 Nov 2022 13:08:21 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxXgw-0000MY-Ev for qemu-devel@nongnu.org; Tue, 22 Nov 2022 13:08:19 -0500 Received: by mail-wm1-x329.google.com with SMTP id t4so11301593wmj.5 for ; Tue, 22 Nov 2022 10:08:18 -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=dxHXsv2E4iYr9vm2mCwNgEjbUPevhHxvL9iTZPxK6ik=; b=J36gG8+li/1U5SvhnXHxVbbqoz7dwjLfSuNtG2kwOYFhixDNle0ehgtiNXgWjZZrH+ fEF+F7Ndtz/Oa94AM8b8Ulbo3ppe+xt5TpuSm7Sgqf4pWnxyAEW+kasAKbzBmj6Mbqm/ hY326979HKVHTs+T0Ww+VUaNXAt0Xnv1nB+O4g7kv05jp50XmA2GJ1Y0LbI8St6d+Q5W dciKyXQHR4oHJis8r5PTp8HKsj1y7uUKaFCTKog5Ljz4i1Q5Ean2mJe/vwMG0me0gj5u nC5aOWoh60zNGJTwh9zra7FR9nVi5RWrlfq5tXHHY91cAJIENtXVdKb03t57JWDTxCcR gTWA== 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=dxHXsv2E4iYr9vm2mCwNgEjbUPevhHxvL9iTZPxK6ik=; b=kGRlKB341ckKh7sQvG53Gcs5WzPVn23G2BAeb06l5r+LF9ycAr3I87WZP2LaFXHEki 3XkgC5+hf/KU99QSRoeoG/K0I2Iq60NTGkRtKtxfctSrdntZxGdQno9PlyD4OhokOKFB KwPDpw2LPnCPaKtgvz35NP4DKSKtoF2Rl/Q6h0v1/Gwtq8sg6Y0mOPunB10+Rkcuwg7f 7RscfnmHhRG5TUV6q7VMa9kUcJffToK1EFZ4fMb6KQblRdvPiqHS9cy7Jad5Vhem+1H0 OVg66JNUdPMBvMPs84vxJzs2AN7HVl1G6zWTqK2B/yrJzsYvKjJ7blJ+PhEadSqMdkex nypw== X-Gm-Message-State: ANoB5pkkgxovnnjFnVqlckECMS6tL6YuVom1BOA+acFxC2sSGP0ywciC 3MqJgfMpFYrzZjPqLsY/+0EK8yA3Mr/lzg== X-Received: by 2002:a05:600c:538d:b0:3d0:47c:9fe9 with SMTP id hg13-20020a05600c538d00b003d0047c9fe9mr3568654wmb.40.1669140496460; Tue, 22 Nov 2022 10:08:16 -0800 (PST) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id q2-20020adffec2000000b00241d544c9b1sm7758916wrs.90.2022.11.22.10.08.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Nov 2022 10:08:15 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Richard Henderson , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= Subject: [PATCH 2/3] tcg: Factor init_ffi_layouts() out of tcg_context_init() Date: Tue, 22 Nov 2022 19:08:03 +0100 Message-Id: <20221122180804.938-3-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221122180804.938-1-philmd@linaro.org> References: <20221111074101.2069454-27-richard.henderson@linaro.org> <20221122180804.938-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=philmd@linaro.org; helo=mail-wm1-x329.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 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é --- tcg/tcg.c | 83 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 8aa6fc9a25..9b24b4d863 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -572,7 +572,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[] */ @@ -753,44 +795,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);