From patchwork Wed Oct 18 17:18:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitar Dimitrov X-Patchwork-Id: 155022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4946990vqb; Wed, 18 Oct 2023 10:19:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsqsyqA2jAGrlkylB1yzGUFfcCKa0BXLbl+/HmLzvZuHP9c7508sse2RykW3suLCKw0wl5 X-Received: by 2002:a05:620a:bc9:b0:775:9bda:b12d with SMTP id s9-20020a05620a0bc900b007759bdab12dmr7482567qki.32.1697649560769; Wed, 18 Oct 2023 10:19:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697649560; cv=pass; d=google.com; s=arc-20160816; b=JQpeOEvhYVboCbqk/fb3HiXok23alJqZhHHlV/6jPyO1habGvkOza6iR5u4p7PZ+Rh 5gdGbL7WBM4/+YzgRu5w3YBQ2BQZq3QCXMJ+jwSrE6aWKUr4Le/AtK8uZIJ2BulcR+xK LeorFZoWNrpTShzDVEJzSY29O9X1PWe+2eQ820eNM9SMJvkNowacIIMPdXpSti655MS2 2f1sm9Vux4FFc+L6IcUijB0UbxEDRa71bQsMIe5QhwedoEVLsdJtKRaXBlOu4d3ldwns y4d3go539/GQUO4XLJr/ODKhsN2Zo/ncyX8/lkuzpVM02CgIDs0wrcKxAY/nNHoKeA4A 2DKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=sVovgwHrPMWWMcqPPpMMLUrM94CBpLd+Pa0j/ra4D/s=; fh=Zyb1vQGxdvnMawSSeMgW+3ERdyd9yyvghhfyyNjcI6A=; b=bJoVXzbg0NwgeugGGZubbQDS+NZLry+dFq7/qYVj6KPoxgGj80JkvQDyjP2gFTncp0 6Po5rQDTHJAWc33xYnosyuUhbeSY/C1P4HrhETHhbwULZZu8TOVB87229fwA/Vndg7FW V+gIH9NB4kW5J+T3gP/b7uO0SeGj5WPS8kytIMZgzuwCGh3OG1aAcp5yy7zxUqf7tS23 LL60Nwd4fNWdV+50aSrEdD7/6Sqs7t1HaHa7pNxpEAglYSTx7rIPDOUztw+QtivwTYi3 mtyuV33gr3/LouiukMLVqm+yBy6BE9YNx6rWqN/bubTojchK+GUszsgrTjyv+sndegIH c74w== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@dinux.eu header.s=default header.b=TQetdbil; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d26-20020a0cb2da000000b0066d14dca029si239519qvf.555.2023.10.18.10.19.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 10:19:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@dinux.eu header.s=default header.b=TQetdbil; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88C77385771E for ; Wed, 18 Oct 2023 17:19:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server28.superhosting.bg (server28.superhosting.bg [217.174.156.11]) by sourceware.org (Postfix) with ESMTPS id 228653858C54 for ; Wed, 18 Oct 2023 17:18:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 228653858C54 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dinux.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dinux.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 228653858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.174.156.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697649537; cv=none; b=OzmykZ/xEysdK9UCwZzjLYtmHFH/d2Np5RuP6/t5SeJUs2XTMN7SwNmqHBNr3JyEj2zp5etmzMCWZDey1Rne+cSjy7+vfC5WW49EzJAdN/p5XoNWSK83kz+knzBwiFwerE8rYDMsnZ3lj/mK5c0lqhIvGjp5/ievEhW8kt5Ar9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697649537; c=relaxed/simple; bh=wx1R4nwPW8lwn8ZIbyM/DvqKtoIJlNvflwsgDZYZvYM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=J/oDiS4dZ/cCZOxg3odqEsdxo3UhTA3/UINHXz43tPcCRlqRq62rQqxgmtKcnGUs+vZWfo/3AK6f0rkCuERr6gSrqv94fX5dtjD9NvwvgXaQF4I6WZ/f4hukur+FOQkIK6+aUljXZ3n1CRtNELb74c/49mEXJrzahEZ/FioHbJk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dinux.eu; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=sVovgwHrPMWWMcqPPpMMLUrM94CBpLd+Pa0j/ra4D/s=; b=TQetdbil9/lci5qEIqD4FdRPdc 6+WChU8K1LDfd5AypzSFGR3m8Iwa2tnEwXYdsbBB5XCJuGtAAOKhS9yCylelGSXh8Q27osL0fJBiB +kQi3pHpHaD+C3v9vk/+Q0bxa0DnYZtvxc7ccn8VubUlLq/tAcIXeQsGbO0ya+jVFTcrNjRlpJ+X7 DBPQbRRPFF3KlaA/yZXNyxV3jKAAQ9L3jqDOIKfBU2ZRlrGKMHdiMWhgKmVDOiX4bG3YXsKSiqNN1 RbGN0KS6nzx5QzZ7WmwXaCzzNVoxB3Vd5j2EPlmpK8P3TYHTJf5mAgbhAXUOpPtCLZ2IdMUTGvw3G gGScjTIA==; Received: from [95.42.20.142] (port=58966 helo=kendros.lan) by server28.superhosting.bg with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.1) (envelope-from ) id 1qtABy-0001Zr-20; Wed, 18 Oct 2023 20:18:49 +0300 From: Dimitar Dimitrov To: gcc-patches@gcc.gnu.org Cc: Dimitar Dimitrov Subject: [committed] pru: Implement TARGET_INSN_COST Date: Wed, 18 Oct 2023 20:18:42 +0300 Message-ID: <20231018171842.266046-1-dimitar@dinux.eu> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server28.superhosting.bg X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - dinux.eu X-Get-Message-Sender-Via: server28.superhosting.bg: authenticated_id: dimitar@dinux.eu X-Authenticated-Sender: server28.superhosting.bg: dimitar@dinux.eu X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780114585983290100 X-GMAIL-MSGID: 1780114585983290100 This patch slightly improves the embench-iot benchmark score for PRU code size. There is also small improvement in a few real-world firmware programs. Embench-iot size ------------------------------------------ Benchmark before after delta --------- ---- ---- ----- aha-mont64 4.15 4.15 0 crc32 6.04 6.04 0 cubic 21.64 21.62 -0.02 edn 6.37 6.37 0 huffbench 18.63 18.55 -0.08 matmult-int 5.44 5.44 0 md5sum 25.56 25.43 -0.13 minver 12.82 12.76 -0.06 nbody 15.09 14.97 -0.12 nettle-aes 4.75 4.75 0 nettle-sha256 4.67 4.67 0 nsichneu 3.77 3.77 0 picojpeg 4.11 4.11 0 primecount 7.90 7.90 0 qrduino 7.18 7.16 -0.02 sglib-combined 13.63 13.59 -0.04 slre 5.19 5.19 0 st 14.23 14.12 -0.11 statemate 2.34 2.34 0 tarfind 36.85 36.64 -0.21 ud 10.51 10.46 -0.05 wikisort 7.44 7.41 -0.03 --------- ----- ----- Geometric mean 8.42 8.40 -0.02 Geometric SD 2.00 2.00 0 Geometric range 12.68 12.62 -0.06 Reg-tested pru-unknown-elf, and committed to trunk. gcc/ChangeLog: * config/pru/pru.cc (pru_insn_cost): New function. (TARGET_INSN_COST): Define for PRU. Signed-off-by: Dimitar Dimitrov --- gcc/config/pru/pru.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/gcc/config/pru/pru.cc b/gcc/config/pru/pru.cc index 6e8112be64a..fd1924e38dc 100644 --- a/gcc/config/pru/pru.cc +++ b/gcc/config/pru/pru.cc @@ -783,6 +783,39 @@ pru_rtx_costs (rtx x, machine_mode mode, } } } + +/* Insn costs on PRU are straightforward because: + - Insns emit 0, 1 or more instructions. + - All instructions are 32-bit length. + - All instructions execute in 1 cycle (sans memory access delays). + The "length" attribute maps nicely to the insn cost. */ + +static int +pru_insn_cost (rtx_insn *insn, bool speed) +{ + /* Use generic cost calculation for unrecognized insns. */ + if (recog_memoized (insn) < 0) + return pattern_cost (insn, speed); + + unsigned int len = get_attr_length (insn); + + gcc_assert ((len % 4) == 0); + + int cost = COSTS_N_INSNS (len / 4); + /* Some insns have zero length (e.g. blockage, pruloop_end). + In such cases give the minimum cost, because a return of + 0 would incorrectly indicate that the insn cost is unknown. */ + if (cost == 0) + cost = 1; + + /* Writes are usually posted, so they take 1 cycle. Reads + from DMEM usually take 3 cycles. + See TI document SPRACE8A, Device-Specific PRU Read Latency Values. */ + if (speed && get_attr_type (insn) == TYPE_LD) + cost += COSTS_N_INSNS (2); + + return cost; +} static GTY(()) rtx eqdf_libfunc; static GTY(()) rtx nedf_libfunc; @@ -3175,6 +3208,9 @@ pru_unwind_word_mode (void) #undef TARGET_RTX_COSTS #define TARGET_RTX_COSTS pru_rtx_costs +#undef TARGET_INSN_COST +#define TARGET_INSN_COST pru_insn_cost + #undef TARGET_PRINT_OPERAND #define TARGET_PRINT_OPERAND pru_print_operand