From patchwork Mon Jul 1 02:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13717513 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 AC089C27C4F for ; Mon, 1 Jul 2024 02:51:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sO78V-0002xn-1R; Sun, 30 Jun 2024 22:51:23 -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 1sO78T-0002tw-An for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:21 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sO78R-0008Vn-EK for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:21 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7066f68e22cso1474730b3a.2 for ; Sun, 30 Jun 2024 19:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719802278; x=1720407078; 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=mPMDVI+D07uyiyyk8Iq5xR3y1Ye6RQN5Bs9ydJnDyA0=; b=Az0Twaeh5w2XSbykktmKCOSS43tx9AFv10//13yy3pktqNsOUwUDGE/4iygAuK5+gu CDroVflXbZzxsni9I//OoEJANSS9ndItebNECqLM+OcSzCrk1E4NQRUznwwPeR0ZNld4 0Lt6Sei0iyNy7hcwEr2Ia6/HF4C5RKitxsihM6DI/N6GfJJZGIW/KLBlNybGA6iKvPEI +siVbGDdDS9Yx+1BQL/O5oQYMOY2/ossUoF4p0Kp0ZgV73cy7vewwE/wJTPA0VPuFa2M ugsnKH+cZbrxJxVe08YN23AdUpKB/ygt4HHG3zISJaayJdJ6HVDpOYS5fW7LEumCloHb EOxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719802278; x=1720407078; 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=mPMDVI+D07uyiyyk8Iq5xR3y1Ye6RQN5Bs9ydJnDyA0=; b=V9mIqYOJGzG/Fc6LLkOGqCwHjiTct1JbFbMOLQH4D3JKFY+EAD4oJQD3lmmqr6Aktp LPquhBNKmOhD9I+Bf9ogOeMgZNB71qkaXs0RHWrY8XGJFrvsuQE2QkKVs61CTVjEZSvm HNROP4uSCYABuKb9VTGI75u4Ykq6fVpXjtfwClmJeVZixuI78BN2hMEZQOPQXgiiJsQo 08H0Se5IlANvZ3PkpRz68PHVc0Dl7NvLMO8/r5fxAEo/wUX61zF0bFZ6CIE2MuGQJclq qa5eMO03/GRnhk5GRT0j3kEMOt6PSqCYjvk8117k3k+GJ4Nc5D6qbf2kSkWqekO7zY1I tr2Q== X-Gm-Message-State: AOJu0YxA4inUURr14lorGRrrXIUKPbS8HvCrBtmTEurKtbFG8IrKsrA2 xgpVkqK4yjJBKdwTPebO8U3DTjiSs6kzD3OI+fi85Bi1VDZDjYZDhSeG8Qrkgs78AxZv7qfJdMh F X-Google-Smtp-Source: AGHT+IFBMU+AcKDU/8esAshINhmce7uSp6vOsLD8OT/pjWRYbcsND7ZA/6+ii/ac2/Ii68phtKJctw== X-Received: by 2002:a05:6a20:7fa9:b0:1bd:253e:28e with SMTP id adf61e73a8af0-1bef61398b1mr3590112637.16.1719802277424; Sun, 30 Jun 2024 19:51:17 -0700 (PDT) Received: from stoup.. (174-21-76-141.tukw.qwest.net. [174.21.76.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91d3b9349sm5531698a91.37.2024.06.30.19.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 19:51:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 1/5] target/i386: Tidy cc_op_str usage Date: Sun, 30 Jun 2024 19:51:11 -0700 Message-Id: <20240701025115.1265117-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240701025115.1265117-1-richard.henderson@linaro.org> References: <20240701025115.1265117-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Make const. Use the read-only strings directly; do not copy them into an on-stack buffer with snprintf. Allow for holes in the cc_op_str array, now present with CC_OP_POPCNT. Fixes: 460231ad369 ("target/i386: give CC_OP_POPCNT low bits corresponding to MO_TL") Signed-off-by: Richard Henderson --- target/i386/cpu-dump.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/target/i386/cpu-dump.c b/target/i386/cpu-dump.c index 3bb8e44091..dc6723aede 100644 --- a/target/i386/cpu-dump.c +++ b/target/i386/cpu-dump.c @@ -27,7 +27,7 @@ /***********************************************************/ /* x86 debug */ -static const char *cc_op_str[CC_OP_NB] = { +static const char * const cc_op_str[] = { [CC_OP_DYNAMIC] = "DYNAMIC", [CC_OP_EFLAGS] = "EFLAGS", @@ -347,7 +347,6 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; int eflags, i, nb; - char cc_op_name[32]; static const char *seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" }; eflags = cpu_compute_eflags(env); @@ -456,10 +455,16 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) env->dr[6], env->dr[7]); } if (flags & CPU_DUMP_CCOP) { - if ((unsigned)env->cc_op < CC_OP_NB) - snprintf(cc_op_name, sizeof(cc_op_name), "%s", cc_op_str[env->cc_op]); - else - snprintf(cc_op_name, sizeof(cc_op_name), "[%d]", env->cc_op); + const char *cc_op_name = NULL; + char cc_op_buf[32]; + + if ((unsigned)env->cc_op < ARRAY_SIZE(cc_op_str)) { + cc_op_name = cc_op_str[env->cc_op]; + } + if (cc_op_name == NULL) { + snprintf(cc_op_buf, sizeof(cc_op_buf), "[%d]", env->cc_op); + cc_op_name = cc_op_buf; + } #ifdef TARGET_X86_64 if (env->hflags & HF_CS64_MASK) { qemu_fprintf(f, "CCS=%016" PRIx64 " CCD=%016" PRIx64 " CCO=%s\n", From patchwork Mon Jul 1 02:51:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13717517 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 7FADEC3064D for ; Mon, 1 Jul 2024 02:52:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sO78Z-00031u-Kk; Sun, 30 Jun 2024 22:51:27 -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 1sO78X-00030g-84 for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:25 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sO78S-0008Vs-2z for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:24 -0400 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-6bce380eb96so1308153a12.0 for ; Sun, 30 Jun 2024 19:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719802279; x=1720407079; 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=5uYPQnTpDkityzLolaGQ63NdFXXcedgiMTlSb315wZQ=; b=AGQf/h9Tm9ZDOHxbD7gnwh4KeCRPat0bH7RtRenbXXWduENbHx/E0RHyNXod69o4IS cx0YVkm0tLoiggEMM074mrfLEEbuj3zNZSlnyc7sy17l1yZ05Lf9gXL6GAqIYGY9TE33 HWxfypXIj/mg49yjgh6Aqd2HQOcVVAiUcOviBcueA5U/5XhuP0a7XidGyWB2CFiOQxFp SQjxfpJbH2+5MbVLklT+m5UzY9kv+eeFUaVgd3n0vIhK5bEXzW+9llmz1thOq+zuIYTD RRVirF5fQs7t6netCbJV6hNiqftPeEFWVjtlW20t2IkIrVgH1162pBt0rHh5jO+QZZGk Rp/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719802279; x=1720407079; 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=5uYPQnTpDkityzLolaGQ63NdFXXcedgiMTlSb315wZQ=; b=TdK5FFWK7KTLYgjZqPFAd5ir+FV0SldkY+mw6NSH1rWrhlYnKXLnzwWPcfGUL2oFQJ p1w/RZ+Xq3LRYCMXWhUyuG7B3wy6UsFsVUESylryXHqWQxb6e3a0NdYlzJkt53yw7Gcs v8Ing9Bf6WYFxA0Ox7O24fYcoK/x1iXypEGDu6e43oz/Mukpb+t6lpqQmu6ckLuZOheb elzU2P6FkZjPLU6dWDAjuXqjQ40ehxcMAdMuk9Jl2yIDOm/HfohgbAnkfJNGRU4zXbXO SkmLink9Z+NfnkHQzkIIS+WB6lrYM8dg3K6csqorg1o+zJBQk6YDZ/gbC4udkqQaJ6XI /eXQ== X-Gm-Message-State: AOJu0YyC70h0ComYR0ecY+Io2wDYcwhchA9ff9FyMMPgKQls9Ut4yq7E 0V+W+GGVzmcnLrn83Xz2sViswICZn/YvuTJVAkb4VjgDc6wl6wPPq2D1SzENNa1/mT59ZwNmh9R N X-Google-Smtp-Source: AGHT+IELSYvp+N+Rp7B7MSQP6p7wWyGbOrfSctWPobh4fogKBulgBP1/NNLgQNMrzTpYlzD8kQKiAg== X-Received: by 2002:a17:90a:f28b:b0:2c9:35c4:dabe with SMTP id 98e67ed59e1d1-2c93d786945mr1646441a91.44.1719802278376; Sun, 30 Jun 2024 19:51:18 -0700 (PDT) Received: from stoup.. (174-21-76-141.tukw.qwest.net. [174.21.76.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91d3b9349sm5531698a91.37.2024.06.30.19.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 19:51:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 2/5] target/i386: Convert cc_op_live to a function Date: Sun, 30 Jun 2024 19:51:12 -0700 Message-Id: <20240701025115.1265117-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240701025115.1265117-1-richard.henderson@linaro.org> References: <20240701025115.1265117-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.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, T_SPF_TEMPERROR=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Assert that op is known. Signed-off-by: Richard Henderson --- target/i386/tcg/translate.c | 56 +++++++++++++++++++------------- target/i386/tcg/decode-new.c.inc | 2 +- target/i386/tcg/emit.c.inc | 6 ++-- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 95bad55bf4..e5a8aaf793 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -290,26 +290,38 @@ enum { }; /* Bit set if the global variable is live after setting CC_OP to X. */ -static const uint8_t cc_op_live[CC_OP_NB] = { - [CC_OP_DYNAMIC] = USES_CC_DST | USES_CC_SRC | USES_CC_SRC2, - [CC_OP_EFLAGS] = USES_CC_SRC, - [CC_OP_MULB ... CC_OP_MULQ] = USES_CC_DST | USES_CC_SRC, - [CC_OP_ADDB ... CC_OP_ADDQ] = USES_CC_DST | USES_CC_SRC, - [CC_OP_ADCB ... CC_OP_ADCQ] = USES_CC_DST | USES_CC_SRC | USES_CC_SRC2, - [CC_OP_SUBB ... CC_OP_SUBQ] = USES_CC_DST | USES_CC_SRC | USES_CC_SRCT, - [CC_OP_SBBB ... CC_OP_SBBQ] = USES_CC_DST | USES_CC_SRC | USES_CC_SRC2, - [CC_OP_LOGICB ... CC_OP_LOGICQ] = USES_CC_DST, - [CC_OP_INCB ... CC_OP_INCQ] = USES_CC_DST | USES_CC_SRC, - [CC_OP_DECB ... CC_OP_DECQ] = USES_CC_DST | USES_CC_SRC, - [CC_OP_SHLB ... CC_OP_SHLQ] = USES_CC_DST | USES_CC_SRC, - [CC_OP_SARB ... CC_OP_SARQ] = USES_CC_DST | USES_CC_SRC, - [CC_OP_BMILGB ... CC_OP_BMILGQ] = USES_CC_DST | USES_CC_SRC, - [CC_OP_ADCX] = USES_CC_DST | USES_CC_SRC, - [CC_OP_ADOX] = USES_CC_SRC | USES_CC_SRC2, - [CC_OP_ADCOX] = USES_CC_DST | USES_CC_SRC | USES_CC_SRC2, - [CC_OP_CLR] = 0, - [CC_OP_POPCNT] = USES_CC_DST, -}; +static uint8_t cc_op_live(CCOp op) +{ + switch (op) { + case CC_OP_CLR: + return 0; + case CC_OP_EFLAGS: + return USES_CC_SRC; + case CC_OP_POPCNT: + case CC_OP_LOGICB ... CC_OP_LOGICQ: + return USES_CC_DST; + case CC_OP_MULB ... CC_OP_MULQ: + case CC_OP_ADDB ... CC_OP_ADDQ: + case CC_OP_INCB ... CC_OP_INCQ: + case CC_OP_DECB ... CC_OP_DECQ: + case CC_OP_SHLB ... CC_OP_SHLQ: + case CC_OP_SARB ... CC_OP_SARQ: + case CC_OP_BMILGB ... CC_OP_BMILGQ: + case CC_OP_ADCX: + return USES_CC_DST | USES_CC_SRC; + case CC_OP_ADOX: + return USES_CC_SRC | USES_CC_SRC2; + case CC_OP_SUBB ... CC_OP_SUBQ: + return USES_CC_DST | USES_CC_SRC | USES_CC_SRCT; + case CC_OP_DYNAMIC: + case CC_OP_ADCB ... CC_OP_ADCQ: + case CC_OP_SBBB ... CC_OP_SBBQ: + case CC_OP_ADCOX: + return USES_CC_DST | USES_CC_SRC | USES_CC_SRC2; + default: + g_assert_not_reached(); + } +} static void set_cc_op_1(DisasContext *s, CCOp op, bool dirty) { @@ -320,7 +332,7 @@ static void set_cc_op_1(DisasContext *s, CCOp op, bool dirty) } /* Discard CC computation that will no longer be used. */ - dead = cc_op_live[s->cc_op] & ~cc_op_live[op]; + dead = cc_op_live(s->cc_op) & ~cc_op_live(op); if (dead & USES_CC_DST) { tcg_gen_discard_tl(cpu_cc_dst); } @@ -816,7 +828,7 @@ static void gen_mov_eflags(DisasContext *s, TCGv reg) src2 = cpu_cc_src2; /* Take care to not read values that are not live. */ - live = cc_op_live[s->cc_op] & ~USES_CC_SRCT; + live = cc_op_live(s->cc_op) & ~USES_CC_SRCT; dead = live ^ (USES_CC_DST | USES_CC_SRC | USES_CC_SRC2); if (dead) { TCGv zero = tcg_constant_tl(0); diff --git a/target/i386/tcg/decode-new.c.inc b/target/i386/tcg/decode-new.c.inc index 0d846c32c2..ba4b8d16f9 100644 --- a/target/i386/tcg/decode-new.c.inc +++ b/target/i386/tcg/decode-new.c.inc @@ -2792,7 +2792,7 @@ static void disas_insn(DisasContext *s, CPUState *cpu) tcg_gen_mov_i32(cpu_cc_op, decode.cc_op_dynamic); } set_cc_op(s, decode.cc_op); - cc_live = cc_op_live[decode.cc_op]; + cc_live = cc_op_live(decode.cc_op); } else { cc_live = 0; } diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index fc7477833b..38b399783e 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -3531,18 +3531,20 @@ static void gen_shift_dynamic_flags(DisasContext *s, X86DecodedInsn *decode, TCG { TCGv_i32 count32 = tcg_temp_new_i32(); TCGv_i32 old_cc_op; + uint8_t live; decode->cc_op = CC_OP_DYNAMIC; decode->cc_op_dynamic = tcg_temp_new_i32(); assert(decode->cc_dst == s->T0); - if (cc_op_live[s->cc_op] & USES_CC_DST) { + live = cc_op_live(s->cc_op); + if (live & USES_CC_DST) { decode->cc_dst = tcg_temp_new(); tcg_gen_movcond_tl(TCG_COND_EQ, decode->cc_dst, count, tcg_constant_tl(0), cpu_cc_dst, s->T0); } - if (cc_op_live[s->cc_op] & USES_CC_SRC) { + if (live & USES_CC_SRC) { tcg_gen_movcond_tl(TCG_COND_EQ, decode->cc_src, count, tcg_constant_tl(0), cpu_cc_src, decode->cc_src); } From patchwork Mon Jul 1 02:51:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13717516 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 EDBBAC3064D for ; Mon, 1 Jul 2024 02:52:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sO78X-00030h-Ac; Sun, 30 Jun 2024 22:51:25 -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 1sO78U-0002xL-Qg for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:22 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sO78S-00007m-TZ for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:22 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-2c84df0e2f4so1601400a91.1 for ; Sun, 30 Jun 2024 19:51:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719802279; x=1720407079; 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=+mPvMUbmRUW5qOg66PJMTfVpv43K7IU1VZRf6V6fQ1Q=; b=V5/JjILYl8P0sxw3n2cUbZh/sMn5dztL6nI3t28zgPpENiEMoeQlsj9yaQ2OjshKoi WJdZhW1WDprayRfjLCXoduGM5wweEafs+aZFS5D42nEGxUA5Ti4Of6FNLNdL2/V7qQWl mag/oO0c7IGP+BQS9TKc9pBlpxBe7y1LKaiEL4B1M8ykI0P6Ee4nPNzQ6FRzhzCETqow D+d500UDnQja70WlBwYrGxmJtZ2pcdrcGLL9gqC0B1R2cS2Spzee0qw1ICcYQRUyG+Tn 89xF6c0QoMiq3tKGilB8W3mo0POR0Ob2c2+LP5sJNpocJmoifO7OaBab2jW53hPcfrjC sVlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719802279; x=1720407079; 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=+mPvMUbmRUW5qOg66PJMTfVpv43K7IU1VZRf6V6fQ1Q=; b=TrUzLUe6EFrngqAUweg7jwOOdOjxE6DbjzUfJbcIGAwQj54CZpbWMeco3trXRRBWax njrJEwrga/wGYcFrXmT+eoT4bIIn62/8q+RNeh/wByLH4l37tjaNqt4ARPWjX0pld6Dz 9fFURDrMrEQKYaF1SMC4zdbImTcKhOXpi28jy4txJTmGq0E48Pz2aSg8bEjRP0NYpGtl Qz1HSVb7bQRdbbt64OWzRzRx2y49LQ+RTVHcnB51qy9gU8/IdFhqJ0CMmH0mq0Q9bGBo BTyemmX1IgP0OkmMYcGP+9fMj28wFzBi3UMHLURWZMx54Xf/eQAWWA33l4Z3k/gKFgZo wmMw== X-Gm-Message-State: AOJu0Yz63QAjsm+nyk8GwosIR+9efDEabDBXXCPIfgGu+5jQUxj5yROg XzpXxXbNDutDvlV4gz/bMfS0axrnrM9a1nSwPrb0UVcpnoaTC9pKgloGs7ZdxP7gSFr/OElRLXH 3 X-Google-Smtp-Source: AGHT+IF6pDvzWK0bOiycY1uCErclF6JZrL67rAeQrWa2qa13XrLBXJUAFjg0jzFdzW4tc1aedpn0og== X-Received: by 2002:a17:90a:5b0e:b0:2c8:946b:eea2 with SMTP id 98e67ed59e1d1-2c93d1b9307mr7041641a91.7.1719802279273; Sun, 30 Jun 2024 19:51:19 -0700 (PDT) Received: from stoup.. (174-21-76-141.tukw.qwest.net. [174.21.76.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91d3b9349sm5531698a91.37.2024.06.30.19.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 19:51:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 3/5] target/i386: Rearrange CCOp Date: Sun, 30 Jun 2024 19:51:13 -0700 Message-Id: <20240701025115.1265117-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240701025115.1265117-1-richard.henderson@linaro.org> References: <20240701025115.1265117-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Define CC_OP_{FIRST,LAST}_BWLQ. Remove CC_OP_NB. Give the first few enumerators explicit integer constants. Move CC_OP_POPCNT up in the enumeration; remove unused CC_OP_POPCNT*__ placeholders. Align the BWLQ enumerators. This will be used to simplify ((op - CC_OP_*B) & 3). Signed-off-by: Richard Henderson --- target/i386/cpu.h | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 29daf37048..df4272fdae 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1270,14 +1270,27 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, * are only needed for conditional branches. */ typedef enum { - CC_OP_DYNAMIC, /* must use dynamic code to get cc_op */ - CC_OP_EFLAGS, /* all cc are explicitly computed, CC_SRC = flags */ - CC_OP_ADCX, /* CC_DST = C, CC_SRC = rest. */ - CC_OP_ADOX, /* CC_SRC2 = O, CC_SRC = rest. */ - CC_OP_ADCOX, /* CC_DST = C, CC_SRC2 = O, CC_SRC = rest. */ - CC_OP_CLR, /* Z and P set, all other flags clear. */ + CC_OP_DYNAMIC = 0, /* must use dynamic code to get cc_op */ + CC_OP_EFLAGS = 1, /* all cc are explicitly computed, CC_SRC = flags */ + CC_OP_ADCX = 2, /* CC_DST = C, CC_SRC = rest. */ + CC_OP_ADOX = 3, /* CC_SRC2 = O, CC_SRC = rest. */ + CC_OP_ADCOX = 4, /* CC_DST = C, CC_SRC2 = O, CC_SRC = rest. */ + CC_OP_CLR = 5, /* Z and P set, all other flags clear. */ - CC_OP_MULB, /* modify all flags, C, O = (CC_SRC != 0) */ + /* + * Z via CC_DST, all other flags clear. + * Treat CC_OP_POPCNT like the other BWLQ ops in making the low bits + * equal MO_TL; this gives a value of either 6 or 7. + */ +#ifdef TARGET_X86_64 + CC_OP_POPCNT = 7, +#else + CC_OP_POPCNT = 6, +#endif + +#define CC_OP_FIRST_BWLQ CC_OP_POPCNT + + CC_OP_MULB = 8, /* modify all flags, C, O = (CC_SRC != 0) */ CC_OP_MULW, CC_OP_MULL, CC_OP_MULQ, @@ -1332,20 +1345,11 @@ typedef enum { CC_OP_BMILGL, CC_OP_BMILGQ, - /* - * Note that only CC_OP_POPCNT (i.e. the one with MO_TL size) - * is used or implemented, because the translation needs - * to zero-extend CC_DST anyway. - */ - CC_OP_POPCNTB__, /* Z via CC_DST, all other flags clear. */ - CC_OP_POPCNTW__, - CC_OP_POPCNTL__, - CC_OP_POPCNTQ__, - CC_OP_POPCNT = sizeof(target_ulong) == 8 ? CC_OP_POPCNTQ__ : CC_OP_POPCNTL__, - - CC_OP_NB, +#define CC_OP_LAST_BWLQ CC_OP_BMILGQ } CCOp; -QEMU_BUILD_BUG_ON(CC_OP_NB >= 128); + +/* See X86DecodedInsn.cc_op, using int8_t. */ +QEMU_BUILD_BUG_ON(CC_OP_LAST_BWLQ > INT8_MAX); typedef struct SegmentCache { uint32_t selector; From patchwork Mon Jul 1 02:51:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13717512 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 149DDC27C4F for ; Mon, 1 Jul 2024 02:51:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sO78W-000304-6i; Sun, 30 Jun 2024 22:51:25 -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 1sO78V-0002yS-7w for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:23 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sO78T-0000DQ-LB for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:22 -0400 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2c8e7553c9eso1794296a91.3 for ; Sun, 30 Jun 2024 19:51:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719802280; x=1720407080; 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=M3N6rPlpvzYKdcGfQuTrjYcbyNAlpYXYp9ucQoujl0c=; b=MBMM8ZAQ/LynmXoslz7vX4zIJjv7/3x/6x4CHIgo1bYTDREuXGwTVqftSDsBLck1BS 4jIqrL/fsVsaKUK6T4r6vmko274QBcSvG4/T0keJPdNv5JcSdZwtlCm0zFesTG7GymDT nydsCGLE9ce/Pu1HQgZqaNBhSAGzk08H/6X9zQnZ6W/HKEt5OjzhbClqi0InB8cfCkaM O97HBXhuljL9dcymQMSOpPfXpf0EpvoWwjYt8Ydm1ML3gyxmtZe+gcvUzeEkubnGt2p4 8W6E/6eTUuNsnvpzHAqsNYYmLX0puJ2/bEtQqUEtCyd6XPhCCVj88+G+mhVbNYWYhaad JM8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719802280; x=1720407080; 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=M3N6rPlpvzYKdcGfQuTrjYcbyNAlpYXYp9ucQoujl0c=; b=AjC4VBDKq3kwOtbra5Jgntv3I3DY9n1bBNSaftofqFDd2rJgdMgirnFtK2lukHVdEs TZSkz077aeG+LDf3QHK413Shjn+mIk+qlJMc99DoMLcn3S3sRsu4ot30hlbL85FRj6aw 8vIA8nloKHJnOXiEZj/QSgnBaWvgECgcGH+dGXrSPbstogf2QrZfLpYYwF+z064d77JX RBIlirRFxqY6yHibT53dH2cx93+H+6uYXHEeNzvvS7n1ABf1o8CYhWx7luFuV8TKNUAy 2aGpZ2rrv35AbBshAP49Fz5Dokn0PpTVsJclEWNWUPZHHTLN4lhg2O+bmfex3Gt428NO iLMg== X-Gm-Message-State: AOJu0YzRfEYe3l+WfNhq1YuAxYulYiWNlCZJQNUum1sHMkf4l8HjDNdL vTPKwPiGwOC6hfZd+CA7Lhi6BB2Ej5Ym3wbLSl3q8/nLOODMCuQJ58SmvrS8+CQUleKB+ggRtSF z X-Google-Smtp-Source: AGHT+IHPZokYVk3/63oBakFeipGmzM7Rak8PpTpgOviYTVmG8EuKuUj+QkvZW6Py2tfoA9HvDc67aQ== X-Received: by 2002:a17:90a:c084:b0:2c7:c6a1:42c9 with SMTP id 98e67ed59e1d1-2c93d6f22ffmr3648624a91.10.1719802280206; Sun, 30 Jun 2024 19:51:20 -0700 (PDT) Received: from stoup.. (174-21-76-141.tukw.qwest.net. [174.21.76.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91d3b9349sm5531698a91.37.2024.06.30.19.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 19:51:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 4/5] target/i386: Remove default in cc_op_live Date: Sun, 30 Jun 2024 19:51:14 -0700 Message-Id: <20240701025115.1265117-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240701025115.1265117-1-richard.henderson@linaro.org> References: <20240701025115.1265117-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Now that CC_OP_NB is gone, push the assert after the switch. This will allow -Wswitch to diagnose missing entries. Signed-off-by: Richard Henderson --- target/i386/tcg/translate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index e5a8aaf793..e675afca47 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -318,9 +318,8 @@ static uint8_t cc_op_live(CCOp op) case CC_OP_SBBB ... CC_OP_SBBQ: case CC_OP_ADCOX: return USES_CC_DST | USES_CC_SRC | USES_CC_SRC2; - default: - g_assert_not_reached(); } + g_assert_not_reached(); } static void set_cc_op_1(DisasContext *s, CCOp op, bool dirty) From patchwork Mon Jul 1 02:51:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13717514 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 28D6DC3064D for ; Mon, 1 Jul 2024 02:51:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sO78Y-00031H-Qq; Sun, 30 Jun 2024 22:51:27 -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 1sO78W-00030C-Bq for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:24 -0400 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sO78U-0000Gi-D2 for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:51:24 -0400 Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-5ba33b08550so1282289eaf.2 for ; Sun, 30 Jun 2024 19:51:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719802281; x=1720407081; 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=v8ctItCGfyeAkHxXU4PbxRnvrKAFyRywgfWFR/Aj32s=; b=ema0Nc/adOPDBVBO3usYdvf7a3LvHZwU6gPs4LvuvCCrRbStuyDVo1ET9Zv+MpW8sH JTnIcqixzOe/fDyrqH5wnWhkQ9HWd4qi69vs6v2ckCgrbKSoImrnalJhh+wWzpvmykRX IvzMRRPtnmA+dy87kxPL0B29oP6yFyAxcnGcOO9ifU8vQEKHjdcTcp+EA8IXBeB9rp8J lXQwWx+6QoanMXlh1FDlKTYdNcvw6ayDCt/myBxFW8NegvMztR+JmgWrg1+dLY4pbgrW h57yBnOGt6JdNTyTpzYy9dYcgnNB1XJ1tvrMCE1jkwMrGMTbfd5yx0ZLnvdh1nNITBrS TdRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719802281; x=1720407081; 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=v8ctItCGfyeAkHxXU4PbxRnvrKAFyRywgfWFR/Aj32s=; b=LJZuI4dMSeHPV+SFH3uRUFK85tii12eBz4kb9dkfMqaGEMdBFGp9zrbkhlQ8Kc5JhB kA0f6h4iVUr+8x8ZWxtcylPUJ+ldMoIxHt1tyAhbcfL+P5N9ONlmkVE/pFwnQsHiB1e2 wUAoaO/zZAFzsc/FFwhjlYHew+9q2+0iLKZVClotTMKQrAj4hHKTyBABSNugseDfGkq8 JTCTc6cmHVbiYgXfneIABJxsahoFesSC/ck0PfVIu9PQiKhAFyEg/rGoHiypPQhp45Ko UAoBdE9O5rhYVEzCDTj2ZoSOj2dVQrwXJNN3iiFcLnilGsq9hXL2PC51TzZd1OAYvItm 0XWA== X-Gm-Message-State: AOJu0YyHdu2omGRD3Q2aa4lc2Y4xuIZec0CUQYdt5S6htX6rMeV8hz82 nGIsLM0FoVtmhNT9obCmBTqPtMZnbB0DC5LEly3NqDZTv5MSVYF7ePT4UbeHAzgYL5cXawgDhAI k X-Google-Smtp-Source: AGHT+IFnWMAPEcMXFW+JxIMi07bQZZeg/a/6n/CzE9EcIDrjVACaJC9wNILwBMfy+nZ+yMGIfRL/WQ== X-Received: by 2002:a05:6358:7e16:b0:19f:45a6:4965 with SMTP id e5c5f4694b2df-1a6acccd74emr502455955d.7.1719802280921; Sun, 30 Jun 2024 19:51:20 -0700 (PDT) Received: from stoup.. (174-21-76-141.tukw.qwest.net. [174.21.76.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91d3b9349sm5531698a91.37.2024.06.30.19.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jun 2024 19:51:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com Subject: [PATCH 5/5] target/i386: Introduce cc_op_size Date: Sun, 30 Jun 2024 19:51:15 -0700 Message-Id: <20240701025115.1265117-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240701025115.1265117-1-richard.henderson@linaro.org> References: <20240701025115.1265117-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c33; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc33.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Replace arithmetic on cc_op with a helper function. Assert that the op has a size and that it is valid for the configuration. Signed-off-by: Richard Henderson --- target/i386/tcg/translate.c | 29 ++++++++++++++++++----------- target/i386/tcg/emit.c.inc | 3 ++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index e675afca47..e98bed0805 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -322,6 +322,16 @@ static uint8_t cc_op_live(CCOp op) g_assert_not_reached(); } +static MemOp cc_op_size(CCOp op) +{ + MemOp size = op & 3; + + assert(op >= CC_OP_FIRST_BWLQ && op <= CC_OP_LAST_BWLQ); + assert(size <= MO_TL); + + return size; +} + static void set_cc_op_1(DisasContext *s, CCOp op, bool dirty) { int dead; @@ -884,7 +894,7 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s, TCGv reg) switch (s->cc_op) { case CC_OP_SUBB ... CC_OP_SUBQ: /* (DATA_TYPE)CC_SRCT < (DATA_TYPE)CC_SRC */ - size = s->cc_op - CC_OP_SUBB; + size = cc_op_size(s->cc_op); gen_ext_tl(s->cc_srcT, s->cc_srcT, size, false); gen_ext_tl(cpu_cc_src, cpu_cc_src, size, false); return (CCPrepare) { .cond = TCG_COND_LTU, .reg = s->cc_srcT, @@ -892,7 +902,7 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s, TCGv reg) case CC_OP_ADDB ... CC_OP_ADDQ: /* (DATA_TYPE)CC_DST < (DATA_TYPE)CC_SRC */ - size = s->cc_op - CC_OP_ADDB; + size = cc_op_size(s->cc_op); gen_ext_tl(cpu_cc_dst, cpu_cc_dst, size, false); gen_ext_tl(cpu_cc_src, cpu_cc_src, size, false); return (CCPrepare) { .cond = TCG_COND_LTU, .reg = cpu_cc_dst, @@ -910,7 +920,7 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s, TCGv reg) case CC_OP_SHLB ... CC_OP_SHLQ: /* (CC_SRC >> (DATA_BITS - 1)) & 1 */ - size = s->cc_op - CC_OP_SHLB; + size = cc_op_size(s->cc_op); return gen_prepare_sign_nz(cpu_cc_src, size); case CC_OP_MULB ... CC_OP_MULQ: @@ -918,7 +928,7 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s, TCGv reg) .reg = cpu_cc_src }; case CC_OP_BMILGB ... CC_OP_BMILGQ: - size = s->cc_op - CC_OP_BMILGB; + size = cc_op_size(s->cc_op); gen_ext_tl(cpu_cc_src, cpu_cc_src, size, false); return (CCPrepare) { .cond = TCG_COND_EQ, .reg = cpu_cc_src }; @@ -972,10 +982,7 @@ static CCPrepare gen_prepare_eflags_s(DisasContext *s, TCGv reg) case CC_OP_POPCNT: return (CCPrepare) { .cond = TCG_COND_NEVER }; default: - { - MemOp size = (s->cc_op - CC_OP_ADDB) & 3; - return gen_prepare_sign_nz(cpu_cc_dst, size); - } + return gen_prepare_sign_nz(cpu_cc_dst, cc_op_size(s->cc_op)); } } @@ -1016,7 +1023,7 @@ static CCPrepare gen_prepare_eflags_z(DisasContext *s, TCGv reg) return (CCPrepare) { .cond = TCG_COND_ALWAYS }; default: { - MemOp size = (s->cc_op - CC_OP_ADDB) & 3; + MemOp size = cc_op_size(s->cc_op); if (size == MO_TL) { return (CCPrepare) { .cond = TCG_COND_EQ, .reg = cpu_cc_dst }; } else { @@ -1042,7 +1049,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int b, TCGv reg) switch (s->cc_op) { case CC_OP_SUBB ... CC_OP_SUBQ: /* We optimize relational operators for the cmp/jcc case. */ - size = s->cc_op - CC_OP_SUBB; + size = cc_op_size(s->cc_op); switch (jcc_op) { case JCC_BE: gen_ext_tl(s->cc_srcT, s->cc_srcT, size, false); @@ -3176,7 +3183,7 @@ static void disas_insn_old(DisasContext *s, CPUState *cpu, int b) CC_DST alone, setting CC_SRC, and using a CC_OP_SAR of the same width. */ tcg_gen_mov_tl(cpu_cc_src, s->tmp4); - set_cc_op(s, ((s->cc_op - CC_OP_MULB) & 3) + CC_OP_SARB); + set_cc_op(s, CC_OP_SARB + cc_op_size(s->cc_op)); break; default: /* Otherwise, generate EFLAGS and replace the C bit. */ diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 38b399783e..e9d5d196ce 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -3106,7 +3106,8 @@ static bool gen_eflags_adcox(DisasContext *s, X86DecodedInsn *decode, bool want_ * bit, we might as well fish CF out of EFLAGS and save a shift. */ if (want_carry && (!need_flags || s->cc_op == CC_OP_SHLB + MO_TL)) { - tcg_gen_shri_tl(decode->cc_dst, cpu_cc_src, (8 << (s->cc_op - CC_OP_SHLB)) - 1); + MemOp size = cc_op_size(s->cc_op); + tcg_gen_shri_tl(decode->cc_dst, cpu_cc_src, (8 << size) - 1); got_cf = true; } gen_mov_eflags(s, decode->cc_src);