From patchwork Wed Feb 1 12:18:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Batuzov X-Patchwork-Id: 722490 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 3vD2h62DYcz9ryZ for ; Wed, 1 Feb 2017 23:37:10 +1100 (AEDT) Received: from localhost ([::1]:50329 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYu9r-0006gD-Ng for incoming@patchwork.ozlabs.org; Wed, 01 Feb 2017 07:37:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYtsA-00060K-Up for qemu-devel@nongnu.org; Wed, 01 Feb 2017 07:18:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cYts5-0005bw-Vw for qemu-devel@nongnu.org; Wed, 01 Feb 2017 07:18:50 -0500 Received: from bran.ispras.ru ([83.149.199.196]:46067 helo=smtp.ispras.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYts5-0005bY-K4 for qemu-devel@nongnu.org; Wed, 01 Feb 2017 07:18:45 -0500 Received: from bulbul.intra.ispras.ru (spartak.intra.ispras.ru [10.10.3.51]) by smtp.ispras.ru (Postfix) with ESMTP id 99042612E8; Wed, 1 Feb 2017 15:18:44 +0300 (MSK) From: Kirill Batuzov To: qemu-devel@nongnu.org Date: Wed, 1 Feb 2017 15:18:05 +0300 Message-Id: <1485951502-28774-4-git-send-email-batuzovk@ispras.ru> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1485951502-28774-1-git-send-email-batuzovk@ispras.ru> References: <1485951502-28774-1-git-send-email-batuzovk@ispras.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.196 Subject: [Qemu-devel] [PATCH v2 03/20] tcg: support representing vector type with smaller vector or scalar types 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 , Peter Crosthwaite , Kirill Batuzov , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Kirill Batuzov --- This is not as bad as I thought it would be. Only two cases: type == base_type and type != base_type. --- tcg/tcg.c | 136 +++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 45 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 5e69103..18d97ec 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -523,12 +523,54 @@ TCGv_i64 tcg_global_reg_new_i64(TCGReg reg, const char *name) return MAKE_TCGV_I64(idx); } -int tcg_global_mem_new_internal(TCGType type, TCGv_ptr base, +static TCGType tcg_choose_type(TCGType type) +{ + switch (type) { + case TCG_TYPE_I64: + if (TCG_TARGET_REG_BITS == 64) { + return TCG_TYPE_I64; + } + /* Fallthrough */ + case TCG_TYPE_I32: + return TCG_TYPE_I32; + case TCG_TYPE_V128: +#ifdef TCG_TARGET_HAS_REG128 + return TCG_TYPE_V128; +#endif + /* Fallthrough */ + case TCG_TYPE_V64: +#ifdef TCG_TARGET_HAS_REGV64 + return TCG_TYPE_V64; +#else + return tcg_choose_type(TCG_TYPE_I64); +#endif + default: + g_assert_not_reached(); + } +} + +static intptr_t tcg_type_size(TCGType type) +{ + switch (type) { + case TCG_TYPE_I32: + return 4; + case TCG_TYPE_I64: + case TCG_TYPE_V64: + return 8; + case TCG_TYPE_V128: + return 16; + default: + g_assert_not_reached(); + } +} + +int tcg_global_mem_new_internal(TCGType base_type, TCGv_ptr base, intptr_t offset, const char *name) { TCGContext *s = &tcg_ctx; TCGTemp *base_ts = &s->temps[GET_TCGV_PTR(base)]; TCGTemp *ts = tcg_global_alloc(s); + TCGType type = tcg_choose_type(base_type); int indirect_reg = 0, bigendian = 0; #ifdef HOST_WORDS_BIGENDIAN bigendian = 1; @@ -543,47 +585,51 @@ int tcg_global_mem_new_internal(TCGType type, TCGv_ptr base, indirect_reg = 1; } - if (TCG_TARGET_REG_BITS == 32 && type == TCG_TYPE_I64) { - TCGTemp *ts2 = tcg_global_alloc(s); - char buf[64]; - - ts->base_type = TCG_TYPE_I64; - ts->type = TCG_TYPE_I32; + if (type == base_type) { + ts->base_type = type; + ts->type = type; ts->indirect_reg = indirect_reg; ts->mem_allocated = 1; ts->mem_base = base_ts; - ts->mem_offset = offset + bigendian * 4; - pstrcpy(buf, sizeof(buf), name); - pstrcat(buf, sizeof(buf), "_0"); - ts->name = strdup(buf); - - tcg_debug_assert(ts2 == ts + 1); - ts2->base_type = TCG_TYPE_I64; - ts2->type = TCG_TYPE_I32; - ts2->indirect_reg = indirect_reg; - ts2->mem_allocated = 1; - ts2->mem_base = base_ts; - ts2->mem_offset = offset + (1 - bigendian) * 4; - pstrcpy(buf, sizeof(buf), name); - pstrcat(buf, sizeof(buf), "_1"); - ts2->name = strdup(buf); + ts->mem_offset = offset; + ts->name = name; } else { - ts->base_type = type; + int i, count = tcg_type_size(base_type) / tcg_type_size(type); + TCGTemp *ts2, *ts1 = ts; + int cur_offset = + bigendian ? tcg_type_size(base_type) - tcg_type_size(type) : 0; + + ts->base_type = base_type; ts->type = type; ts->indirect_reg = indirect_reg; ts->mem_allocated = 1; ts->mem_base = base_ts; - ts->mem_offset = offset; - ts->name = name; + ts->mem_offset = offset + cur_offset; + ts->name = g_strdup_printf("%s_0", name); + + for (i = 1; i < count; i++) { + ts2 = tcg_global_alloc(s); + tcg_debug_assert(ts2 == ts1 + 1); + cur_offset += (bigendian ? -1 : 1) * tcg_type_size(type); + ts2->base_type = base_type; + ts2->type = type; + ts2->indirect_reg = indirect_reg; + ts2->mem_allocated = 1; + ts2->mem_base = base_ts; + ts2->mem_offset = offset + cur_offset; + ts2->name = g_strdup_printf("%s_%d", name, i); + ts1 = ts2; + } } return temp_idx(s, ts); } -static int tcg_temp_new_internal(TCGType type, int temp_local) +static int tcg_temp_new_internal(TCGType base_type, int temp_local) { TCGContext *s = &tcg_ctx; TCGTemp *ts; int idx, k; + TCGType type = tcg_choose_type(base_type); k = type + (temp_local ? TCG_TYPE_COUNT : 0); idx = find_first_bit(s->free_temps[k].l, TCG_MAX_TEMPS); @@ -593,28 +639,28 @@ static int tcg_temp_new_internal(TCGType type, int temp_local) ts = &s->temps[idx]; ts->temp_allocated = 1; - tcg_debug_assert(ts->base_type == type); + tcg_debug_assert(ts->base_type == base_type); tcg_debug_assert(ts->temp_local == temp_local); } else { ts = tcg_temp_alloc(s); - if (TCG_TARGET_REG_BITS == 32 && type == TCG_TYPE_I64) { - TCGTemp *ts2 = tcg_temp_alloc(s); - - ts->base_type = type; - ts->type = TCG_TYPE_I32; - ts->temp_allocated = 1; - ts->temp_local = temp_local; - - tcg_debug_assert(ts2 == ts + 1); - ts2->base_type = TCG_TYPE_I64; - ts2->type = TCG_TYPE_I32; - ts2->temp_allocated = 1; - ts2->temp_local = temp_local; - } else { - ts->base_type = type; - ts->type = type; - ts->temp_allocated = 1; - ts->temp_local = temp_local; + ts->base_type = base_type; + ts->type = type; + ts->temp_allocated = 1; + ts->temp_local = temp_local; + + if (type != base_type) { + int i, count = tcg_type_size(base_type) / tcg_type_size(type); + TCGTemp *ts2, *ts1 = ts; + + for (i = 1; i < count; i++) { + ts2 = tcg_temp_alloc(s); + tcg_debug_assert(ts2 == ts1 + 1); + ts2->base_type = base_type; + ts2->type = type; + ts2->temp_allocated = 1; + ts2->temp_local = temp_local; + ts1 = ts2; + } } idx = temp_idx(s, ts); }