From patchwork Tue Dec 25 20:54:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 154478 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5211870ljp; Tue, 25 Dec 2018 13:02:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN7GH4yETMo7E3icCSYP9fNKeDzzKgqF+MIzGcLFlh5ii2jB5nTHsh0ezPr02bJbLrh4oibU X-Received: by 2002:ae9:e414:: with SMTP id q20mr15585441qkc.205.1545771740600; Tue, 25 Dec 2018 13:02:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545771740; cv=none; d=google.com; s=arc-20160816; b=cOFUrBu9k7Fv5YVAR14srsd8wckhIZRIIStGatGSwNfHL8PmQXDtHM0Ctqc/0atJNr ZZR0TO/3tqxha/0QTwp5+IduZDZff3klLd+SLx1DqtyCTSJlFCqCHJQMJiB/MO6yy0T+ VPJ6o/Z1mFzR6+MjjYEvmjWuBJ7J6tXWfsIztgquowAaWyzKIPTBPC4qah9RUuL83Z8l nyb9Jv/j5GmTDYJEfhJQyOxyS4ZNjPbR7ddlppgVUf35XHM+m+vDF/SFkwlIoMdWvAC+ yQkJzBWQVChdvodKdhsFqsBaRIy+AtT+dMa02AC9VkhBi2hXiUO1hvqNigotCnOTuB69 /7dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=bnSWepPpVuVUtley4KR6qFD+yjuup1LG9VJXZPML7WA=; b=j+x+csIfIlXLyvlee2CXz4dhllpl+bZ39lBlc1B04v2/yk+N+Nl1EkPZgE6ZRibvPh rHy4Ch+k87rE8rprpj/4LuBgqNhohnAdtagFkcx/cLFHk3ATLUEKTQOt97jhzvUc/vaX MFQ3NbSaW6i8LjoR/j8GAJqOG81N70vMvmknuozqCuOCUZ8D4t3po2YV+1qgV0D7LS4+ 6peND6Zh4j7i8OekRCzcV/9V7gCKcQboRSUnqs8Op9gR/9tQ2wL8f8r0fCWaakBHVHf5 PtPESX77K2HAuHNhhF/g+lHO0LJLx4HZMKa32ebIfK6gUEqcJyWPNMFL9/zp0ijuuerX GQzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=e70911WF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id t15si3792224qta.353.2018.12.25.13.02.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 25 Dec 2018 13:02:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=e70911WF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:43060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbtqG-0002Sb-2o for patch@linaro.org; Tue, 25 Dec 2018 16:02:20 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbtkl-0004MN-JA for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:56:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbtki-00074S-5B for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:56:39 -0500 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:37252) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gbtkh-00073c-Vy for qemu-devel@nongnu.org; Tue, 25 Dec 2018 15:56:36 -0500 Received: by mail-pf1-x436.google.com with SMTP id y126so7080818pfb.4 for ; Tue, 25 Dec 2018 12:56:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bnSWepPpVuVUtley4KR6qFD+yjuup1LG9VJXZPML7WA=; b=e70911WFXcYxRdEZQYo0ZRP9bP8N2WdbrVDPBp5uFbcr701BypsJa0fQ6IbhihLJNo 7Meds6ZbUpgxRlF5n3V7CGuQGoZlTy9hIsaBU/ooYGIBWUlbMexZxMHnFxb7ZEDPT1YJ MoPsLSQXFJN6o4MmQ02hnCWm5sDA5RXBNPBao= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bnSWepPpVuVUtley4KR6qFD+yjuup1LG9VJXZPML7WA=; b=D7ka/KyN1JYC4fBmnROAiU5oWh5Qm6qStOxmezLbQH0tInpAG9q5CO6e7uVlcAWzR2 gkGXyIOlTuxx1OdhO2rRgwplbaMkQtMYRDys6JZVUwGRhi9X44HHVxaryVRGezoz/bb7 z62yWSojfP0q3q5O9Gna1uAmocx+0Q8vfx9yilL6RFCWI5ELrzjk3xLQJxQkkt/a1cTb Wc3TXRa9IoaTIFJLVyd9hioj719p4BgtgcgJbhgkmLa2ThbasWklmru875JS3Hfpdpvm B2EIU0xxuGvKpALdIZ3nVqw+8Zzho3D79YM220Bi0nc4tqNwFs1U2CYcWmc5iQHmiDy0 o5wg== X-Gm-Message-State: AA+aEWbOmAGgJ1/JjOUPPILTBAFMUtSc+O9hr4jylmlay71sqZKgQROr yRM3tyDCpr4MxwrrSGpIKAqnT2XffV4= X-Received: by 2002:a62:b24a:: with SMTP id x71mr18148585pfe.148.1545771394546; Tue, 25 Dec 2018 12:56:34 -0800 (PST) Received: from cloudburst.home (c211-28-135-144.sunsh3.vic.optusnet.com.au. [211.28.135.144]) by smtp.gmail.com with ESMTPSA id t21sm48501628pgg.24.2018.12.25.12.56.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Dec 2018 12:56:33 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 26 Dec 2018 07:54:54 +1100 Message-Id: <20181225205529.10874-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181225205529.10874-1-richard.henderson@linaro.org> References: <20181225205529.10874-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::436 Subject: [Qemu-devel] [PULL 07/42] tcg/riscv: Add support for the constraints X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Michael Clark , Alistair Francis Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alistair Francis Signed-off-by: Alistair Francis Signed-off-by: Michael Clark Reviewed-by: Richard Henderson Message-Id: Signed-off-by: Richard Henderson --- tcg/riscv/tcg-target.inc.c | 168 +++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) -- 2.17.2 diff --git a/tcg/riscv/tcg-target.inc.c b/tcg/riscv/tcg-target.inc.c index 6c969e3973..f853d01803 100644 --- a/tcg/riscv/tcg-target.inc.c +++ b/tcg/riscv/tcg-target.inc.c @@ -116,3 +116,171 @@ static const int tcg_target_call_oarg_regs[] = { TCG_REG_A0, TCG_REG_A1, }; + +#define TCG_CT_CONST_ZERO 0x100 +#define TCG_CT_CONST_S12 0x200 +#define TCG_CT_CONST_N12 0x400 +#define TCG_CT_CONST_M12 0x800 + +static inline tcg_target_long sextreg(tcg_target_long val, int pos, int len) +{ + if (TCG_TARGET_REG_BITS == 32) { + return sextract32(val, pos, len); + } else { + return sextract64(val, pos, len); + } +} + +/* parse target specific constraints */ +static const char *target_parse_constraint(TCGArgConstraint *ct, + const char *ct_str, TCGType type) +{ + switch (*ct_str++) { + case 'r': + ct->ct |= TCG_CT_REG; + ct->u.regs = 0xffffffff; + break; + case 'L': + /* qemu_ld/qemu_st constraint */ + ct->ct |= TCG_CT_REG; + ct->u.regs = 0xffffffff; + /* qemu_ld/qemu_st uses TCG_REG_TMP0 */ +#if defined(CONFIG_SOFTMMU) + tcg_regset_reset_reg(ct->u.regs, tcg_target_call_iarg_regs[0]); + tcg_regset_reset_reg(ct->u.regs, tcg_target_call_iarg_regs[1]); + tcg_regset_reset_reg(ct->u.regs, tcg_target_call_iarg_regs[2]); + tcg_regset_reset_reg(ct->u.regs, tcg_target_call_iarg_regs[3]); + tcg_regset_reset_reg(ct->u.regs, tcg_target_call_iarg_regs[4]); +#endif + break; + case 'I': + ct->ct |= TCG_CT_CONST_S12; + break; + case 'N': + ct->ct |= TCG_CT_CONST_N12; + break; + case 'M': + ct->ct |= TCG_CT_CONST_M12; + break; + case 'Z': + /* we can use a zero immediate as a zero register argument. */ + ct->ct |= TCG_CT_CONST_ZERO; + break; + default: + return NULL; + } + return ct_str; +} + +/* test if a constant matches the constraint */ +static int tcg_target_const_match(tcg_target_long val, TCGType type, + const TCGArgConstraint *arg_ct) +{ + int ct = arg_ct->ct; + if (ct & TCG_CT_CONST) { + return 1; + } + if ((ct & TCG_CT_CONST_ZERO) && val == 0) { + return 1; + } + if ((ct & TCG_CT_CONST_S12) && val == sextreg(val, 0, 12)) { + return 1; + } + if ((ct & TCG_CT_CONST_N12) && -val == sextreg(-val, 0, 12)) { + return 1; + } + if ((ct & TCG_CT_CONST_M12) && val >= -0xfff && val <= 0xfff) { + return 1; + } + return 0; +} + +/* + * RISC-V Base ISA opcodes (IM) + */ + +typedef enum { + OPC_ADD = 0x33, + OPC_ADDI = 0x13, + OPC_AND = 0x7033, + OPC_ANDI = 0x7013, + OPC_AUIPC = 0x17, + OPC_BEQ = 0x63, + OPC_BGE = 0x5063, + OPC_BGEU = 0x7063, + OPC_BLT = 0x4063, + OPC_BLTU = 0x6063, + OPC_BNE = 0x1063, + OPC_DIV = 0x2004033, + OPC_DIVU = 0x2005033, + OPC_JAL = 0x6f, + OPC_JALR = 0x67, + OPC_LB = 0x3, + OPC_LBU = 0x4003, + OPC_LD = 0x3003, + OPC_LH = 0x1003, + OPC_LHU = 0x5003, + OPC_LUI = 0x37, + OPC_LW = 0x2003, + OPC_LWU = 0x6003, + OPC_MUL = 0x2000033, + OPC_MULH = 0x2001033, + OPC_MULHSU = 0x2002033, + OPC_MULHU = 0x2003033, + OPC_OR = 0x6033, + OPC_ORI = 0x6013, + OPC_REM = 0x2006033, + OPC_REMU = 0x2007033, + OPC_SB = 0x23, + OPC_SD = 0x3023, + OPC_SH = 0x1023, + OPC_SLL = 0x1033, + OPC_SLLI = 0x1013, + OPC_SLT = 0x2033, + OPC_SLTI = 0x2013, + OPC_SLTIU = 0x3013, + OPC_SLTU = 0x3033, + OPC_SRA = 0x40005033, + OPC_SRAI = 0x40005013, + OPC_SRL = 0x5033, + OPC_SRLI = 0x5013, + OPC_SUB = 0x40000033, + OPC_SW = 0x2023, + OPC_XOR = 0x4033, + OPC_XORI = 0x4013, + +#if TCG_TARGET_REG_BITS == 64 + OPC_ADDIW = 0x1b, + OPC_ADDW = 0x3b, + OPC_DIVUW = 0x200503b, + OPC_DIVW = 0x200403b, + OPC_MULW = 0x200003b, + OPC_REMUW = 0x200703b, + OPC_REMW = 0x200603b, + OPC_SLLIW = 0x101b, + OPC_SLLW = 0x103b, + OPC_SRAIW = 0x4000501b, + OPC_SRAW = 0x4000503b, + OPC_SRLIW = 0x501b, + OPC_SRLW = 0x503b, + OPC_SUBW = 0x4000003b, +#else + /* Simplify code throughout by defining aliases for RV32. */ + OPC_ADDIW = OPC_ADDI, + OPC_ADDW = OPC_ADD, + OPC_DIVUW = OPC_DIVU, + OPC_DIVW = OPC_DIV, + OPC_MULW = OPC_MUL, + OPC_REMUW = OPC_REMU, + OPC_REMW = OPC_REM, + OPC_SLLIW = OPC_SLLI, + OPC_SLLW = OPC_SLL, + OPC_SRAIW = OPC_SRAI, + OPC_SRAW = OPC_SRA, + OPC_SRLIW = OPC_SRLI, + OPC_SRLW = OPC_SRL, + OPC_SUBW = OPC_SUB, +#endif + + OPC_FENCE = 0x0000000f, +} RISCVInsn;