<div dir="ltr">Hi Martin,<div><br></div><div>Sorry about the delay :)<br><br><div class="gmail_quote"><div dir="ltr">On Tue, Mar 20, 2018 at 11:30 PM Martin J. O'Riordan <<a href="mailto:MartinO@theheart.ie">MartinO@theheart.ie</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-IE" link="blue" vlink="purple"><div class="m_-1336460211183581865WordSection1"><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">Thanks very much Eric for taking the time to carefully explain this to me.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> </span> </p></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-IE" link="blue" vlink="purple"><div class="m_-1336460211183581865WordSection1"><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">So if I am the author of the backend for a new processor technology, or willing to modernise my existing implementation, you would recommend that the ‘</span><span style="font-family:"Courier New";color:black">-mcpu</span><span style="font-family:"Book Antiqua",serif;color:black">’ option is deprecated and probably best not used at all, or perhaps just as a synonym for ‘</span><span style="font-family:"Courier New";color:black">-march + -mtune</span><span style="font-family:"Book Antiqua",serif;color:black">’?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">The first part of the target triple guides the overall high level processor architecture - essentially the CPU - and that I would be better using ‘</span><span style="font-family:"Courier New";color:black">-march</span><span style="font-family:"Book Antiqua",serif;color:black">’ to specify the variants of this CPU architecture for groups of variants that are not binary compatible with each other; effectively my ISA generations.  And that ‘</span><span style="font-family:"Courier New";color:black">-mtune</span><span style="font-family:"Book Antiqua",serif;color:black">’ is used to tune the code-generation for performance of a particular version of my processor from a single group that are otherwise binary compatible.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> </span></p></div></div></blockquote><div><br></div><div>Yes, I agree.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-IE" link="blue" vlink="purple"><div class="m_-1336460211183581865WordSection1"><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">For the past few years, our processor has had essentially the same conceptual hardware architecture, but each generation has had significant changes to the ISA.  Sometimes this is just instructions added or removed, but sometimes it is changes in the binary encoding of instructions, or the assembly syntax used for expressing the instructions, or the scheduling constraints.  I expect that ‘</span><span style="font-family:"Courier New";color:black">-march</span><span style="font-family:"Book Antiqua",serif;color:black">’ would be appropriate for differentiating between these incompatible variations of the architecture.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> </span></p></div></div></blockquote><div><br></div><div>Absolutely.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-IE" link="blue" vlink="purple"><div class="m_-1336460211183581865WordSection1"><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">At the moment I can only think of one use for ‘</span><span style="font-family:"Courier New";color:black">-mtune</span><span style="font-family:"Book Antiqua",serif;color:black">’ though for my target, and that would be to allow fine-tuning of the instructions chosen to handle some kinds of hardware bug fixes; though this would be a rare scenario as usually HW fixes require different code generation, not just schedule tuning.  At the moment my backend is not cache-aware, but if I did implement the prefetch ISDs, then ‘</span><span style="font-family:"Courier New";color:black">-mtune</span><span style="font-family:"Book Antiqua",serif;color:black">’ would I suppose be appropriate for this as the caches can vary from one configuration to another.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">When you say “</span>-mtune is used for more than scheduling<span style="font-family:"Book Antiqua",serif;color:black">”, what kinds of use-case would be good examples?<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> </span></p></div></div></blockquote><div><br></div><div>I'll give you a few examples from the X86 backend that are currently subtarget features because -mtune support really doesn't exist right now - FeatureFast* mostly. A particularly good one to look at is FeatureSlowLEA and a few of the others. These are mostly tuning flags that are in a "generic" x86-64 cpu target because we don't have decent tuning support.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-IE" link="blue" vlink="purple"><div class="m_-1336460211183581865WordSection1"><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">Would this be a reasonable summary?  My original question was because I found that I could not determine a consistent usage of these options in GCC supported targets to guide my own decisions.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">Of course, for targets common to LLVM and GCC, it is essential that LLVM follows the GCC uses of these switches for compatibility; but it is guidance for new targets that I think is missing that could establish best practices for both compiler development communities.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u></span></p></div></div></blockquote><div><br></div><div>Very much so. Last I was in the gcc community this was the guidance that we were giving to new ports :)</div><div><br></div><div>Thanks!</div><div><br></div><div>-eric</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-IE" link="blue" vlink="purple"><div class="m_-1336460211183581865WordSection1"><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">All the best and thanks again,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black">            MartinO<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:black"><u></u> <u></u></span></p><p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Eric Christopher [mailto:<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>] <br><b>Sent:</b> 20 March 2018 20:38<br><b>To:</b> Martin J. O'Riordan <<a href="mailto:MartinO@theheart.ie" target="_blank">MartinO@theheart.ie</a>><br><b>Cc:</b> Richard Hadsell <<a href="mailto:hadsell@blueskystudios.com" target="_blank">hadsell@blueskystudios.com</a>>; LLVM Developers <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span></p></div></div><div lang="EN-IE" link="blue" vlink="purple"><div class="m_-1336460211183581865WordSection1"><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"><br><b>Subject:</b> Re: [cfe-dev] When to use '-mcpu' versus '-march'<u></u><u></u></span></p></div></div><div lang="EN-IE" link="blue" vlink="purple"><div class="m_-1336460211183581865WordSection1"><p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"></span></p><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal" style="margin-bottom:12.0pt">Hi Martin,<u></u><u></u></p><div></div></div></div></div><div lang="EN-IE" link="blue" vlink="purple"><div class="m_-1336460211183581865WordSection1"><div><div><div><p class="MsoNormal">On Tue, Mar 20, 2018 at 1:18 PM Martin J. O'Riordan <<a href="mailto:MartinO@theheart.ie" target="_blank">MartinO@theheart.ie</a>> wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">After the original reply to my query I had a good look at the GCC documentation for these options, and what I discovered is that “there is no consensus” in GCC.  Basically, saying do what GCC does was a non-answer as it clarified nothing.</span><u></u><u></u></p></div></div></blockquote><div><p class="MsoNormal">That's why I made the comments I did on a generic new target which is the suggested consensus.<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">X86 has deprecated ‘</span><span style="font-family:"Courier New";color:black">-mcpu</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ in favour of ‘</span><span style="font-family:"Courier New";color:black">-mtune</span><span style="font-family:"Book Antiqua",serif;color:#943634">’, and it uses ‘</span><span style="font-family:"Courier New";color:black">-mtune</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ to mean that the scheduling, etc. should be biased in favour of more performant code for the processor identified by ‘</span><span style="font-family:"Courier New";color:black">-mtune</span><span style="font-family:"Book Antiqua",serif;color:#943634">’, but that the code is still 100% functional on all other processors in the family identified by ‘</span><span style="font-family:"Courier New";color:black">-march</span><span style="font-family:"Book Antiqua",serif;color:#943634">’. </span><span style="color:#943634"><u></u><u></u></span></p></div></div></blockquote><div><p class="MsoNormal">This is correct.<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">MIPS and ARM seem to have a very different notion of what they mean, and at the end of my examination of these options, I came to the conclusion that there is no common convention for usage and it all seems very haphazard. </span><span style="color:#943634"><u></u><u></u></span></p></div></div></blockquote><div><p class="MsoNormal">MIPS is very specific to using -march and -mtune. -mcpu is an alias to (-march/-mtune).<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">This is what I suggest to people wanting to have new ports.<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">With the processor that I am targeting, the notion of tuning schedules for a particular variant is meaningless, because the schedule is critical in the absence of interlocked instruction execution (and VLIW).  This effectively means that ‘</span><span style="font-family:"Courier New";color:black">-mtune</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ is not appropriate to my platform and leaves me with the toss-up of ‘</span><span style="font-family:"Courier New";color:black">-mcpu</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ versus ‘</span><span style="font-family:"Courier New";color:black">-march</span><span style="font-family:"Book Antiqua",serif;color:#943634">’, and to tell you the truth, I can see little reason to choose one over the other. </span><span style="color:#943634"><u></u><u></u></span></p></div></div></blockquote><div><p class="MsoNormal">-mtune is used for more than scheduling.<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">Most of the time, I want to differentiate based on ISA versions.  That is, the code should be generated for one version of the ISA or another, though for the same basic architecture (ISA can vary a lot from version to version).  ARM seems to use ‘</span><span style="font-family:"Courier New";color:black">-march</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ and ‘</span><span style="font-family:"Courier New";color:black">-mcpu</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ more or less interchangeably, and uses ‘</span><span style="font-family:"Courier New";color:black">+</span><span style="font-family:"Book Antiqua",serif;color:#943634">’ to add features to the value specified. </span><span style="color:#943634"><u></u><u></u></span></p></div></div></blockquote><div><p class="MsoNormal">That's not quite true either and is subtle behavior. Overall I think the ARM strategy is the worst compiler argument method to copy.<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#943634">The majority of GCC target only use ‘</span><span style="font-family:"Courier New";color:black">-mcpu</span><span style="font-family:"Book Antiqua",serif;color:#943634">’, so I think that in the absence of any real and meaningful best practice, that I will just stick with the triples and ‘</span><span style="font-family:"Courier New";color:black">-mcpu</span><span style="font-family:"Book Antiqua",serif;color:#943634">’. </span><span style="color:#943634"><u></u><u></u></span></p></div></div></blockquote><div><p class="MsoNormal">I'd really suggest you not do this, but since it's going to be an out of tree target you, may, of course do what you want.<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">-eric<u></u><u></u></p></div></div></div></div></div></blockquote></div></div></div>