From patchwork Fri Dec 6 13:19:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22131 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E292723A4E for ; Fri, 6 Dec 2013 13:19:45 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id o6sf2239868oag.7 for ; Fri, 06 Dec 2013 05:19:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=hM1tqWBDWnwoqBJDqSqfrFtM7ffkMTkWP5uuVMVxzfQ=; b=dE5rJbIteLV7k22a6FmCtHqQAT3eeYBWEY4a0rNLPrJk/O/2CP/fSyAJYIdy19gXgx X9XD4GDuGf4MFDIwkMUcFTTzeRTAZ+4qaBYGWN5ekqgFLnHyMrUVXvvbzQGg9A8vcuLm rjotV2pFRTXyIuw/SaHrcA5y9vq+sX5D011xfef0aGy1YatdpHQTn4rbBu1jYuWBvww+ 1qgTfzEAA/iD4QVt/jVIs4GvGostRCeHMcK/3EaK7LJP+v8BjhMYTYLdIbAKMoj/057x lMRbMqtkh9/abbEwBnCRSmCLBIs+DgF+oeQ3XFqyFLZImfwNWCRfjNf23fua5Mf8fM93 hdPA== X-Gm-Message-State: ALoCoQkrcXGUt9n5i1ZEvbI8hn/ceJI62AU2dMVjpYm+i6VxqEEdrFfg4T7/lmlvuDrk/ASKhQpx X-Received: by 10.182.245.197 with SMTP id xq5mr1156782obc.27.1386335985504; Fri, 06 Dec 2013 05:19:45 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.73.69 with SMTP id j5ls1371741qev.48.gmail; Fri, 06 Dec 2013 05:19:45 -0800 (PST) X-Received: by 10.58.54.69 with SMTP id h5mr1888992vep.25.1386335985315; Fri, 06 Dec 2013 05:19:45 -0800 (PST) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id q19si23496444vea.63.2013.12.06.05.19.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 06 Dec 2013 05:19:45 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jw12so725424veb.31 for ; Fri, 06 Dec 2013 05:19:45 -0800 (PST) X-Received: by 10.58.178.239 with SMTP id db15mr1926688vec.9.1386335985142; Fri, 06 Dec 2013 05:19:45 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp99143vcz; Fri, 6 Dec 2013 05:19:44 -0800 (PST) X-Received: by 10.204.166.196 with SMTP id n4mr1145728bky.85.1386335984177; Fri, 06 Dec 2013 05:19:44 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id b2si518744bko.165.2013.12.06.05.19.42 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 06 Dec 2013 05:19:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1VovJJ-0007WX-GH; Fri, 06 Dec 2013 13:19:13 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Michael Matz , Claudio Fontana , Dirk Mueller , Laurent Desnogues , kvmarm@lists.cs.columbia.edu, Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Christoffer Dall , Will Newton Subject: [PATCH v2 05/13] target-arm: A64: add support for 2-src data processing and DIV Date: Fri, 6 Dec 2013 13:19:05 +0000 Message-Id: <1386335953-28876-6-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1386335953-28876-1-git-send-email-peter.maydell@linaro.org> References: <1386335953-28876-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Alexander Graf This patch adds support for decoding 2-src data processing insns, and the first users, UDIV and SDIV. Signed-off-by: Alexander Graf [claudio: adapted to new decoder adding the 2-src decoding level, always zero-extend result in 32bit mode] Signed-off-by: Claudio Fontana Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target-arm/helper-a64.c | 21 +++++++++++++ target-arm/helper-a64.h | 2 ++ target-arm/translate-a64.c | 72 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/target-arm/helper-a64.c b/target-arm/helper-a64.c index adb8428..abb98c0 100644 --- a/target-arm/helper-a64.c +++ b/target-arm/helper-a64.c @@ -23,3 +23,24 @@ #include "qemu/host-utils.h" #include "sysemu/sysemu.h" #include "qemu/bitops.h" + +/* C2.4.7 Multiply and divide */ +/* special cases for 0 and LLONG_MIN are mandated by the standard */ +uint64_t HELPER(udiv64)(uint64_t num, uint64_t den) +{ + if (den == 0) { + return 0; + } + return num / den; +} + +int64_t HELPER(sdiv64)(int64_t num, int64_t den) +{ + if (den == 0) { + return 0; + } + if (num == LLONG_MIN && den == -1) { + return LLONG_MIN; + } + return num / den; +} diff --git a/target-arm/helper-a64.h b/target-arm/helper-a64.h index dd28306..e0d6506 100644 --- a/target-arm/helper-a64.h +++ b/target-arm/helper-a64.h @@ -16,3 +16,5 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see . */ +DEF_HELPER_FLAGS_2(udiv64, TCG_CALL_NO_RWG_SE, i64, i64, i64) +DEF_HELPER_FLAGS_2(sdiv64, TCG_CALL_NO_RWG_SE, s64, s64, s64) diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index 5a822a5..ddee285 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -1042,10 +1042,78 @@ static void disas_data_proc_1src(DisasContext *s, uint32_t insn) unsupported_encoding(s, insn); } -/* Data-processing (2 source) */ +static void handle_div(DisasContext *s, bool is_signed, unsigned int sf, + unsigned int rm, unsigned int rn, unsigned int rd) +{ + TCGv_i64 tcg_n, tcg_m, tcg_rd; + tcg_rd = cpu_reg(s, rd); + + if (!sf && is_signed) { + tcg_n = new_tmp_a64(s); + tcg_m = new_tmp_a64(s); + tcg_gen_ext32s_i64(tcg_n, cpu_reg(s, rn)); + tcg_gen_ext32s_i64(tcg_m, cpu_reg(s, rm)); + } else { + tcg_n = read_cpu_reg(s, rn, sf); + tcg_m = read_cpu_reg(s, rm, sf); + } + + if (is_signed) { + gen_helper_sdiv64(tcg_rd, tcg_n, tcg_m); + } else { + gen_helper_udiv64(tcg_rd, tcg_n, tcg_m); + } + + if (!sf) { /* zero extend final result */ + tcg_gen_ext32u_i64(tcg_rd, tcg_rd); + } +} + +/* C3.5.8 Data-processing (2 source) + * 31 30 29 28 21 20 16 15 10 9 5 4 0 + * +----+---+---+-----------------+------+--------+------+------+ + * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd | + * +----+---+---+-----------------+------+--------+------+------+ + */ static void disas_data_proc_2src(DisasContext *s, uint32_t insn) { - unsupported_encoding(s, insn); + unsigned int sf, rm, opcode, rn, rd; + sf = extract32(insn, 31, 1); + rm = extract32(insn, 16, 5); + opcode = extract32(insn, 10, 6); + rn = extract32(insn, 5, 5); + rd = extract32(insn, 0, 5); + + if (extract32(insn, 29, 1)) { + unallocated_encoding(s); + return; + } + + switch (opcode) { + case 2: /* UDIV */ + handle_div(s, false, sf, rm, rn, rd); + break; + case 3: /* SDIV */ + handle_div(s, true, sf, rm, rn, rd); + break; + case 8: /* LSLV */ + case 9: /* LSRV */ + case 10: /* ASRV */ + case 11: /* RORV */ + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: /* CRC32 */ + unsupported_encoding(s, insn); + break; + default: + unallocated_encoding(s); + break; + } } /* C3.5 Data processing - register */