From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7B3F6462EB; Sat, 1 Mar 2025 01:38:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 07C784026C; Sat, 1 Mar 2025 01:38:03 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id AD0844025D for ; Sat, 1 Mar 2025 01:38:01 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1213) id CEAA82038A22; Fri, 28 Feb 2025 16:38:00 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CEAA82038A22 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1740789480; bh=j8NHzOLb9j8ebNchsDWblVTj8rDmVGNBUbFahE0KehQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FA3Br9ng7ydEgu3gtWQdSoafw0vpzOLtxVPFrrnaljhrS5B+xeEwWOKUfjvI95VmD wFpj1SusWDP48Hcpnx6V/D9RCHSBeLEEaO1NZ2JMtDwhfAkh71/XJSJ61M4/msFitB l3JkivxaVJp1EQLTD9mev988GOxYJYh70bjKf3iU= Date: Fri, 28 Feb 2025 16:38:00 -0800 From: Andre Muezerie To: Bruce Richardson Cc: dev@dpdk.org Subject: Re: [PATCH 2/2] devtools/dump-cpu-flags: add tool to update CPU flags table Message-ID: <20250301003800.GA2378@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1740707537-10517-1-git-send-email-andremue@linux.microsoft.com> <1740707537-10517-3-git-send-email-andremue@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Fri, Feb 28, 2025 at 02:33:04PM +0000, Bruce Richardson wrote: > On Thu, Feb 27, 2025 at 05:52:17PM -0800, Andre Muezerie wrote: > > This patchset allows users to specify the CPU for which the generated > > code should be optimized for by passing the CPU name. > > > > MSVC does not provide this functionality natively, so logic was > > added. This additional logic relies on a table which stores instruction > > set availability (like AXV512F) for different CPUs. > > To make it easier to update this table a new devtool is introduced > > with this patch. The new tool generates the table entries for all CPUs > > listed in an input file using a recent version of the compiler, which > > has all the information needed. This reduces enormously the amount > > of work needed to update the table in msvc/meson.build and makes the > > process much less error prone. > > > > Signed-off-by: Andre Muezerie > > --- > > devtools/dump-cpu-flags/README.md | 25 +++++ > > devtools/dump-cpu-flags/cpu-names.txt | 120 +++++++++++++++++++++ > > devtools/dump-cpu-flags/dump-cpu-flags.cpp | 119 ++++++++++++++++++++ > > devtools/dump-cpu-flags/dump-cpu-flags.py | 41 +++++++ > > 4 files changed, 305 insertions(+) > > create mode 100644 devtools/dump-cpu-flags/README.md > > create mode 100644 devtools/dump-cpu-flags/cpu-names.txt > > create mode 100644 devtools/dump-cpu-flags/dump-cpu-flags.cpp > > create mode 100644 devtools/dump-cpu-flags/dump-cpu-flags.py > > > > diff --git a/devtools/dump-cpu-flags/README.md b/devtools/dump-cpu-flags/README.md > > new file mode 100644 > > index 0000000000..3db69f9f8f > > --- /dev/null > > +++ b/devtools/dump-cpu-flags/README.md > > @@ -0,0 +1,25 @@ > > +# Generating updated CPU flags > > + > > +File `config\x86\msvc\meson.build` has a table with flags indicating instruction set support for a variety of CPU types. > > + > > +Script `dump-cpu-flags.py` can be used to generate updated entries for this table. > > + > > +The CPU names are stored in file `cpu-names.txt`, which is consumed by `dump-cpu-flags.py`. The formatting used in that file is described at the top of the file itself. > > + > > +The script relies on the information embedded in the g++ compiler. This means that an updated table can automatically be generated by switching to a newer version of the compiler. This avoids the need to manually edit the entries, which is error prone. With the script the table entries can just copied and pasted into `meson.build`. The only thing that might need to be done is adding new CPU names to cpu-names.txt, when new CPUs are released. > > + > > +**NOTE**: CPUs not known to the compiler will result in errors, which can be ignored (`dump-cpu-flags.py` will ignore these errors and continue). For best results use the latest g++ compiler available. > > + > > +Below is a sample output, where an error was logged because the compiler did not know about a CPU named ‘raptorlake’. > > + > > +```sh > > +$ ./dump-cpu-flags.py > > + 'x86-64-v2': [], > > + 'x86-64-v3': ['AVX', 'AVX2'], > > + 'x86-64-v4': ['AVX', 'AVX2', 'AVX512F', 'AVX512VL', 'AVX512BW', 'AVX512DQ', 'AVX512CD'], > > + 'alderlake': ['AVX', 'PCLMUL', 'RDRND', 'AVX2', 'RDSEED', 'AES', 'VPCLMULQDQ', 'GFNI'], > > +cc1plus: error: bad value (‘raptorlake’) for ‘-march=’ switch > > +cc1plus: note: valid arguments to ‘-march=’ switch are: nocona core2 nehalem corei7 westmere sandybridge... > > + 'silvermont': ['PCLMUL', 'RDRND'], > > + 'slm': ['PCLMUL', 'RDRND'], > > +``` > > \ No newline at end of file > > How about having the tool output a valid meson.build file, that can then be > used directly without copy-paste. While I know such a thing would end up > with us having deep subdir structures, it could be just loaded from e.g. > config/x86/msvc/cpu-flags/meson.build, for example. > > /Bruce That's an interesting idea. It could be done, but when I think that this table will probably get updated no more than once per release I don't see much reason to to come up with something more sofisticated. Sometimes it's better to keep things simple.