Received: from eggs.gnu.org ([2001:4830:134:3::10]:40723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhTmq-0003lN-C7 for qemu-devel@nongnu.org; Wed, 30 Sep 2015 22:40:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhTmp-0007cm-7T for qemu-devel@nongnu.org; Wed, 30 Sep 2015 22:40:00 -0400 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]:33584) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhTmp-0007cc-05 for qemu-devel@nongnu.org; Wed, 30 Sep 2015 22:39:59 -0400 Received: by pacex6 with SMTP id ex6so58855132pac.0 for ; Wed, 30 Sep 2015 19:39:58 -0700 (PDT) Sender: Richard Henderson From: Richard Henderson Date: Thu, 1 Oct 2015 12:38:39 +1000 Message-Id: <1443667126-6257-8-git-send-email-rth@twiddle.net> In-Reply-To: <1443667126-6257-1-git-send-email-rth@twiddle.net> References: <1443667126-6257-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [PATCH 07/14] target-tilegx: Implement complex multiply instructions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: gang.chen.5i5j@gmail.com Signed-off-by: Richard Henderson --- target-tilegx/helper.c | 40 ++++++++++++++++++++++++++++++++++++++++ target-tilegx/helper.h | 3 +++ target-tilegx/translate.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/target-tilegx/helper.c b/target-tilegx/helper.c index cad5dae..36b287f 100644 --- a/target-tilegx/helper.c +++ b/target-tilegx/helper.c @@ -97,3 +97,43 @@ uint64_t helper_crc32_32(uint64_t accum, uint64_t input) /* zlib crc32 converts the accumulator and output to one's complement. */ return crc32(accum ^ 0xffffffff, buf, 4) ^ 0xffffffff; } + +uint64_t helper_cmula(uint64_t srcd, uint64_t srca, uint64_t srcb) +{ + uint32_t reala = (int16_t)srca; + uint32_t imaga = (int16_t)(srca >> 16); + uint32_t realb = (int16_t)srcb; + uint32_t imagb = (int16_t)(srcb >> 16); + uint32_t reald = srcd; + uint32_t imagd = srcd >> 32; + uint32_t realr = reala * realb - imaga * imagb + reald; + uint32_t imagr = reala * imagb + imaga * realb + imagd; + + return deposit64(realr, 32, 32, imagr); +} + +uint64_t helper_cmulaf(uint64_t srcd, uint64_t srca, uint64_t srcb) +{ + uint32_t reala = (int16_t)srca; + uint32_t imaga = (int16_t)(srca >> 16); + uint32_t realb = (int16_t)srcb; + uint32_t imagb = (int16_t)(srcb >> 16); + uint32_t reald = (int16_t)srcd; + uint32_t imagd = (int16_t)(srcd >> 16); + int32_t realr = reala * realb - imaga * imagb; + int32_t imagr = reala * imagb + imaga * realb; + + return deposit32((realr >> 15) + reald, 16, 16, (imagr >> 15) + imagd); +} + +uint64_t helper_cmul2(uint64_t srca, uint64_t srcb, int shift, int round) +{ + uint32_t reala = (int16_t)srca; + uint32_t imaga = (int16_t)(srca >> 16); + uint32_t realb = (int16_t)srcb; + uint32_t imagb = (int16_t)(srcb >> 16); + int32_t realr = reala * realb - imaga * imagb + round; + int32_t imagr = reala * imagb + imaga * realb + round; + + return deposit32(realr >> shift, 16, 16, imagr >> shift); +} diff --git a/target-tilegx/helper.h b/target-tilegx/helper.h index 72c8e92..82d84f1 100644 --- a/target-tilegx/helper.h +++ b/target-tilegx/helper.h @@ -6,6 +6,9 @@ DEF_HELPER_FLAGS_1(revbits, TCG_CALL_NO_RWG_SE, i64, i64) DEF_HELPER_FLAGS_3(shufflebytes, TCG_CALL_NO_RWG_SE, i64, i64, i64, i64) DEF_HELPER_FLAGS_2(crc32_8, TCG_CALL_NO_RWG_SE, i64, i64, i64) DEF_HELPER_FLAGS_2(crc32_32, TCG_CALL_NO_RWG_SE, i64, i64, i64) +DEF_HELPER_FLAGS_3(cmula, TCG_CALL_NO_RWG_SE, i64, i64, i64, i64) +DEF_HELPER_FLAGS_3(cmulaf, TCG_CALL_NO_RWG_SE, i64, i64, i64, i64) +DEF_HELPER_FLAGS_4(cmul2, TCG_CALL_NO_RWG_SE, i64, i64, i64, int, int) DEF_HELPER_FLAGS_2(v1multu, TCG_CALL_NO_RWG_SE, i64, i64, i64) DEF_HELPER_FLAGS_2(v1shl, TCG_CALL_NO_RWG_SE, i64, i64, i64) diff --git a/target-tilegx/translate.c b/target-tilegx/translate.c index 9f86fd3..d7e4d52 100644 --- a/target-tilegx/translate.c +++ b/target-tilegx/translate.c @@ -276,6 +276,15 @@ static void gen_mul_half(TCGv tdest, TCGv tsrca, TCGv tsrcb, tcg_temp_free(t); } +static void gen_cmul2(TCGv tdest, TCGv tsrca, TCGv tsrcb, int sh, int rd) +{ + TCGv_i32 tsh = tcg_const_i32(sh); + TCGv_i32 trd = tcg_const_i32(rd); + gen_helper_cmul2(tdest, tsrca, tsrcb, tsh, trd); + tcg_temp_free_i32(tsh); + tcg_temp_free_i32(trd); +} + static TileExcp gen_st_opcode(DisasContext *dc, unsigned dest, unsigned srca, unsigned srcb, TCGMemOp memop, const char *name) { @@ -759,13 +768,33 @@ static TileExcp gen_rrr_opcode(DisasContext *dc, unsigned opext, mnemonic = "cmpne"; break; case OE_RRR(CMULAF, 0, X0): + gen_helper_cmulaf(tdest, load_gr(dc, dest), tsrca, tsrcb); + mnemonic = "cmulaf"; + break; case OE_RRR(CMULA, 0, X0): + gen_helper_cmula(tdest, load_gr(dc, dest), tsrca, tsrcb); + mnemonic = "cmula"; + break; case OE_RRR(CMULFR, 0, X0): + gen_cmul2(tdest, tsrca, tsrcb, 15, 1 << 14); + mnemonic = "cmulfr"; + break; case OE_RRR(CMULF, 0, X0): + gen_cmul2(tdest, tsrca, tsrcb, 15, 0); + mnemonic = "cmulf"; + break; case OE_RRR(CMULHR, 0, X0): + gen_cmul2(tdest, tsrca, tsrcb, 16, 1 << 15); + mnemonic = "cmulhr"; + break; case OE_RRR(CMULH, 0, X0): + gen_cmul2(tdest, tsrca, tsrcb, 16, 0); + mnemonic = "cmulh"; + break; case OE_RRR(CMUL, 0, X0): - return TILEGX_EXCP_OPCODE_UNIMPLEMENTED; + gen_helper_cmula(tdest, load_zero(dc), tsrca, tsrcb); + mnemonic = "cmul"; + break; case OE_RRR(CRC32_32, 0, X0): gen_helper_crc32_32(tdest, tsrca, tsrcb); mnemonic = "crc32_32"; -- 2.4.3