From nobody Tue Nov 26 19:53:41 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=quicinc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1705905513801338.6760956246187; Sun, 21 Jan 2024 22:38:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rRnuU-0003Ah-Kk; Mon, 22 Jan 2024 01:35:54 -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 1rRnuE-00031X-N2 for qemu-devel@nongnu.org; Mon, 22 Jan 2024 01:35:40 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rRnuA-0005lx-MT for qemu-devel@nongnu.org; Mon, 22 Jan 2024 01:35:38 -0500 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40M42Pgf013123; Mon, 22 Jan 2024 06:35:31 GMT Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vr6xn328r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jan 2024 06:35:31 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 40M6ZUCd027379 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jan 2024 06:35:30 GMT Received: from hu-bcain-lv.qualcomm.com (10.49.16.6) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Sun, 21 Jan 2024 22:35:29 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s= qcppdkim1; bh=dnhe60Lq1qSKHbSZOB4x0e/kKq0lCce9CFpfSWWFrs0=; b=EQ Y03vmdvY2QGbrSqU0y1M3HzYyNGEPrYVRpB8fosAD0tp1K8qavh9viWlwfVYNSo7 nqSAXOT5XgIa9XpOcET9hHlugPcJYL4mueb2pg/tMCPiF9R6WedMl6KsDMa8IaEk Nx0mGkjfeYjlPh7LY4mKiMvzea3ILleUkwJYfiEITqjlhW3bwOf1pzvpmoX7GvHW zYxmj67d0d32yImiFRAOP1uGst/RstHIx2TAp2GAaMFHiW03MgaF5pvmeBnOlJ7n 5XgXuGCIYYYdRiaShGH5oF9NpRZFmRW5NGXS9U6aCKD4mqYZSNVzEiPItAskWMLE YQzU/NeV3BYrycmDi1Nw== From: Brian Cain To: CC: , , , , , , , , , , Subject: [PULL 14/15] Hexagon (target/hexagon) Remove old dectree.py Date: Sun, 21 Jan 2024 22:35:00 -0800 Message-ID: <20240122063501.782041-15-bcain@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240122063501.782041-1-bcain@quicinc.com> References: <20240122063501.782041-1-bcain@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: qskOteU_YEmYOhd5cAidAbsmLEvxawDa X-Proofpoint-ORIG-GUID: qskOteU_YEmYOhd5cAidAbsmLEvxawDa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-21_04,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 mlxscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 suspectscore=0 bulkscore=0 mlxlogscore=800 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401220046 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=205.220.168.131; envelope-from=bcain@quicinc.com; helo=mx0a-0031df01.pphosted.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, 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-ZM-MESSAGEID: 1705905515619100001 From: Taylor Simpson Now that we are using QEMU decodetree.py, remove the old decoder Signed-off-by: Taylor Simpson Reviewed-by: Brian Cain Message-Id: <20240115221443.365287-4-ltaylorsimpson@gmail.com> Signed-off-by: Brian Cain --- target/hexagon/decode.c | 344 ------------------------ target/hexagon/dectree.py | 403 ---------------------------- target/hexagon/gen_dectree_import.c | 49 ---- target/hexagon/meson.build | 12 - target/hexagon/opcodes.c | 29 -- target/hexagon/opcodes.h | 2 - 6 files changed, 839 deletions(-) delete mode 100755 target/hexagon/dectree.py diff --git a/target/hexagon/decode.c b/target/hexagon/decode.c index 160b23a895..a40210ca1e 100644 --- a/target/hexagon/decode.c +++ b/target/hexagon/decode.c @@ -88,175 +88,6 @@ static int shift_left(DisasContext *ctx, int x, int n, = int immno) /* Include the generated helpers for the decoder */ #include "decodetree_trans_funcs_generated.c.inc" =20 -typedef struct { - const struct DectreeTable *table_link; - const struct DectreeTable *table_link_b; - Opcode opcode; - enum { - DECTREE_ENTRY_INVALID, - DECTREE_TABLE_LINK, - DECTREE_SUBINSNS, - DECTREE_EXTSPACE, - DECTREE_TERMINAL - } type; -} DectreeEntry; - -typedef struct DectreeTable { - unsigned int (*lookup_function)(int startbit, int width, uint32_t opco= de); - unsigned int size; - unsigned int startbit; - unsigned int width; - const DectreeEntry table[]; -} DectreeTable; - -#define DECODE_NEW_TABLE(TAG, SIZE, WHATNOT) \ - static const DectreeTable dectree_table_##TAG; -#define TABLE_LINK(TABLE) /* NOTHING */ -#define TERMINAL(TAG, ENC) /* NOTHING */ -#define SUBINSNS(TAG, CLASSA, CLASSB, ENC) /* NOTHING */ -#define EXTSPACE(TAG, ENC) /* NOTHING */ -#define INVALID() /* NOTHING */ -#define DECODE_END_TABLE(...) /* NOTHING */ -#define DECODE_MATCH_INFO(...) /* NOTHING */ -#define DECODE_LEGACY_MATCH_INFO(...) /* NOTHING */ -#define DECODE_OPINFO(...) /* NOTHING */ - -#include "dectree_generated.h.inc" - -#undef DECODE_OPINFO -#undef DECODE_MATCH_INFO -#undef DECODE_LEGACY_MATCH_INFO -#undef DECODE_END_TABLE -#undef INVALID -#undef TERMINAL -#undef SUBINSNS -#undef EXTSPACE -#undef TABLE_LINK -#undef DECODE_NEW_TABLE -#undef DECODE_SEPARATOR_BITS - -#define DECODE_SEPARATOR_BITS(START, WIDTH) NULL, START, WIDTH -#define DECODE_NEW_TABLE_HELPER(TAG, SIZE, FN, START, WIDTH) \ - static const DectreeTable dectree_table_##TAG =3D { \ - .size =3D SIZE, \ - .lookup_function =3D FN, \ - .startbit =3D START, \ - .width =3D WIDTH, \ - .table =3D { -#define DECODE_NEW_TABLE(TAG, SIZE, WHATNOT) \ - DECODE_NEW_TABLE_HELPER(TAG, SIZE, WHATNOT) - -#define TABLE_LINK(TABLE) \ - { .type =3D DECTREE_TABLE_LINK, .table_link =3D &dectree_table_##TABLE= }, -#define TERMINAL(TAG, ENC) \ - { .type =3D DECTREE_TERMINAL, .opcode =3D TAG }, -#define SUBINSNS(TAG, CLASSA, CLASSB, ENC) \ - { \ - .type =3D DECTREE_SUBINSNS, \ - .table_link =3D &dectree_table_DECODE_SUBINSN_##CLASSA, \ - .table_link_b =3D &dectree_table_DECODE_SUBINSN_##CLASSB \ - }, -#define EXTSPACE(TAG, ENC) { .type =3D DECTREE_EXTSPACE }, -#define INVALID() { .type =3D DECTREE_ENTRY_INVALID, .opcode =3D XX_LAST_O= PCODE }, - -#define DECODE_END_TABLE(...) } }; - -#define DECODE_MATCH_INFO(...) /* NOTHING */ -#define DECODE_LEGACY_MATCH_INFO(...) /* NOTHING */ -#define DECODE_OPINFO(...) /* NOTHING */ - -#include "dectree_generated.h.inc" - -#undef DECODE_OPINFO -#undef DECODE_MATCH_INFO -#undef DECODE_LEGACY_MATCH_INFO -#undef DECODE_END_TABLE -#undef INVALID -#undef TERMINAL -#undef SUBINSNS -#undef EXTSPACE -#undef TABLE_LINK -#undef DECODE_NEW_TABLE -#undef DECODE_NEW_TABLE_HELPER -#undef DECODE_SEPARATOR_BITS - -static const DectreeTable dectree_table_DECODE_EXT_EXT_noext =3D { - .size =3D 1, .lookup_function =3D NULL, .startbit =3D 0, .width =3D 0, - .table =3D { - { .type =3D DECTREE_ENTRY_INVALID, .opcode =3D XX_LAST_OPCODE }, - } -}; - -static const DectreeTable *ext_trees[XX_LAST_EXT_IDX]; - -static void decode_ext_init(void) -{ - int i; - for (i =3D EXT_IDX_noext; i < EXT_IDX_noext_AFTER; i++) { - ext_trees[i] =3D &dectree_table_DECODE_EXT_EXT_noext; - } - for (i =3D EXT_IDX_mmvec; i < EXT_IDX_mmvec_AFTER; i++) { - ext_trees[i] =3D &dectree_table_DECODE_EXT_EXT_mmvec; - } -} - -typedef struct { - uint32_t mask; - uint32_t match; -} DecodeITableEntry; - -#define DECODE_NEW_TABLE(TAG, SIZE, WHATNOT) /* NOTHING */ -#define TABLE_LINK(TABLE) /* NOTHING */ -#define TERMINAL(TAG, ENC) /* NOTHING */ -#define SUBINSNS(TAG, CLASSA, CLASSB, ENC) /* NOTHING */ -#define EXTSPACE(TAG, ENC) /* NOTHING */ -#define INVALID() /* NOTHING */ -#define DECODE_END_TABLE(...) /* NOTHING */ -#define DECODE_OPINFO(...) /* NOTHING */ - -#define DECODE_MATCH_INFO_NORMAL(TAG, MASK, MATCH) \ - [TAG] =3D { \ - .mask =3D MASK, \ - .match =3D MATCH, \ - }, - -#define DECODE_MATCH_INFO_NULL(TAG, MASK, MATCH) \ - [TAG] =3D { .match =3D ~0 }, - -#define DECODE_MATCH_INFO(...) DECODE_MATCH_INFO_NORMAL(__VA_ARGS__) -#define DECODE_LEGACY_MATCH_INFO(...) /* NOTHING */ - -static const DecodeITableEntry decode_itable[XX_LAST_OPCODE] =3D { -#include "dectree_generated.h.inc" -}; - -#undef DECODE_MATCH_INFO -#define DECODE_MATCH_INFO(...) DECODE_MATCH_INFO_NULL(__VA_ARGS__) - -#undef DECODE_LEGACY_MATCH_INFO -#define DECODE_LEGACY_MATCH_INFO(...) DECODE_MATCH_INFO_NORMAL(__VA_ARGS__) - -static const DecodeITableEntry decode_legacy_itable[XX_LAST_OPCODE] =3D { -#include "dectree_generated.h.inc" -}; - -#undef DECODE_OPINFO -#undef DECODE_MATCH_INFO -#undef DECODE_LEGACY_MATCH_INFO -#undef DECODE_END_TABLE -#undef INVALID -#undef TERMINAL -#undef SUBINSNS -#undef EXTSPACE -#undef TABLE_LINK -#undef DECODE_NEW_TABLE -#undef DECODE_SEPARATOR_BITS - -void decode_init(void) -{ - decode_ext_init(); -} - void decode_send_insn_to(Packet *packet, int start, int newloc) { Insn tmpinsn; @@ -587,7 +418,6 @@ apply_extender(Packet *pkt, int i, uint32_t extender) uint32_t base_immed; =20 immed_num =3D pkt->insn[i].which_extended; - g_assert(immed_num =3D=3D opcode_which_immediate_is_extended(pkt->insn= [i].opcode)); base_immed =3D pkt->insn[i].immed[immed_num]; =20 pkt->insn[i].immed[immed_num] =3D extender | fZXTN(6, 32, base_immed); @@ -630,174 +460,6 @@ static SlotMask get_valid_slots(const Packet *pkt, un= signed int slot) } } =20 -#define DECODE_NEW_TABLE(TAG, SIZE, WHATNOT) /* NOTHING */ -#define TABLE_LINK(TABLE) /* NOTHING */ -#define TERMINAL(TAG, ENC) /* NOTHING */ -#define SUBINSNS(TAG, CLASSA, CLASSB, ENC) /* NOTHING */ -#define EXTSPACE(TAG, ENC) /* NOTHING */ -#define INVALID() /* NOTHING */ -#define DECODE_END_TABLE(...) /* NOTHING */ -#define DECODE_MATCH_INFO(...) /* NOTHING */ -#define DECODE_LEGACY_MATCH_INFO(...) /* NOTHING */ - -#define DECODE_REG(REGNO, WIDTH, STARTBIT) \ - insn->regno[REGNO] =3D ((encoding >> STARTBIT) & ((1 << WIDTH) - 1)); - -#define DECODE_IMPL_REG(REGNO, VAL) \ - insn->regno[REGNO] =3D VAL; - -#define DECODE_IMM(IMMNO, WIDTH, STARTBIT, VALSTART) \ - insn->immed[IMMNO] |=3D (((encoding >> STARTBIT) & ((1 << WIDTH) - 1))= ) << \ - (VALSTART); - -#define DECODE_IMM_SXT(IMMNO, WIDTH) \ - insn->immed[IMMNO] =3D ((((int32_t)insn->immed[IMMNO]) << (32 - WIDTH)= ) >> \ - (32 - WIDTH)); - -#define DECODE_IMM_NEG(IMMNO, WIDTH) \ - insn->immed[IMMNO] =3D -insn->immed[IMMNO]; - -#define DECODE_IMM_SHIFT(IMMNO, SHAMT) \ - if ((!insn->extension_valid) || \ - (insn->which_extended !=3D IMMNO)) { \ - insn->immed[IMMNO] <<=3D SHAMT; \ - } - -#define DECODE_OPINFO(TAG, BEH) \ - case TAG: \ - { BEH } \ - break; \ - -/* - * Fill in the operands of the instruction - * dectree_generated.h.inc has a DECODE_OPINFO entry for each opcode - * For example, - * DECODE_OPINFO(A2_addi, - * DECODE_REG(0,5,0) - * DECODE_REG(1,5,16) - * DECODE_IMM(0,7,21,9) - * DECODE_IMM(0,9,5,0) - * DECODE_IMM_SXT(0,16) - * with the macros defined above, we'll fill in a switch statement - * where each case is an opcode tag. - */ -static void -decode_op(Insn *insn, Opcode tag, uint32_t encoding) -{ - insn->immed[0] =3D 0; - insn->immed[1] =3D 0; - insn->opcode =3D tag; - if (insn->extension_valid) { - insn->which_extended =3D opcode_which_immediate_is_extended(tag); - } - - switch (tag) { -#include "dectree_generated.h.inc" - default: - break; - } - - insn->generate =3D opcode_genptr[tag]; - - insn->iclass =3D iclass_bits(encoding); -} - -#undef DECODE_REG -#undef DECODE_IMPL_REG -#undef DECODE_IMM -#undef DECODE_IMM_SHIFT -#undef DECODE_OPINFO -#undef DECODE_MATCH_INFO -#undef DECODE_LEGACY_MATCH_INFO -#undef DECODE_END_TABLE -#undef INVALID -#undef TERMINAL -#undef SUBINSNS -#undef EXTSPACE -#undef TABLE_LINK -#undef DECODE_NEW_TABLE -#undef DECODE_SEPARATOR_BITS - -static unsigned int -decode_subinsn_tablewalk(Insn *insn, const DectreeTable *table, - uint32_t encoding) -{ - unsigned int i; - Opcode opc; - if (table->lookup_function) { - i =3D table->lookup_function(table->startbit, table->width, encodi= ng); - } else { - i =3D extract32(encoding, table->startbit, table->width); - } - if (table->table[i].type =3D=3D DECTREE_TABLE_LINK) { - return decode_subinsn_tablewalk(insn, table->table[i].table_link, - encoding); - } else if (table->table[i].type =3D=3D DECTREE_TERMINAL) { - opc =3D table->table[i].opcode; - if ((encoding & decode_itable[opc].mask) !=3D decode_itable[opc].m= atch) { - return 0; - } - decode_op(insn, opc, encoding); - return 1; - } else { - return 0; - } -} - -static unsigned int get_insn_a(uint32_t encoding) -{ - return extract32(encoding, 0, 13); -} - -static unsigned int get_insn_b(uint32_t encoding) -{ - return extract32(encoding, 16, 13); -} - -static unsigned int -decode_insns_tablewalk(Insn *insn, const DectreeTable *table, - uint32_t encoding) -{ - unsigned int i; - unsigned int a, b; - Opcode opc; - if (table->lookup_function) { - i =3D table->lookup_function(table->startbit, table->width, encodi= ng); - } else { - i =3D extract32(encoding, table->startbit, table->width); - } - if (table->table[i].type =3D=3D DECTREE_TABLE_LINK) { - return decode_insns_tablewalk(insn, table->table[i].table_link, - encoding); - } else if (table->table[i].type =3D=3D DECTREE_SUBINSNS) { - a =3D get_insn_a(encoding); - b =3D get_insn_b(encoding); - b =3D decode_subinsn_tablewalk(insn, table->table[i].table_link_b,= b); - a =3D decode_subinsn_tablewalk(insn + 1, table->table[i].table_lin= k, a); - if ((a =3D=3D 0) || (b =3D=3D 0)) { - return 0; - } - return 2; - } else if (table->table[i].type =3D=3D DECTREE_TERMINAL) { - opc =3D table->table[i].opcode; - if ((encoding & decode_itable[opc].mask) !=3D decode_itable[opc].m= atch) { - if ((encoding & decode_legacy_itable[opc].mask) !=3D - decode_legacy_itable[opc].match) { - return 0; - } - } - decode_op(insn, opc, encoding); - return 1; - } else if (table->table[i].type =3D=3D DECTREE_EXTSPACE) { - /* - * For now, HVX will be the only coproc - */ - return decode_insns_tablewalk(insn, ext_trees[EXT_IDX_mmvec], enco= ding); - } else { - return 0; - } -} - /* * Section 10.3 of the Hexagon V73 Programmer's Reference Manual * @@ -858,7 +520,6 @@ static uint16_t get_slot1_subinsn(uint32_t encoding) static unsigned int decode_insns(DisasContext *ctx, Insn *insn, uint32_t encoding) { - const DectreeTable *table; if (parse_bits(encoding) !=3D 0) { if (decode_normal(ctx, encoding) || decode_hvx(ctx, encoding)) { @@ -866,8 +527,6 @@ decode_insns(DisasContext *ctx, Insn *insn, uint32_t en= coding) insn->iclass =3D iclass_bits(encoding); return 1; } - /* Start with PP table - 32 bit instructions */ - table =3D &dectree_table_DECODE_ROOT_32; g_assert_not_reached(); } else { uint32_t iclass =3D get_duplex_iclass(encoding); @@ -889,11 +548,8 @@ decode_insns(DisasContext *ctx, Insn *insn, uint32_t e= ncoding) return 2; } } - /* start with EE table - duplex instructions */ - table =3D &dectree_table_DECODE_ROOT_EE; g_assert_not_reached(); } - return decode_insns_tablewalk(insn, table, encoding); } =20 static void decode_add_endloop_insn(Insn *insn, int loopnum) diff --git a/target/hexagon/dectree.py b/target/hexagon/dectree.py deleted file mode 100755 index 3b32948a04..0000000000 --- a/target/hexagon/dectree.py +++ /dev/null @@ -1,403 +0,0 @@ -#!/usr/bin/env python3 - -## -## Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Res= erved. -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; if not, see . -## - -import io -import re - -import sys -import iset - -encs =3D { - tag: "".join(reversed(iset.iset[tag]["enc"].replace(" ", ""))) - for tag in iset.tags - if iset.iset[tag]["enc"] !=3D "MISSING ENCODING" -} - -enc_classes =3D set([iset.iset[tag]["enc_class"] for tag in encs.keys()]) -subinsn_enc_classes =3D set( - [enc_class for enc_class in enc_classes if enc_class.startswith("SUBIN= SN_")] -) -ext_enc_classes =3D set( - [ - enc_class - for enc_class in enc_classes - if enc_class not in ("NORMAL", "16BIT") and not enc_class.startswi= th("SUBINSN_") - ] -) - -try: - subinsn_groupings =3D iset.subinsn_groupings -except AttributeError: - subinsn_groupings =3D {} - -for tag, subinsn_grouping in subinsn_groupings.items(): - encs[tag] =3D "".join(reversed(subinsn_grouping["enc"].replace(" ", ""= ))) - -dectree_normal =3D {"leaves": set()} -dectree_16bit =3D {"leaves": set()} -dectree_subinsn_groupings =3D {"leaves": set()} -dectree_subinsns =3D {name: {"leaves": set()} for name in subinsn_enc_clas= ses} -dectree_extensions =3D {name: {"leaves": set()} for name in ext_enc_classe= s} - -for tag in encs.keys(): - if tag in subinsn_groupings: - dectree_subinsn_groupings["leaves"].add(tag) - continue - enc_class =3D iset.iset[tag]["enc_class"] - if enc_class.startswith("SUBINSN_"): - if len(encs[tag]) !=3D 32: - encs[tag] =3D encs[tag] + "0" * (32 - len(encs[tag])) - dectree_subinsns[enc_class]["leaves"].add(tag) - elif enc_class =3D=3D "16BIT": - if len(encs[tag]) !=3D 16: - raise Exception( - 'Tag "{}" has enc_class "{}" and not an encoding ' - + "width of 16 bits!".format(tag, enc_class) - ) - dectree_16bit["leaves"].add(tag) - else: - if len(encs[tag]) !=3D 32: - raise Exception( - 'Tag "{}" has enc_class "{}" and not an encoding ' - + "width of 32 bits!".format(tag, enc_class) - ) - if enc_class =3D=3D "NORMAL": - dectree_normal["leaves"].add(tag) - else: - dectree_extensions[enc_class]["leaves"].add(tag) - -faketags =3D set() -for tag, enc in iset.enc_ext_spaces.items(): - faketags.add(tag) - encs[tag] =3D "".join(reversed(enc.replace(" ", ""))) - dectree_normal["leaves"].add(tag) - -faketags |=3D set(subinsn_groupings.keys()) - - -def every_bit_counts(bitset): - for i in range(1, len(next(iter(bitset)))): - if len(set([bits[:i] + bits[i + 1 :] for bits in bitset])) =3D=3D = len(bitset): - return False - return True - - -def auto_separate(node): - tags =3D node["leaves"] - if len(tags) <=3D 1: - return - enc_width =3D len(encs[next(iter(tags))]) - opcode_bit_for_all =3D [ - all([encs[tag][i] in "01" for tag in tags]) for i in range(enc_wid= th) - ] - opcode_bit_is_0_for_all =3D [ - opcode_bit_for_all[i] and all([encs[tag][i] =3D=3D "0" for tag in = tags]) - for i in range(enc_width) - ] - opcode_bit_is_1_for_all =3D [ - opcode_bit_for_all[i] and all([encs[tag][i] =3D=3D "1" for tag in = tags]) - for i in range(enc_width) - ] - differentiator_opcode_bit =3D [ - opcode_bit_for_all[i] - and not (opcode_bit_is_0_for_all[i] or opcode_bit_is_1_for_all[i]) - for i in range(enc_width) - ] - best_width =3D 0 - for width in range(4, 0, -1): - for lsb in range(enc_width - width, -1, -1): - bitset =3D set([encs[tag][lsb : lsb + width] for tag in tags]) - if all(differentiator_opcode_bit[lsb : lsb + width]) and ( - len(bitset) =3D=3D len(tags) or every_bit_counts(bitset) - ): - best_width =3D width - best_lsb =3D lsb - caught_all_tags =3D len(bitset) =3D=3D len(tags) - break - if best_width !=3D 0: - break - if best_width =3D=3D 0: - raise Exception( - "Could not find a way to differentiate the encodings " - + "of the following tags:\n{}".format("\n".join(tags)) - ) - if caught_all_tags: - for width in range(1, best_width): - for lsb in range(enc_width - width, -1, -1): - bitset =3D set([encs[tag][lsb : lsb + width] for tag in ta= gs]) - if all(differentiator_opcode_bit[lsb : lsb + width]) and l= en( - bitset - ) =3D=3D len(tags): - best_width =3D width - best_lsb =3D lsb - break - else: - continue - break - node["separator_lsb"] =3D best_lsb - node["separator_width"] =3D best_width - node["children"] =3D [] - for value in range(2**best_width): - child =3D {} - bits =3D "".join(reversed("{:0{}b}".format(value, best_width))) - child["leaves"] =3D set( - [tag for tag in tags if encs[tag][best_lsb : best_lsb + best_w= idth] =3D=3D bits] - ) - node["children"].append(child) - for child in node["children"]: - auto_separate(child) - - -auto_separate(dectree_normal) -auto_separate(dectree_16bit) -if subinsn_groupings: - auto_separate(dectree_subinsn_groupings) -for dectree_subinsn in dectree_subinsns.values(): - auto_separate(dectree_subinsn) -for dectree_ext in dectree_extensions.values(): - auto_separate(dectree_ext) - -for tag in faketags: - del encs[tag] - - -def table_name(parents, node): - path =3D parents + [node] - root =3D path[0] - tag =3D next(iter(node["leaves"])) - if tag in subinsn_groupings: - enc_width =3D len(subinsn_groupings[tag]["enc"].replace(" ", "")) - else: - tag =3D next(iter(node["leaves"] - faketags)) - enc_width =3D len(encs[tag]) - determining_bits =3D ["_"] * enc_width - for parent, child in zip(path[:-1], path[1:]): - lsb =3D parent["separator_lsb"] - width =3D parent["separator_width"] - value =3D parent["children"].index(child) - determining_bits[lsb : lsb + width] =3D list( - reversed("{:0{}b}".format(value, width)) - ) - if tag in subinsn_groupings: - name =3D "DECODE_ROOT_EE" - else: - enc_class =3D iset.iset[tag]["enc_class"] - if enc_class in ext_enc_classes: - name =3D "DECODE_EXT_{}".format(enc_class) - elif enc_class in subinsn_enc_classes: - name =3D "DECODE_SUBINSN_{}".format(enc_class) - else: - name =3D "DECODE_ROOT_{}".format(enc_width) - if node !=3D root: - name +=3D "_" + "".join(reversed(determining_bits)) - return name - - -def print_node(f, node, parents): - if len(node["leaves"]) <=3D 1: - return - name =3D table_name(parents, node) - lsb =3D node["separator_lsb"] - width =3D node["separator_width"] - print( - "DECODE_NEW_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))".format( - name, 2**width, lsb, width - ), - file=3Df, - ) - for child in node["children"]: - if len(child["leaves"]) =3D=3D 0: - print("INVALID()", file=3Df) - elif len(child["leaves"]) =3D=3D 1: - (tag,) =3D child["leaves"] - if tag in subinsn_groupings: - class_a =3D subinsn_groupings[tag]["class_a"] - class_b =3D subinsn_groupings[tag]["class_b"] - enc =3D subinsn_groupings[tag]["enc"].replace(" ", "") - if "RESERVED" in tag: - print("INVALID()", file=3Df) - else: - print( - 'SUBINSNS({},{},{},"{}")'.format(tag, class_a, cla= ss_b, enc), - file=3Df, - ) - elif tag in iset.enc_ext_spaces: - enc =3D iset.enc_ext_spaces[tag].replace(" ", "") - print('EXTSPACE({},"{}")'.format(tag, enc), file=3Df) - else: - enc =3D "".join(reversed(encs[tag])) - print('TERMINAL({},"{}")'.format(tag, enc), file=3Df) - else: - print("TABLE_LINK({})".format(table_name(parents + [node], chi= ld)), file=3Df) - print( - "DECODE_END_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))".format( - name, 2**width, lsb, width - ), - file=3Df, - ) - print(file=3Df) - parents.append(node) - for child in node["children"]: - print_node(f, child, parents) - parents.pop() - - -def print_tree(f, tree): - print_node(f, tree, []) - - -def print_match_info(f): - for tag in sorted(encs.keys(), key=3Diset.tags.index): - enc =3D "".join(reversed(encs[tag])) - mask =3D int(re.sub(r"[^1]", r"0", enc.replace("0", "1")), 2) - match =3D int(re.sub(r"[^01]", r"0", enc), 2) - suffix =3D "" - print( - "DECODE{}_MATCH_INFO({},0x{:x}U,0x{:x}U)".format(suffix, tag, = mask, match), - file=3Df, - ) - - -regre =3D re.compile(r"((? 1: - raise Exception('Tag "{}" has split register field!'.forma= t(tag)) - reg_enc_field =3D reg_enc_fields[0] - if 2 ** len(reg_enc_field) !=3D reg_num_choices: - raise Exception( - 'Tag "{}" has incorrect register field width!'.format(= tag) - ) - print( - " DECODE_REG({},{},{})".format( - regno, len(reg_enc_field), enc.index(reg_enc_field) - ), - file=3Df, - ) - if reg_type in num_registers and reg_num_choices !=3D num_regi= sters[reg_type]: - print( - " DECODE_MAPPED_REG({},{})".format(regno, reg_m= apping), - file=3Df, - ) - regno +=3D 1 - - def implicit_register_key(reg): - return implicit_registers[reg] - - for reg in sorted( - set( - [ - r - for r in ( - iset.iset[tag]["rregs"].split(",") - + iset.iset[tag]["wregs"].split(",") - ) - if r in implicit_registers - ] - ), - key=3Dimplicit_register_key, - ): - print( - " DECODE_IMPL_REG({},{})".format(regno, implicit_re= gisters[reg]), - file=3Df, - ) - regno +=3D 1 - if imms and imms[0][0].isupper(): - imms =3D reversed(imms) - for imm in imms: - if imm[0].isupper(): - immno =3D 1 - else: - immno =3D 0 - imm_type =3D imm[0] - imm_width =3D int(imm[1]) - imm_shift =3D imm[2] - if imm_shift: - imm_shift =3D int(imm_shift) - else: - imm_shift =3D 0 - if imm_type.islower(): - imm_letter =3D "i" - else: - imm_letter =3D "I" - remainder =3D imm_width - for m in reversed(list(re.finditer(imm_letter + "+", enc))): - remainder -=3D m.end() - m.start() - print( - " DECODE_IMM({},{},{},{})".format( - immno, m.end() - m.start(), m.start(), remainder - ), - file=3Df, - ) - if remainder !=3D 0: - if imm[2]: - imm[2] =3D ":" + imm[2] - raise Exception( - 'Tag "{}" has an incorrect number of ' - + 'encoding bits for immediate "{}"'.format(tag, "".jo= in(imm)) - ) - if imm_type.lower() in "sr": - print(" DECODE_IMM_SXT({},{})".format(immno, imm_wi= dth), file=3Df) - if imm_type.lower() =3D=3D "n": - print(" DECODE_IMM_NEG({},{})".format(immno, imm_wi= dth), file=3Df) - if imm_shift: - print( - " DECODE_IMM_SHIFT({},{})".format(immno, imm_sh= ift), file=3Df - ) - print(")", file=3Df) - - -if __name__ =3D=3D "__main__": - with open(sys.argv[1], "w") as f: - print_tree(f, dectree_normal) - print_tree(f, dectree_16bit) - if subinsn_groupings: - print_tree(f, dectree_subinsn_groupings) - for name, dectree_subinsn in sorted(dectree_subinsns.items()): - print_tree(f, dectree_subinsn) - for name, dectree_ext in sorted(dectree_extensions.items()): - print_tree(f, dectree_ext) - print_match_info(f) - print_op_info(f) diff --git a/target/hexagon/gen_dectree_import.c b/target/hexagon/gen_dectr= ee_import.c index ee354677fd..87f20c14f1 100644 --- a/target/hexagon/gen_dectree_import.c +++ b/target/hexagon/gen_dectree_import.c @@ -56,24 +56,6 @@ const char * const opcode_syntax[XX_LAST_OPCODE] =3D { #undef EXTINSN }; =20 -const char * const opcode_rregs[] =3D { -#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS, -#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing = */ -#include "op_regs_generated.h.inc" - NULL -#undef REGINFO -#undef IMMINFO -}; - -const char * const opcode_wregs[] =3D { -#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS, -#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing = */ -#include "op_regs_generated.h.inc" - NULL -#undef REGINFO -#undef IMMINFO -}; - const OpcodeEncoding opcode_encodings[] =3D { #define DEF_ENC32(TAG, ENCSTR) \ [TAG] =3D { .encoding =3D ENCSTR }, @@ -130,8 +112,6 @@ static void gen_iset_table(FILE *out) fprintf(out, "\t\'%s\' : {\n", opcode_names[i]); fprintf(out, "\t\t\'tag\' : \'%s\',\n", opcode_names[i]); fprintf(out, "\t\t\'syntax\' : \'%s\',\n", opcode_syntax[i]); - fprintf(out, "\t\t\'rregs\' : \'%s\',\n", opcode_rregs[i]); - fprintf(out, "\t\t\'wregs\' : \'%s\',\n", opcode_wregs[i]); fprintf(out, "\t\t\'enc\' : \'%s\',\n", get_opcode_enc(i)); fprintf(out, "\t\t\'enc_class\' : \'%s\',\n", get_opcode_enc_class= (i)); fprintf(out, "\t},\n"); @@ -150,33 +130,6 @@ static void gen_tags_list(FILE *out) fprintf(out, "];\n\n"); } =20 -static void gen_enc_ext_spaces_table(FILE *out) -{ - fprintf(out, "enc_ext_spaces =3D {\n"); -#define DEF_EXT_SPACE(SPACEID, ENCSTR) \ - fprintf(out, "\t\'%s\' : \'%s\',\n", #SPACEID, ENCSTR); -#include "imported/encode.def" -#undef DEF_EXT_SPACE - fprintf(out, "};\n\n"); -} - -static void gen_subinsn_groupings_table(FILE *out) -{ - fprintf(out, "subinsn_groupings =3D {\n"); -#define DEF_PACKED32(TAG, TYPEA, TYPEB, ENCSTR) \ - do { \ - fprintf(out, "\t\'%s\' : {\n", #TAG); \ - fprintf(out, "\t\t\'name\' : \'%s\',\n", #TAG); \ - fprintf(out, "\t\t\'class_a\' : \'%s\',\n", #TYPEA); \ - fprintf(out, "\t\t\'class_b\' : \'%s\',\n", #TYPEB); \ - fprintf(out, "\t\t\'enc\' : \'%s\',\n", ENCSTR); \ - fprintf(out, "\t},\n"); \ - } while (0); -#include "imported/encode.def" -#undef DEF_PACKED32 - fprintf(out, "};\n\n"); -} - int main(int argc, char *argv[]) { FILE *outfile; @@ -193,8 +146,6 @@ int main(int argc, char *argv[]) =20 gen_iset_table(outfile); gen_tags_list(outfile); - gen_enc_ext_spaces_table(outfile); - gen_subinsn_groupings_table(outfile); =20 fclose(outfile); return 0; diff --git a/target/hexagon/meson.build b/target/hexagon/meson.build index 1bd1ebcba1..fb480afc03 100644 --- a/target/hexagon/meson.build +++ b/target/hexagon/meson.build @@ -122,18 +122,6 @@ hexagon_ss.add(iset_py) =20 # # Step 4 -# We use the dectree.py script to generate the decode tree header file -# -dectree_generated =3D custom_target( - 'dectree_generated.h.inc', - output: 'dectree_generated.h.inc', - depends: [iset_py], - env: {'PYTHONPATH': meson.current_build_dir()}, - command: [python, files('dectree.py'), '@OUTPUT@'], -) -hexagon_ss.add(dectree_generated) - -# # Generate the input to the QEMU decodetree.py script # normal_decode_generated =3D custom_target( diff --git a/target/hexagon/opcodes.c b/target/hexagon/opcodes.c index 35d790cdd5..1f7f3def38 100644 --- a/target/hexagon/opcodes.c +++ b/target/hexagon/opcodes.c @@ -111,33 +111,4 @@ void opcode_init(void) #include "op_attribs_generated.h.inc" #undef OP_ATTRIB #undef ATTRIBS - - decode_init(); -} - - -#define NEEDLE "IMMEXT(" - -int opcode_which_immediate_is_extended(Opcode opcode) -{ - const char *p; - - g_assert(opcode < XX_LAST_OPCODE); - g_assert(GET_ATTRIB(opcode, A_EXTENDABLE)); - - p =3D opcode_short_semantics[opcode]; - p =3D strstr(p, NEEDLE); - g_assert(p); - p +=3D strlen(NEEDLE); - while (isspace(*p)) { - p++; - } - /* lower is always imm 0, upper always imm 1. */ - if (islower(*p)) { - return 0; - } else if (isupper(*p)) { - return 1; - } else { - g_assert_not_reached(); - } } diff --git a/target/hexagon/opcodes.h b/target/hexagon/opcodes.h index 6e90e00fe2..fa7e321950 100644 --- a/target/hexagon/opcodes.h +++ b/target/hexagon/opcodes.h @@ -53,6 +53,4 @@ extern const OpcodeEncoding opcode_encodings[XX_LAST_OPCO= DE]; =20 void opcode_init(void); =20 -int opcode_which_immediate_is_extended(Opcode opcode); - #endif --=20 2.25.1