From patchwork Mon Dec 11 09:47:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Lewis X-Patchwork-Id: 1874423 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=gwDFJI9F; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SpcPK31L5z20Gv for ; Mon, 11 Dec 2023 20:48:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 238D4385829C for ; Mon, 11 Dec 2023 09:48:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id A243A3858C98 for ; Mon, 11 Dec 2023 09:47:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A243A3858C98 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A243A3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702288065; cv=none; b=tyDSRuYF3/UV5LVpIifX8314Lmf34HxZJBRCf+zlWbqBLaYseJ9/oVQ5mQUoBTbqkuufM/Nt5aP9Lr9p6kUCNGk15BD/VRJjtuX6MiGdQqGRPEpZljRG/N6Pky7zm3IA/5bFM2+PrJ15Wlzs8E3K3VTImMxEW1DePlp3iph9FsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702288065; c=relaxed/simple; bh=EQxveASLDB5n1tRzibO1gyG7GUMyfPNHlBz4f1xYJDM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=O3luZ3YY2P1KYWgIey+h5OXor7oxYQMHfyjOl3vOFJnsDJ/ettkSMP+viN551vhyI8JISUExfq4hLAHV7rlVfOQm86sdqLuMNUHPQ9H+xxJNEc9nEMRkKLFgqmHQkJHk67H5x5NpiFCe0IYYWiA9ag19sJ/A7k2iZAx4su1Cuzc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-50bfd8d5c77so4749460e87.1 for ; Mon, 11 Dec 2023 01:47:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702288061; x=1702892861; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=UMYAYhj0juR5BhwJDXUd2WPJyHBggrXYqN+rD8C7fSQ=; b=gwDFJI9F18GD2rzmt0VXKV2GK91TL0ccr/x+Rlo+eUbnNiCiRZGOo4QCkzwwqMkFrU UfDhOjs54HLaxHi1xBLLYr7Rbgo5Ua64lRDaXdBFtK7YUTh+XlLy3+YvNRjF8QiByy9T GoHzDnqJnCpkDrxQoQ2ntxSfqffXk60u498N1M9E4U/fdWnAdEe+vQ2TZvafyRIYpaUK 2eiKxdYNLMGtK5Byr2zuRsopI96Y67oLAXMWphSGhBi30qtH26cSJem46vfONfaDoYTO 2/wNn5YEjXl5aOhCRGrSHy4ukkFwDNlmv4MIaAYjJ89EmtICzfskQx9ozpD0EHZI9OpV KfPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702288061; x=1702892861; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UMYAYhj0juR5BhwJDXUd2WPJyHBggrXYqN+rD8C7fSQ=; b=aEtmv4zXL/iwDbqmhmXAeC8S/+j8LyfCkhvFnD9S+s8HrwsDmOVqv8w63f36KRaKRL IvUhQZLmsbgsuldoM7c133fM1VDtGprZO+50mgHxKrKrPDfUdi5kjO1Wlb1aAHCEiC5g w1zIZ3e89O+kLYHH2m64nsZY+IfCOY4mgWubzp4XL4/DHaRGfePTCg0YufCEdpc5pfkc shb10WvMeKghQ+y0kCQ1NhEFs11xcrxeiKOtsTBjIfhRjXssZOw9oJ2xibutPRRwkEVO Op/xjJH8/ua7e/Y69DsOvwhsc6j6OkZkgSDg0c8jz+qVo42EUmE+ej6McabZSFQ288ki lzXA== X-Gm-Message-State: AOJu0YzKD5hPnZRUXEBrApcilus9Q5TFDFzbFnwUDg6g3r7Ul+JVLn8g 2D2ih5RFYqZWQvl77Xc24YfDeTk7fI6ejcgY0GH7/Q== X-Google-Smtp-Source: AGHT+IEP9r6WRGlO8cRbyGS0SPXIZ4ADTvEchYAalkAJDSCOH0BoBtGp3x0HRlDaSbYJctP6GbvEFA== X-Received: by 2002:a05:6512:6cb:b0:50b:fbdf:de7d with SMTP id u11-20020a05651206cb00b0050bfbdfde7dmr1038789lff.154.1702288061160; Mon, 11 Dec 2023 01:47:41 -0800 (PST) Received: from slewis-laptop.ba.rivosinc.com ([51.52.155.69]) by smtp.gmail.com with ESMTPSA id a16-20020adffad0000000b003333b8eb84fsm8128298wrs.113.2023.12.11.01.47.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 01:47:40 -0800 (PST) From: Sergei Lewis To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/3] RISC-V: movmem for RISCV with V extension Date: Mon, 11 Dec 2023 09:47:26 +0000 Message-Id: <20231211094728.1623032-2-slewis@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231211094728.1623032-1-slewis@rivosinc.com> References: <20231211094728.1623032-1-slewis@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog * config/riscv/riscv.md (movmem): Use riscv_vector::expand_block_move, if and only if we know the entire operation can be performed using one vector load followed by one vector store gcc/testsuite/ChangeLog * gcc.target/riscv/rvv/base/movmem-1.c: New test --- gcc/config/riscv/riscv.md | 22 +++++++ .../gcc.target/riscv/rvv/base/movmem-1.c | 59 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/movmem-1.c diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index eed997116b0..88fde290a8a 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -2359,6 +2359,28 @@ FAIL; }) +;; inlining general memmove is a pessimisation: we can't avoid having to decide +;; which direction to go at runtime, which is costly in instruction count +;; however for situations where the entire move fits in one vector operation +;; we can do all reads before doing any writes so we don't have to worry +;; so generate the inline vector code in such situations +;; nb. prefer scalar path for tiny memmoves +(define_expand "movmem" + [(parallel [(set (match_operand:BLK 0 "general_operand") + (match_operand:BLK 1 "general_operand")) + (use (match_operand:P 2 "")) + (use (match_operand:SI 3 "const_int_operand"))])] + "TARGET_VECTOR" +{ + if ((INTVAL (operands[2]) >= TARGET_MIN_VLEN/8) + && (INTVAL (operands[2]) <= TARGET_MIN_VLEN) + && riscv_vector::expand_block_move (operands[0], operands[1], + operands[2])) + DONE; + else + FAIL; +}) + ;; Expand in-line code to clear the instruction cache between operand[0] and ;; operand[1]. (define_expand "clear_cache" diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/movmem-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/movmem-1.c new file mode 100644 index 00000000000..b930241ae5d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/movmem-1.c @@ -0,0 +1,59 @@ +/* { dg-do compile } */ +/* { dg-add-options riscv_v } */ +/* { dg-additional-options "-O3" } */ +/* { dg-final { check-function-bodies "**" "" } } */ + +#include + +#define MIN_VECTOR_BYTES (__riscv_v_min_vlen/8) + +/* tiny memmoves should not be vectorised +** f1: +** li\s+a2,15 +** tail\s+memmove +*/ +char * f1 (char *a, char const *b) +{ + return memmove (a, b, 15); +} + +/* vectorise+inline minimum vector register width with LMUL=1 +** f2: +** ( +** vsetivli\s+zero,16,e8,m1,ta,ma +** | +** li\s+[ta][0-7],\d+ +** vsetvli\s+zero,[ta][0-7],e8,m1,ta,ma +** ) +** vle8\.v\s+v\d+,0\(a1\) +** vse8\.v\s+v\d+,0\(a0\) +** ret +*/ +char * f2 (char *a, char const *b) +{ + return memmove (a, b, MIN_VECTOR_BYTES); +} + +/* vectorise+inline up to LMUL=8 +** f3: +** li\s+[ta][0-7],\d+ +** vsetvli\s+zero,[ta][0-7],e8,m8,ta,ma +** vle8\.v\s+v\d+,0\(a1\) +** vse8\.v\s+v\d+,0\(a0\) +** ret +*/ +char * f3 (char *a, char const *b) +{ + return memmove (a, b, MIN_VECTOR_BYTES*8); +} + +/* don't vectorise if the move is too large for one operation +** f4: +** li\s+a2,\d+ +** tail\s+memmove +*/ +char * f4 (char *a, char const *b) +{ + return memmove (a, b, MIN_VECTOR_BYTES*8+1); +} +