<div> </div><div> </div><div>09.07.2020, 14:16, "Craig Topper via llvm-dev" <llvm-dev@lists.llvm.org>:</div><blockquote><div>I think i'd prefer to have the output type match the input type. Makes it more similar to other intrinsics and binary operators. We should be able to zero extend the inputs if you want something like 64x64->128.<div> </div><div>Are you planning to expose this to C through clang? What types would we expose?</div></div></blockquote><div>Like we could do v4i64 __builtin_clmul128(v2i64, v2i64) (using vector extensions) but really it is 128+128->256 and we are just using these funny types to represent __int128 and __int256....and then emit a i256 multiply in the IR. And also expose the 64+64->i128 as</div><div> </div><div>void __builtin_clmul64(uint64_t l, uint64_t r, uint64_t *lo, uint64_t *hi)</div><blockquote><div><div>~Craig</div><div> </div></div> <div><div>On Thu, Jul 9, 2020 at 10:28 AM Krzysztof Parzyszek via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:</div><blockquote style="border-left-color:rgb( 204 , 204 , 204 );border-left-style:solid;border-left-width:1px;margin:0px 0px 0px 0.8ex;padding-left:1ex">FWIW, Hexagon has a pass to recognize polynomial multiplication:<br />  llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp<br />See "PolynomialMultiplyRecognize"<br /><br />--<br />Krzysztof Parzyszek  <a href="mailto:kparzysz@quicinc.com">kparzysz@quicinc.com</a>   AI tools development<br /><br />> -----Original Message-----<br />> From: llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org">llvm-dev-bounces@lists.llvm.org</a>> On Behalf Of Shawn Landden<br />> via llvm-dev<br />> Sent: Thursday, July 9, 2020 11:40 AM<br />> To: Roman Lebedev <<a href="mailto:lebedev.ri@gmail.com">lebedev.ri@gmail.com</a>><br />> Cc: <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br />> Subject: [EXT] Re: [llvm-dev] [RFC] carry-less multiplication instruction<br />><br />><br />><br />> 05.07.2020, 05:22, "Roman Lebedev" <<a href="mailto:lebedev.ri@gmail.com">lebedev.ri@gmail.com</a>>:<br />> > On Sun, Jul 5, 2020 at 12:18 PM Shawn Landden via llvm-dev<br />> > <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br />> >>  Carry-less multiplication[1] instructions exist (at least optionally) on<br />> many architectures: armv8, RISC-V, x86_64, POWER, SPARC, C64x, and possibly<br />> more.<br />> >><br />> >>  This proposal is to add a llvm.clmul instruction. Or if that is<br />> >> contentious, llvm.experimental.bitmanip.clmul instruction. It takes<br />> >> two integer operands of the same width, and returns an integer with<br />> >> twice the width of the operands. (Is there a good reason to make<br />> >> these the same width, as all the other operations do even when it<br />> >> doesn’t really make sense for the mathematical operation–like<br />> >> multiplication or ctpop/ctlz/cttz?)<br />> >><br />> >>  If the CPU does not have a dedication clmul operation, it can be lowered<br />> to regular multiplication, by using holes to avoid carrys.<br />> >><br />> >>  ==Where is clmul used?==<br />> >><br />> >>  While somewhat specialized, the RISC-V manual documents many uses:<br />> >> [2]<br />> >><br />> >>  The classic applications forclmulare Cyclic Redundancy Check (CRC)<br />> >> [11, 26]<br />> >><br />> >>  and Galois/CounterMode (GCM), but more applications exist, including the<br />> following examples.There are obvious applications in hashing and pseudo<br />> random number generations. For exam-ple, it has been reported that hashes<br />> based on carry-less multiplications can outperform Google’sCityHash [17].<br />> >><br />> >>  clmulof a number with itself inserts zeroes between each input bit. This<br />> can be useful for generatingMorton code [23].<br />> >><br />> >>  clmulof a number with -1 calculates the prefix XOR operation. This<br />> >> can be useful for decodinggray codes.Another application of XOR<br />> >> prefix sums calculated withclmulis branchless tracking of<br />> >> quotedstrings in high-performance parsers. [16]<br />> >><br />> >>  Carry-less multiply can also be used to implement Erasure code<br />> >> efficiently. [14]<br />> >><br />> >>  ==clmul lowering without hardware support==<br />> >>  A 8x8=>16 clmul can also be lowered to a 32x32=>64 multiplication when<br />> there is no specialized instruction (also 15x15=>30, to a 60x60=>120, or if<br />> bitreverse is available 16x16=>32 to TWO 64x64=>64 multiplications)[3].<br />> >><br />> >>  [1] <a href="https://en.wikipedia.org/wiki/Carry-less_product">https://en.wikipedia.org/wiki/Carry-less_product</a><br />> >>  [2] (page 30)<br />> >> <a href="https://raw.githubusercontent.com/riscv/riscv-bitmanip/master/bitmani">https://raw.githubusercontent.com/riscv/riscv-bitmanip/master/bitmani</a><br />> >> p-0.92.pdf<br />> >>  [3] <a href="https://www.bearssl.org/constanttime.html">https://www.bearssl.org/constanttime.html</a><br />> ><br />> > What benefit would this intrinsic would bring to the middle-end IR,<br />> > over it's current naive expanded form?<br />> ><br />> > Note that teaching backends to produce it, or even adding it to<br />> > backend (ISD opcodes) and matching it in DAGCombiner has much lower<br />> > barrier of entry, i would suggest to start there.<br />> It cannot be matched.<br />> ><br />> >>  (First posted to discord<br />> >><br />> >>  --<br />> >>  Shawn Landden<br />> ><br />> > Roman<br />> ><br />> >>  _______________________________________________<br />> >>  LLVM Developers mailing list<br />> >>  <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br />> >>  <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br />><br />> --<br />> Shawn Landden<br />><br />> _______________________________________________<br />> LLVM Developers mailing list<br />> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br />> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br />_______________________________________________<br />LLVM Developers mailing list<br /><a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br /><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></blockquote></div>,<p>_______________________________________________<br />LLVM Developers mailing list<br /><a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br /><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></p></blockquote><div> </div><div> </div><div>-- </div><div>Shawn Landden</div><div> </div>