From nobody Wed Nov 27 15:49:46 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=1698401176; cv=none; d=zohomail.com; s=zohoarc; b=UCY9MBY5Qr9E5wYYRvu51V183BJAxgsdIwEJjPqralJCwJsaSAhAz0J8LgsWln/y2yE4ymWvXpKPaaIVfm9fohf8OKa4/7stH8mg3Q/r8YRyzyHIfGO/DK+AgZzDJu8VZAyG9NYVLH0xPcZhHfLId4zO1SUOcjBqy2LE+1bbkxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698401176; h=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=NXV5yiccgCtWbAwpjJPMg1VAWxIO6BfuvJPWxNh/94E=; b=ENmDKZWzxg55gM5Nkj/vWYgtE8N3XH9yyrhSy7P0FGWWhImNrYvHQBQIDfxuZhdsJy8EYZ6Q4oPX/hyUj/vr9aQAVR0LcJQ+Ykhr/gue4j6iXLCyAiIhu7Zxey2uqHP6L2xjga+lta3p3ttGrJsJkV4cQtlu0ZlciMlLpVNI5Qs= 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 1698401176852972.93738915423; Fri, 27 Oct 2023 03:06:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qwJiT-0003Dh-Oh; Fri, 27 Oct 2023 06:05: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 1qwJiP-0003Cc-P7 for qemu-devel@nongnu.org; Fri, 27 Oct 2023 06:05:17 -0400 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 1qwJiN-0002AP-Dh for qemu-devel@nongnu.org; Fri, 27 Oct 2023 06:05:17 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-480-H4p2KwgqOdWRRw0ljK5yXw-1; Fri, 27 Oct 2023 06:05:08 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 944FD29ABA1F; Fri, 27 Oct 2023 10:05:07 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BCFD492BFC; Fri, 27 Oct 2023 10:05:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698401111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NXV5yiccgCtWbAwpjJPMg1VAWxIO6BfuvJPWxNh/94E=; b=hJAER2dafhdAVVL1fM2jY6WvQbNTdZCNbV8OaPG4CCtjMCE43aojdDWouCPlRGrx5jlBce Nz6PdQo+KhzIdrHYL5Z1mO0542wzpHvjlebvQEzmwV7BZD3MUmpzIsB7y1X1F9hxzualhM Q3qgmWlcO6wD3y/zCOtcoZYylGoqeXo= X-MC-Unique: H4p2KwgqOdWRRw0ljK5yXw-1 From: Thomas Huth To: Peter Maydell Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org, Sebastian Mitterle , Ilya Leoshkevich , Laurent Vivier , Thomas Huth Subject: [risu PATCH 1/2] risugen: allow instructions with length > 32 bit Date: Fri, 27 Oct 2023 12:04:40 +0200 Message-ID: <20231027100441.375223-2-thuth@redhat.com> In-Reply-To: <20231027100441.375223-1-thuth@redhat.com> References: <20231027100441.375223-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 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=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1698401177420100001 Content-Type: text/plain; charset="utf-8" RISU currently only supports instructions with a length of 16 bit or 32 bit, however classical CISC systems like s390x also have instructions that are longer than 32 bit. Thus let's change the generator to support longer instructions, too. This adds support for 48-bit instructions on s390x, while the other architectures are just minimally changed to preserve the current state. Signed-off-by: Thomas Huth --- risugen | 48 +++++++++++++++++++++++++++++------------- risugen_arm.pm | 6 +++--- risugen_common.pm | 2 +- risugen_loongarch64.pm | 4 ++-- risugen_m68k.pm | 6 +++--- risugen_ppc64.pm | 4 ++-- risugen_s390x.pm | 17 +++++++++++---- 7 files changed, 57 insertions(+), 30 deletions(-) diff --git a/risugen b/risugen index fa94a39..833b459 100755 --- a/risugen +++ b/risugen @@ -105,6 +105,16 @@ sub read_tokenised_line(*) return @tokens; } =20 +sub check_bitmask($$) +{ + my ($fixedbits, $fixedbitmask) =3D @_; + + if ((($fixedbits & $fixedbitmask) !=3D $fixedbits) + || (($fixedbits & ~$fixedbitmask) !=3D 0)) { + die "internal error: fixed bits not lined up with mask"; + } +} + sub parse_config_file($) { # Read in the config file defining the instructions we can generate @@ -160,10 +170,11 @@ sub parse_config_file($) exit(1); } =20 - my $fixedbits =3D 0; - my $fixedbitmask =3D 0; + my @fixedbits =3D (0, 0, 0, 0); + my @fixedbitmask =3D (0, 0, 0, 0); my $bitpos =3D 32; - my $insnwidth =3D 32; + my $wordpos =3D 0; + my $insnwidth =3D 0; my $seenblock =3D 0; =20 while (@bits) { @@ -217,36 +228,43 @@ sub parse_config_file($) =20 my $bitmask =3D oct("0b". '1' x $bitlen); $bitpos -=3D $bitlen; + $insnwidth +=3D $bitlen; if ($bitpos < 0) { print STDERR "$file:$.: ($insn $enc) too many bits specifi= ed\n"; exit(1); } =20 if (defined $bitval) { - $fixedbits |=3D ($bitval << $bitpos); - $fixedbitmask |=3D ($bitmask << $bitpos); + $fixedbits[$wordpos] |=3D ($bitval << $bitpos); + $fixedbitmask[$wordpos] |=3D ($bitmask << $bitpos); } else { - push @fields, [ $var, $bitpos, $bitmask ]; + push @fields, [ $var, $bitpos, $bitmask, $wordpos ]; + } + + if ($bitpos =3D=3D 0) { + check_bitmask($fixedbits[$wordpos], $fixedbitmask[$wordpos= ]); + + $wordpos +=3D 1; + if (@bits) { + $bitpos =3D 32; + } } } if ($bitpos =3D=3D 16) { # assume this is a half-width thumb instruction # Note that we don't fiddle with the bitmasks or positions, # which means the generated insn will be in the high halfword! - $insnwidth =3D 16; - } elsif ($bitpos !=3D 0) { - print STDERR "$file:$.: ($insn $enc) not enough bits specified= \n"; + check_bitmask($fixedbits[$wordpos], $fixedbitmask[$wordpos]); + } elsif ($bitpos !=3D 0 && $bitpos !=3D 32) { + print STDERR "$file:$.: ($insn $enc) not enough bits specified= ($bitpos)\n"; exit(1); } - if ((($fixedbits & $fixedbitmask) !=3D $fixedbits) - || (($fixedbits & ~$fixedbitmask) !=3D 0)) { - die "internal error: fixed bits not lined up with mask"; - } # Stick the fixedbit info on the front of the array now we know it $insnrec->{name} =3D $insnname; $insnrec->{width} =3D $insnwidth; - $insnrec->{fixedbits} =3D $fixedbits; - $insnrec->{fixedbitmask} =3D $fixedbitmask; + $insnrec->{fixedbits} =3D [ @fixedbits ]; + $insnrec->{fixedbitmask} =3D [ @fixedbitmask ]; + $insnrec->{words} =3D $wordpos; $insnrec->{fields} =3D [ @fields ]; if (@insn_groups) { $insnrec->{groups} =3D [ @insn_groups ]; diff --git a/risugen_arm.pm b/risugen_arm.pm index 8d423b1..9dd6139 100644 --- a/risugen_arm.pm +++ b/risugen_arm.pm @@ -964,15 +964,15 @@ sub gen_one_insn($$) my $insn =3D int(rand(0xffffffff)); my $insnname =3D $rec->{name}; my $insnwidth =3D $rec->{width}; - my $fixedbits =3D $rec->{fixedbits}; - my $fixedbitmask =3D $rec->{fixedbitmask}; + my $fixedbits =3D (@{ $rec->{fixedbits} })[0]; + my $fixedbitmask =3D (@{ $rec->{fixedbitmask} })[0]; my $constraint =3D $rec->{blocks}{"constraints"}; my $memblock =3D $rec->{blocks}{"memory"}; =20 $insn &=3D ~$fixedbitmask; $insn |=3D $fixedbits; for my $tuple (@{ $rec->{fields} }) { - my ($var, $pos, $mask) =3D @$tuple; + my ($var, $pos, $mask, $wordpos) =3D @$tuple; my $val =3D ($insn >> $pos) & $mask; # XXX (claudio) ARM-specific - maybe move to arm.risu? # Check constraints here: diff --git a/risugen_common.pm b/risugen_common.pm index 71ee996..c816895 100644 --- a/risugen_common.pm +++ b/risugen_common.pm @@ -116,7 +116,7 @@ sub eval_with_fields($$$$$) { my $calling_package =3D caller; my $evalstr =3D "{ package $calling_package; "; for my $tuple (@{ $rec->{fields} }) { - my ($var, $pos, $mask) =3D @$tuple; + my ($var, $pos, $mask, $wordpos) =3D @$tuple; my $val =3D ($insn >> $pos) & $mask; $evalstr .=3D "my (\$$var) =3D $val; "; } diff --git a/risugen_loongarch64.pm b/risugen_loongarch64.pm index 5394fdc..8c74b6e 100644 --- a/risugen_loongarch64.pm +++ b/risugen_loongarch64.pm @@ -390,8 +390,8 @@ sub gen_one_insn($$) my $insn =3D int(rand(0xffffffff)); my $insnname =3D $rec->{name}; my $insnwidth =3D $rec->{width}; - my $fixedbits =3D $rec->{fixedbits}; - my $fixedbitmask =3D $rec->{fixedbitmask}; + my $fixedbits =3D (@{ $rec->{fixedbits} })[0]; + my $fixedbitmask =3D (@{ $rec->{fixedbitmask} })[0]; my $constraint =3D $rec->{blocks}{"constraints"}; my $memblock =3D $rec->{blocks}{"memory"}; my $safefloat =3D $rec->{blocks}{"safefloat"}; diff --git a/risugen_m68k.pm b/risugen_m68k.pm index 7d62b13..49f3100 100644 --- a/risugen_m68k.pm +++ b/risugen_m68k.pm @@ -111,8 +111,8 @@ sub gen_one_insn($$) my $insn =3D int(rand(0xffffffff)); my $insnname =3D $rec->{name}; my $insnwidth =3D $rec->{width}; - my $fixedbits =3D $rec->{fixedbits}; - my $fixedbitmask =3D $rec->{fixedbitmask}; + my $fixedbits =3D (@{ $rec->{fixedbits} })[0]; + my $fixedbitmask =3D (@{ $rec->{fixedbitmask} })[0]; my $constraint =3D $rec->{blocks}{"constraints"}; my $memblock =3D $rec->{blocks}{"memory"}; =20 @@ -120,7 +120,7 @@ sub gen_one_insn($$) $insn |=3D $fixedbits; =20 for my $tuple (@{ $rec->{fields} }) { - my ($var, $pos, $mask) =3D @$tuple; + my ($var, $pos, $mask, $wordpos) =3D @$tuple; my $val =3D ($insn >> $pos) & $mask; # Check constraints here: # not allowed to use or modify sp (A7) or fp (A6) diff --git a/risugen_ppc64.pm b/risugen_ppc64.pm index b241172..d1d3fc9 100644 --- a/risugen_ppc64.pm +++ b/risugen_ppc64.pm @@ -300,8 +300,8 @@ sub gen_one_insn($$) my $insn =3D int(rand(0xffffffff)); my $insnname =3D $rec->{name}; my $insnwidth =3D $rec->{width}; - my $fixedbits =3D $rec->{fixedbits}; - my $fixedbitmask =3D $rec->{fixedbitmask}; + my $fixedbits =3D (@{ $rec->{fixedbits} })[0]; + my $fixedbitmask =3D (@{ $rec->{fixedbitmask} })[0]; my $constraint =3D $rec->{blocks}{"constraints"}; my $memblock =3D $rec->{blocks}{"memory"}; =20 diff --git a/risugen_s390x.pm b/risugen_s390x.pm index 260e2dd..04ea6fb 100644 --- a/risugen_s390x.pm +++ b/risugen_s390x.pm @@ -84,15 +84,21 @@ sub gen_one_insn($$) INSN: while(1) { my ($forcecond, $rec) =3D @_; my $insn =3D int(rand(0xffffffff)); + my $insn48 =3D int(rand(0xffff0000)); my $insnname =3D $rec->{name}; my $insnwidth =3D $rec->{width}; - my $fixedbits =3D $rec->{fixedbits}; - my $fixedbitmask =3D $rec->{fixedbitmask}; + my @fixedbits =3D (@{ $rec->{fixedbits} }); + my @fixedbitmask =3D (@{ $rec->{fixedbitmask} }); my $constraint =3D $rec->{blocks}{"constraints"}; my $memblock =3D $rec->{blocks}{"memory"}; =20 - $insn &=3D ~$fixedbitmask; - $insn |=3D $fixedbits; + $insn &=3D ~$fixedbitmask[0]; + $insn |=3D $fixedbits[0]; + + if ($insnwidth =3D=3D 48) { + $insn48 &=3D ~$fixedbitmask[1]; + $insn48 |=3D $fixedbits[1]; + } =20 if (defined $constraint) { # user-specified constraint: evaluate in an environment @@ -121,6 +127,9 @@ sub gen_one_insn($$) insn16(($insn >> 16) & 0xffff); } else { insn32($insn); + if ($insnwidth =3D=3D 48) { + insn16(($insn48 >> 16) & 0xffff); + } } =20 return; --=20 2.41.0