From patchwork Thu Aug 20 17:22:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Gang X-Patchwork-Id: 509180 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 057DB1402A2 for ; Fri, 21 Aug 2015 07:53:58 +1000 (AEST) Received: from localhost ([::1]:37320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSXmV-0004di-JU for incoming@patchwork.ozlabs.org; Thu, 20 Aug 2015 17:53:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSTYN-00077V-5s for qemu-devel@nongnu.org; Thu, 20 Aug 2015 13:23:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZSTYH-0001RF-PM for qemu-devel@nongnu.org; Thu, 20 Aug 2015 13:23:02 -0400 Received: from col004-omc3s15.hotmail.com ([65.55.34.153]:60851) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZSTYH-0001RB-HZ for qemu-devel@nongnu.org; Thu, 20 Aug 2015 13:22:57 -0400 Received: from COL130-W4 ([65.55.34.136]) by COL004-OMC3S15.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Thu, 20 Aug 2015 10:22:56 -0700 X-TMN: [sQNGPN0K+LmU8iuHiX0dNQX/tn/o2oL2] X-Originating-Email: [xili_gchen_5257@hotmail.com] Message-ID: From: gchen gchen To: Peter Maydell , "rth@twiddle.net" , Chris Metcalf , =?iso-8859-1?B?QW5kcmVhcyBG5HJiZXI=?= , "walt@tilera.com" , Riku Voipio Date: Fri, 21 Aug 2015 01:22:56 +0800 Importance: Normal In-Reply-To: <55D60D32.2030705@hotmail.com> References: <55D608BF.4050806@hotmail.com> , <55D60D32.2030705@hotmail.com> MIME-Version: 1.0 X-OriginalArrivalTime: 20 Aug 2015 17:22:56.0971 (UTC) FILETIME=[DAEDC1B0:01D0DB6C] X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 65.55.34.153 Cc: qemu-devel Subject: [Qemu-devel] [PATCH 08/16] target-tilegx: Add several helpers for instructions translation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The related instructions are exception, cntlz, cnttz, shufflebytes, and add_saturate. Signed-off-by: Chen Gang --- target-tilegx/helper.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ target-tilegx/helper.h | 5 +++ 2 files changed, 88 insertions(+) create mode 100644 target-tilegx/helper.c create mode 100644 target-tilegx/helper.h -- 1.9.3 diff --git a/target-tilegx/helper.c b/target-tilegx/helper.c new file mode 100644 index 0000000..5ab41cd --- /dev/null +++ b/target-tilegx/helper.c @@ -0,0 +1,83 @@ +/* + * QEMU TILE-Gx helpers + * + * Copyright (c) 2015 Chen Gang + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + * + */ + +#include "cpu.h" +#include "qemu-common.h" +#include "exec/helper-proto.h" + +#define SIGNBIT32 0x80000000 + +int64_t helper_add_saturate(CPUTLGState *env, uint64_t rsrc, uint64_t rsrcb) +{ + uint32_t rdst = rsrc + rsrcb; + + if (((rdst ^ rsrc) & SIGNBIT32) && !((rsrc ^ rsrcb) & SIGNBIT32)) { + rdst = ~(((int32_t)rsrc>> 31) ^ SIGNBIT32); + } + + return (int64_t)rdst; +} + +void helper_exception(CPUTLGState *env, uint32_t excp) +{ + CPUState *cs = CPU(tilegx_env_get_cpu(env)); + + cs->exception_index = excp; + cpu_loop_exit(cs); +} + +uint64_t helper_cntlz(uint64_t arg) +{ + return clz64(arg); +} + +uint64_t helper_cnttz(uint64_t arg) +{ + return ctz64(arg); +} + +/* + * Functional Description + * uint64_t a = rf[SrcA]; + * uint64_t b = rf[SrcB]; + * uint64_t d = rf[Dest]; + * uint64_t output = 0; + * unsigned int counter; + * for (counter = 0; counter < (WORD_SIZE / BYTE_SIZE); counter++) + * { + * int sel = getByte (b, counter) & 0xf; + * uint8_t byte = (sel < 8) ? getByte (d, sel) : getByte (a, (sel - 8)); + * output = setByte (output, counter, byte); + * } + * rf[Dest] = output; + */ +uint64_t helper_shufflebytes(uint64_t rdst, uint64_t rsrc, uint64_t rsrcb) +{ + uint64_t vdst = 0; + int count; + + for (count = 0; count < 64; count += 8) { + uint64_t sel = rsrcb>> count; + uint64_t src = (sel & 8) ? rsrc : rdst; + vdst |= ((src>> ((sel & 7) * 8)) & 0xff) << count; + } + + return vdst; +} diff --git a/target-tilegx/helper.h b/target-tilegx/helper.h new file mode 100644 index 0000000..1411c19 --- /dev/null +++ b/target-tilegx/helper.h @@ -0,0 +1,5 @@ +DEF_HELPER_2(exception, noreturn, env, i32) +DEF_HELPER_FLAGS_1(cntlz, TCG_CALL_NO_RWG_SE, i64, i64) +DEF_HELPER_FLAGS_1(cnttz, TCG_CALL_NO_RWG_SE, i64, i64) +DEF_HELPER_FLAGS_3(shufflebytes, TCG_CALL_NO_RWG_SE, i64, i64, i64, i64) +DEF_HELPER_3(add_saturate, s64, env, i64, i64)