From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 81860C35274 for ; Mon, 18 Dec 2023 12:58:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFD8c-0002og-F1; Mon, 18 Dec 2023 07:54:26 -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 1rFD8b-0002o2-Ek for qemu-riscv@nongnu.org; Mon, 18 Dec 2023 07:54:25 -0500 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rFD8Z-0004wG-Us for qemu-riscv@nongnu.org; Mon, 18 Dec 2023 07:54:25 -0500 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6d7609cb6d2so312471b3a.1 for ; Mon, 18 Dec 2023 04:54:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1702904062; x=1703508862; 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=i8rzVcCRKDFqmG0n6+Dd5TCpeM1lIcu/rUiXyvezW+Y=; b=V3sGv7Z1JbaKSoka3iTc+NcoUtKW5MTEQTmeIbuqrI0CqfhDMYLrXvSURgOXizkoe7 s98GPioCZ0cHN0328NS0L/ZaRgKr2WTJWV/16nqF2eNVBrH1V7fjC5huN85sy/wd3lNp EncUbBrQYu5KxVOSUjZGIfzJ2WyeJcRk4+SU9uMErgoH8nYfcC19cWSl0RdgaUZxRUxv WSP1/7UTYriKa9o8VzXPGlBcsl7Hs6lnkGGy599sZmZl5KPKip6yuEuQym8f126MBEJk a9aEBJghBQdxz0CYOK4X/Om/Rmv+ivoGrJ7ToE72ikDZLMrLiy2AwKCZytbwgRxsKsRT USlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702904062; x=1703508862; 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=i8rzVcCRKDFqmG0n6+Dd5TCpeM1lIcu/rUiXyvezW+Y=; b=DO4FbunycrFNT96fuGsPZLQnCJ/cBBIBzNOjzw6Iz5KQE4P73FenVn14V0vytuvKh/ v13sd8Z5wxoJGAL7+G8xzBdIuoSG4K/u8TBERsPLmDmQRr0dEe/PQ6S0F3puyzrJgGBn 5dHwAO9TigN0+JgpcTx5UR1S22MAhNfCLKNlkKzBKX0J3G3EERwyGUHNlT4PYczJOG2W 7SQ9LwJT21h5SKrUm71pV1IUjPRSxOjwygv8BSGG6IUIGJhWLcKQJ9j0satvFyGH6v8q B08ziVpEJvPoayI4++O71ueQm2tov0dDM9e6pzIggeRo2CvBPZEPizNdYpSk8d5BskWD veRA== X-Gm-Message-State: AOJu0Ywc2Fh0xDuLkvLXbFEoNznnC6Tw0FlD4dqL5//72r1ju0zCSbZB hhs/OGJy/2xAoGLkfSaAHy88Cw== X-Google-Smtp-Source: AGHT+IF6yZXA6KAW8dLHAdO544NUNdmfgmRhwrfppZApt5u3ZoTG5v6eKewHStJgIdixgEwvnTqWuw== X-Received: by 2002:a05:6a20:d413:b0:18f:97c:4f6d with SMTP id il19-20020a056a20d41300b0018f097c4f6dmr7325361pzb.121.1702904062703; Mon, 18 Dec 2023 04:54:22 -0800 (PST) Received: from grind.. ([179.93.21.205]) by smtp.gmail.com with ESMTPSA id c2-20020a170902848200b001d09c539c96sm7494897plo.229.2023.12.18.04.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 04:54:22 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, ajones@ventanamicro.com, Daniel Henrique Barboza Subject: [PATCH v13 12/26] target/riscv/tcg: add riscv_cpu_write_misa_bit() Date: Mon, 18 Dec 2023 09:53:20 -0300 Message-ID: <20231218125334.37184-13-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218125334.37184-1-dbarboza@ventanamicro.com> References: <20231218125334.37184-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=dbarboza@ventanamicro.com; helo=mail-pf1-x42b.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-riscv@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-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org Sender: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org We have two instances of the setting/clearing a MISA bit from env->misa_ext and env->misa_ext_mask pattern. And the next patch will end up adding one more. Create a helper to avoid code repetition. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Reviewed-by: LIU Zhiwei Reviewed-by: Andrew Jones --- target/riscv/tcg/tcg-cpu.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index 2affc1f771..f8c35ba060 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -42,6 +42,20 @@ static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) GUINT_TO_POINTER(ext_offset)); } +static void riscv_cpu_write_misa_bit(RISCVCPU *cpu, uint32_t bit, + bool enabled) +{ + CPURISCVState *env = &cpu->env; + + if (enabled) { + env->misa_ext |= bit; + env->misa_ext_mask |= bit; + } else { + env->misa_ext &= ~bit; + env->misa_ext_mask &= ~bit; + } +} + static void riscv_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb) { @@ -828,13 +842,9 @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name, */ env->priv_ver = PRIV_VERSION_1_12_0; } - - env->misa_ext |= misa_bit; - env->misa_ext_mask |= misa_bit; - } else { - env->misa_ext &= ~misa_bit; - env->misa_ext_mask &= ~misa_bit; } + + riscv_cpu_write_misa_bit(cpu, misa_bit, value); } static void cpu_get_misa_ext_cfg(Object *obj, Visitor *v, const char *name, @@ -878,7 +888,6 @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = { */ static void riscv_cpu_add_misa_properties(Object *cpu_obj) { - CPURISCVState *env = &RISCV_CPU(cpu_obj)->env; bool use_def_vals = riscv_cpu_is_generic(cpu_obj); int i; @@ -899,13 +908,8 @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) NULL, (void *)misa_cfg); object_property_set_description(cpu_obj, name, desc); if (use_def_vals) { - if (misa_cfg->enabled) { - env->misa_ext |= bit; - env->misa_ext_mask |= bit; - } else { - env->misa_ext &= ~bit; - env->misa_ext_mask &= ~bit; - } + riscv_cpu_write_misa_bit(RISCV_CPU(cpu_obj), bit, + misa_cfg->enabled); } } } -- 2.43.0