From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 9AE423858D1E for ; Tue, 19 Mar 2024 02:54:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9AE423858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ventanamicro.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9AE423858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::329 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710816855; cv=none; b=kHu3hPmTV7DpwkUoadYNDgWmOj/GGuQ0ZTipaPTGPl3xLoOaYwULviSMTStD/5kyViGKVBZTLKmwj70f3YNmO/yneRHouK3qEt7DGZPjj9zVGHkATOXCfYr77r6igLH099NdSUfUSNqTEXIr5O8ovYhGoDZFyItEMoiVwgqM/9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710816855; c=relaxed/simple; bh=Qxd5t94zjb0eTA3rwtfhV7vE+e28kCq9Hzd0fjEiPEs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=lIAs6FfmLRHdcc8JVs9gq8I2yp/Hj2BItPVcWaF1t38STwzzywUc3QrTjvsHLeMpzAJyNjGKYjvSG2tc5Ebo4+HqlXBfUMKGevRXrFq3y81eE9LMZ6uejwGoxDlYch3xO8A6CapSyK0PDcrYCei0EUz9fxqLXh3KYrRJYwUPc74= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6e67451b084so2822182a34.2 for ; Mon, 18 Mar 2024 19:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1710816852; x=1711421652; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=IkRiTvwjTVzPpxVyJ5cLjX8gQrFp4FTHpBIrHFtuj0c=; b=cHozzQTmAACHwQAmce7gUEilIq1MflzYEsIqDeZvWDBRbhAT0UPBxem3SjrDxWBPe4 JpsU4xI+jtsgcb9K6mzSeKzWhCIOvBOAlwne6BRnTXsedDy+cePmTxdKFR4bRO78BuiD boNjDG50aCSePRZCPNeJ4f4J9PdRGdoVqoINekpGM8xB3ohv1vjp9z1lTh+L3o4lo6TR UAY6d7yZ2It/YB+L4D6mYwzDxq73lYlEApWJPY0Fpg6ipDiK9pB5VjzbfuNMbx4aVmKx 6mTgVVaT1yEGOQGhXqaXiiy2hAnLhSyoW92KmiXUW1UDtLi/XGLwYxXYzr8G2KonxjUi xc6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710816852; x=1711421652; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IkRiTvwjTVzPpxVyJ5cLjX8gQrFp4FTHpBIrHFtuj0c=; b=j3yEPm4/sFOve/dgHWa8B0AjHyEloa8dytT+N6ABReLt0eTE6un/G77wQqbnHAtEsF rjuX29Xf7w69DrnQRD8VvhGYXWhyT8HUfo0ItYcOMHj7IVNm86eA9vRf0E8Yo6QGiwxd bQuy34NO7wJnaZnRZShq4QVClYKWN9jQxm1Q88bnVcQ1lXD5ZgmF8a6kCv84Joc+61Gr ZDPOq48CYFGuKGU9HTUJkzAclPilWF/isX+V2tV38qHAB4QmG14VMJHyk8xKYCd+ogyF loBzAzGMGXO1Qfut3ldTuRNqR1ljA1a3jOPLeVxgGC+DFfzMxvSAOgiWjCFuXW2l//32 Cgzw== X-Forwarded-Encrypted: i=1; AJvYcCVBzgpbp+cWNfcSRY7cSWnlPenBCTgid9kTw+18UT+PX8pzVyCN4jR/m2gRT+0HWvaxWH5RpTH3qpQ1QfaJ+GYls4vks9F4Tg== X-Gm-Message-State: AOJu0Yw9CoTI0nonP8rbudukp/K2GrxgVtdoF7AsEqj+uJvFU+bV1RuE 9ML5M+MSK7jUtBW/VcCUchPS0R4H4z1dgZydH9mesk4HZoyzV39AZafz4BOiQdY= X-Google-Smtp-Source: AGHT+IF3iOQiDCKfWZ/q2V2I3tYfH8DNZc67q617mimKIgln3oA521iKtcBAhWeLHdM9BT6mm2D8/w== X-Received: by 2002:a05:6870:8a2b:b0:229:7f3f:bb6a with SMTP id p43-20020a0568708a2b00b002297f3fbb6amr833380oaq.32.1710816852463; Mon, 18 Mar 2024 19:54:12 -0700 (PDT) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id gk14-20020a0568703c0e00b002260aa9ec72sm988604oab.26.2024.03.18.19.54.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Mar 2024 19:54:12 -0700 (PDT) Message-ID: <35aff817-bcea-4e5f-9a23-9928e0f65043@ventanamicro.com> Date: Mon, 18 Mar 2024 20:54:09 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH] RISC-V: Add XiangShan Nanhu microarchitecture. Content-Language: en-US To: Jiawei , gcc-patches@gcc.gnu.org Cc: kito.cheng@sifive.com, palmer@dabbelt.com, christoph.muellner@vrull.eu, wuwei2016@iscas.ac.cn, shihua@iscas.ac.cn, shiyulong@iscas.ac.cn, chenyixuan@iscas.ac.cn References: <20240227085243.605255-1-jiawei@iscas.ac.cn> From: Jeff Law In-Reply-To: <20240227085243.605255-1-jiawei@iscas.ac.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 List-Id: On 2/27/24 1:52 AM, Jiawei wrote: > From: Chen Jiawei > > Co-Authored by: Lin Jiawei > > This patch add XiangShan Nanhu cpu microarchitecture, > Nanhu is a 6-issue, superscalar, out-of-order processor. > More details see: https://xiangshan-doc.readthedocs.io/zh-cn/latest/arch > > gcc/ChangeLog: > > * config/riscv/riscv-cores.def (RISCV_TUNE): New def. > (RISCV_CORE): Ditto. > * config/riscv/riscv-opts.h (enum > * riscv_microarchitecture_type): New option. > * config/riscv/riscv.cc: New def. > * config/riscv/riscv.md: New include. > * config/riscv/xiangshan.md: New file. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/mcpu-xiangshan-nanhu.c: New test. As was discussed last Tuesday, this should be safe, even at this late stage in the gcc-14 cycle. > > +/* Costs to use when optimizing for xiangshan nanhu. */ > +static const struct riscv_tune_param xiangshan_nanhu_tune_info = { > + {COSTS_N_INSNS (3), COSTS_N_INSNS (3)}, /* fp_add */ > + {COSTS_N_INSNS (3), COSTS_N_INSNS (3)}, /* fp_mul */ > + {COSTS_N_INSNS (10), COSTS_N_INSNS (20)}, /* fp_div */ > + {COSTS_N_INSNS (3), COSTS_N_INSNS (3)}, /* int_mul */ > + {COSTS_N_INSNS (6), COSTS_N_INSNS (6)}, /* int_div */ > + 6, /* issue_rate */ > + 3, /* branch_cost */ > + 3, /* memory_cost */ > + 3, /* fmv_cost */ > + true, /* slow_unaligned_access */ > + false, /* use_divmod_expansion */ > + RISCV_FUSE_ZEXTW | RISCV_FUSE_ZEXTH, /* fusible_ops */ > + NULL, /* vector cost */ Is your integer division really that fast? The table above essentially says that your cpu can do integer division in 6 cycles. > + > +(define_insn_reservation "xiangshan_mul" 3 > + (and (eq_attr "tune" "xiangshan") > + (eq_attr "type" "imul")) > + "xs_mdu_rs") > + > +(define_insn_reservation "xiangshan_div" 21 > + (and (eq_attr "tune" "xiangshan") > + (eq_attr "type" "idiv")) > + "xs_mdu_rs") Whereas your pipeline description says it's 21c. I strongly suspect you want to increase the cost of the int_div in the tuning table. And with a the higher cost you probably want to turn on use_divmod_expansion. I'll also note that your scheduler description also indicates your division is fully pipelined. Is that correct? if not, you'll want to adjust that reservation. > + > +(define_insn_reservation "xiangshan_sfdiv" 11 > + (and (eq_attr "tune" "xiangshan") > + (eq_attr "type" "fdiv") > + (eq_attr "mode" "SF")) > + "xs_fmisc_rs") > + > +(define_insn_reservation "xiangshan_sfsqrt" 17 > + (and (eq_attr "tune" "xiangshan") > + (eq_attr "type" "fsqrt") > + (eq_attr "mode" "SF")) > + "xs_fmisc_rs") > + > +(define_insn_reservation "xiangshan_dfdiv" 21 > + (and (eq_attr "tune" "xiangshan") > + (eq_attr "type" "fdiv") > + (eq_attr "mode" "DF")) > + "xs_fmisc_rs") > + > +(define_insn_reservation "xiangshan_dfsqrt" 37 > + (and (eq_attr "tune" "xiangshan") > + (eq_attr "type" "fsqrt") > + (eq_attr "mode" "DF")) > + "xs_fmisc_rs") Similarly these say your fpdiv and fpsqrt are fully pipelined. It's certainly possible, but I suspect it's really just an oversight. Given these values you may also want to adjust the cost of an fp division in the cost table. Finally with such high values for for the div/sqrt units, we find that the DFA "blows up" causing genattrtab to run for a very long time. We'll have to keep an eye on that. And just to be clear, I think these can be done as a followup patch. I'm going to push this patch as-is rather than make any adjustments -- you almost certainly know the processor's capabilities better than myself or anyone else on this list :-) Jeff