From patchwork Tue Jun 29 18:54:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 468358 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp5264935jao; Tue, 29 Jun 2021 12:49:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpr70LoTPfAUfbiO6JXcRJPdyGR1YpDZc+pi3E+/4XjngVst73wVoT4tBHMS8M7gphVyvN X-Received: by 2002:a67:e9c5:: with SMTP id q5mr17807533vso.4.1624996167934; Tue, 29 Jun 2021 12:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624996167; cv=none; d=google.com; s=arc-20160816; b=nt8tWZmtWqtO5SWcmBYDrS+IQAyUEHIQNJDR5QiwFfyuVyA3vu++x4Bxv12Vm2to7q Z7NrB+DxkUxvOWi5oaJc3m1sE73VF7jKk2V0KrVjHqILaFUWNXUAoImkmbC7AZatfEvO d0VRgznN1WJD3C2zD79Vujn4Pqr0vyLQJwaXbHSxqIja5oTwUcagJkkaqDXDuFCijx9L /2WD8kajVl77hLM7RLimXgxHJoW84GPQEK401KWc71yf2Qf603CrDrXIrwSkfw45Sy9j jfB14n7USUkN9rehTB2hKuxhsN08+8ljnpBwlqm1vflGOh7SU/iQ7yklk59XTeZM1DbR AoHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=+KG72/HkSkkW/EnHZzWfX4mj5faPrZ7wY+xxoD2yGxc=; b=YxZxwLVO+VVtSWK/7IlINLlR+2j+oi1u7RhZWc9+rgbxnmsv1T5VYwxk51CiTmyfeL 0/X4lRBGInhtEWv52itiIimHD7BYrBvA6iw874i4Fh6fu2EZ+45Lt7I7w2Oa67xwK0dz 3HXJtv1csJr58X+klARYeBhVWSXTWiFN0l0qLK3+teykUnpFxTj9R5ZJI9SvFFkMhbUs OSaDv06d2SWdWtskINY0ikzuwOiv7elEJg1bBU5ckzRjDef00XVy35tNHW1ZWtinuiCm S+Ta6Us6WW9PCqxlnenLImu9ZN4DOxyi3TwzZfaeRvk5o5AD+DFdzr57BpQ34YxPF+T4 j/bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="G859DM/L"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x18si15822452vsr.302.2021.06.29.12.49.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jun 2021 12:49:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="G859DM/L"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyJjb-0001xG-CK for patch@linaro.org; Tue, 29 Jun 2021 15:49:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyIwN-00040v-0H for qemu-devel@nongnu.org; Tue, 29 Jun 2021 14:58:36 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:42876) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lyIwC-0002xi-8g for qemu-devel@nongnu.org; Tue, 29 Jun 2021 14:58:32 -0400 Received: by mail-pj1-x1030.google.com with SMTP id ce18-20020a17090aff12b0290170a3e3eb07so3093332pjb.1 for ; Tue, 29 Jun 2021 11:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+KG72/HkSkkW/EnHZzWfX4mj5faPrZ7wY+xxoD2yGxc=; b=G859DM/LoMEcQliF0zGqf5jbuXDOtmfhbHTmy+XTD4xYMX7GhJPNtkD2eedpX3u2tl 0lz7mG63WWrzSMmIb/+Fs2bQtIG9R/ym9yfU5awy3ebS8sygS6+2h28HWlp0+SO1J4P5 PUyuCk2f24d8kk8glVqEAPj7T8xoKbNtR7vf9uyMYpz0sUbGygi/PF9mRnshr2d3BTKM QMsOLrPdPjNclyt+nXFKi04gU0K4+DZtVe+YNeX4t0va1MJReq86hg0NF6rYoJrCS45W l6FyHPAkliO2z8J8Ql82IaidHlzi4WKwWFwxueDpcOJjbKGzjPAwfb6r/Wt0H8cHr98U Cu6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+KG72/HkSkkW/EnHZzWfX4mj5faPrZ7wY+xxoD2yGxc=; b=mHvNa1HSS8hBbMLmCy38b2c0RvGz6VGiDQVmg4LyVzppkFcvbbnWbaGtfwBHBDxffD YeQWJltt6SuPGDzQ/TyVFiuo1cJrtUOl2YOW1fX4CHRK0Cmwq4n6SL7SvooxazHGe2iI 01sp9oKrsC8AjdmbEfqZHPeYkOkkXBB1zdTUiopFVnF7tOWA843yyOS07hT2jbOTQgIQ WqN+Qx7u4wJIbNVTM/4x67ID2xBRIbWbylAy3NAwVGoIFy1hKxp7OKhASmA2V94hPPvL vtEzW/5x7hSuhV0L2AFbPpxAAXOkDJi336Tw5kEGn2UV2En/sjUhRFWmps2lMoGNBxU6 rodw== X-Gm-Message-State: AOAM530yP/0r/D1LACL0Ymw19xhjxPMBYXPVSnrk18eayaIx8fj5sLiS krvGGLsYTyiU+fn/LeG+pJP0pSaZKuwNNg== X-Received: by 2002:a17:90a:a607:: with SMTP id c7mr35657392pjq.199.1624993103032; Tue, 29 Jun 2021 11:58:23 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id 21sm18002849pfh.103.2021.06.29.11.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 11:58:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 42/63] tcg/ppc: Split out tcg_out_bswap16 Date: Tue, 29 Jun 2021 11:54:34 -0700 Message-Id: <20210629185455.3131172-43-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210629185455.3131172-1-richard.henderson@linaro.org> References: <20210629185455.3131172-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" With the use of a suitable temporary, we can use the same algorithm when src overlaps dst. The result is the same number of instructions either way. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- tcg/ppc/tcg-target.c.inc | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) -- 2.25.1 diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc index 50347182d7..ad46ce32ca 100644 --- a/tcg/ppc/tcg-target.c.inc +++ b/tcg/ppc/tcg-target.c.inc @@ -789,6 +789,24 @@ static inline void tcg_out_sari64(TCGContext *s, TCGReg dst, TCGReg src, int c) tcg_out32(s, SRADI | RA(dst) | RS(src) | SH(c & 0x1f) | ((c >> 4) & 2)); } +static void tcg_out_bswap16(TCGContext *s, TCGReg dst, TCGReg src) +{ + TCGReg tmp = dst == src ? TCG_REG_R0 : dst; + + /* + * In the following, + * dep(a, b, m) -> (a & ~m) | (b & m) + * + * Begin with: src = xxxxabcd + */ + /* tmp = rol32(src, 24) & 0x000000ff = 0000000c */ + tcg_out_rlw(s, RLWINM, tmp, src, 24, 24, 31); + /* tmp = dep(tmp, rol32(src, 8), 0x0000ff00) = 000000dc */ + tcg_out_rlw(s, RLWIMI, tmp, src, 8, 16, 23); + + tcg_out_mov(s, TCG_TYPE_REG, dst, tmp); +} + /* Emit a move into ret of arg, if it can be done in one insn. */ static bool tcg_out_movi_one(TCGContext *s, TCGReg ret, tcg_target_long arg) { @@ -2779,21 +2797,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, case INDEX_op_bswap16_i32: case INDEX_op_bswap16_i64: - a0 = args[0], a1 = args[1]; - /* a1 = abcd */ - if (a0 != a1) { - /* a0 = (a1 r<< 24) & 0xff # 000c */ - tcg_out_rlw(s, RLWINM, a0, a1, 24, 24, 31); - /* a0 = (a0 & ~0xff00) | (a1 r<< 8) & 0xff00 # 00dc */ - tcg_out_rlw(s, RLWIMI, a0, a1, 8, 16, 23); - } else { - /* r0 = (a1 r<< 8) & 0xff00 # 00d0 */ - tcg_out_rlw(s, RLWINM, TCG_REG_R0, a1, 8, 16, 23); - /* a0 = (a1 r<< 24) & 0xff # 000c */ - tcg_out_rlw(s, RLWINM, a0, a1, 24, 24, 31); - /* a0 = a0 | r0 # 00dc */ - tcg_out32(s, OR | SAB(TCG_REG_R0, a0, a0)); - } + tcg_out_bswap16(s, args[0], args[1]); break; case INDEX_op_bswap32_i32: