From nobody Tue Nov 26 06:48:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709118820; cv=none; d=zohomail.com; s=zohoarc; b=iD7SH3LnktJeVyC5u6I55b3mL4FxaKZPVpYoVqsH3XzTJvWwqVFjXd0doqkNXneFeffR6OAKF+FqvUKsPK1ARMGG03HqPRbi4XhiwnU1WTICkVKQ07oVyb6Am2ts1nr9Gs54hIPNcdXpEibW+dW7T9vIw5AQ0Z9Wpyf+naUPdBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709118820; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2lITc8wdXp+om+78er1UP4KPqGeYdYRVhMnXnbWICmk=; b=L4V5CXZYcpU6KkqfOLilPj03g0X8z/b9/H/2S7PMfWtSAScZ7dDXLx+d6w6PxavSoiM7WepHHpORZxaCCDUTVjddxggRFpvQve1lZwJryLr8azefq/ErEEStD0yVo88nVG/2OysQlC9XgLHlIDWGQsqefwGhXihCBoHS09xdf7Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709118820298396.8390372530897; Wed, 28 Feb 2024 03:13:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfHr5-0004fH-9P; Wed, 28 Feb 2024 06:12:07 -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 1rfHr2-0004e9-GZ for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:12:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfHqz-0003mv-3u for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:12:04 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-19-lGthTntBNvGcFddv4V28oQ-1; Wed, 28 Feb 2024 06:11:58 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a3ee69976dfso218031566b.3 for ; Wed, 28 Feb 2024 03:11:58 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id j3-20020a1709062a0300b00a3e799969aesm1718568eje.119.2024.02.28.03.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:11:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709118720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2lITc8wdXp+om+78er1UP4KPqGeYdYRVhMnXnbWICmk=; b=Ud8oic6JxBGShA6leySCYGvUjnhJ73b6SPkVIoDHPGHraPTSZ7FPUDi12tQMTc7h53DS8p D5A6Nq4L1Z1wv2q9Pj79IxH7n8WPbKGMLpejx1WBmFCvE9MiOzNCjTFV3aWukbXFON3Qlt d2fshituR57UQX96S91SlVFx2EjmlkQ= X-MC-Unique: lGthTntBNvGcFddv4V28oQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709118716; x=1709723516; 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=2lITc8wdXp+om+78er1UP4KPqGeYdYRVhMnXnbWICmk=; b=FdB4fixDqBrYjih9TSaa00LnlFOKuDI992zwe9sUiVI2WFn7T+s/tj7aJR4c3DCRIM gecMguMoHnQyCZIvsj9jfM9QvGgLi/7zSATcoS+OKIlcJT5HT2fp7+SJGvJ6eQ2EdNMw FFFKPiOBW/4e5o7PgP0OFRI7yUTOQ96u3ukjNHmkBVlEGBmbH0gGLoWMTykheqXh+Gg7 u29+8G0L3m8c8AVAvkdIq7qNmcQ6TPn5vBslZ2SK22WoAn7JZRaAz0wBxV8pZ1tBcjLw tJDuWWwx2I8/ndflF6LdUIzp8djWYrnRRJhUL1UNRtDvnW9aB9nQqdvSvebHiSdXbX5F dnlQ== X-Gm-Message-State: AOJu0YwtWzk3NDN6TQmm0+xPYL0hlIFm4g8W3GwmDbUMPogKuvduRAho SQ00CTekLXbi96pUigtT1yZpFlqDp9In6Khi5Zv9O734HKYQqRoYEtqw7GxqwDirg+q1g7FQEYi AMVHB5qVUIvJu11+pFNAQ/lEC97PrhxCEgUfD0tnYXHOnt3gKdfLkDbNgAdOdSz25TMFl9Ifft7 oKkR8wtwN3s1I6E7e6wRNInkLHrwtKVkS4678B X-Received: by 2002:a17:906:7b50:b0:a43:ef3d:e42e with SMTP id n16-20020a1709067b5000b00a43ef3de42emr1070680ejo.18.1709118716268; Wed, 28 Feb 2024 03:11:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGd6l3IV++Garq8LNTghNvXUWGaaYs3683iYhinNRSy6U/kgbKGUANq0V+iXD9qpPe6gJ0HWQ== X-Received: by 2002:a17:906:7b50:b0:a43:ef3d:e42e with SMTP id n16-20020a1709067b5000b00a43ef3de42emr1070660ejo.18.1709118715685; Wed, 28 Feb 2024 03:11:55 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 1/4] target/i386: use TSTEQ/TSTNE to test low bits Date: Wed, 28 Feb 2024 12:11:48 +0100 Message-ID: <20240228111151.287738-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228111151.287738-1-pbonzini@redhat.com> References: <20240228111151.287738-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709118821058100003 Content-Type: text/plain; charset="utf-8" When testing the sign bit or equality to zero of a partial register, it is useful to use a single TSTEQ or TSTNE operation. It can also be used to test the parity flag, using bit 0 of the population count. Do not do this for 32- and 64-bit values however, to avoid large immediates. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 28 ++++++++++++++++++++-------- target/i386/tcg/emit.c.inc | 5 ++--- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 07f642dc9e9..fe9021833e3 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -927,11 +927,21 @@ typedef struct CCPrepare { bool no_setcond; } CCPrepare; =20 +static CCPrepare gen_prepare_sign_nz(TCGv src, MemOp size) +{ + if (size =3D=3D MO_TL) { + return (CCPrepare) { .cond =3D TCG_COND_LT, .reg =3D src, .mask = =3D -1 }; + } else { + return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D src, .mask= =3D -1, + .imm =3D 1ull << ((8 << size) - 1) }; + } +} + /* compute eflags.C to reg */ static CCPrepare gen_prepare_eflags_c(DisasContext *s, TCGv reg) { TCGv t0, t1; - int size, shift; + MemOp size; =20 switch (s->cc_op) { case CC_OP_SUBB ... CC_OP_SUBQ: @@ -966,9 +976,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 =3D s->cc_op - CC_OP_SHLB; - shift =3D (8 << size) - 1; - return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_src, - .mask =3D (target_ulong)1 << shift }; + return gen_prepare_sign_nz(cpu_cc_src, size); =20 case CC_OP_MULB ... CC_OP_MULQ: return (CCPrepare) { .cond =3D TCG_COND_NE, @@ -1028,8 +1036,7 @@ static CCPrepare gen_prepare_eflags_s(DisasContext *s= , TCGv reg) default: { MemOp size =3D (s->cc_op - CC_OP_ADDB) & 3; - TCGv t0 =3D gen_ext_tl(reg, cpu_cc_dst, size, true); - return (CCPrepare) { .cond =3D TCG_COND_LT, .reg =3D t0, .mask= =3D -1 }; + return gen_prepare_sign_nz(cpu_cc_dst, size); } } } @@ -1076,8 +1083,13 @@ static CCPrepare gen_prepare_eflags_z(DisasContext *= s, TCGv reg) default: { MemOp size =3D (s->cc_op - CC_OP_ADDB) & 3; - TCGv t0 =3D gen_ext_tl(reg, cpu_cc_dst, size, false); - return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D t0, .mask= =3D -1 }; + if (size =3D=3D MO_TL) { + return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D cpu_c= c_dst, + .mask =3D -1 }; + } else { + return (CCPrepare) { .cond =3D TCG_COND_TSTEQ, .reg =3D cp= u_cc_dst, + .mask =3D -1, .imm =3D (1ull << (8 <<= size)) - 1 }; + } } } } diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index 6bcf88ecd71..0e00f6635dd 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1209,7 +1209,7 @@ static void gen_CMPccXADD(DisasContext *s, CPUX86Stat= e *env, X86DecodedInsn *dec [JCC_Z] =3D TCG_COND_EQ, [JCC_BE] =3D TCG_COND_LEU, [JCC_S] =3D TCG_COND_LT, /* test sign bit by comparing against 0 = */ - [JCC_P] =3D TCG_COND_EQ, /* even parity - tests low bit of popcou= nt */ + [JCC_P] =3D TCG_COND_TSTEQ, /* even parity - tests low bit of pop= count */ [JCC_L] =3D TCG_COND_LT, [JCC_LE] =3D TCG_COND_LE, }; @@ -1260,8 +1260,7 @@ static void gen_CMPccXADD(DisasContext *s, CPUX86Stat= e *env, X86DecodedInsn *dec case JCC_P: tcg_gen_ext8u_tl(s->tmp0, s->T0); tcg_gen_ctpop_tl(s->tmp0, s->tmp0); - tcg_gen_andi_tl(s->tmp0, s->tmp0, 1); - cmp_lhs =3D s->tmp0, cmp_rhs =3D tcg_constant_tl(0); + cmp_lhs =3D s->tmp0, cmp_rhs =3D tcg_constant_tl(1); break; =20 case JCC_S: --=20 2.43.2 From nobody Tue Nov 26 06:48:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709118808; cv=none; d=zohomail.com; s=zohoarc; b=hGpNbWsaduUYglbrIobk1GLHWXs2QG9PrW9CH8a85UkooFfzHysFQYQuG28Mlu3+gc+gIuGKb88p4bOzKw+4jgyDDxUjyfwJoEfoKhHy4QckcFRNpOmEDAn3aXdQTbD/+ybiphMnXj5DOKfWJ53Nj55paR0539CBKuH7I7ZYARA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709118808; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vdiqFmI9WNRUmhfY3Qso6ESXzjkal8TeG/51RyozoDo=; b=ERluCF+i5C9OJi9bGyJ/0Kr5tC94zedPsdoBpmCfJwQAw2niKzE+//waJBzneVjQvX49Ku4Pzvc2FuDxB5ELpiNz5RytDB0GXH76kzxAkNOWOgaTElx8BOmASONS/ZXbFV4y//rM0+poBxkiLQF9fgXAN5jvtf/YfC70y2FP+3w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709118808797430.7328273691371; Wed, 28 Feb 2024 03:13:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfHr8-0004gO-4Z; Wed, 28 Feb 2024 06:12:10 -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 1rfHr6-0004fr-K0 for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:12:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfHr2-0003nA-6G for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:12:08 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-642-GZAi8HvsOviYFxewEttv8w-1; Wed, 28 Feb 2024 06:12:01 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a3ede65e32bso177711766b.1 for ; Wed, 28 Feb 2024 03:12:01 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id qo12-20020a170907874c00b00a43c51efb11sm1264669ejc.3.2024.02.28.03.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:11:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709118723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vdiqFmI9WNRUmhfY3Qso6ESXzjkal8TeG/51RyozoDo=; b=Hosfy6p4Hgu0VVeOLydxeVfNU6NffZHYFbhkcpbR5DNJw3Tv0bpUnd+qi+8QIUWD4euCEq gQFFOqDMdlpt3xns3mMd6aFhK4mpaiCb+lhzY3knWdmnnQ5kaikzuBtEqlypnTNbaguSu+ MbIv1+f/nBIrtqd9SNSY7NmZtHXCINU= X-MC-Unique: GZAi8HvsOviYFxewEttv8w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709118719; x=1709723519; 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=vdiqFmI9WNRUmhfY3Qso6ESXzjkal8TeG/51RyozoDo=; b=vfoop8y5LJYaY+VdfZfgOz4dAi99HcDYsYru3M3rOUhA50SKxCR2xUNaN5R/Oj9dj3 kJUp0RHCwRxI1l4gmyNLOsXHfEwgvY57LaZXn2UtMmt/g+oFRFG6J4iirfQE2F0X0iio Khasb2/2wLa+5BQY2T6QQq9ky7yc7y5KUmB/QsjhU6H70LqQcNkhZPxJwWMVvHqX2CoP 9aGvKE294ZApapGdhVV9hXgBt6RDKJQSDwGKX/Lvwr/PHG1BFjflkLcF1Hojb/fiEcFg kGSeQxfTjShIcTo9AvyhPOeCdRZahTpsJQGpW8weWOUSbQCusvbRmQ+mtZ9KMrp5wh8U 0h2g== X-Gm-Message-State: AOJu0YyCJSzGg1ZCGpavL9TsfsJ0MMnRjNBvhcIP15+awowNQkYO3FCx jdCtshQLldqOgi/4dq5j7IeOwx9Jt0biVZxrqxSpq97i94ZO1cg+T7NBthOrRN2gwCPv2arXtA+ 7uAeeLt2bwI06LgUWpS4ArPmonn+Y1JFmw27O3Ev7yy9Jb8bzhemNuWdgoXjLKSSCGhrnI27Y5n pCAwezmsFcEHV35rhv/Ou+uWSTodb5phujQDn/ X-Received: by 2002:a17:906:15c1:b0:a43:72d6:f1fe with SMTP id l1-20020a17090615c100b00a4372d6f1femr4926838ejd.77.1709118719481; Wed, 28 Feb 2024 03:11:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3334Lqps0/8fvkQjUrC8JcdfSZxB2qb3b3g/NXmrIQD8iajx6xxgMykBn5JJV+Z3YBBLdBA== X-Received: by 2002:a17:906:15c1:b0:a43:72d6:f1fe with SMTP id l1-20020a17090615c100b00a4372d6f1femr4926821ejd.77.1709118719096; Wed, 28 Feb 2024 03:11:59 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 2/4] target/i386: use TSTEQ/TSTNE to check flags Date: Wed, 28 Feb 2024 12:11:49 +0100 Message-ID: <20240228111151.287738-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228111151.287738-1-pbonzini@redhat.com> References: <20240228111151.287738-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709118810931100007 Content-Type: text/plain; charset="utf-8" The new condition obviously come in handy when testing individual bits of EFLAGS, and they make it possible to remove the .mask field of CCPrepare. Lowering to shift+and is done by the optimizer if necessary. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index fe9021833e3..63d520e0cba 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -995,8 +995,8 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s, = TCGv reg) case CC_OP_EFLAGS: case CC_OP_SARB ... CC_OP_SARQ: /* CC_SRC & 1 */ - return (CCPrepare) { .cond =3D TCG_COND_NE, - .reg =3D cpu_cc_src, .mask =3D CC_C }; + return (CCPrepare) { .cond =3D TCG_COND_TSTNE, + .reg =3D cpu_cc_src, .mask =3D -1, .imm =3D C= C_C }; =20 default: /* The need to compute only C from CC_OP_DYNAMIC is important @@ -1013,8 +1013,8 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s= , TCGv reg) static CCPrepare gen_prepare_eflags_p(DisasContext *s, TCGv reg) { gen_compute_eflags(s); - return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_src, - .mask =3D CC_P }; + return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc_src, + .mask =3D -1, .imm =3D CC_P }; } =20 /* compute eflags.S to reg */ @@ -1028,8 +1028,8 @@ static CCPrepare gen_prepare_eflags_s(DisasContext *s= , TCGv reg) case CC_OP_ADCX: case CC_OP_ADOX: case CC_OP_ADCOX: - return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_src, - .mask =3D CC_S }; + return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc_src, + .mask =3D -1, .imm =3D CC_S }; case CC_OP_CLR: case CC_OP_POPCNT: return (CCPrepare) { .cond =3D TCG_COND_NEVER, .mask =3D -1 }; @@ -1057,8 +1057,8 @@ static CCPrepare gen_prepare_eflags_o(DisasContext *s= , TCGv reg) .reg =3D cpu_cc_src, .mask =3D -1 }; default: gen_compute_eflags(s); - return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_src, - .mask =3D CC_O }; + return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc_src, + .mask =3D -1, .imm =3D CC_O }; } } =20 @@ -1073,8 +1073,8 @@ static CCPrepare gen_prepare_eflags_z(DisasContext *s= , TCGv reg) case CC_OP_ADCX: case CC_OP_ADOX: case CC_OP_ADCOX: - return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_src, - .mask =3D CC_Z }; + return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc_src, + .mask =3D -1, .imm =3D CC_Z }; case CC_OP_CLR: return (CCPrepare) { .cond =3D TCG_COND_ALWAYS, .mask =3D -1 }; case CC_OP_POPCNT: @@ -1152,8 +1152,8 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) break; case JCC_BE: gen_compute_eflags(s); - cc =3D (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_sr= c, - .mask =3D CC_Z | CC_C }; + cc =3D (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc= _src, + .mask =3D -1, .imm =3D CC_Z | CC_C }; break; case JCC_S: cc =3D gen_prepare_eflags_s(s, reg); @@ -1167,8 +1167,8 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) reg =3D s->tmp0; } tcg_gen_addi_tl(reg, cpu_cc_src, CC_O - CC_S); - cc =3D (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D reg, - .mask =3D CC_O }; + cc =3D (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D reg, + .mask =3D -1, .imm =3D CC_O }; break; default: case JCC_LE: @@ -1177,8 +1177,8 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) reg =3D s->tmp0; } tcg_gen_addi_tl(reg, cpu_cc_src, CC_O - CC_S); - cc =3D (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D reg, - .mask =3D CC_O | CC_Z }; + cc =3D (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D reg, + .mask =3D -1, .imm =3D CC_O | CC_Z }; break; } break; --=20 2.43.2 From nobody Tue Nov 26 06:48:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709118790; cv=none; d=zohomail.com; s=zohoarc; b=Rs6UswCwSH78HomQjgUEw2fMlIxMKERk1OPDpzCKZxizRdoOhX5eFJPQFDFrYLnCNsF9NKi5I1xZPF08aFsx+kPJU699p61smob3V/7foNzz8EPLSkByhEyW04NqiWC2r2zX+vIUr3xe1Pf4zOqWEBMzWEHExNplcApejh6yQh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709118790; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wUSO+qZ4tNs0ir8YxjqhY4NacCQoW943sxnYhbULbKk=; b=MdmlR37FP4w7H7p0MLT7G6rGaLwOeYlojKhtFauwIAuiV4enkgaNIAkuRLlZVqabfxLnN9alB3U6fa77aLEET7sQJlDiPABzgEaLkmocTogDDoKbQrG6WODCJKvpIG8AapeHgwwadCKFM8zigo5GHR55QT5Et8L5ww35aQJ/0gs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709118790686728.3583733854433; Wed, 28 Feb 2024 03:13:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfHrB-0004ix-O6; Wed, 28 Feb 2024 06:12:13 -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 1rfHr9-0004go-5D for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:12:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfHr6-0003ne-ET for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:12:10 -0500 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-VWHrIgezOMKDFPSOFbe1kQ-1; Wed, 28 Feb 2024 06:12:06 -0500 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-56542d424cdso2955521a12.2 for ; Wed, 28 Feb 2024 03:12:06 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id ti6-20020a170907c20600b00a43c3e5e008sm1286195ejc.205.2024.02.28.03.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:12:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709118727; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wUSO+qZ4tNs0ir8YxjqhY4NacCQoW943sxnYhbULbKk=; b=HGrT4QhUJ9791clu/ZAK2hJzMiC/79WmiV8XoyHrQ2DyuM9eQb9zOAP85Ab4nGQ7xIZeIy Cvhj4v6gp0Gd2eoVJ1WAxBJkkhoo6XXHouRQmmxgz18cFStl+WXr28cwGg0pUNgou6pCv5 0LczbIGfjq+qkiX6JzOSbBtV3VkyUtI= X-MC-Unique: VWHrIgezOMKDFPSOFbe1kQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709118724; x=1709723524; 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=wUSO+qZ4tNs0ir8YxjqhY4NacCQoW943sxnYhbULbKk=; b=rZ734eEO+G5YJQkND6Ki+u4Qm/fmGr4oKUmAhubYsi7IGAiH7/IdteI78pqcNjspt9 utKzqVUNjePHXS/YeBPH8sC6XFQExGKUciEmQFi3XBJK+19Fp5dBfpHWa0gzeEROQXcS VWJqXxg/jI93N7qs+X0a3EzEJ8rswyO9wVnDIycbW1w4nrmstQ433q/ATVcpB4ZGtxvk SqXhGNHhMGaxKP37Aqm5YW1IAxHWucdtVoMW3c4yuYvzjfyoG030IGwbTe6g4aqHt1Df eg5u81rK6xsNMbjFs9FD+l8dYELsT12ilCU+zElgblymICS0NvXKoibFNnR7zbN0A2EL l5Pg== X-Gm-Message-State: AOJu0Yyc3FIOWgFGbNRLZlHgRGnwVTXyqbdZqjhxN3wgvU/GzRFWH9GA jvbZebqeKrkhnD63rADYvH0E9OwQf+D/dSNcNi4ZwL4Wn3hMTPO1md+FAnbD5apiN9+xM5fCaE2 1hNRRmp1tovYJmERjvxcg9bLRfG3Iq+ixgKvEiaN52rCL6v3rybvW5H2DwimBw+VytbrUVgDG6n fKqNXSnHwG5NhruVDw4XCikqMGNxYoTb8yC9xc X-Received: by 2002:a17:906:d192:b0:a43:2290:7689 with SMTP id c18-20020a170906d19200b00a4322907689mr5733357ejz.65.1709118723718; Wed, 28 Feb 2024 03:12:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGalDDsXcf1+kfbie99oGFSvP5y8mZW3invQnXSotjlrRHSzn8THRUuuR+J3iovdFihR9cYrA== X-Received: by 2002:a17:906:d192:b0:a43:2290:7689 with SMTP id c18-20020a170906d19200b00a4322907689mr5733343ejz.65.1709118723314; Wed, 28 Feb 2024 03:12:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 3/4] target/i386: remove mask from CCPrepare Date: Wed, 28 Feb 2024 12:11:50 +0100 Message-ID: <20240228111151.287738-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228111151.287738-1-pbonzini@redhat.com> References: <20240228111151.287738-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709118792615100006 Content-Type: text/plain; charset="utf-8" With the introduction of TSTEQ and TSTNE the .mask field is always -1, so remove all the now-unnecessary code. Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- target/i386/tcg/translate.c | 81 +++++++++++++------------------------ 1 file changed, 27 insertions(+), 54 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 63d520e0cba..6b4522c226d 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -922,7 +922,6 @@ typedef struct CCPrepare { TCGv reg; TCGv reg2; target_ulong imm; - target_ulong mask; bool use_reg2; bool no_setcond; } CCPrepare; @@ -930,9 +929,9 @@ typedef struct CCPrepare { static CCPrepare gen_prepare_sign_nz(TCGv src, MemOp size) { if (size =3D=3D MO_TL) { - return (CCPrepare) { .cond =3D TCG_COND_LT, .reg =3D src, .mask = =3D -1 }; + return (CCPrepare) { .cond =3D TCG_COND_LT, .reg =3D src }; } else { - return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D src, .mask= =3D -1, + return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D src, .imm =3D 1ull << ((8 << size) - 1) }; } } @@ -961,17 +960,17 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s= , TCGv reg) t0 =3D gen_ext_tl(reg, cpu_cc_dst, size, false); add_sub: return (CCPrepare) { .cond =3D TCG_COND_LTU, .reg =3D t0, - .reg2 =3D t1, .mask =3D -1, .use_reg2 =3D tru= e }; + .reg2 =3D t1, .use_reg2 =3D true }; =20 case CC_OP_LOGICB ... CC_OP_LOGICQ: case CC_OP_CLR: case CC_OP_POPCNT: - return (CCPrepare) { .cond =3D TCG_COND_NEVER, .mask =3D -1 }; + return (CCPrepare) { .cond =3D TCG_COND_NEVER }; =20 case CC_OP_INCB ... CC_OP_INCQ: case CC_OP_DECB ... CC_OP_DECQ: return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_src, - .mask =3D -1, .no_setcond =3D true }; + .no_setcond =3D true }; =20 case CC_OP_SHLB ... CC_OP_SHLQ: /* (CC_SRC >> (DATA_BITS - 1)) & 1 */ @@ -980,23 +979,23 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s= , TCGv reg) =20 case CC_OP_MULB ... CC_OP_MULQ: return (CCPrepare) { .cond =3D TCG_COND_NE, - .reg =3D cpu_cc_src, .mask =3D -1 }; + .reg =3D cpu_cc_src }; =20 case CC_OP_BMILGB ... CC_OP_BMILGQ: size =3D s->cc_op - CC_OP_BMILGB; t0 =3D gen_ext_tl(reg, cpu_cc_src, size, false); - return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D t0, .mask =3D= -1 }; + return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D t0 }; =20 case CC_OP_ADCX: case CC_OP_ADCOX: return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_dst, - .mask =3D -1, .no_setcond =3D true }; + .no_setcond =3D true }; =20 case CC_OP_EFLAGS: case CC_OP_SARB ... CC_OP_SARQ: /* CC_SRC & 1 */ return (CCPrepare) { .cond =3D TCG_COND_TSTNE, - .reg =3D cpu_cc_src, .mask =3D -1, .imm =3D C= C_C }; + .reg =3D cpu_cc_src, .imm =3D CC_C }; =20 default: /* The need to compute only C from CC_OP_DYNAMIC is important @@ -1005,7 +1004,7 @@ static CCPrepare gen_prepare_eflags_c(DisasContext *s= , TCGv reg) gen_helper_cc_compute_c(reg, cpu_cc_dst, cpu_cc_src, cpu_cc_src2, cpu_cc_op); return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D reg, - .mask =3D -1, .no_setcond =3D true }; + .no_setcond =3D true }; } } =20 @@ -1014,7 +1013,7 @@ static CCPrepare gen_prepare_eflags_p(DisasContext *s= , TCGv reg) { gen_compute_eflags(s); return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc_src, - .mask =3D -1, .imm =3D CC_P }; + .imm =3D CC_P }; } =20 /* compute eflags.S to reg */ @@ -1029,10 +1028,10 @@ static CCPrepare gen_prepare_eflags_s(DisasContext = *s, TCGv reg) case CC_OP_ADOX: case CC_OP_ADCOX: return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc_src, - .mask =3D -1, .imm =3D CC_S }; + .imm =3D CC_S }; case CC_OP_CLR: case CC_OP_POPCNT: - return (CCPrepare) { .cond =3D TCG_COND_NEVER, .mask =3D -1 }; + return (CCPrepare) { .cond =3D TCG_COND_NEVER }; default: { MemOp size =3D (s->cc_op - CC_OP_ADDB) & 3; @@ -1048,17 +1047,16 @@ static CCPrepare gen_prepare_eflags_o(DisasContext = *s, TCGv reg) case CC_OP_ADOX: case CC_OP_ADCOX: return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_src2, - .mask =3D -1, .no_setcond =3D true }; + .no_setcond =3D true }; case CC_OP_CLR: case CC_OP_POPCNT: - return (CCPrepare) { .cond =3D TCG_COND_NEVER, .mask =3D -1 }; + return (CCPrepare) { .cond =3D TCG_COND_NEVER }; case CC_OP_MULB ... CC_OP_MULQ: - return (CCPrepare) { .cond =3D TCG_COND_NE, - .reg =3D cpu_cc_src, .mask =3D -1 }; + return (CCPrepare) { .cond =3D TCG_COND_NE, .reg =3D cpu_cc_src }; default: gen_compute_eflags(s); return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc_src, - .mask =3D -1, .imm =3D CC_O }; + .imm =3D CC_O }; } } =20 @@ -1074,21 +1072,19 @@ static CCPrepare gen_prepare_eflags_z(DisasContext = *s, TCGv reg) case CC_OP_ADOX: case CC_OP_ADCOX: return (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc_src, - .mask =3D -1, .imm =3D CC_Z }; + .imm =3D CC_Z }; case CC_OP_CLR: - return (CCPrepare) { .cond =3D TCG_COND_ALWAYS, .mask =3D -1 }; + return (CCPrepare) { .cond =3D TCG_COND_ALWAYS }; case CC_OP_POPCNT: - return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D cpu_cc_src, - .mask =3D -1 }; + return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D cpu_cc_src }; default: { MemOp size =3D (s->cc_op - CC_OP_ADDB) & 3; if (size =3D=3D MO_TL) { - return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D cpu_c= c_dst, - .mask =3D -1 }; + return (CCPrepare) { .cond =3D TCG_COND_EQ, .reg =3D cpu_c= c_dst }; } else { return (CCPrepare) { .cond =3D TCG_COND_TSTEQ, .reg =3D cp= u_cc_dst, - .mask =3D -1, .imm =3D (1ull << (8 <<= size)) - 1 }; + .imm =3D (1ull << (8 << size)) - 1 }; } } } @@ -1116,7 +1112,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) gen_extu(size, s->tmp4); t0 =3D gen_ext_tl(s->tmp0, cpu_cc_src, size, false); cc =3D (CCPrepare) { .cond =3D TCG_COND_LEU, .reg =3D s->tmp4, - .reg2 =3D t0, .mask =3D -1, .use_reg2 =3D t= rue }; + .reg2 =3D t0, .use_reg2 =3D true }; break; =20 case JCC_L: @@ -1129,7 +1125,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) gen_exts(size, s->tmp4); t0 =3D gen_ext_tl(s->tmp0, cpu_cc_src, size, true); cc =3D (CCPrepare) { .cond =3D cond, .reg =3D s->tmp4, - .reg2 =3D t0, .mask =3D -1, .use_reg2 =3D t= rue }; + .reg2 =3D t0, .use_reg2 =3D true }; break; =20 default: @@ -1153,7 +1149,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) case JCC_BE: gen_compute_eflags(s); cc =3D (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D cpu_cc= _src, - .mask =3D -1, .imm =3D CC_Z | CC_C }; + .imm =3D CC_Z | CC_C }; break; case JCC_S: cc =3D gen_prepare_eflags_s(s, reg); @@ -1168,7 +1164,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) } tcg_gen_addi_tl(reg, cpu_cc_src, CC_O - CC_S); cc =3D (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D reg, - .mask =3D -1, .imm =3D CC_O }; + .imm =3D CC_O }; break; default: case JCC_LE: @@ -1178,7 +1174,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int = b, TCGv reg) } tcg_gen_addi_tl(reg, cpu_cc_src, CC_O - CC_S); cc =3D (CCPrepare) { .cond =3D TCG_COND_TSTNE, .reg =3D reg, - .mask =3D -1, .imm =3D CC_O | CC_Z }; + .imm =3D CC_O | CC_Z }; break; } break; @@ -1203,16 +1199,6 @@ static void gen_setcc1(DisasContext *s, int b, TCGv = reg) return; } =20 - if (cc.cond =3D=3D TCG_COND_NE && !cc.use_reg2 && cc.imm =3D=3D 0 && - cc.mask !=3D 0 && (cc.mask & (cc.mask - 1)) =3D=3D 0) { - tcg_gen_shri_tl(reg, cc.reg, ctztl(cc.mask)); - tcg_gen_andi_tl(reg, reg, 1); - return; - } - if (cc.mask !=3D -1) { - tcg_gen_andi_tl(reg, cc.reg, cc.mask); - cc.reg =3D reg; - } if (cc.use_reg2) { tcg_gen_setcond_tl(cc.cond, reg, cc.reg, cc.reg2); } else { @@ -1231,10 +1217,6 @@ static inline void gen_jcc1_noeob(DisasContext *s, i= nt b, TCGLabel *l1) { CCPrepare cc =3D gen_prepare_cc(s, b, s->T0); =20 - if (cc.mask !=3D -1) { - tcg_gen_andi_tl(s->T0, cc.reg, cc.mask); - cc.reg =3D s->T0; - } if (cc.use_reg2) { tcg_gen_brcond_tl(cc.cond, cc.reg, cc.reg2, l1); } else { @@ -1250,10 +1232,6 @@ static inline void gen_jcc1(DisasContext *s, int b, = TCGLabel *l1) CCPrepare cc =3D gen_prepare_cc(s, b, s->T0); =20 gen_update_cc_op(s); - if (cc.mask !=3D -1) { - tcg_gen_andi_tl(s->T0, cc.reg, cc.mask); - cc.reg =3D s->T0; - } set_cc_op(s, CC_OP_DYNAMIC); if (cc.use_reg2) { tcg_gen_brcond_tl(cc.cond, cc.reg, cc.reg2, l1); @@ -2518,11 +2496,6 @@ static void gen_cmovcc1(DisasContext *s, int b, TCGv= dest, TCGv src) { CCPrepare cc =3D gen_prepare_cc(s, b, s->T1); =20 - if (cc.mask !=3D -1) { - TCGv t0 =3D tcg_temp_new(); - tcg_gen_andi_tl(t0, cc.reg, cc.mask); - cc.reg =3D t0; - } if (!cc.use_reg2) { cc.reg2 =3D tcg_constant_tl(cc.imm); } --=20 2.43.2 From nobody Tue Nov 26 06:48:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709118790; cv=none; d=zohomail.com; s=zohoarc; b=LP+jqxmB1ZbWZkh7ayrtynuK0urInpS5powQMERNGl4mR8dum/+te9apMMlEuX0mW8ZVs74mQ+ovc9FeOfTTD3qb3q0y+dLheJjTPSRzLXfZa30cRVRY7Z5dl5rYNtEoTaH8ah7X+3ZeFmhxZuESA5QjhdKBBPL+/FklXkQZtqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709118790; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=E4xniBqKVQ8epVCqI0n5qgziT3RjBUH01hHZILRtuQM=; b=O63S7SIOkM4a0zPSy235H50NfiY60sp3BR+hpO/4qJ/zS+hpQuj6r55rhMo1aNv6QvQg/6r/PeUWRHNPJTFT5ZILY0C7M/Ot8tM6eMuWW5bubZ5zTc1NnOqADQmrOCvf+DG1xVKHFkLhlG3VWRtT6R6lJK+OhNcI0p4WfVbDzAQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709118790649901.3688087571866; Wed, 28 Feb 2024 03:13:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfHrD-0004jU-VU; Wed, 28 Feb 2024 06:12:15 -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 1rfHrC-0004j0-Iv for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:12:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rfHr9-0003xz-SU for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:12:14 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-BKDMruPXPjqS9qhOl-AnXw-1; Wed, 28 Feb 2024 06:12:09 -0500 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-56544b5af9dso3726982a12.2 for ; Wed, 28 Feb 2024 03:12:09 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id ew15-20020a056402538f00b005667a11b951sm201783edb.86.2024.02.28.03.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:12:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709118731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E4xniBqKVQ8epVCqI0n5qgziT3RjBUH01hHZILRtuQM=; b=YDB7MW142+6ShxEOQTQtfwdjTWs/Ti0u2C/NAmLlNAYnj4shUF6tifpXPa8tGy3cPBhyFh g5w96vezjDGp8vMSxk+pBXK/jIQBe5vSOzILfLLS+VEm2SjbictOl2AdqgJ63whdDhOohQ N3cq8AjUKD06XSvDzxCRvugfffo/81M= X-MC-Unique: BKDMruPXPjqS9qhOl-AnXw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709118727; x=1709723527; 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=E4xniBqKVQ8epVCqI0n5qgziT3RjBUH01hHZILRtuQM=; b=CzRbn2XUOY+cB3suVabE6fyfZpn/Bxq8NQGYwViCJrxL1PBur1QAB/QIWNe0zFumZ/ o1f7u3Yw5LmUF3uugrUtxI1KJohS3dPk5NInRSxzlAvabx15/mwDKBzlV4gXzwsK11Sk EUc4eE/nUN2gaC+HYnPOdztk2/HUR9NHgNn449zzKrJHyuVeajOB7JQdXPZldeq/bYeE fra7+sVFBXE71XVSqWiK8Wy7Saq9JotQEApxT7qUj0jqDceaIsMSwDMnWpd2gQIUSLYh BdoZ2yy8UOH8BBU0LVk1Eym3BW1rrqAeZUFSPTM7xNiygaz5doCx1O7mKQtK6CjPF0s6 fH8Q== X-Gm-Message-State: AOJu0YwCYO/mEnqFQZOvmPdLGiaEe/b4aicCtj1co4AajQ8oWJbLruxF Z0z3XSXQO6hpMBJQVZ34bNUkL1ZzdW4ZUH0iAvL+mMSjt2ABHHhPN+zXZ0Gh0pymbgUrV9JaTii /W8Nfziuq/ORJEWfzzrUjS4i/0Ru4Z58wQ49qinbivMX6EfTINhUxfaEHmADji7Xag8a/kXCbCf JcRd+ogiJkM25IH26rDfkiIZz6Zp1KEVmLekRK X-Received: by 2002:aa7:cd42:0:b0:566:de7:ac4a with SMTP id v2-20020aa7cd42000000b005660de7ac4amr4813361edw.6.1709118727204; Wed, 28 Feb 2024 03:12:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEk1GerRv+EgQ3vF+yLX9DlBKU8itm9sxU7f9dGpIlfp6ddHG5/sAI8467S73xgq4MWcZJfWQ== X-Received: by 2002:aa7:cd42:0:b0:566:de7:ac4a with SMTP id v2-20020aa7cd42000000b005660de7ac4amr4813348edw.6.1709118726889; Wed, 28 Feb 2024 03:12:06 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org Subject: [PATCH 4/4] tcg/optimize: optimize TSTNE using smask and zmask Date: Wed, 28 Feb 2024 12:11:51 +0100 Message-ID: <20240228111151.287738-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228111151.287738-1-pbonzini@redhat.com> References: <20240228111151.287738-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709118792612100005 Content-Type: text/plain; charset="utf-8" Generalize the existing optimization of "TSTNE x,sign" and "TSTNE x,-1". This can be useful in some cases when the i386 frontend creates opcodes that test against 0xff or 0x80. Signed-off-by: Paolo Bonzini --- tcg/optimize.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 752cc5c56b6..ab976a5bbe7 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -793,6 +793,7 @@ static int do_constant_folding_cond1(OptContext *ctx, T= CGOp *op, TCGArg dest, TCGArg *p1, TCGArg *p2, TCGArg *pcond) { TCGCond cond; + TempOptInfo *i1; bool swap; int r; =20 @@ -810,19 +811,21 @@ static int do_constant_folding_cond1(OptContext *ctx,= TCGOp *op, TCGArg dest, return -1; } =20 + i1 =3D arg_info(*p1); + /* * TSTNE x,x -> NE x,0 - * TSTNE x,-1 -> NE x,0 + * TSTNE x,i -> NE x,0 if i includes all nonzero bits of x */ - if (args_are_copies(*p1, *p2) || arg_is_const_val(*p2, -1)) { + if (args_are_copies(*p1, *p2) || + (arg_is_const(*p2) && (i1->z_mask & ~arg_info(*p2)->val) =3D=3D 0)= ) { *p2 =3D arg_new_constant(ctx, 0); *pcond =3D tcg_tst_eqne_cond(cond); return -1; } =20 - /* TSTNE x,sign -> LT x,0 */ - if (arg_is_const_val(*p2, (ctx->type =3D=3D TCG_TYPE_I32 - ? INT32_MIN : INT64_MIN))) { + /* TSTNE x,i -> LT x,0 if i only includes sign bit copies */ + if (arg_is_const(*p2) && (arg_info(*p2)->val & ~i1->s_mask) =3D=3D 0) { *p2 =3D arg_new_constant(ctx, 0); *pcond =3D tcg_tst_ltge_cond(cond); return -1; --=20 2.43.2