From patchwork Fri Dec 2 05:39:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 630198 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp715340pvb; Thu, 1 Dec 2022 21:41:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf4IYPT0IxB889FiO/8J+KOBDydSrbGKXRt+d1u4rrDXsxXf/UY5bJaKM7qBFhmMyCpHACBJ X-Received: by 2002:ac8:4698:0:b0:39c:1435:423e with SMTP id g24-20020ac84698000000b0039c1435423emr47969198qto.490.1669959674000; Thu, 01 Dec 2022 21:41:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669959673; cv=none; d=google.com; s=arc-20160816; b=Z6C2hAGujGI9GOsZqJ7ZRek9bDR51oOQjxio0JsKJveArjUt/8TZHcEKoEPc5smBge h/OFyMsDLfewNPf3NP+Xf01HQEc7bfaSayy/kvD9EQG0mfnn4BKyy8X6C5WGP5XBZYYw I+CGxswYmfTGiUt3pybUBjiqCFlpBH3qoYkUzZwkSKPjTDEtFD49iI3CK+4BrZjVTTt5 gcDZfxP8Ezg4dXY5ahcC0QdL/buVrsXffceNSoh90RBUK1Tv5XBSLlDolCX99H1MCgTl SKrYd5ImZ5CV2bEu2oH590O4ff+udVcfPb4fylywmsRNN9NwrTZlYPoihc0OLqxsWIfI KnPg== 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=QFUsNAuul+J55fC7tXSY0WCt3qBCcqJEW4LFQbi3f+k=; b=JPXNtrkNHIIyfXTzD76XtMKj/9LwQwXreq11mcyoHq80tzS2kAHWAC9gmNNtJ0dazC ILlpwiW5Z4YTf7tLLy6lYTXhw3/wigeMjNZJpaYCuw6siGxT0Rb6LrG8VxocvyWFVBwi XfPVale0+s7G8baCiSaG/oK6VxFTFDokzESPs7Sav50f5JA8LcXOrlTI7t9YUfTB2X3K jg/aACJR+Gc1X+n6lebSYiMjcPrim8idaaGp2qzmSUoGUPyIkrGiM4/xmwmyA9HvWPOl rFyQ0JKhRh/n61V6dGTw9Swz6byezBfkWIamQHifQ79dkgq3evXuxNcNJsmBzxVFQfuQ +l4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dHmvXM15; 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 3-20020ac85643000000b003a2045e3688si3232179qtt.665.2022.12.01.21.41.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Dec 2022 21:41:13 -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=dHmvXM15; 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 1p0ymn-0002js-OF; Fri, 02 Dec 2022 00:40:33 -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 1p0ymm-0002j7-6S for qemu-devel@nongnu.org; Fri, 02 Dec 2022 00:40:32 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p0ymk-0003JP-Ls for qemu-devel@nongnu.org; Fri, 02 Dec 2022 00:40:31 -0500 Received: by mail-pl1-x62b.google.com with SMTP id 4so3752254pli.0 for ; Thu, 01 Dec 2022 21:40:30 -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=QFUsNAuul+J55fC7tXSY0WCt3qBCcqJEW4LFQbi3f+k=; b=dHmvXM15b8M9xyG+bXPSETkVSHIHP+oX7Ira3ds0EpmlCouJBVeeMTvl9p8AAdYb5i URcOyNk3T+NGyznLuhqa5Qd78SJzWBAg9aErzkpheyaAWlD+yssFcJLB595lbAbyutXi 345Z8MOvVYs77Hz1lijxPCgOD7YYpF0ZKHy8/3sPFfd6tKaY1QW6tUB6Zd7kGm6lBCL7 uuWc+co9aa7mqi7nvmiCNcTof7ySPXXZa99IQ/ctKxuPC6PSaLKoUjHjGm1HOo/Yp+Tt 6vnlH6X6vFHod0J5mcEMxxB/6jBbvWs52iYrazrlzgLkJrlC2v3skeIaE5d94ZteS5rP buvQ== 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=QFUsNAuul+J55fC7tXSY0WCt3qBCcqJEW4LFQbi3f+k=; b=ISsOxF/kMOJI2Zwx1LqdbsbU5dK4wTPxod2q9fdWc1Vx3KWMxqm0ABFUlprH+SMQP1 pmgflX9hpF7d4AN9jF6AMfbEzigBIj7AFjoWiBJgtLGWrm2xPD/uk1BoBFgAkHlH7wLW tJGgaj59D3zNFByqEPeGno01uRBE4GLvcwQaftVD5G6JN3wA345YgblPnANnZknmtup8 fLvVhPv0KpfMaW9Di294EPariAuXj5pn7yadIR4K3B0HWdWb/51u6Cey8XWKKmY+IngO 2rfaogXgrOjTR08QyEYW22v6pJo1+NKbWX1x62sJ50jaiXEHTk3+hQ46U1bVT+uF54Cx 0GJA== X-Gm-Message-State: ANoB5pnzb7bdwASOIhSL1pJAc2suZeNjLhce9gojC5GRioKkAk1qAvsv cq+nz3gJjH6cTyOs1T7JjmjQgK1jwad+V4SF X-Received: by 2002:a17:90a:be02:b0:219:8199:ef57 with SMTP id a2-20020a17090abe0200b002198199ef57mr4702388pjs.129.1669959629932; Thu, 01 Dec 2022 21:40:29 -0800 (PST) Received: from stoup.. ([2602:47:d48a:1201:e3cc:2e37:17d4:f1d5]) by smtp.gmail.com with ESMTPSA id d12-20020a170903230c00b00186f0f59c85sm4637075plh.235.2022.12.01.21.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 21:40:29 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 30/34] tcg: Convert typecode_to_ffi from array to function Date: Thu, 1 Dec 2022 21:39:54 -0800 Message-Id: <20221202053958.223890-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221202053958.223890-1-richard.henderson@linaro.org> References: <20221202053958.223890-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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] 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); } }