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 Message-ID: From: gchen gchen Date: Fri, 21 Aug 2015 01:22:56 +0800 In-Reply-To: <55D60D32.2030705@hotmail.com> References: <55D608BF.4050806@hotmail.com> , <55D60D32.2030705@hotmail.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: [Qemu-devel] [PATCH 08/16] target-tilegx: Add several helpers for instructions translation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , "rth@twiddle.net" , Chris Metcalf , =?iso-8859-1?B?QW5kcmVhcyBG5HJiZXI=?= , "walt@tilera.com" , Riku Voipio Cc: qemu-devel The related instructions are exception=2C cntlz=2C cnttz=2C shufflebytes=2C= and=0A= add_saturate.=0A= =0A= Signed-off-by: Chen Gang =0A= ---=0A= target-tilegx/helper.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++= +++=0A= target-tilegx/helper.h | 5 +++=0A= 2 files changed=2C 88 insertions(+)=0A= create mode 100644 target-tilegx/helper.c=0A= create mode 100644 target-tilegx/helper.h=0A= =0A= diff --git a/target-tilegx/helper.c b/target-tilegx/helper.c=0A= new file mode 100644=0A= index 0000000..5ab41cd=0A= --- /dev/null=0A= +++ b/target-tilegx/helper.c=0A= @@ -0=2C0 +1=2C83 @@=0A= +/*=0A= + * QEMU TILE-Gx helpers=0A= + *=0A= + * Copyright (c) 2015 Chen Gang=0A= + *=0A= + * This library is free software=3B you can redistribute it and/or=0A= + * modify it under the terms of the GNU Lesser General Public=0A= + * License as published by the Free Software Foundation=3B either=0A= + * version 2.1 of the License=2C or (at your option) any later version.=0A= + *=0A= + * This library is distributed in the hope that it will be useful=2C=0A= + * but WITHOUT ANY WARRANTY=3B without even the implied warranty of=0A= + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU=0A= + * Lesser General Public License for more details.=0A= + *=0A= + * You should have received a copy of the GNU Lesser General Public=0A= + * License along with this library=3B if not=2C see=0A= + * =0A= + */=0A= +=0A= +#include "cpu.h"=0A= +#include "qemu-common.h"=0A= +#include "exec/helper-proto.h"=0A= +=0A= +#define SIGNBIT32 0x80000000=0A= +=0A= +int64_t helper_add_saturate(CPUTLGState *env=2C uint64_t rsrc=2C uint64_t = rsrcb)=0A= +{=0A= + uint32_t rdst =3D rsrc + rsrcb=3B=0A= +=0A= + if (((rdst ^ rsrc) & SIGNBIT32) && !((rsrc ^ rsrcb) & SIGNBIT32)) {=0A= + rdst =3D ~(((int32_t)rsrc>> 31) ^ SIGNBIT32)=3B=0A= + }=0A= +=0A= + return (int64_t)rdst=3B=0A= +}=0A= +=0A= +void helper_exception(CPUTLGState *env=2C uint32_t excp)=0A= +{=0A= + CPUState *cs =3D CPU(tilegx_env_get_cpu(env))=3B=0A= +=0A= + cs->exception_index =3D excp=3B=0A= + cpu_loop_exit(cs)=3B=0A= +}=0A= +=0A= +uint64_t helper_cntlz(uint64_t arg)=0A= +{=0A= + return clz64(arg)=3B=0A= +}=0A= +=0A= +uint64_t helper_cnttz(uint64_t arg)=0A= +{=0A= + return ctz64(arg)=3B=0A= +}=0A= +=0A= +/*=0A= + * Functional Description=0A= + * uint64_t a =3D rf[SrcA]=3B=0A= + * uint64_t b =3D rf[SrcB]=3B=0A= + * uint64_t d =3D rf[Dest]=3B=0A= + * uint64_t output =3D 0=3B=0A= + * unsigned int counter=3B=0A= + * for (counter =3D 0=3B counter < (WORD_SIZE / BYTE_SIZE)=3B counter++)= =0A= + * {=0A= + * int sel =3D getByte (b=2C counter) & 0xf=3B=0A= + * uint8_t byte =3D (sel < 8) ? getByte (d=2C sel) : getByte (a=2C (sel - = 8))=3B=0A= + * output =3D setByte (output=2C counter=2C byte)=3B=0A= + * }=0A= + * rf[Dest] =3D output=3B=0A= + */=0A= +uint64_t helper_shufflebytes(uint64_t rdst=2C uint64_t rsrc=2C uint64_t rs= rcb)=0A= +{=0A= + uint64_t vdst =3D 0=3B=0A= + int count=3B=0A= +=0A= + for (count =3D 0=3B count < 64=3B count +=3D 8) {=0A= + uint64_t sel =3D rsrcb>> count=3B=0A= + uint64_t src =3D (sel & 8) ? rsrc : rdst=3B=0A= + vdst |=3D ((src>> ((sel & 7) * 8)) & 0xff) << count=3B=0A= + }=0A= +=0A= + return vdst=3B=0A= +}=0A= diff --git a/target-tilegx/helper.h b/target-tilegx/helper.h=0A= new file mode 100644=0A= index 0000000..1411c19=0A= --- /dev/null=0A= +++ b/target-tilegx/helper.h=0A= @@ -0=2C0 +1=2C5 @@=0A= +DEF_HELPER_2(exception=2C noreturn=2C env=2C i32)=0A= +DEF_HELPER_FLAGS_1(cntlz=2C TCG_CALL_NO_RWG_SE=2C i64=2C i64)=0A= +DEF_HELPER_FLAGS_1(cnttz=2C TCG_CALL_NO_RWG_SE=2C i64=2C i64)=0A= +DEF_HELPER_FLAGS_3(shufflebytes=2C TCG_CALL_NO_RWG_SE=2C i64=2C i64=2C i64= =2C i64)=0A= +DEF_HELPER_3(add_saturate=2C s64=2C env=2C i64=2C i64)=0A= --=0A= 1.9.3=0A= =