From patchwork Sat Dec 24 23:57:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 636698 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp932910pvb; Sat, 24 Dec 2022 16:14:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXsBArauwuCHk7uH8JBAjpABDGgTldL4Ey2SZS6KQTi2LXHikuRThag2M2VWomayjE2QoH4C X-Received: by 2002:a0c:e78d:0:b0:4d7:f4ef:2a88 with SMTP id x13-20020a0ce78d000000b004d7f4ef2a88mr17607706qvn.21.1671927255262; Sat, 24 Dec 2022 16:14:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671927255; cv=none; d=google.com; s=arc-20160816; b=N/aDUd5IZuFMf47Mmw/79qrNPjp12AN652kJrTTgiURV/jPnQwMW5fUyZntvokiZYl LW0vo/pK+4SQV8iq52dZGEMYRvU5su4H7uZCmThwYO7+nsM09oS9hdNQXt+dhAPNi2sq 295MHeSPUgKvrklMJk5sZL1on6EeVEXLbZczcDdNIYoNum/ZuNenP+/6EJowCokCfRVV VVCZn5I/Os68L4snf7ynUPFAB56aY7KRMjV2D7rOFu/RIMQKUgDnbKBTS0grSNFNxRQc 89bz8jXtC0AocUdg0bTXQawVEx0Mm3gYUnIRo6SUQQQplfR1HCaBhY7pexWHlb4S4ycP cxQg== 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=6kRUHzLHjPRludB9lggQQFcCT178U0N5vVARh39rZgA=; b=pZ9/TTcjZpp3QwrGDXOFJ6Q1xsfc3BG6Vrb7ayYyhalO/7opjVtXA9FO9o81a+I8bQ X9Ws6o04sdOrug4ZEu1iY2pUEktAuCW8OkrjUGwudPCx8jk6LccBnfA7mzfFHXO+3gUq aYulSXDP0BsFOyb0yNZnu7WHnLrFFm8C2jmXEk3EZVR0ZF7zuZCHl6vhSxmz1MWLPHWr YMGzI4s4Ft1fYBCaiL0ppKH6xOKyvXYegdM62fRH1XJ5a4DPITPF3s3k2BCm9uXeJ63i mbRpa4YID7iAtPVWbAqlWJfz8xQBckwyzboqUP6QYhb4U8+58euQ0k/fa3VnHo9oiLI+ VEwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="DtP4qs0/"; 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 ow1-20020a05620a820100b006edbffbf44fsi2569121qkn.369.2022.12.24.16.14.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 24 Dec 2022 16:14:15 -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="DtP4qs0/"; 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 1p9EP1-0002nU-32; Sat, 24 Dec 2022 18:58:07 -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 1p9EOv-0002aI-Jk for qemu-devel@nongnu.org; Sat, 24 Dec 2022 18:58:02 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p9EOt-0006NW-UN for qemu-devel@nongnu.org; Sat, 24 Dec 2022 18:58:01 -0500 Received: by mail-pj1-x102e.google.com with SMTP id q17-20020a17090aa01100b002194cba32e9so11950141pjp.1 for ; Sat, 24 Dec 2022 15:57:59 -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=6kRUHzLHjPRludB9lggQQFcCT178U0N5vVARh39rZgA=; b=DtP4qs0/jieOPAziMg7vW2olieGnLGcKLSs5f/Jxs0WmdQuM84bYy0L9EXM2odBMX6 izaeyklfE1x1Iy30+aUdYTwhScwdvsEWR0Q6oZhvHw0jXaIt4ANYUZ2I95yohwLOFAU1 QFHJuTJqeFbQM71VjDASuSZv1oMdq5F9rS4IhSo4SGN/lRF+Vwx2UsuOVTiW5bnDfjX6 XREzvwVhKNXhNSNtCVkojx2Y4XBgyNqhkvi+GnPUC4SauafJXLMuS8CTDcbghjWznfSN JbUFRoWa/mO5Kmp5M7g8FoEreGalD9BiSs/VneH8a0Q1h7pcTtrHa4rjwYtXXbbV8mCD x2YQ== 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=6kRUHzLHjPRludB9lggQQFcCT178U0N5vVARh39rZgA=; b=76bFmVBMyGsu+uy+vfnw0s77Z3O/NPvHTPFBWBy0uZl0t7CcPd/cCBFMwco2wmteLs DwalJ3Mr71KC1frju4ZU6G6nEwk67VGsUp3UDj78HDH7bpN9zQk8vCIPMpLkIAAHpKm4 J8HmlskGGTL8+tnDy4GCgNAfUtK4JoNhinyNWsjDMawgqqcWLnD61pJsmrWqG+rDBaak Q+k7NuHT7fb/SGU7npI1vZLs9beA2XQsZZsZv4EicVvGAXqi5S0c6qne+Y3+ei+shqFg /F/OInZfi/twkySd1vtL9+YyhJ/BFfTv/30FuIvz+9oDJZS5DgUFKKRD1bkPVW9JlPqi g0qA== X-Gm-Message-State: AFqh2kqaxZ/rkXajE0gdrTtsFPzjs9ZLfR2mPG7ic+ajAANF1QkOjDvj 0KK+Lkc2pze8c/4ilaVLInE8r3+5QOMsrD6N X-Received: by 2002:a17:903:32c3:b0:189:7819:e5c with SMTP id i3-20020a17090332c300b0018978190e5cmr21133237plr.6.1671926279146; Sat, 24 Dec 2022 15:57:59 -0800 (PST) Received: from stoup.. (76-14-210-194.or.wavecable.com. [76.14.210.194]) by smtp.gmail.com with ESMTPSA id cp12-20020a170902e78c00b00187022627d7sm4599716plb.36.2022.12.24.15.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Dec 2022 15:57:58 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, philmd@linaro.org Subject: [PATCH v5 39/43] tcg: Convert typecode_to_ffi from array to function Date: Sat, 24 Dec 2022 15:57:16 -0800 Message-Id: <20221224235720.842093-40-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::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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é In the unlikely case of invalid typecode mask, the function will abort instead of returning a NULL pointer. 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-2-philmd@linaro.org> --- tcg/tcg.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 74f7491d73..46cce228a0 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -555,14 +555,24 @@ static GHashTable *helper_table; #ifdef CONFIG_TCG_INTERPRETER static GHashTable *ffi_table; -static ffi_type * const typecode_to_ffi[8] = { - [dh_typecode_void] = &ffi_type_void, - [dh_typecode_i32] = &ffi_type_uint32, - [dh_typecode_s32] = &ffi_type_sint32, - [dh_typecode_i64] = &ffi_type_uint64, - [dh_typecode_s64] = &ffi_type_sint64, - [dh_typecode_ptr] = &ffi_type_pointer, -}; +static ffi_type *typecode_to_ffi(int argmask) +{ + switch (argmask) { + case dh_typecode_void: + return &ffi_type_void; + case dh_typecode_i32: + return &ffi_type_uint32; + case dh_typecode_s32: + return &ffi_type_sint32; + case dh_typecode_i64: + return &ffi_type_uint64; + case dh_typecode_s64: + return &ffi_type_sint64; + case dh_typecode_ptr: + return &ffi_type_pointer; + } + g_assert_not_reached(); +} #endif typedef struct TCGCumulativeArgs { @@ -779,14 +789,14 @@ static void tcg_context_init(unsigned max_cpus) 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.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]; + ca->args[j] = typecode_to_ffi(typecode); } }