From patchwork Tue Oct 31 20:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Henrique Barboza X-Patchwork-Id: 1857771 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=Y7H7s60E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SKht021xzz1yQ5 for ; Wed, 1 Nov 2023 07:43:04 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxvXA-0005Yj-PR; Tue, 31 Oct 2023 16:40:21 -0400 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 1qxvWu-0005PM-MV for qemu-devel@nongnu.org; Tue, 31 Oct 2023 16:40:04 -0400 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxvWt-0007dV-3G for qemu-devel@nongnu.org; Tue, 31 Oct 2023 16:40:04 -0400 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-5afa5dbc378so44779767b3.0 for ; Tue, 31 Oct 2023 13:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1698784801; x=1699389601; darn=nongnu.org; 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=u7/QjhdY3KBtGGnqIOs7Ww/gYUu7Gb/03wH1v5rdfK0=; b=Y7H7s60EAP7u1Gt3qivETNYkKGQl0XNP9nUhk+nDkQljeym8RKWKQQ9aBtfdcRMrOF P0IlMRkY3Bxu8653iKE6YR+oYpyQWl6BR/osnmvPdwHdc09b6TowsrWuAxsR0bE6T+MJ 9Zj+t24SV4Dj55ks3lGsAZ0Yy481bUY2Rl3fKJpfJgnJLNOu1PiAVQKLatzudePyR/b2 +t/gIcegWXITKCxYPZaDfEfrE6A78VVQpP0/Kr8cLgo0kMVy2siJcj45KUUwzRUgRh3Y wiqAHNLrSBsiAPRaPP3NtH/8IksJMFNT7cj+iIinZmIulwUn+UcsqLbtoeZQBY4XQ6d1 wi0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698784801; x=1699389601; 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=u7/QjhdY3KBtGGnqIOs7Ww/gYUu7Gb/03wH1v5rdfK0=; b=HH7Nv/9fNoaqmytzm9BFYNB/tk+xCTjJ9948wcTW8oBEDcTaNPUUj4I8SkXm274q22 STGemOPvmCg5JeIX2IrCuToVOnuL9HGzMfF9KafyGcw2t3BnVfCwkySm/FodHMxcAC/b JXv2OiXrPeeu6kDWA0ffftsEUwsUNG/jpct69idtf/2DB81/kxMAVS8HxW6bMU51vKao OSbR3bmL7IzP7Mz5REepDrLlaTOUlJ9OCYBAVqjTitK4nWfwR7b/ti3auu7EkqY1aye1 pf9yLq6NJoSNpN5l2zAQnhLveOTVWCLcsZB61AhSHsyJo8lR3jtwBb7gDNbCVpWKEZPC H9Kw== X-Gm-Message-State: AOJu0YwIfIPSMKbNY/OK9sxa3GuQehIzZWWljzOfgmjRgy1f6Ik4oSRk PjbCdArFRpXfx1gR5SVa4bngYlx1Pwe5Wm36UZM= X-Google-Smtp-Source: AGHT+IGBf1xiktDdB6p0A+YSCjyrHK6NWyBRZG+EbeAU7YX+R8skw19UiOzpwGZm+oGPfC1v+FGAaw== X-Received: by 2002:a81:4521:0:b0:5a7:aa7f:17d5 with SMTP id s33-20020a814521000000b005a7aa7f17d5mr10612710ywa.11.1698784800839; Tue, 31 Oct 2023 13:40:00 -0700 (PDT) Received: from grind.. ([179.193.10.161]) by smtp.gmail.com with ESMTPSA id k1-20020a81ff01000000b005add997ae53sm1272802ywn.81.2023.10.31.13.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 13:40:00 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, ajones@ventanamicro.com, Daniel Henrique Barboza Subject: [PATCH v7 13/16] target/riscv/tcg: add hash table insert helpers Date: Tue, 31 Oct 2023 17:39:13 -0300 Message-ID: <20231031203916.197332-14-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231031203916.197332-1-dbarboza@ventanamicro.com> References: <20231031203916.197332-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1130; envelope-from=dbarboza@ventanamicro.com; helo=mail-yw1-x1130.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, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Previous patches added several g_hash_table_insert() patterns. Add two helpers, one for each user hash, to make the code cleaner. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones --- target/riscv/tcg/tcg-cpu.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index 4a915acff4..9127249f85 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -42,6 +42,18 @@ static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) GUINT_TO_POINTER(ext_offset)); } +static void cpu_cfg_ext_add_user_opt(uint32_t ext_offset, bool value) +{ + g_hash_table_insert(multi_ext_user_opts, GUINT_TO_POINTER(ext_offset), + (gpointer)value); +} + +static void cpu_misa_ext_add_user_opt(uint32_t bit, bool value) +{ + g_hash_table_insert(misa_ext_user_opts, GUINT_TO_POINTER(bit), + (gpointer)value); +} + static void riscv_cpu_write_misa_bit(RISCVCPU *cpu, uint32_t bit, bool enabled) { @@ -715,9 +727,7 @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name, return; } - g_hash_table_insert(misa_ext_user_opts, - GUINT_TO_POINTER(misa_bit), - (gpointer)value); + cpu_misa_ext_add_user_opt(misa_bit, value); prev_val = env->misa_ext & misa_bit; @@ -844,18 +854,14 @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name, continue; } - g_hash_table_insert(misa_ext_user_opts, - GUINT_TO_POINTER(bit), - (gpointer)value); + cpu_misa_ext_add_user_opt(bit, profile->enabled); riscv_cpu_write_misa_bit(cpu, bit, profile->enabled); } for (i = 0; profile->ext_offsets[i] != RISCV_PROFILE_EXT_LIST_END; i++) { ext_offset = profile->ext_offsets[i]; - g_hash_table_insert(multi_ext_user_opts, - GUINT_TO_POINTER(ext_offset), - (gpointer)profile->enabled); + cpu_cfg_ext_add_user_opt(ext_offset, profile->enabled); isa_ext_update_enabled(cpu, ext_offset, profile->enabled); } } @@ -918,9 +924,7 @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, multi_ext_cfg->name, lower); } - g_hash_table_insert(multi_ext_user_opts, - GUINT_TO_POINTER(multi_ext_cfg->offset), - (gpointer)value); + cpu_cfg_ext_add_user_opt(multi_ext_cfg->offset, value); prev_val = isa_ext_is_enabled(cpu, multi_ext_cfg->offset);