From patchwork Sat Dec 24 23:57:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 636692 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp932672pvb; Sat, 24 Dec 2022 16:13:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXuwa3ZNvF58r2B8L5lHTFZ0jEfnln7/1BVISpjpNE4Mz7qNlvZla9C1aWmxzQraIpCpnfuO X-Received: by 2002:a05:622a:181e:b0:3a5:ed7:1644 with SMTP id t30-20020a05622a181e00b003a50ed71644mr31117993qtc.45.1671927184408; Sat, 24 Dec 2022 16:13:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671927184; cv=none; d=google.com; s=arc-20160816; b=XqfffmU9+6qHcu2BQwpF4sG07oKPZ3lR2NDlYd8xugTC0V8Pu1rPtVuk0dN20bkUGG yxM3Khq7C1R1Z7XmTDmRR7zhlnf0B5kI4+a2pP8B5niaWdKkiVZGLTxaklxisSXggWcO XdnhYinZvnRz1Cojv4A1ppyZvQSkUUcBrl9sDdQXysWuDOcMNPzzi4n4rGugxAKtI8HD VUN8NnQQjbPIeW7l2lbMtdTu84Vl8Fzcszz6BvBbctdRo/Y/9XCEuaiVeja5pHcDj6Q8 DRnODHL7QpPwqN+c7eLuGGWmEyYdd/CPiaTjIMGe2JviS3RVtwumw7DyQiC8jcSne42a UA9A== 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=OBljFhYIHpDHYp33JDsunVI9K3ZsXt/tBvc3MWwAFFM=; b=pzMokEiGjWxc4gIMVO1Hjm3zRYmAn2OSWTATn6splNI6pflY3rLcuruO2YxZ9ssOk5 jFr9S3M5/cT1mew/JmtrhBuPiB9mPfYDzb8K6CQ8j4AKJii2EEhlhgi9iRhUvsfx8RTR 9mEPQlzaFpOmGtuJju8j2p6cdFzCxUZrR7p/2kugT6sv0CJfCnc/YtQdOzhjsfnNE7Cn hLyyx3FDcOmp6jnj694TlbmWrkTbvbah7fBshN5+3Px6lYA7e19Ki7o0lwTJwSQSCT3y HTGxUaMvDYlSWjSx+6N2+cUOnPtg6+wEUs2i+up2KHtfL1xzRrlCfflWYKc2Yaj7qYjR Rb5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x6hPkZed; 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 ci13-20020a05622a260d00b003a691a2f8a2si2745647qtb.292.2022.12.24.16.13.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 24 Dec 2022 16:13:04 -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=x6hPkZed; 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 1p9ES4-0007OQ-Lu; Sat, 24 Dec 2022 19:01:16 -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 1p9ERt-0007NF-Au for qemu-devel@nongnu.org; Sat, 24 Dec 2022 19:01:06 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p9ERr-0000hV-2L for qemu-devel@nongnu.org; Sat, 24 Dec 2022 19:01:05 -0500 Received: by mail-pj1-x1029.google.com with SMTP id v23so7965251pju.3 for ; Sat, 24 Dec 2022 16:01:01 -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=OBljFhYIHpDHYp33JDsunVI9K3ZsXt/tBvc3MWwAFFM=; b=x6hPkZedHFS9asNrOOvRyaILARQszcH/ErxYSNFWPCWyt/1OBl7hCyRn4QTfLxm37X 0NJy47FN+xlkbgsVK3uhivLU2tsYFcaJ7iQ2I1ieE2dOA1VKQAkYx3SLy+TxY192rnww qdFoVmU2O1NlHOh1CENtx+QXtafQ+we8yY1v+m+Ld0xP9nI/ql10u/ALC1SFwNdpodaQ HA/0ySRSLpDP2FVQitGq+ubYZwXNWW/zW5Vuk+obAfp4NtoI09rKiwqg0TMfHwecXjr9 N09RI9l+ErzsbyhWgJJE1QPJv2LAzh7BCziPCdx58wSDM3CAMf6h2I3UnoQh4jEz2tvD ID8g== 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=OBljFhYIHpDHYp33JDsunVI9K3ZsXt/tBvc3MWwAFFM=; b=HV0bm6hfiAtq6rEJtLZjIirKgrzxCz6s9X8rPurqyhi6Ha4o/kuVMrLmHln6pfdIBp 6jnRDntfs89gQztex9befQV9AAdYLudTmBsinpz1Z4I0M3WmHZtAyuSQVklGOHtXgG/n G4blSadNIhMDBB3jBHTTdc6o+oUI1mJVF5VTtQUYv3fYyyzvERPCnhdUwtmT6uQ7xHsI YaTSYvPtr2oQxg7S+hHdWK4skzA80obtonTKwETJmQYP52U0fhOCZr+DVr6haw39dU+d CoJbEP1QKIz7dreFh403I3QX+Rkk3k2FxMsTsmUgy41ubg7Eb7qWoLdFVHbI9lrqZ/yf okOg== X-Gm-Message-State: AFqh2krVGoEN+TyVet/2Up3nMj5x47Y/WIfyFBG1noIN1fLToEvd2WDr nPIBKbPxpY2L6X1Amswet1ZVQZLG6xJyNMnE X-Received: by 2002:a17:90a:8b14:b0:219:752e:c071 with SMTP id y20-20020a17090a8b1400b00219752ec071mr31651582pjn.6.1671926460733; Sat, 24 Dec 2022 16:01:00 -0800 (PST) Received: from stoup.. (76-14-210-194.or.wavecable.com. [76.14.210.194]) by smtp.gmail.com with ESMTPSA id e32-20020a630f20000000b00478fd9bb6c7sm4161280pgl.75.2022.12.24.16.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Dec 2022 16:01:00 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, philmd@linaro.org Subject: [PATCH v5 40/43] tcg: Factor init_ffi_layouts() out of tcg_context_init() Date: Sat, 24 Dec 2022 15:57:17 -0800 Message-Id: <20221224235720.842093-41-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221224235720.842093-1-richard.henderson@linaro.org> References: <20221224235720.842093-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.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] Reviewed-by: Richard Henderson 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);