From patchwork Tue Dec 13 21:25:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 633540 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3347022pvb; Tue, 13 Dec 2022 13:37:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf6JaIbN91/1JJJOVCl+Pd/Q7xdxc/cuNPi/hnYrdfNiYYSht2NGaO/P9QLKlKyzxA4RZseS X-Received: by 2002:a05:622a:1a26:b0:39c:da21:6c01 with SMTP id f38-20020a05622a1a2600b0039cda216c01mr40926121qtb.3.1670967459806; Tue, 13 Dec 2022 13:37:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670967459; cv=none; d=google.com; s=arc-20160816; b=NJJ1L9OR1LwgWzZXB9J4kfGdZBccWobzxMPksuddM8YRu28NYrDU7ZjSSZR0XJPcJg 7TR87+Rk5R56/sELTMLQx+HSlBaHRIBTF5HttyW5HjiLeBLKe0/pxIJN0ijHpOM3lcFE etPgZ0nPgAdJwH8nAltUnmmVH8Xk+nRbqa2coNwad2V55eT0hzbsoGaYIydB2eBbyvbm GWJA5EqernAjLX0WzhUD3u2U2Ab7rWyC+2Wot+jQBSnBBIe7ZrgywIH0tSZoJXYqOdj+ BHNZYJkcJrdb5F9oXQTZYFdRBXBnrFb8icON4SqmhXFVJ972QBirK8mS8ZYoQUJoy4IH NYIA== 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=N2cPBGoFx9/U1vkjp2P/tUKZU/Kz6D+DjQdC2D6+s43w+GdQDI/cyzgcUqUkS2GDkN bnq6Uugwjw37E/ta2LT4fWADtjSDQ5VcEmgl3u8r5BOdMXCVJDEvSrRBhVPZVzfu5oY2 dMISorWiYPnYCNk/gN2N1rux7g1UUkn1SxJ7d/6eNCKanFGVX/aDh7N6CxyZH7NB/Iah OssGGLm4wwL2imgJ9YXPU8fIdQ6W1OCH/Q0qXAiKyxPr3GPvfPO0Fk9uhfQFUxkNTaGw Udr8IXzhcw0+PiLREfqIjQtAzirVU/EanVAnLgo1meomnT81DNWVU6MwbgEiZP5kVJgj auKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VccumtVu; 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 c22-20020a379a16000000b006ff0245b21esi6573328qke.263.2022.12.13.13.37.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Dec 2022 13:37:39 -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=VccumtVu; 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 1p5Cmy-0000iV-RA; Tue, 13 Dec 2022 16:26:12 -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 1p5Cmw-0000h2-Og for qemu-devel@nongnu.org; Tue, 13 Dec 2022 16:26:10 -0500 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p5Cmu-0003Dw-QI for qemu-devel@nongnu.org; Tue, 13 Dec 2022 16:26:10 -0500 Received: by mail-oi1-x22f.google.com with SMTP id v70so1050002oie.3 for ; Tue, 13 Dec 2022 13:26:07 -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=VccumtVuwewimi/cUVu4XEDvuSAlRKh9q3tJP0rNqXR9hr8hbqn5jv0rUaieYRKvj3 ZmU6L5EGH9nEteYUPwg6/7wmlPR6MEJL9tQVl8UQYgB++3uNkP/SiCTMx5yvbMJAp9N0 qlCeQOIVeR4yd+l+pEUKT52iksA9OFi+KZlAz2vLzsQiJ067/RDuVSJVcmkLkTSfE7Cc uU8hN2r5dT6bkQfQy0c5nT2lalEzSrrOEBvKnIcjV8OIqd05dey1Y83v56orDFxPlBTW kQ36PVdI1Kpr4iRnTtwu1YF/u6QI5uCu4sQD4cxLqc845r6757zRYVfouFk3zmk6CQFb lbYQ== 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=U3qxo04I85vkIWswN14WOwg5pi0seLrQl7nrfnu1uzA254YgkTBs7H2q2QPtfC6Z6o Z3ks7YAO3hxUh/4H0QdhEO7FVV/kM3hVlxP9IgdCWShybeUuy8kIdZwnzzjcasgvYgpm tpnNKsrO8Ij2fWSqbnxXIL8LuNTa6IV9f3hEVGngqOOTYo0poajN3arQF6iES5TtTwr3 qjmXxxSijSoH3s4seJDF43lCt1TqLl7QTgktPP8jy+H7FAc7ZLN299IgXLU3fyW7xi1b Uv2tcWqqvBwK1wVWv5PUPNse8EQPx5tM1G3U7lrytNSclQttxFNv8yNTZjdIhZg6pLZD +Q5g== X-Gm-Message-State: ANoB5plhqNeHudvcyYr0A0xa40zAHAK0I+4MY9RZGrgiIViEZP0GBJbt lfjUlsgWgIzjtHxLHFNRoLPaTUumXZ578pMFDvQ= X-Received: by 2002:a05:6808:1b1e:b0:35e:4589:19cf with SMTP id bx30-20020a0568081b1e00b0035e458919cfmr13206339oib.42.1670966767685; Tue, 13 Dec 2022 13:26:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 13:26:07 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v4 23/27] tcg: Convert typecode_to_ffi from array to function Date: Tue, 13 Dec 2022 15:25:37 -0600 Message-Id: <20221213212541.1820840-24-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::22f; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22f.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); } }